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 — gh-161420: Process mimalloc's delayed frees on every generic malloc again by maikschulze · Pull Request #161533 · python/cpython

Conversation

@maikschulze

@maikschulze maikschulze commented Nov 7, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Since mimalloc 2.5.2 (gh-159111), _mi_malloc_generic() processes delayed frees from other threads only every 100th call, so blocks over 64 KiB that other threads freed can pile up, up to about 100 per heap. This processes them on every generic malloc again, as before.

Peak RSS of the example from the issue, free-threaded release builds:

Peak RSS main this PR
macOS 5,900–8,000 MiB 410–500 MiB
Linux 9,500–11,000 MiB 420–540 MiB
Windows 8,000–8,200 MiB 430–450 MiB

No measurable difference for small objects (pyperf, macOS and Linux).

I used an AI assistant to investigate this and draft the patch; I reviewed and tested the changes myself.

Sorry, something went wrong.

Uh oh!

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

All reactions
@maikschulze
pythongh-161420: Process mimalloc's delayed frees on every generic ma…
9ba8532
…lloc again

Since the update to mimalloc 2.5.2 (pythongh-159111), _mi_malloc_generic() processes the heap's delayed
frees only every 100 calls. A block over MI_MEDIUM_OBJ_SIZE_MAX has a page of its own, so a free of
it from another thread is a delayed free, and every allocation of such a block is a generic malloc:
each thread could keep up to about 100 large blocks that other threads had freed. Process the
delayed frees on every generic malloc again, as mimalloc 2.1 did; the deferred-free callback and
the periodic collection stay batched.
@bedevere-app bedevere-app Bot added the awaiting review label Nov 7, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Nov 7, 2026
Free-threaded 3.14.10 and 3.15.2 keep memory freed by other threads: 10 GB peaks since the mimalloc 2.5.2 update #161420
Closed
@corona10
corona10 self-requested a review November 7, 2026 06:22
@corona10 corona10 self-assigned this Nov 7, 2026
@corona10 corona10 added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Nov 7, 2026
corona10
corona10 reviewed Nov 7, 2026
View reviewed changes
Comment thread Objects/mimalloc/page.c Resolved

Uh oh!

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

corona10
corona10 reviewed Nov 7, 2026
View reviewed changes
Comment thread Misc/NEWS.d/next/Core_and_Builtins/2026-11-07-09-30-00.gh-issue-161420.mIdFre.rst Resolved

Uh oh!

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

corona10
corona10 requested changes Nov 7, 2026
View reviewed changes

@corona10 corona10 left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please write descption to be concisely as possible.

Sorry, something went wrong.

Uh oh!

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

All reactions
@bedevere-app bedevere-app Bot added awaiting changes and removed awaiting review labels Nov 7, 2026
@bedevere-app

bedevere-app Bot commented Nov 7, 2026

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

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

@maikschulze @corona10
Apply batched suggestions from code review
b4fe0c0
Co-authored-by: Donghee Na <[email protected]>
@python-cla-bot

python-cla-bot Bot commented Nov 7, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

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

@maikschulze

maikschulze commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot added awaiting change review and removed awaiting changes labels Nov 7, 2026
@bedevere-app

bedevere-app Bot commented Nov 7, 2026

Copy link
Copy Markdown

Thanks for making the requested changes!

@corona10: please review the changes made to this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app
bedevere-app Bot requested a review from corona10 November 7, 2026 07:01
corona10
corona10 approved these changes Nov 7, 2026
View reviewed changes

@corona10 corona10 left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

Sorry, something went wrong.

Uh oh!

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

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting change review labels Nov 7, 2026
@corona10
corona10 enabled auto-merge (squash) November 7, 2026 07:12
@corona10
corona10 merged commit b8dd06f into python:main Nov 7, 2026
61 of 64 checks passed

Uh oh!

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

@bedevere-app bedevere-app Bot removed the awaiting merge label Nov 7, 2026
@miss-islington-app

miss-islington-app Bot commented Nov 7, 2026

Copy link
Copy Markdown

Thanks @maikschulze for the PR, and @corona10 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app

bedevere-app Bot commented Nov 7, 2026

Copy link
Copy Markdown

GH-161537 is a backport of this pull request to the 3.15 branch.

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Nov 7, 2026
@bedevere-app

bedevere-app Bot commented Nov 7, 2026

Copy link
Copy Markdown

GH-161538 is a backport of this pull request to the 3.14 branch.

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Nov 7, 2026
corona10 pushed a commit that referenced this pull request Nov 7, 2026
@miss-islington @maikschulze
[3.14] gh-161420: Process mimalloc's delayed frees on every generic m…
e03963c
…alloc again (gh-161533) (gh-161538)

gh-161420: Process mimalloc's delayed frees on every generic malloc again (gh-161533)
(cherry picked from commit b8dd06f)

Co-authored-by: Maik Schulze <[email protected]>
corona10 pushed a commit that referenced this pull request Nov 7, 2026
@miss-islington @maikschulze
[3.15] gh-161420: Process mimalloc's delayed frees on every generic m…
d52dd4a
…alloc again (gh-161533) (gh-161537)

gh-161420: Process mimalloc's delayed frees on every generic malloc again (gh-161533)
(cherry picked from commit b8dd06f)

Co-authored-by: Maik Schulze <[email protected]>
@vstinner

vstinner commented Nov 7, 2026

Copy link
Copy Markdown
Member

@corona10: Should we keep track of mimalloc 2.5 downstream changes made in Python? Should the change be reported and fixed to mimalloc upstream?

All reactions

Sorry, something went wrong.

Uh oh!

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

@corona10

corona10 commented Nov 7, 2026

Copy link
Copy Markdown
Member

It’s already reported in microsoft/mimalloc#1117.

And comments starts with “CPython:” in mimalloc of CPython repo means that it’s our downstream modification, so it’s already tracked.

vstinner reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

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

Reviewers

@corona10 corona10 corona10 approved these changes

Uh oh!

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

Assignees

@corona10 corona10

Labels

None yet

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

@maikschulze @vstinner @corona10
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.