← Back to Pull requests

gc: Keep reused task stacks pooled and release idle ones promptly #64434

Closed
unknown closed this pull request without merging on Nov 17, 2026 15:58 UTC
View on GitHub
unknown unknown commented on Oct 28, 2026 21:35 UTC
Author

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, mprotect and 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_POOL move to a shared pool, which gives half of its idle stacks back per trim. A thread keeps at most MAX_LOCAL_STACKS_PER_POOL stacks of each size; beyond that its oldest one moves to the shared pool (the one just released may still be running), and jl_malloc_stack takes 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; stack mmaps 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 8 GC.gc() | 1045 | 99 |

Assisted-by: Claude Code (Opus 5.5)

Diff: 261 lines (+195 / -66) across 3 files Reviewer: KristofferC Review duration: 28463m
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
0.39
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
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
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 39.2% (MEDIUM) · Higher = larger blast radius
39.2%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 15.5% · Safe to merge
15.5%