]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-112532: Use separate mimalloc heaps for GC objects (gh-113263)
authorSam Gross <colesbury@gmail.com>
Tue, 26 Dec 2023 16:53:20 +0000 (11:53 -0500)
committerGitHub <noreply@github.com>
Tue, 26 Dec 2023 16:53:20 +0000 (01:53 +0900)
commitacf3bcc8861983dcd6896682283a480450f9a1e3
tree50a9438ef437e6e7493f1cec683c8c0463dd2886
parent8f5b9987066f46daa67b622d913ff2c51c949ed4
gh-112532: Use separate mimalloc heaps for GC objects (gh-113263)

* gh-112532: Use separate mimalloc heaps for GC objects

In `--disable-gil` builds, we now use four separate heaps in
anticipation of using mimalloc to find GC objects when the GIL is
disabled. To support this, we also make a few changes to mimalloc:

* `mi_heap_t` and `mi_tld_t` initialization is split from allocation.
  This allows us to have a `mi_tld_t` per-`PyThreadState`, which is
  important to keep interpreter isolation, since the same OS thread may
  run in multiple interpreters (using different PyThreadStates.)

* Heap abandoning (mi_heap_collect_ex) can now be called from a
  different thread than the one that created the heap. This is necessary
  because we may clear and delete the containing PyThreadStates from a
  different thread during finalization and after fork().

* Use enum instead of defines and guard mimalloc includes.

* The enum typedef will be convenient for future PRs that use the type.
* Guarding the mimalloc includes allows us to unconditionally include
  pycore_mimalloc.h from other header files that rely on things like
  `struct _mimalloc_thread_state`.

* Only define _mimalloc_thread_state in Py_GIL_DISABLED builds
Include/internal/mimalloc/mimalloc/internal.h
Include/internal/pycore_mimalloc.h
Include/internal/pycore_pystate.h
Include/internal/pycore_tstate.h
Objects/mimalloc/heap.c
Objects/mimalloc/init.c
Objects/obmalloc.c
Python/pylifecycle.c
Python/pystate.c