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 — mimalloc: additional integration and changes for `--disable-gil` builds · Issue #112532 · python/cpython

mimalloc: additional integration and changes for --disable-gil builds #112532

New issue
Copy link
New issue
Copy link
Closed
Closed
mimalloc: additional integration and changes for --disable-gil builds#112532
Copy link
Assignees
colesbury
Labels
3.13only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-free-threadingtype-featureA feature request or enhancementA feature request or enhancement

Description

@colesbury
colesbury
opened on Nov 29, 2023
Issue body actions

Feature or enhancement

Mimalloc was added as an allocator in #90815. The --disable-gil builds need further integration with mimalloc, as well as some modifications to mimalloc to support thread-safe garbage collection in --disable-gil builds and the dictionary accesses that mostly avoid locking.

These changes can be split up across multiple PRs.

  • Currently, when mimalloc is enabled, all allocations go to the default heap. This is fine for PyMem_Malloc calls, but we need separate heaps for PyObject_Malloc and PyObject_GC_New. We should associate some mi_heap_ts with each PyThreadState. Every PyThreadState needs four heaps: one for PyMem_Malloc, one for non-GC objects (via PyObject_Malloc), one for GC objects with managed dicts (extra pre-header) and one for GC objects without a managed dict. We need some way to know which heap to use in _PyObject_MiMalloc. There's not a great way to do this, but I suggest adding something like a "current pyobject heap" variable to PyThreadState. It should generally point to the PyObject_Malloc heap, but PyObject_GC_New should temporarily override it to point to the correct GC heap when called
  • --disable-gil should imply --with-mimalloc and require mimalloc (i.e., disallow changing the allocator with PYTHONMALLOC).
  • We should tag each mi_heap_t and mi_page_t with a number identifying which type of allocation it's associated with. This is important for when pages are abandoned (i.e., when a thread exits with live blocks remaining) and the page is no longer associated with a heap. The GC still needs to identify which of those pages store GC-enabled objects. (see colesbury/nogil-3.12@d447b69)
  • When claiming a page from an abandoned segment, mimalloc should associate it with the correct heap from the current thread. In other words, pages that store GC-enabled objects should only be put back in the correct GC heap.

cc @DinoV

Linked PRs

  • gh-112532: Require mimalloc in --disable-gil builds #112883
  • gh-112532: Use separate mimalloc heaps for GC objects #113263
  • gh-112532: Fix peg generator build.py for mimalloc build #113492
  • gh-112532: Isolate abandoned segments by interpreter #113717
  • gh-112532: Tag mimalloc heaps and pages #113742
  • gh-112532: Fix memory block count for free-threaded build #113995
  • gh-112532: Improve mimalloc page visiting #114133
Reacted by stonebig

Activity

Next
  1. colesbury
    added
    type-featureA feature request or enhancementA feature request or enhancement
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    3.13only security fixesonly security fixes
    topic-free-threading
    on Nov 29, 2023
  2. colesbury
    added a commit that references this issue on Dec 8, 2023

    pythongh-112532: Require mimalloc in `--disable-gil` builds

    e7c5b91
  3. corona10
    added a commit that references this issue on Dec 12, 2023

    gh-112532: Require mimalloc in `--disable-gil` builds (gh-112883)

    fdee7b7
  4. colesbury
    added 5 commits that reference this issue on Dec 18, 2023

    pythongh-112532: Use separate mimalloc heaps for GC objects

    572e191

    pythongh-112532: Use separate mimalloc heaps for GC objects

    6c0a1c0

    pythongh-112532: Use separate mimalloc heaps for GC objects

    950389b

    pythongh-112532: Use separate mimalloc heaps for GC objects

    8a00bdf

    pythongh-112532: Isolate abandoned segments by interpreter

    4cb12d2
  5. corona10
    added 3 commits that reference this issue on Dec 26, 2023

    gh-112532: Use separate mimalloc heaps for GC objects (gh-113263)

    acf3bcc

    pythongh-112532: Fix peg generator for mimalloc build

    3f91a0b

    gh-112532: Fix peg generator build.py for mimalloc build (gh-113492)

    e5cce70
  6. colesbury
    added a commit that references this issue on Jan 4, 2024

    pythongh-112532: Isolate abandoned segments by interpreter

    53d2fcc
  7. 28 remaining items

  8. aisk
    added a commit that references this issue on Feb 11, 2024

    pythongh-112532: Improve mimalloc page visiting (python#114133)

    fe6f15f
  9. colesbury commented on Feb 14, 2024

    @colesbury
    colesbury
    on Feb 14, 2024
    ContributorAuthor
    More actions

    I think think this is done now. There are still a few QSBR-related mimalloc changes, but those will be tracked in #115103.

  10. colesbury
    closed this as completedon Feb 14, 2024
  11. Glyphack
    added 7 commits that reference this issue on Sep 2, 2024

    pythongh-112532: Require mimalloc in `--disable-gil` builds (pythongh…

    9c15f7a

    pythongh-112532: Use separate mimalloc heaps for GC objects (pythongh…

    ec0914f

    pythongh-112532: Fix peg generator build.py for mimalloc build (pytho…

    b3e1a96

    pythongh-112532: Isolate abandoned segments by interpreter (python#11…

    08aeb73

    pythongh-112532: Tag mimalloc heaps and pages (python#113742)

    41c71be

    pythongh-112532: Fix memory block count for free-threaded build (pyth…

    084255b

    pythongh-112532: Improve mimalloc page visiting (python#114133)

    8c906f4
  12. Jarred-Sumner
    added a commit that references this issue on Jul 15, 2026

    theap: let a parked thread hand its heaps to the scavenger

    a327057
  13. corona10
    added 2 commits that reference this issue on Oct 10, 2026

    Re-apply CPython-specific changes to mimalloc v2.5.2

    fa3a143

    Re-apply CPython-specific changes to mimalloc v2.5.2

    836dced
  14. corona10
    added 2 commits that reference this issue on Oct 22, 2026

    gh-159111: Update vendored mimalloc to v2.5.2 (gh-159112)

    aff7a2e

    [3.15] pythongh-159111: Update vendored mimalloc to v2.5.2 (pythongh-…

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

Metadata

Metadata

Assignees

  • @colesbury
    colesbury

Labels

3.13only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-free-threadingtype-featureA feature request or enhancementA feature request or enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402520 — 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.