gc: Keep reused task stacks pooled and release idle ones promptly #64434
All Vouch review confidence checks passed
Residual risk 0.15 = Change Risk (0.39) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.39 · 261 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.333
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #64434"
general
weight: 0.35
KristofferC
Based on the comment in https://github.com/JuliaLang/julia/pull/64407#issuecomment-6476004893 (and I also found the idea here in a separate benchmark experiment I ran). I still haven't looked through this properly but putting it up because I am about to go to bed...
---------
🤖
The stock GC trimmed the task stack pools of one thread per collection, round-robin over every TLS slot including GC threads, freeing half of each pool whether or not its stacks were in use. A workload that keeps spawning tasks had its stacks unmapped and mapped again (
munmap,mmap,mprotectand fresh page faults each time), while idle stacks after a burst of tasks were kept for dozens of collections.Stacks also pile up on the wrong threads: a task's stack is taken from the pool of the thread that starts it and returned to the pool of the thread it finishes on, so one thread keeps mapping stacks while another accumulates them.
Now each pool tracks a low-water mark, so only stacks that went unused since the last trim count as idle. Trims happen at most once a second, or on an explicit full collection, so how many stacks survive no longer depends on how often the GC runs. Idle stacks beyond
MIN_STACK_MAPPINGS_PER_POOLmove to a shared pool, which gives half of its idle stacks back per trim. A thread keeps at mostMAX_LOCAL_STACKS_PER_POOLstacks of each size; beyond that its oldest one moves to the shared pool (the one just released may still be running), andjl_malloc_stacktakes from the shared pool before mapping a new stack. A dead thread's pools are now emptied after its unreachable tasks' stacks are added to them, not before.Linux x86_64 (THP
madvise), on top of #64407, medians; stackmmaps per run in parentheses:| | before | after |
|---|---:|---:|
|
fib(24),-t 1,GC.gc()between runs | 312 ms (15492) | 128 ms (0) | |fib(27),-t 8| 253 ms (676) | 189 ms (0) || 50 × burst of 500 blocked tasks,
-t 64| 213 ms (3464) | 182 ms (99) | | stack mappings after a burst of 2000, then 8GC.gc()| 1045 | 99 |Assisted-by: Claude Code (Opus 5.5)