[3.13] GH-133136: Revise QSBR to reduce excess memory held (gh-135473) by nascheme · Pull Request #136480 · python/cpython · GitHub
Skip to content

[3.13] GH-133136: Revise QSBR to reduce excess memory held (gh-135473) - #136480

Merged
nascheme merged 2 commits into
python:3.13from
nascheme:gh-133136-qsbr-defer-3.13
Jul 30, 2025
Merged

[3.13] GH-133136: Revise QSBR to reduce excess memory held (gh-135473)#136480
nascheme merged 2 commits into
python:3.13from
nascheme:gh-133136-qsbr-defer-3.13

Conversation

@nascheme

@nascheme nascheme commented Jul 9, 2025

Copy link
Copy Markdown
Member

The free threading build uses QSBR to delay the freeing of dictionary keys and list arrays when the objects are accessed by multiple threads in order to allow concurrent reads to proceed with holding the object lock. The requests are processed in batches to reduce execution overhead, but for large memory blocks this can lead to excess memory usage.

Take into account the size of the memory block when deciding when to process QSBR requests.

Also track the amount of memory being held by QSBR for mimalloc pages. Advance the write sequence if this memory exceeds a limit. Advancing the sequence will allow it to be freed more quickly.

Process the held QSBR items from the "eval breaker", rather than from _PyMem_FreeDelayed(). This gives a higher chance that the global read sequence has advanced enough so that items can be freed.

(cherry picked from commit 113de85)

Co-authored-by: Sam Gross colesbury@gmail.com

…35473)

The free threading build uses QSBR to delay the freeing of dictionary
keys and list arrays when the objects are accessed by multiple threads
in order to allow concurrent reads to proceed with holding the object
lock. The requests are processed in batches to reduce execution
overhead, but for large memory blocks this can lead to excess memory
usage.

Take into account the size of the memory block when deciding when to
process QSBR requests.

Also track the amount of memory being held by QSBR for mimalloc pages.
Advance the write sequence if this memory exceeds a limit.  Advancing
the sequence will allow it to be freed more quickly.

Process the held QSBR items from the "eval breaker", rather than from
`_PyMem_FreeDelayed()`.  This gives a higher chance that the global read
sequence has advanced enough so that items can be freed.

(cherry picked from commit 113de85)

Co-authored-by: Neil Schemenauer <nas-github@arctrix.com>
Co-authored-by: Sam Gross <colesbury@gmail.com>
@nascheme

nascheme commented Jul 9, 2025

Copy link
Copy Markdown
Member Author

@nascheme
nascheme marked this pull request as ready for review July 9, 2025 20:51
@nascheme
nascheme requested a review from Yhg1s July 9, 2025 20:51
@Yhg1s

Yhg1s commented Jul 29, 2025

Copy link
Copy Markdown
Member

@nascheme
nascheme merged commit 5c16f69 into python:3.13 Jul 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants