Skip to content

perf: keep hot scheduler state on separate cache lines - #1232

Merged
kacy merged 1 commit into
mainfrom
perf/sched-cache-lines
Oct 28, 2026
Merged

kacy merged 1 commit into
mainfrom
perf/sched-cache-lines

Conversation

@kacy

@kacy kacy commented Oct 28, 2026

Copy link
Copy Markdown
Owner

lock_sweep/spawn became bimodal at #1226: some runs took about 160 ms and others about 280 ms. The instruction count rose by only 0.3%. With one worker the time was unchanged. At 16 workers, user CPU went from 2.0 s to 3.4 s. That pattern is cache-line contention, not extra work.

#1226 added statics, which moved the shared stack-pool mutex onto the same cache line as SCHEDULER. Every scheduler call reads SCHEDULER, so each lock of the pool evicted that line from every core. Inside the scheduler, searching (a compare-and-swap on every spawn) and the injector queue sat next to the workers and slab pointers. Adjacent Worker entries also shared lines, so a thief locking one worker's queue evicted its neighbour's.

This change puts the stack pool, the scheduler, searching, the injector and each worker on their own 64-byte lines.

Interleaved medians at 16 workers on cores 0-7,16-23, main against this branch:

row main this branch
lock_sweep/spawn 255 ms 155 ms
green_fanout 1085 ms 885 ms
lock_sweep/breaker 146 ms 142 ms

The other concurrency rows are unchanged. chan_fanout lands anywhere from about 70 to 130 ms in both builds.

@kacy
kacy merged commit 744c66f into main Oct 28, 2026
4 checks passed
@kacy
kacy deleted the perf/sched-cache-lines branch October 28, 2026 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant