gh-90815: Add mimalloc memory allocator (#109914)

* Add mimalloc v2.12

Modified src/alloc.c to remove include of alloc-override.c and not
compile new handler.

Did not include the following files:

 - include/mimalloc-new-delete.h
 - include/mimalloc-override.h
 - src/alloc-override-osx.c
 - src/alloc-override.c
 - src/static.c
 - src/region.c

mimalloc is thread safe and shares a single heap across all runtimes,
therefore finalization and getting global allocated blocks across all
runtimes is different.

* mimalloc: minimal changes for use in Python:

 - remove debug spam for freeing large allocations
 - use same bytes (0xDD) for freed allocations in CPython and mimalloc
   This is important for the test_capi debug memory tests

* Don't export mimalloc symbol in libpython.
* Enable mimalloc as Python allocator option.
* Add mimalloc MIT license.
* Log mimalloc in Lib/test/pythoninfo.py.
* Document new mimalloc support.
* Use macro defs for exports as done in:
  https://github.com/python/cpython/pull/31164/

Co-authored-by: Sam Gross <colesbury@gmail.com>
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
Dino Viehland 2023-10-30 08:43:11 -07:00 committed by GitHub
parent 4ebf2fae96
commit 05f2f0ac92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
61 changed files with 16792 additions and 161 deletions

View file

@ -921,6 +921,9 @@ conflict.
* ``pymalloc``: use the :ref:`pymalloc allocator <pymalloc>` for
:c:macro:`PYMEM_DOMAIN_MEM` and :c:macro:`PYMEM_DOMAIN_OBJ` domains and use
the :c:func:`malloc` function for the :c:macro:`PYMEM_DOMAIN_RAW` domain.
* ``mimalloc``: use the :ref:`mimalloc allocator <mimalloc>` for
:c:macro:`PYMEM_DOMAIN_MEM` and :c:macro:`PYMEM_DOMAIN_OBJ` domains and use
the :c:func:`malloc` function for the :c:macro:`PYMEM_DOMAIN_RAW` domain.
Install :ref:`debug hooks <pymem-debug-hooks>`:
@ -928,6 +931,7 @@ conflict.
allocators <default-memory-allocators>`.
* ``malloc_debug``: same as ``malloc`` but also install debug hooks.
* ``pymalloc_debug``: same as ``pymalloc`` but also install debug hooks.
* ``mimalloc_debug``: same as ``mimalloc`` but also install debug hooks.
.. versionchanged:: 3.7
Added the ``"default"`` allocator.

View file

@ -579,6 +579,13 @@ also be used to improve performance.
Enable computed gotos in evaluation loop (enabled by default on supported
compilers).
.. option:: --without-mimalloc
Disable the fast mimalloc allocator :ref:`mimalloc <mimalloc>`
(enabled by default).
See also :envvar:`PYTHONMALLOC` environment variable.
.. option:: --without-pymalloc
Disable the specialized Python memory allocator :ref:`pymalloc <pymalloc>`