Skip to content

Excessive QSBR memory usage when delay freeing large blocks. #132519

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
tom-pytel opened this issue Apr 14, 2025 · 1 comment
Open

Excessive QSBR memory usage when delay freeing large blocks. #132519

tom-pytel opened this issue Apr 14, 2025 · 1 comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-free-threading type-bug An unexpected behavior, bug, or error

Comments

@tom-pytel
Copy link
Contributor

tom-pytel commented Apr 14, 2025

Bug report

Bug description:

I ran across this while profiling memory usage in #130771. The results are same for both that and list objects which use QSBR to free memory, so this is a QSBR thing. Note this is an extreme synthetic case, this CAN happen but does not mean it WILL happen in real-world apps.

Memory usage numbers:

             VmHWM
GIL      135104 kB  - normal GIL-enabled baseline
noGIL   6702788 kB  - free-threaded current QSBR behavior

Test script:

import threading
from queue import Queue

def thrdfunc(queue):
    while True:
        l = queue.get()

        l.append(0)  # force resize in non-parent thread which will free using _PyMem_FreeDelayed()

queue = Queue(maxsize=2)

threading.Thread(target=thrdfunc, args=(queue,)).start()

while True:
    l = [None] * int(3840*2160*3/8)  # sys.getsizeof(l) ~= 3840*2160*3 bytes

    queue.put(l)

See PR for proposed fix.

CPython versions tested on:

3.14

Operating systems tested on:

No response

Linked PRs

@tom-pytel tom-pytel added the type-bug An unexpected behavior, bug, or error label Apr 14, 2025
tom-pytel added a commit to tom-pytel/cpython that referenced this issue Apr 14, 2025
@picnixz picnixz added interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-free-threading labels Apr 14, 2025
@ZeroIntensity
Copy link
Member

Triage: should we close this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-free-threading type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants