Repository navigation
Upgrade mimalloc version from 2.1.2 to 2.5.2 #159111
Copy link
Copy link
Closed
Labels
3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixesperformancePerformance or resource usagePerformance or resource usagesprinttopic-free-threadingtype-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
Upgrading to mimalloc to 3.x.x would need huge architecture changes, maybe we need to write a PEP for this.
But upgrading to latest 2.5.2 version would get following benefits.
- Some CPython downstream changes are already applied to upstream.
- microsoft/mimalloc@0c4041fa: custom heap and page tags
- microsoft/mimalloc@d9aa19a7: sub-processes to isolate abandoned segments per interpreter
- microsoft/mimalloc@855e3b25: visit all abandoned blocks per sub-process
- microsoft/mimalloc@66052f13:
MI_PRIM_THREAD_IDhook for a custom thread id
- Handling abandoned segments have been improved.
- microsoft/mimalloc@bdda13b8: track abandoned segments in per-arena bitmaps instead of a global list
- microsoft/mimalloc@64edbc92, microsoft/mimalloc@9c96d05e: reclaim an abandoned segment when freeing into it (on by default)
- microsoft/mimalloc@ee92b337: don't reclaim segments when freeing from a thread whose heap is already abandoned
- microsoft/mimalloc@7774e800: don't visit full pages on a collection
- Several memory leakage issues are fixed.
- microsoft/mimalloc@d7a72c49: fix thread data leak
- microsoft/mimalloc@96b69d7e: fix leak where OS-allocated abandoned segments were not always reclaimed
- microsoft/mimalloc@635d626c: fix leak in abandoned block visiting
- microsoft/mimalloc@acd6f6ce, microsoft/mimalloc@4e50cec3: fix purge expiry handling so arena memory is actually returned to the OS
- Security fixes are applied.
- microsoft/mimalloc@ef3867f5: guard against free list corruption in the double-free check
- microsoft/mimalloc@25d6dcfc: check for overflow in
claim_huge_pages - microsoft/mimalloc@4bc8b2f9: check size limits in
mi_manage_os_memory/mi_reserve_os_memory - microsoft/mimalloc@66b93802, microsoft/mimalloc@204c6cbc — validate overlong environment values and
strtolerrors when readingMIMALLOC_*options
I 've applied changes in my local but we need to veify this on free-threading performance benchmark from Meta.
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Linked PRs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixesperformancePerformance or resource usagePerformance or resource usagesprinttopic-free-threadingtype-featureA feature request or enhancementA feature request or enhancement
Projects
- StatusShow more project fieldsDone
Activity
corona10 commentedon Oct 10, 2026
IMO, we don't need to backport this change to previous version since we did not chage anything about mimalloc for a while.
StanFromIreland commentedon Oct 11, 2026
See also #113141.
Merge remote-tracking branch 'upstream/main' into pythongh-159111
Merge remote-tracking branch 'upstream/main' into pythongh-159111
daanx commentedon Oct 17, 2026
(I am the mimalloc maintainer): Ah, apologies, I wasn't aware of this effort @corona10 :-( -- I just added a comment in #113141 about recent efforts to update to mimalloc v3 for the next CPython release -- hope that doesn't interfere with the current efforts too much. I think is better though than upgrading the v2 version, as v3 has many improvements. Hope we can work on this.
corona10 commentedon Oct 17, 2026
Yeah please send a draft PR as I replied. There are a lot of things to be verified. I am fine to move on v3 directly as possible.
4 remaining items
[3.15] pythongh-159111: Update vendored mimalloc to v2.5.2 (pythongh-…
pythongh-159111: Mark remaining CPython-specific changes in vendored …
pythongh-159111: Mark remaining CPython-specific changes in vendored …
pythongh-159111: Restore arc4random_buf() usage on Cygwin in vendored…
pythongh-159111: Remove the mimalloc update entry from What's New in …
gh-159111: Add missing downstream changes when upgrade to 2.5.2. (gh-…
[3.14] gh-159111: Update vendored mimalloc to v2.5.2 (gh-159112) (gh-…
[3.15] gh-159111: Update vendored mimalloc to v2.5.2 (gh-159112) (gh-…
corona10 commentedon Oct 22, 2026
@DinoV and I agreed to target v3 for the main branch, but we'll upgrade to 2.5.2 for now, since we still need to backport these changes.
cc @daanx