Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 3.13
Choose a base branch
from

Conversation

nascheme
Copy link
Member

@nascheme nascheme commented Jul 9, 2025

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
Copy link
Member Author

nascheme commented Jul 9, 2025

@Yhg1s This needs release manager approval due to the ABI dump file changing. The ABI change is to the _qsbr_thread_state structure, which I believe is not actually exposed to extensions. Hugo already approved the 3.14 backport of this change.

@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
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.

1 participant
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy