GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [3.14] gh-145615: Fix mimalloc page leak in the free-threaded build (gh-145626) by miss-islington · Pull Request #145691 · python/cpython

Conversation

@miss-islington

@miss-islington miss-islington commented Mar 9, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Fix three issues that caused mimalloc pages to be leaked until the
owning thread exited:

  1. In _PyMem_mi_page_maybe_free(), move pages out of the full queue
    when relying on QSBR to defer freeing the page. Pages in the full
    queue are never searched by mi_page_queue_find_free_ex(), so a page
    left there is unusable for allocations.

  2. Move _PyMem_mi_page_clear_qsbr() from _mi_page_free_collect() to
    _mi_page_thread_free_collect() where it only fires when all blocks
    on the page are free (used == 0). The previous placement was too
    broad: it cleared QSBR state whenever local_free was non-NULL, but
    _mi_page_free_collect() is called from non-allocation paths (e.g.,
    page visiting in mi_heap_visit_blocks) where the page is not being
    reused.

  3. In _PyMem_mi_page_maybe_free(), use the page's heap tld to find the
    correct thread state for QSBR list insertion instead of
    PyThreadState_GET(). During stop-the-world pauses, the function may
    process pages belonging to other threads, so the current thread
    state is not necessarily the owner of the page.
    (cherry picked from commit d76df75)

Co-authored-by: Sam Gross [email protected]

  • Issue: Free threading memory leak #145615

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@colesbury @miss-islington
pythongh-145615: Fix mimalloc page leak in the free-threaded build (p…
2a3a642
…ythongh-145626)

Fix three issues that caused mimalloc pages to be leaked until the
owning thread exited:

1. In _PyMem_mi_page_maybe_free(), move pages out of the full queue
   when relying on QSBR to defer freeing the page. Pages in the full
   queue are never searched by mi_page_queue_find_free_ex(), so a page
   left there is unusable for allocations.

2. Move _PyMem_mi_page_clear_qsbr() from _mi_page_free_collect() to
   _mi_page_thread_free_collect() where it only fires when all blocks
   on the page are free (used == 0). The previous placement was too
   broad: it cleared QSBR state whenever local_free was non-NULL, but
   _mi_page_free_collect() is called from non-allocation paths (e.g.,
   page visiting in mi_heap_visit_blocks) where the page is not being
   reused.

3. In _PyMem_mi_page_maybe_free(), use the page's heap tld to find the
   correct thread state for QSBR list insertion instead of
   PyThreadState_GET(). During stop-the-world pauses, the function may
   process pages belonging to other threads, so the current thread
   state is not necessarily the owner of the page.
(cherry picked from commit d76df75)

Co-authored-by: Sam Gross <[email protected]>
@bedevere-app bedevere-app Bot added the topic-free-threading label Mar 9, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Mar 9, 2026
gh-145615: Fix mimalloc page leak in the free-threaded build #145626
Merged
@bedevere-app bedevere-app Bot added the awaiting review label Mar 9, 2026
@colesbury colesbury added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Mar 9, 2026
@bedevere-bot

bedevere-bot commented Mar 9, 2026

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @colesbury for commit 2a3a642 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F145691%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Mar 9, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Mar 9, 2026
Free threading memory leak #145615
Closed
@colesbury
colesbury merged commit ba1ea3a into python:3.14 Mar 9, 2026
83 of 91 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting review label Mar 9, 2026
@miss-islington
miss-islington deleted the backport-d76df75-3.14 branch March 9, 2026 18:18
meta-codesync Bot pushed a commit to facebookincubator/MetaPython that referenced this pull request Mar 10, 2026
@colesbury @meta-codesync
gh-145615: Fix mimalloc page leak in the free-threaded build
3b6bed0
Summary:
Cherry-pick of python/cpython#145691

Fix three issues that caused mimalloc pages to be leaked until the
owning thread exited:

1. In _PyMem_mi_page_maybe_free(), move pages out of the full queue
   when relying on QSBR to defer freeing the page. Pages in the full
   queue are never searched by mi_page_queue_find_free_ex(), so a page
   left there is unusable for allocations.

2. Move _PyMem_mi_page_clear_qsbr() from _mi_page_free_collect() to
   _mi_page_thread_free_collect() where it only fires when all blocks
   on the page are free (used == 0). The previous placement was too
   broad: it cleared QSBR state whenever local_free was non-NULL, but
   _mi_page_free_collect() is called from non-allocation paths (e.g.,
   page visiting in mi_heap_visit_blocks) where the page is not being
   reused.

3. In _PyMem_mi_page_maybe_free(), use the page's heap tld to find the
   correct thread state for QSBR list insertion instead of
   PyThreadState_GET(). During stop-the-world pauses, the function may
   process pages belonging to other threads, so the current thread
   state is not necessarily the owner of the page.

Reviewed By: itamaro

Differential Revision: D95830120

fbshipit-source-id: 0367568aebe8ae20b6ba95b688be0a9242d9a772
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

topic-free-threading

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@miss-islington @bedevere-bot @colesbury
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.