-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 config.toml option #81782
Conversation
* Swap jemalloc to mimalloc * Fix aligned alloc. * Bump libmimalloc-sys. * Include lock-file.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Mark-Simulacrum (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
This comment has been minimized.
This comment has been minimized.
We probably would need bors for benchmarks? |
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit 35d9352 with merge 86f3a470dd7fa102be01dc6d84ecc6920f8af32a... |
☀️ Try build successful - checks-actions |
Queued 86f3a470dd7fa102be01dc6d84ecc6920f8af32a with parent f9435f4, future comparison URL. |
Finished benchmarking try commit (86f3a470dd7fa102be01dc6d84ecc6920f8af32a): comparison url. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up. @bors rollup=never |
While there are major decrease in the instruction counts (yay!), the wall-clock time does not share a similarly stark change (though bootstrap times are all universally better) and there's a large increase in max-rss on some benchmarks. Pretty interesting tradeoff, overall. |
Pretty good results, I think! How well the benchmarks measure multi-threaded performance? I believe I see even better results in such a setup. If we want to add mimalloc support, maybe the best option would be to add mimalloc as a new config.toml option? Mimalloc is in active development, so results may improve even more in the future. |
Not at all currently I think, |
Remove misleading OSX from config.toml option comments as it is not really supported.
Added mimalloc option support for config.toml as a reference via 22f306c. Removed misleading OSX mention from config.toml.example comments of jemalloc. |
Is there a reason this intends to add mimalloc, instead of replacing jemalloc? I'm not seeing clear reasons we would want to have both as options. I am also not seeing any huge increases in max-rss - 20-25% is pretty typical variability I think. |
By difficult I mean perhaps infeasible. The compiler allocator system is currently designed for drop-in allocator use, as we need to support system allocators on some architectures. It seems reasonable and elegant design to me where function override can be leveraged. Any drop-in allocator has to support these paths as well as they can to be able to compete with other drop-in allocators. This is a fair game as such. For ad-hoc testing we can change the free call to non-standard version for rustc, but I don't think it provides a path forward here. AFAIK it does not help with LLVM override either. So, if we do it, we should do it for completeness, and perhaps for curiosity. Edit: Even though I tried quickly, adding new dependencies to
Other crates there have a special |
It's disappointing if we've boxed ourselves into a corner where we can't use sized deallocation APIs anymore. Many years ago we actually made a design decision to used sized deallocation wherever possible. I think we should try hard to be able to use sized deallocation again, because I don't think we ever officially went back on that decision. |
cc @alexcrichton -- did we actually decide to drop sized deallocation at any point? :( |
The problem, IIRC, has nothing to do with Rust-the-language or whether we've boxed ourselves out of this, but rather it has everything to do with how we distribute and build the compiler itself. The compiler is built as This means that rustc, due to how its built, has no way of using To leverage sized deallocation I think what needs to happen is:
AFAIK none of this is a light undertaking. Depending on the allocator is also may only benefit one platform instead of all. |
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🎉 Experiment
|
@Mark-Simulacrum Regarding your earlier question, |
☔ The latest upstream changes (presumably #82896) made this pull request unmergeable. Please resolve the merge conflicts. |
In addition to the above, my view is that the discussion so far has all the input right and we would just need the decision shall we switch allocator at this point. How I see this is that if we decide to stay with the drop-in allocator approach for now or for some time, |
And for details why I think "
|
@alexcrichton wrote:
As long as we never assume we can call our free function on something that LLVM allocated, couldn't we just make LLVM support calling an allocator other than the system allocator, and then assume that if someone uses a shared LLVM, they want to use whatever allocator that LLVM is built to use? That way we don't have to do any kind of interposition on the system allocator at all. |
As this one needs macOS updates, closing this for now. After #83152 is merged, this can be compared again with macOS support. Thanks all! |
…mulacrum Use tikv-jemallocator in rustc/rustdoc in addition to jemalloc-sys when enabled. In rust-lang#81782 it was mentioned that one reason rustc may benefit from minimalloc is it doesn't use the `sdallocx` api from jemalloc. Currently, on unix, rust uses jemalloc by importing its symbols to use them with the default, System (libc) global allocator. This PR switches its global alloc to `tikv-jemallocator`, which correctly uses sized deallocation (https://docs.rs/tikv-jemallocator/0.4.1/src/tikv_jemallocator/lib.rs.html#121-126). `tikv-jemallocator`, as far as I can tell, is a more up-to-date set of bindings to jemalloc than `jemallocator` The perf results of this pr are in large part due to the version upgrade of jemalloc, but sized deallocation has a non-trivial improvement, particularly to rustdoc. This pr also includes changes to bootstrap to correctly pass the jemalloc feature through to the rustdoc build
@nothingnesses AFAIK macOS is not supported by |
And I verified this, the macOS override part is not there yet for |
It looks like they improved macOS overriding support in v1.7.3: microsoft/mimalloc@c47de7e |
Edit: After the results, changed mimalloc to be introduced as its own option in
config.toml.example
and added support via 22f306c. Changed title accordingly and dropped WIP status.Edit: After review comments, changed mimalloc to replace jemalloc as config.toml option.