Skip to content

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

Not planned
@tom-pytel

Description

@tom-pytel

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

Activity

added a commit that references this issue on Apr 14, 2025

pythongh-132519: fix excessive mem usage in QSBR with large blocks

ZeroIntensity

ZeroIntensity commented on Apr 19, 2025

@ZeroIntensity
Member

Triage: should we close this?

kumaraditya303

kumaraditya303 commented on Jun 10, 2025

@kumaraditya303
Contributor

Closing this in favor of #133136

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Excessive QSBR memory usage when delay freeing large blocks. · Issue #132519 · python/cpython

      Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

      Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant