gh-144319: Fix huge page leak in datastack chunk allocator#147963
Merged
pablogsal merged 1 commit intopython:mainfrom Apr 5, 2026
Merged
gh-144319: Fix huge page leak in datastack chunk allocator#147963pablogsal merged 1 commit intopython:mainfrom
pablogsal merged 1 commit intopython:mainfrom
Conversation
Member
Author
|
CC: @Fidget-Spinner |
maurycy
reviewed
Apr 1, 2026
maurycy
reviewed
Apr 1, 2026
Fidget-Spinner
approved these changes
Apr 3, 2026
Member
Fidget-Spinner
left a comment
There was a problem hiding this comment.
Other than the stylistic stuff @maurycy pointed out, I think this looks fine.
The original fix rounded datastack chunk allocations in pystate.c so that _PyObject_VirtualFree() would receive the full huge page mapping size. Change direction and move that logic into _PyObject_VirtualAlloc() and _PyObject_VirtualFree() instead. The key invariant is that munmap() must see the full mapped size, so alloc and free now apply the same platform-specific rounding in the allocator layer. This keeps _PyStackChunk bookkeeping in requested-size units, avoids a hardcoded 2 MB assumption, and also covers other small virtual-memory users such as the JIT tracer state allocation in optimizer.c.
Member
Author
|
I changed direction from the |
Fidget-Spinner
approved these changes
Apr 5, 2026
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.
The datastack chunk allocator (
allocate_chunkinpystate.c) and othersmall virtual-memory users such as the JIT tracer allocate through
_PyObject_VirtualAlloc()using the logical requested size. When huge pagesare enabled, the arena allocator may round those mappings up to the platform
huge page size, so freeing with the smaller requested size can make
munmap()fail withEINVALand leak the mapping.This change moves the rounding logic into
_PyObject_VirtualAlloc()/_PyObject_VirtualFree()so allocation and free always agree on the fullmapped size. Keeping it in the allocator layer also avoids a hardcoded 2 MB
assumption in
pystate.cand fixes the JIT tracer allocation path at thesame time.