-
Notifications
You must be signed in to change notification settings - Fork 6.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reorder and align LRUCacheShard data members to reduce false sharing #2568
Conversation
@IslamAbdelRahman has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
Err... Windows doesn't support this... |
@IslamAbdelRahman can you check whether it is really aligned in GCC too? |
Also wouldn't you also align the highly accessed members at the end so they don't do false sharing with each other. For attributes: For Windows: __declspec(align(n)) gcc/clang: _attribute__((__aligned__((n)))) |
Thanks @grooverdan for the attributes You mean usage_, lru_usage_ and mutex each have it's own cache line ? |
@IslamAbdelRahman updated the pull request - view changes - changes since last import |
Yes marking attributes to their own l1 cache line is what I had in mind as by the description they are heavily written. You can test with perf c2c |
Looks like you have having trouble with heap allocations. Seems like overloading new with aligned alloc is needed. Here are some definitions that may help. |
@IslamAbdelRahman still not supported on Windows. |
@IslamAbdelRahman updated the pull request - view changes - changes since last import |
@IslamAbdelRahman has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
I just disabled it for windows, now it pass :D |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May consider @grooverdan 's suggestion too. But either way, it is good to go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, what we want is to align since elems_
, as it is the beginning of frequently changing parameter and from there they are exactly 64 bytes. This is hard to do with the alignment annotation.
abandoned for the sake of #2620 |
Reorder data members in LRUCacheShard so that the members that we update frequently don't share the same cache line with members that are mostly read-only