gh-90815: Add mimalloc memory allocator - #109914
Conversation
8b3ec52 to
06e86d7
Compare
e8c4f01 to
2dd8675
Compare
commented
Sep 27, 2023
2dd8675 to
672b6f4
Compare
672b6f4 to
41b62cb
Compare
commented
Sep 27, 2023
|
@ericsnowcurrently Yep, and much of the autoconf stuff is taken from there... I just finally filled in the description with a little more background on where things are coming from :) |
41b62cb to
0dbe76b
Compare
commented
Sep 27, 2023
I expect that most of this PR is a relatively vanilla use of mimalloc in CPython, like @tiran's PR is. Would it be much trouble to keep the whole PR vanilla and have a follow-up PR that applies the customizations to mimalloc (e.g. per-thread allocator state)? That distinction would help, possibly a lot, when reviewing. |
7bda1e4 to
35d1ebd
Compare
commented
Oct 23, 2023
|
Okay, the default is now pymalloc, for now |
Any thoughts? I think this got missed earlier in the review flurry. I've not seen any substantive discussion about why bundling is a good idea, which feels like it's worth proper consideration, given it's short-term easier but long-term expensive. I understand upstreaming it initially is going to take some time, but it is going to be worthwhile for cpython upstream maintenance long-term too, as you can avoid:
This also, of course, has the advantage of forcing one to document what the changes are which I think should be done either way. |
left a comment
There was a problem hiding this comment.
See also issue #111499: PYTHONMALLOCSTATS=1 fails with fatal error at Python exit. Using mimalloc, Python is not affected :-)
commented
Oct 30, 2023
|
@DinoV: I pushed a few cleanup changes. I fixed the outdated doc which still said that mimalloc is the default. |
commented
Oct 30, 2023
commented
Oct 30, 2023
It's worth further discussion. CC @daanx |
commented
Oct 30, 2023
|
Congrats @DinoV, I merged your PR :-) Do you want to propose a follow-up PR to enable it by default when |
commented
Oct 30, 2023
|
Looks like this broke the WASM buildbot: https://buildbot.python.org/all/#/builders/1046/builds/3371. |
commented
Oct 30, 2023
Yep, looks like there's an implicit function definition: |
commented
Oct 30, 2023
I wrote PR #111524 to fix WASI build. |
commented
Oct 31, 2023
|
I wrote 4 follow-up PRs to fix different issues:
While mimalloc C code is built on Windows, Python cannot currently use mimalloc on Windows: see PR #111528. |
This adds mimalloc as an optional (but preferred when available) allocator to CPython. This is a bit of a mashup of the work from #109914 and the work of @colesbury to use mimalloc for no-gil and various updates to bring it up to current CPython.
The configuration logic added by @tiran is re-used and we keep pymalloc support unlike in the version from @colesbury. mimalloc is updated to 2.12 and along with a few changes @colesbury made to it.
This has run into some issues with subinterpreter support in that the allocator's are now stored in thread state and are per-thread. Sub interpreters in some scenarios will create a thread state on one thread and run that on another thread. Most of these are documented in the code base as being known issues. I've modified these so that we will find the right thread based upon the current thread ID and switch to it rather than getting the head thread. This seems pretty reasonable but looks pretty weird when we need to do it at interpreter shutdown.