Commit 757d0f9
committed
perf: relax EpochLock memory ordering from seq_cst to acquire/release
The epoch counter is used to detect if meshing occurred during a
lock-free operation. Sequential consistency is stronger than needed.
The correctness argument:
- Writers (meshing thread) use release ordering when incrementing the
epoch, ensuring all prior/subsequent meshing work is properly ordered
- Readers use acquire ordering, ensuring they see all meshing work
that happened before the release store they observe
- Additionally, mprotect() on source pages during meshing provides a
hard barrier that catches any actual data races
This is safe because:
1. There's only one writer (meshing thread holds all locks)
2. If a reader doesn't see an epoch change, either meshing hasn't
started, or the reader's work is on unrelated data
3. If the reader's work would conflict with meshing, mprotect causes
a fault that synchronizes the threads
No performance change expected on x86 (already uses acquire/release
for seq_cst atomics), but may improve performance on ARM/POWER.1 parent e0124d4 commit 757d0f9
1 file changed
+12
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
45 | 48 | | |
46 | 49 | | |
47 | 50 | | |
48 | 51 | | |
49 | 52 | | |
50 | 53 | | |
51 | 54 | | |
52 | | - | |
53 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
54 | 59 | | |
55 | 60 | | |
56 | 61 | | |
57 | 62 | | |
| 63 | + | |
| 64 | + | |
58 | 65 | | |
59 | | - | |
60 | | - | |
| 66 | + | |
61 | 67 | | |
62 | 68 | | |
63 | | - | |
| 69 | + | |
64 | 70 | | |
65 | 71 | | |
66 | 72 | | |
| |||
0 commit comments