Skip to content

Experimental memory allocator with vendored mimalloc #29123

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

Closed
wants to merge 33 commits into from

Conversation

tiran
Copy link
Member

@tiran tiran commented Oct 21, 2021

EXPERIMENTAL This is an experimental pull request and a proof of concept. mimalloc integration is in a very early stage.

Vendor and hook up mimalloc. The PR only replaces raw memory allocator and Python's internal obmalloc with mimalloc. It does not use any of the advanced features of mimalloc such as heaps.

  • Includes mimalloc v1.7.1 and additional fixes
  • --with-mimalloc=yes by default (for testing)
  • --with-pymalloc=no by default
  • --with-freelists=yes

mimalloc requires C11 <stdatomic.h> on POSIX platforms to provide atomic operations such as CAS. GCC on RHEL 7 / CentOS 7 is too old. GCC 4.9 and clang 3.6 seem to be minimum versions. Users need install Red Hat Developer Toolset 10.0 from Software Collections. The CentOS 7-based manylinux2014 container image comes with GCC 10.2 pre-installed.

related mimalloc tickets

Initial benchmarks

Initial benchmarks should be taken with a big grain of salt. It seems like mimalloc is in the same ballpark as libc malloc + obmalloc with slightly better performance in some cases. I haven't measured memory consumption yet.

with mimalloc, without pymalloc, without freelists

In general about same performance, with some benchmarks 7% faster to 12% slower, https://gist.github.com/pablogsal/33fce1cbe5f908c1d85cae5d678f50a6

with mimalloc, without pymalloc, with freelists

In general 2% speedup, with some benchmarks 9% faster to 6% slower, https://gist.github.com/pablogsal/8027937b71cd30f17aaaa5ef7c885d3e

debug output

>>> sys._debugmallocstats()
mimalloc (version: 171)
heap stats:     peak      total      freed    current       unit      count  
  reserved:   256.0 mb   256.0 mb       0 b    256.0 mb       1 b              not all freed!
 committed:    20.0 mb    20.0 mb       0 b     20.0 mb       1 b              not all freed!
     reset:     1.0 mb     1.0 mb       0 b      1.0 mb       1 b              not all freed!
   touched:       0 b        0 b    932.3 kb  -932.3 kb       1 b              ok
  segments:       5          5          1          4                           not all freed!
-abandoned:       0          0          0          0                           ok
   -cached:       0          0          0          0                           ok
     pages:      94        123         29         94                           not all freed!
-abandoned:       0          0          0          0                           ok
 -extended:       0   
 -noretire:       0   
     mmaps:       0   
   commits:      69   
   threads:       0          0          0          0                           ok
  searches:     0.0 avg
numa nodes:       1
   elapsed:       5.572 s
   process: user: 0.073 s, system: 0.007 s, faults: 0, rss: 11.9 mb, commit: 20.0 mb
...

@tiran tiran added type-feature A feature request or enhancement sprint DO-NOT-MERGE labels Oct 21, 2021
@tiran tiran force-pushed the mimalloc branch 3 times, most recently from 3cadf5e to f865363 Compare October 21, 2021 17:35
@tiran tiran force-pushed the mimalloc branch 3 times, most recently from e1cecad to a4e7165 Compare October 24, 2021 16:46
@tiran tiran added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 24, 2021
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @tiran for commit a4e71652eaacf491eb682d99fdbb0a521b8cb33f 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 24, 2021
@tiran tiran added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 25, 2021
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @tiran for commit b6f5965e657df821b2345433163293d5345d5bab 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 25, 2021
@tiran tiran added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 25, 2021
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @tiran for commit 11efb79362b5f49e441d3a24da01f3740a2222d5 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 25, 2021
@tiran tiran force-pushed the mimalloc branch 2 times, most recently from d3a1605 to 8d7373a Compare October 25, 2021 10:26
@tiran tiran added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 25, 2021
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @tiran for commit 8d7373a0c3f1f47b1320087f8deafc7bd7c9ad4a 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 25, 2021
@insilications
Copy link

Saw your PR in microsoft/mimalloc#475. This is great. I'm using mimalloc as a drop-in replacement with the ENV variables:

PYTHONMALLOC=malloc MIMALLOC_PAGE_RESET=0 MIMALLOC_LARGE_OS_PAGES=1 LD_PRELOAD='/usr/lib64/libmimalloc.so'

I expected that this upstream integration would bring other benefits, but it would not be able to use mimalloc's allocation of large OS pages?

@tiran tiran added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 26, 2021
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @tiran for commit 8d7373a0c3f1f47b1320087f8deafc7bd7c9ad4a 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 26, 2021
tiran and others added 26 commits January 13, 2022 11:39
ifeq is not portable. Original patch by Neil.

Co-authored-by: Neil Schemenauer <[email protected]>
Signed-off-by: Christian Heimes <[email protected]>
Use mimalloc's ``static.c`` to include mimalloc library into obmalloc.
This allows us to prefix all symbols with ``_Py_`` prefix.

Signed-off-by: Christian Heimes <[email protected]>
@tiran
Copy link
Member Author

tiran commented Apr 6, 2022

This PR has been replaced by #31164.

@tiran tiran closed this Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants