-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Replace jemalloc with mimalloc #92249
Closed
Closed
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 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 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 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 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 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 |
---|---|---|
|
@@ -582,9 +582,9 @@ changelog-seen = 2 | |
# Map debuginfo paths to `/rust/$sha/...`, generally only set for releases | ||
#remap-debuginfo = false | ||
|
||
# Link the compiler against `jemalloc`, where on Linux and OSX it should | ||
# Link the compiler against `mimalloc`, where on Linux and OSX it should | ||
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. Could we use mimalloc on Windows too? It is created by MS so it should be supported, probably. |
||
# override the default allocator for rustc and LLVM. | ||
#jemalloc = false | ||
#mimalloc = false | ||
|
||
# Run tests in various test suites with the "nll compare mode" in addition to | ||
# running the tests in normal mode. Largely only used on CI and during local | ||
|
This file contains 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 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 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 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 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 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 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 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.
Thanks for the superseded PR, great to see this is progressing! Out of curiosity, I tried enabling debugs for libmimalloc-sys on macOS BigSur and I could not get the debug statistics increasing with
env MIMALLOC_VERBOSE=1 MIMALLOC_SHOW_STATS=1 ./x.py build
with this commit:Maybe something more is missing? This is where I got stuck earlier. I can try again if someone has these working, maybe something related to my debug-enable? On Linux however, these do show values when override works.
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.
Hmm, I did not test this in macOS because I don't have a machine accessible. Windows is not supported because static linking cannot be used with override. Not sure what the next steps are...
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.
The results look really good to me, so I think we should try to find a way to fix this, if possible. I am happy to test this, but I am not proficient with macOS either. Maybe @sfackler or @ehuss have ideas what to try next (as you fixed
jemalloc
for macOS earlier)?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.
Also, @thomcc may be interested to give new ideas.
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.
You have to enable stats when building or they aren't tracked, (see: https://github.com/microsoft/mimalloc/blob/master/include/mimalloc-types.h#L32-L33). I don't remember if theres support in the mimalloc (or -sys) crates directly, but setting
env CFLAGS="-DMI_STAT=1"
orenv CFLAGS="-DMI_STAT=2"
when building should makecc
do it, hopefully.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.
@thomcc Thanks, I checked this in detail. In my debug build I enable
MI_DEBUG_FULL
inCMakeLists.txt
and this will enableMI_DEBUG=3
definition. This then again will setMI_STAT=2
https://github.com/microsoft/mimalloc/blob/master/include/mimalloc-types.h#L421-L427. I cannot easily see what could go wrong, but to be sure, I'll try with a separate forced setting toMI_STAT
.If the statistics are valid, then
mi_macos_override_malloc
seems not to be called, perhaps due to similar reasonsjemalloc
originally did not work (#82423), where the linker is optimizing away some needed call paths. We would need to figure out what is still missing formimalloc
. My skills need sharpening here, so any hints on how to do it best are welcome :)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.
Do you have your integration code published anywhere? If not I can take a stab, but would like to avoid redundant work.
I think the mi_macos_override_malloc stuff is requires a little bit of extra work. most of the documentatoin mimalloc has about what's required to override on macos is a bit dated (or wrong) too (interposing happens by default, flat namespace should not be required).
Also, the zone override is not intended to be used on its own, but that's fixable.
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.
@thomcc Thank you for taking a look! My current changes are just testing and stats debug related, which we discussed above. I do not have anything else outside this PR.
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.
Taking more of a look, it's very unsurprising that you can't call
_mi_macos_override_malloc
directly, it's a static private function. It's also only included when mimalloc is built as a dynamic library (there are various reasons for this, but I think the main one is that mimalloc attempts interposing, and prior to macOS 10.12, this could only be done as a dynamic lib with someDYLD_
environment vars defined).There are at least a few issues with the way rustc will need to use it. Nothing that seems enormous, thankfully, I'll see if I can come up with a fixed version we can test out, and upstream if it works fine.
The biggest issue is probably that I don't have an easy way to test on older versions of macOS, so will be taking a stab in them. I also don't know how far back rustc supports for the host (I know libstd supports back to 10.7, though). Also, does rustc fork itself during execution? If so, that may complicate things a little, at least in terms of testing.
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.
No. It only spawns a new thread to run the compilation on.