-
Notifications
You must be signed in to change notification settings - Fork 4.1k
perf: avoid false sharing in block-stm #25766
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
base: main
Are you sure you want to change the base?
Conversation
| // A similar index for tracking validation. | ||
| validationIdx atomic.Uint64 | ||
|
|
||
| _ cpu.CacheLinePad |
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.
we keep executionIdx and validationIdx in the same cache line, because each executor thread will read both anyway.
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.
How did you determine that this yields any perf improvements? Can you attach your local benchmarks here?
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.
we keep
executionIdxandvalidationIdxin the same cache line, because each executor thread will read both anyway.
I don't think so. Executors read both executionIdx and validationIdx both indices, but they read and write different ones most of the time (executution workers increment executionIdx, validators bump validationIdx).
Keeping them in the same cache line means those writes will constantly invalidate each other’s cache line even though the fields track unrelated counters.
That false sharing is exactly what the padding was supposed to prevent.
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.
we keep
executionIdxandvalidationIdxin the same cache line, because each executor thread will read both anyway.I don't think so. Executors read both
executionIdxandvalidationIdxboth indices, but they read and write different ones most of the time (executution workers incrementexecutionIdx, validators bumpvalidationIdx). Keeping them in the same cache line means those writes will constantly invalidate each other’s cache line even though the fields track unrelated counters. That false sharing is exactly what the padding was supposed to prevent.
I mean at the beginning of the loop, each executor will read both executionIdx and validationIdx to compare them for priority.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #25766 +/- ##
=======================================
Coverage 70.56% 70.57%
=======================================
Files 838 838
Lines 54570 54570
=======================================
+ Hits 38508 38513 +5
+ Misses 16062 16057 -5
🚀 New features to boost your workflow:
|
|
would be good to share some before/after results and your interpretation here. i ran it on my macbook and saw improvements on |
Description
I seems to observe a little bit improvement on my laptop with this change, using the builtin benchmarks.
The benchmark difference might be accidental though, either my laptop don't have enough cpus or the assumptions are wrong.