-
Notifications
You must be signed in to change notification settings - Fork 13.3k
reintroduce jemalloc and use it as the Vec<T> and exchange allocator #14006
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
Conversation
|
||
$$(JEMALLOC_LIB_$(1)): $$(JEMALLOC_DEPS) $$(MKFILE_DEPS) | ||
@$$(call E, make: jemalloc) | ||
cd "$(S)src/jemalloc"; autoconf |
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.
We don't currently depend on autotools, and I think that is explicitly done. Can we fork jemalloc, configure it, check in ./configure
and use the fork?
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.
yeah, we could do this via a fork - it would also be a good place to put the configure cache with the workaround for the Windows cross-compilation issue
cc me |
I think this is going to require further discussion before merging since there's some disagreement about how we should treat allocations that require special alignment. My preference is:
|
It's possible to build an allocator respecting alignment around It shouldn't be necessary to rewrite all of the standard collections in order to use types with alignment requirements higher than the platform's choice. The The exchange allocator itself has no The missing piece on *nix operating systems is an aligned
I don't really think this is a pressing need. I don't think there's a use case for using libc malloc instead of jemalloc, because it's portable to the same platforms as Rust. Debian and Fedora want us to provide an |
Statically linking jemalloc with mingw-w64 is broken. It could be dynamically linked there for now or left out... https://sourceforge.net/p/mingw-w64/bugs/395/ |
I discovered a workaround for the Windows issue, which is passing |
unsafe fn alloc(cap: uint) -> *mut Vec<()> { | ||
let cap = cap.checked_add(&mem::size_of::<Vec<()>>()).unwrap(); | ||
// this should use the real alignment, but the new representation will take care of that | ||
let ret = rust_malloc(cap, 8) as *mut Vec<()>; |
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.
Malloc uses 16 bytes as a default I think, shouldn't this use that?
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.
It uses 16 bytes on x86_64, but I think it uses 8 bytes on x86 and ARM. The only types we currently have with > 8 byte alignment are feature gated (f128, simd) so I'm using this as a hack until ~[T]/~str are removed. I think 8 is better since it won't regress anything.
This module only contains wrappers for malloc and realloc with out-of-memory checks.
…=Veykril Replace soft breaks in markdown with spaces cc rust-lang/rust-analyzer#13988 (comment)
Closes #11807