-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
gh-142518: Improve mimalloc allocator docs #145224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lysnikolaou
wants to merge
1
commit into
python:main
Choose a base branch
from
lysnikolaou:allocator-docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+63
−18
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -205,7 +205,9 @@ behavior when requesting zero bytes, are available for allocating and releasing | |||||
| memory from the Python heap. | ||||||
|
|
||||||
| The :ref:`default memory allocator <default-memory-allocators>` uses the | ||||||
| :ref:`pymalloc memory allocator <pymalloc>`. | ||||||
| :ref:`pymalloc memory allocator <pymalloc>`. In the | ||||||
| :term:`free-threaded <free threading>` build, the default is the | ||||||
| :ref:`mimalloc memory allocator <mimalloc>` instead. | ||||||
|
|
||||||
| .. warning:: | ||||||
|
|
||||||
|
|
@@ -215,6 +217,11 @@ The :ref:`default memory allocator <default-memory-allocators>` uses the | |||||
|
|
||||||
| The default allocator is now pymalloc instead of system :c:func:`malloc`. | ||||||
|
|
||||||
| .. versionchanged:: 3.13 | ||||||
|
|
||||||
| In the :term:`free-threaded <free threading>` build, the default allocator | ||||||
| is now :ref:`mimalloc <mimalloc>`. | ||||||
|
|
||||||
| .. c:function:: void* PyMem_Malloc(size_t n) | ||||||
|
|
||||||
| Allocates *n* bytes and returns a pointer of type :c:expr:`void*` to the | ||||||
|
|
@@ -340,7 +347,9 @@ memory from the Python heap. | |||||
| the :ref:`Customize Memory Allocators <customize-memory-allocators>` section. | ||||||
|
|
||||||
| The :ref:`default object allocator <default-memory-allocators>` uses the | ||||||
| :ref:`pymalloc memory allocator <pymalloc>`. | ||||||
| :ref:`pymalloc memory allocator <pymalloc>`. In the | ||||||
| :term:`free-threaded <free threading>` build, the default is the | ||||||
| :ref:`mimalloc memory allocator <mimalloc>` instead. | ||||||
|
|
||||||
| .. warning:: | ||||||
|
|
||||||
|
|
@@ -420,23 +429,24 @@ Default Memory Allocators | |||||
|
|
||||||
| Default memory allocators: | ||||||
|
|
||||||
| =============================== ==================== ================== ===================== ==================== | ||||||
| Configuration Name PyMem_RawMalloc PyMem_Malloc PyObject_Malloc | ||||||
| =============================== ==================== ================== ===================== ==================== | ||||||
| Release build ``"pymalloc"`` ``malloc`` ``pymalloc`` ``pymalloc`` | ||||||
| Debug build ``"pymalloc_debug"`` ``malloc`` + debug ``pymalloc`` + debug ``pymalloc`` + debug | ||||||
| Release build, without pymalloc ``"malloc"`` ``malloc`` ``malloc`` ``malloc`` | ||||||
| Debug build, without pymalloc ``"malloc_debug"`` ``malloc`` + debug ``malloc`` + debug ``malloc`` + debug | ||||||
| =============================== ==================== ================== ===================== ==================== | ||||||
| =================================== ======================= ================== ===================== ==================== | ||||||
| Configuration Name PyMem_RawMalloc PyMem_Malloc PyObject_Malloc | ||||||
| =================================== ======================= ================== ===================== ==================== | ||||||
| Release build ``"pymalloc"`` ``malloc`` ``pymalloc`` ``pymalloc`` | ||||||
| Debug build ``"pymalloc_debug"`` ``malloc`` + debug ``pymalloc`` + debug ``pymalloc`` + debug | ||||||
| Release build, without pymalloc ``"malloc"`` ``malloc`` ``malloc`` ``malloc`` | ||||||
| Debug build, without pymalloc ``"malloc_debug"`` ``malloc`` + debug ``malloc`` + debug ``malloc`` + debug | ||||||
| Free-threaded build ``"mimalloc"`` ``malloc`` ``mimalloc`` ``mimalloc`` | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
In main branch, |
||||||
| Free-threaded debug build ``"mimalloc_debug"`` ``malloc`` + debug ``mimalloc`` + debug ``mimalloc`` + debug | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||||||
| =================================== ======================= ================== ===================== ==================== | ||||||
|
|
||||||
| Legend: | ||||||
|
|
||||||
| * Name: value for :envvar:`PYTHONMALLOC` environment variable. | ||||||
| * ``malloc``: system allocators from the standard C library, C functions: | ||||||
| :c:func:`malloc`, :c:func:`calloc`, :c:func:`realloc` and :c:func:`free`. | ||||||
| * ``pymalloc``: :ref:`pymalloc memory allocator <pymalloc>`. | ||||||
| * ``mimalloc``: :ref:`mimalloc memory allocator <mimalloc>`. The pymalloc | ||||||
| allocator will be used if mimalloc support isn't available. | ||||||
| * ``mimalloc``: :ref:`mimalloc memory allocator <mimalloc>`. | ||||||
| * "+ debug": with :ref:`debug hooks on the Python memory allocators | ||||||
| <pymem-debug-hooks>`. | ||||||
| * "Debug build": :ref:`Python build in debug mode <debug-build>`. | ||||||
|
|
@@ -733,9 +743,27 @@ The mimalloc allocator | |||||
|
|
||||||
| .. versionadded:: 3.13 | ||||||
|
|
||||||
| Python supports the mimalloc allocator when the underlying platform support is available. | ||||||
| mimalloc "is a general purpose allocator with excellent performance characteristics. | ||||||
| Initially developed by Daan Leijen for the runtime systems of the Koka and Lean languages." | ||||||
| Python supports the `mimalloc <https://github.com/microsoft/mimalloc/>`__ | ||||||
| allocator when the underlying platform support is available. | ||||||
| mimalloc is a general purpose allocator with excellent performance | ||||||
| characteristics, initially developed by Daan Leijen for the runtime systems | ||||||
| of the Koka and Lean languages. | ||||||
|
|
||||||
| Unlike :ref:`pymalloc <pymalloc>`, which is optimized for small objects (512 | ||||||
| bytes or fewer), mimalloc handles allocations of any size. | ||||||
|
|
||||||
| In the :term:`free-threaded <free threading>` build, mimalloc is the default | ||||||
| and **required** allocator for the :c:macro:`PYMEM_DOMAIN_MEM` and | ||||||
| :c:macro:`PYMEM_DOMAIN_OBJ` domains. It cannot be disabled in free-threaded | ||||||
| builds. The free-threaded build uses per-thread mimalloc heaps, which allows | ||||||
| allocation and deallocation to proceed without locking in most cases. | ||||||
|
|
||||||
| In the default (non-free-threaded) build, mimalloc is available but not the | ||||||
| default allocator. It can be selected at runtime using | ||||||
| :envvar:`PYTHONMALLOC`\ ``=mimalloc`` (or ``mimalloc_debug`` to include | ||||||
| :ref:`debug hooks <pymem-debug-hooks>`). It can be disabled at build time | ||||||
| using the :option:`--without-mimalloc` configure option, but this option | ||||||
| cannot be combined with :option:`--disable-gil`. | ||||||
|
|
||||||
| tracemalloc C API | ||||||
| ================= | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
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.
We have a new
free-threaded buildterm that you can use if you aren't planning on backporting this past 3.14.