heap: near oom headroom extension - #390
Draft
IlyasShabi wants to merge 1 commit into
Draft
Conversation
IlyasShabi
requested review from
nsavoire,
r1viollet and
szegedi
as code owners
August 10, 2026 12:33
IlyasShabi
force-pushed
the
ishabi/near-oom-callback
branch
from
August 10, 2026 12:34
d1e68da to
6875943
Compare
Overall package sizeSelf size: 2.48 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | pprof-format | 2.3.1 | 504.33 kB | 504.33 kB | | source-map | 0.8.0 | 185.66 kB | 185.66 kB | | node-gyp-build | 4.8.4 | 13.86 kB | 13.86 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
IlyasShabi
marked this pull request as draft
August 10, 2026 12:43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Current behavior
When V8 signals "near the heap limit" occurs the callback raises the heap limit by a fixed
heapLimitExtensionSize, up tomaxHeapLimitExtensionCounttimes, so it can capture an allocation profile before the process dies.Because
GetAllocationProfile()itself allocates, it can re-enter the callback while a capture is in progress. The old code handled that reentrant case separately, returningcurrent_heap_limit + heapLimitExtensionSize, falling back to a hard-coded size.Issues
maxHeapLimitExtensionCountmean two different things and the total granted memory hard to reason about.current_heap_limit + extension.Proposed solution
Grant near-OOM headroom sized to what V8 needs, like Node.js does — not a fixed constant.
What Node.js does? extends the heap by one young generation, but only after checking there's actually memory available, and caps how many times it grows. https://github.com/nodejs/node/blob/main/src/env.cc#L2105
What this PR does? when no size is set, auto-sizes the extension to one young generation
heap_size_limit() - current_heap_limitwith a 10 Mb fallback. Rescue extensions during a capture no longer count against the extension budget, and the math is overflow-safe.