@@ -204,8 +204,11 @@ The following function sets, modeled after the ANSI C standard, but specifying
204204behavior when requesting zero bytes, are available for allocating and releasing
205205memory from the Python heap.
206206
207- The :ref: `default memory allocator <default-memory-allocators >` uses the
208- :ref: `pymalloc memory allocator <pymalloc >`.
207+ In the GIL-enabled build (default build) the
208+ :ref:`default memory allocator <default-memory-allocators>` uses the
209+ :ref:`pymalloc memory allocator <pymalloc>`, whereas in the
210+ :term:`free-threaded build`, the default is the
211+ :ref:`mimalloc memory allocator <mimalloc>` instead.
209212
210213.. warning::
211214
@@ -215,6 +218,11 @@ The :ref:`default memory allocator <default-memory-allocators>` uses the
215218
216219 The default allocator is now pymalloc instead of system :c:func:`malloc`.
217220
221+ .. versionchanged:: 3.13
222+
223+ In the :term:`free-threaded <free threading>` build, the default allocator
224+ is now :ref:`mimalloc <mimalloc>`.
225+
218226.. c:function:: void* PyMem_Malloc(size_t n)
219227
220228 Allocates *n* bytes and returns a pointer of type :c:expr:`void*` to the
@@ -340,7 +348,9 @@ memory from the Python heap.
340348 the :ref:`Customize Memory Allocators <customize-memory-allocators>` section.
341349
342350The :ref:`default object allocator <default-memory-allocators>` uses the
343- :ref:`pymalloc memory allocator <pymalloc>`.
351+ :ref:`pymalloc memory allocator <pymalloc>`. In the
352+ :term:`free-threaded <free threading>` build, the default is the
353+ :ref:`mimalloc memory allocator <mimalloc>` instead.
344354
345355.. warning::
346356
@@ -420,23 +430,24 @@ Default Memory Allocators
420430
421431Default memory allocators:
422432
423- =============================== ==================== ================== ===================== ====================
424- Configuration Name PyMem_RawMalloc PyMem_Malloc PyObject_Malloc
425- =============================== ==================== ================== ===================== ====================
426- Release build ``"pymalloc" `` ``malloc `` ``pymalloc `` ``pymalloc ``
427- Debug build ``"pymalloc_debug" `` ``malloc `` + debug ``pymalloc `` + debug ``pymalloc `` + debug
428- Release build, without pymalloc ``"malloc" `` ``malloc `` ``malloc `` ``malloc ``
429- Debug build, without pymalloc ``"malloc_debug" `` ``malloc `` + debug ``malloc `` + debug ``malloc `` + debug
430- =============================== ==================== ================== ===================== ====================
433+ =================================== ======================= ==================== ====================== ======================
434+ Configuration Name PyMem_RawMalloc PyMem_Malloc PyObject_Malloc
435+ =================================== ======================= ==================== ====================== ======================
436+ Release build ``"pymalloc" `` ``malloc `` ``pymalloc `` ``pymalloc ``
437+ Debug build ``"pymalloc_debug" `` ``malloc `` + debug ``pymalloc `` + debug ``pymalloc `` + debug
438+ Release build, without pymalloc ``"malloc" `` ``malloc `` ``malloc `` ``malloc ``
439+ Debug build, without pymalloc ``"malloc_debug" `` ``malloc `` + debug ``malloc `` + debug ``malloc `` + debug
440+ Free-threaded build ``"mimalloc" `` ``mimalloc `` ``mimalloc `` ``mimalloc ``
441+ Free-threaded debug build ``"mimalloc_debug" `` ``mimalloc `` + debug ``mimalloc `` + debug ``mimalloc `` + debug
442+ =================================== ======================= ==================== ====================== ======================
431443
432444Legend:
433445
434446* Name: value for :envvar: `PYTHONMALLOC ` environment variable.
435447* ``malloc ``: system allocators from the standard C library, C functions:
436448 :c:func: `malloc `, :c:func: `calloc `, :c:func: `realloc ` and :c:func: `free `.
437449* ``pymalloc ``: :ref: `pymalloc memory allocator <pymalloc >`.
438- * ``mimalloc ``: :ref: `mimalloc memory allocator <mimalloc >`. The pymalloc
439- allocator will be used if mimalloc support isn't available.
450+ * ``mimalloc ``: :ref: `mimalloc memory allocator <mimalloc >`.
440451* "+ debug": with :ref: `debug hooks on the Python memory allocators
441452 <pymem-debug-hooks>`.
442453* "Debug build": :ref: `Python build in debug mode <debug-build >`.
@@ -733,9 +744,27 @@ The mimalloc allocator
733744
734745.. versionadded :: 3.13
735746
736- Python supports the mimalloc allocator when the underlying platform support is available.
737- mimalloc "is a general purpose allocator with excellent performance characteristics.
738- Initially developed by Daan Leijen for the runtime systems of the Koka and Lean languages."
747+ Python supports the `mimalloc <https://github.com/microsoft/mimalloc/ >`__
748+ allocator when the underlying platform support is available.
749+ mimalloc is a general purpose allocator with excellent performance
750+ characteristics, initially developed by Daan Leijen for the runtime systems
751+ of the Koka and Lean languages.
752+
753+ Unlike :ref: `pymalloc <pymalloc >`, which is optimized for small objects (512
754+ bytes or fewer), mimalloc handles allocations of any size.
755+
756+ In the :term:`free-threaded <free threading>` build, mimalloc is the default
757+ and **required** allocator for the :c:macro:`PYMEM_DOMAIN_MEM` and
758+ :c:macro:`PYMEM_DOMAIN_OBJ` domains. It cannot be disabled in free-threaded
759+ builds. The free-threaded build uses per-thread mimalloc heaps, which allows
760+ allocation and deallocation to proceed without locking in most cases.
761+
762+ In the default (non-free-threaded) build, mimalloc is available but not the
763+ default allocator. It can be selected at runtime using
764+ :envvar:`PYTHONMALLOC`\ ``=mimalloc`` (or ``mimalloc_debug `` to include
765+ :ref: `debug hooks <pymem-debug-hooks >`). It can be disabled at build time
766+ using the :option:`--without-mimalloc` configure option, but this option
767+ cannot be combined with :option:`--disable-gil`.
739768
740769tracemalloc C API
741770=================
0 commit comments