]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.13] GH-133136: Revise QSBR to reduce excess memory held (gh-135473) (gh-136480)
authorNeil Schemenauer <nas-github@arctrix.com>
Wed, 30 Jul 2025 18:06:44 +0000 (11:06 -0700)
committerGitHub <noreply@github.com>
Wed, 30 Jul 2025 18:06:44 +0000 (11:06 -0700)
commit5c16f699d22cba23d6d6c9438c3886889aa1a546
treecc39cd6a7f7ef4a1ddb95fe040a37e25f31555c6
parentd3b5f838ec44d0297a0990e11838f39395aa7d60
[3.13] GH-133136: Revise QSBR to reduce excess memory held (gh-135473) (gh-136480)

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 113de8545ffe74a4a1dddb9351fa1cbd3562b621)

Co-authored-by: Neil Schemenauer <nas-github@arctrix.com>
Co-authored-by: Sam Gross <colesbury@gmail.com>
Doc/data/python3.13.abi
Include/internal/pycore_pymem.h
Include/internal/pycore_qsbr.h
Misc/NEWS.d/next/Core_and_Builtins/2025-06-03-21-06-22.gh-issue-133136.Usnvri.rst [new file with mode: 0644]
Objects/dictobject.c
Objects/listobject.c
Objects/obmalloc.c
Python/ceval_gil.c
Python/qsbr.c