-
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
jemalloc does not seem to be working for rustc on macos #82423
Comments
You can't override the macos malloc by shadowing its symbols (I think very early allocations in the loader still use the original malloc or something?). Instead, jemalloc actually hooks directly into some macos allocator APIs to replace the guts behind the original symbols IIRC. |
This is where the magic happens I believe: https://github.com/jemalloc/jemalloc/blob/025d8c37c93a69ec0aa5d8a55e3793cb480a5ac8/src/zone.c#L436-L469 |
Thanks @sfackler for taking a look! Do you happen to know if there's some way to validate that it is working? When I run |
Ah - when statically linking to jemalloc, the zone_register constructor function appears to be dropped by the linker: jemalloc/jemalloc#708. The compiler already manually marks other bits of jemalloc as Extending that with #[used]
static _F7: unsafe extern "C" fn() = _rjem_je_zone_register;
extern "C" {
fn _rjem_je_zone_register();
} Gets it registered properly for me with a little test crate. |
Ah, I can confirm with those changes it seems to be working. I might do some benchmarking to see how it does, but pending #81782, it may not be necessary. |
I ran a few benchmarks, and it looks promising:
(Not sure why the prebuilt nightly is so much slower. Maybe some random setting like MACOSX_DEPLOYMENT_TARGET?) These are pretty typical numbers of the various projects I tried. I also tested tikv-jemalloc-sys, but I didn't see much difference from the current jemalloc. |
Pretty neat! |
You should make sure this works on macOS pre-10.12, as this version changed how a number of things work (without looking at jemalloc, possibly most relevant being interpose) |
Fix jemalloc usage on OSX Closes rust-lang#82423
Fix jemalloc usage on OSX Closes rust-lang#82423
Fix jemalloc usage on OSX Closes rust-lang#82423
Fix jemalloc usage on OSX Closes rust-lang#82423
Fix jemalloc usage on OSX Closes rust-lang#82423
Fix jemalloc usage on OSX Closes rust-lang#82423
Fix jemalloc usage on OSX Closes rust-lang#82423
jemalloc is supposed to be enabled on macos for rustc, but with all the testing I've done, it does not appear to work.
Noted by Thom Chiovoloni on Zulip here, the jemalloc-sys crate prevents using unprefixed symbols here, which IIUC, means that it is building with symbols like
__rjem_malloc
, which AFAIK are never actually used.If it indeed does not work, then I think it would be good to consider either looking into fixing it (which I suspect may not be easy), or stop building it on CI.
Tested with most recent nightly (
rustc 1.52.0-nightly (3e826bb11 2021-02-21)
) and master (a15f484).The text was updated successfully, but these errors were encountered: