]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.14] GH-133136: Revise QSBR to reduce excess memory held (gh-135473) (#135912)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 8 Jul 2025 17:58:01 +0000 (19:58 +0200)
committerGitHub <noreply@github.com>
Tue, 8 Jul 2025 17:58:01 +0000 (10:58 -0700)
commit6a2a2906f805ce6b4e8315da32e7a4ad0aa6bace
treed5bed367ffe050a55fd11a9e5f8283ea3442a96e
parent66f85f4be84964d2ffb9611d05cebb986c2abf2d
[3.14] GH-133136: Revise QSBR to reduce excess memory held (gh-135473) (#135912)

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.14.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/codeobject.c
Objects/dictobject.c
Objects/listobject.c
Objects/obmalloc.c
Python/ceval_gil.c
Python/qsbr.c