Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign uprustc: Allow changing the default allocator #27400
Conversation
rust-highfive
assigned
pcwalton
Jul 30, 2015
This comment has been minimized.
This comment has been minimized.
|
r? @pcwalton (rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
|
r? @brson cc @nnethercote |
rust-highfive
assigned
brson
and unassigned
pcwalton
Jul 30, 2015
alexcrichton
force-pushed the
alexcrichton:less-jemalloc
branch
2 times, most recently
to
8517834
Jul 30, 2015
pnkfelix
reviewed
Jul 30, 2015
| @@ -49,15 +49,16 @@ impl<'a, 'v> visit::Visitor<'v> for CrateReader<'a> { | |||
| } | |||
|
|
|||
| fn dump_crates(cstore: &CStore) { | |||
| debug!("resolved crates:"); | |||
This comment has been minimized.
This comment has been minimized.
pnkfelix
Jul 30, 2015
Member
Was the switch from debug! to info! (and likewise from log::DEBUG to log::INFO) deliberate, or an accident?
I would have thought we could (and should) leave it as it was, under debug!
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jul 30, 2015
Author
Member
Yeah this was currently intentional but I wouldn't mind changing it back. Whenever someone's having weird behavior with loading crates I typically ask them to set RUST_LOG=rustc::metadata::creader,rustc::metadata::loader to get info like this, but debug! means it's all compiled out by default.
Along those lines I'd somewhat prefer to have it be info! but I don't have much of a preference either way
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton: can I ask what the code would look like for a program (such as Servo) to implement allocation wrappers? I know we talked about this at Whistler but I don't remember the details and now that you have an implementation to reference it might be easier to describe. Thank you. |
This comment has been minimized.
This comment has been minimized.
|
Certainly! You'd basically just create a copy of |
retep998
reviewed
Jul 30, 2015
| mod imp { | ||
| use core::mem::size_of; | ||
| use libc::{BOOL, DWORD, HANDLE, LPVOID, SIZE_T, INVALID_HANDLE_VALUE}; | ||
| use libc::{WriteFile}; |
This comment has been minimized.
This comment has been minimized.
retep998
reviewed
Jul 30, 2015
| struct Header(*mut u8); | ||
|
|
||
| const HEAP_REALLOC_IN_PLACE_ONLY: DWORD = 0x00000010; | ||
| const STD_OUTPUT_HANDLE: DWORD = -11i32 as u32; |
This comment has been minimized.
This comment has been minimized.
retep998
reviewed
Jul 30, 2015
|
|
||
| extern "system" { | ||
| fn GetProcessHeap() -> HANDLE; | ||
| fn GetStdHandle(nStdHandle: DWORD) -> HANDLE; |
This comment has been minimized.
This comment has been minimized.
alexcrichton
force-pushed the
alexcrichton:less-jemalloc
branch
from
8517834
to
6b95b66
Jul 30, 2015
retep998
reviewed
Jul 31, 2015
|
|
||
| #[cfg(windows)] | ||
| mod imp { | ||
| use core::mem::size_of; |
This comment has been minimized.
This comment has been minimized.
alexcrichton
force-pushed the
alexcrichton:less-jemalloc
branch
from
6b95b66
to
5dbf9be
Jul 31, 2015
This comment has been minimized.
This comment has been minimized.
|
This feels very complex, makes me want to remove jemalloc. |
This comment has been minimized.
This comment has been minimized.
|
Considering how jemalloc is responsible for #26647 and is also really brittle when used under conemu #14600 (comment). You know, this reminds me of the time we had green threaded IO, then split it using virtual dispatch between a green and a native portion, then later dropped the green part entirely. |
This comment has been minimized.
This comment has been minimized.
|
jemalloc tends to have _way_ better performance than libc's malloc or the
system malloc, though. At least, in my understanding...
|
This comment has been minimized.
This comment has been minimized.
Could you elaborate a bit on this? I can certainly more aggressively document various aspects and I certainly wouldn't mind rewriting various code paths. I don't think that we want to just look at this and jettison jemalloc, though, as there are very real other use cases for swapping out for custom allocators (such as Servo's memory tracking, embedded systems with different allocators, etc). If we followed reasoning like this I would also say that supporting both dylibs/rlibs at the same time is pretty complex, but I don't feel the need to remove that distinction. There's concrete use cases for both so we just need to support both in as robust a manner as possible.
I don't think that this is the same situation as here most notably because there's no virtual dispatch here. This is a static decision which is made that has no costs associated with it (unlike the virtual dispatch). Like I said above, complexity is not a reason to jettison something, it's a reason to rethink why it's so complex and consider other options, but in this case I don't consider removing jemalloc an option. If there are bugs on Windows caused by our usage of jemalloc (I was unaware of these), then we should track them down and fix them, but removing it from all platforms is a pretty heavy hammer. |
This comment has been minimized.
This comment has been minimized.
|
I'm currently running a crater build for this PR |
This comment has been minimized.
This comment has been minimized.
|
Crater reports one regression but I have confirmed locally that it was spurious. |
This comment has been minimized.
This comment has been minimized.
|
A few comments...
|
This comment has been minimized.
This comment has been minimized.
|
|
alexcrichton
force-pushed the
alexcrichton:less-jemalloc
branch
from
5dbf9be
to
31b083f
Aug 4, 2015
This comment has been minimized.
This comment has been minimized.
|
|
alexcrichton
force-pushed the
alexcrichton:less-jemalloc
branch
2 times, most recently
from
9e1e50d
to
49632c0
Aug 5, 2015
This comment has been minimized.
This comment has been minimized.
|
|
alexcrichton
force-pushed the
alexcrichton:less-jemalloc
branch
from
49632c0
to
234b1bc
Aug 5, 2015
This comment has been minimized.
This comment has been minimized.
|
@bors: r=brson abd839 |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
|
alexcrichton
force-pushed the
alexcrichton:less-jemalloc
branch
from
adbd839
to
9d21851
Aug 14, 2015
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Aug 14, 2015
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@bors: retry On Fri, Aug 14, 2015 at 12:19 PM, bors notifications@github.com wrote:
|
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Aug 14, 2015
This comment has been minimized.
This comment has been minimized.
|
|
alexcrichton
force-pushed the
alexcrichton:less-jemalloc
branch
from
9d21851
to
45bf1ed
Aug 14, 2015
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
bors
added a commit
that referenced
this pull request
Aug 14, 2015
This comment has been minimized.
This comment has been minimized.
|
@bors: retry force |
alexcrichton commentedJul 30, 2015
This commit is an implementation of RFC 1183 which allows swapping out
the default allocator on nightly Rust. No new stable surface area should be
added as a part of this commit.
Two new attributes have been added to the compiler:
#![needs_allocator]- this is used by liballoc (and likely only liballoc) toindicate that it requires an allocator crate to be in scope.
#![allocator]- this is a indicator that the crate is an allocator which cansatisfy the
needs_allocatorattribute above.The ABI of the allocator crate is defined to be a set of symbols that implement
the standard Rust allocation/deallocation functions. The symbols are not
currently checked for exhaustiveness or typechecked. There are also a number of
restrictions on these crates:
needing an allocator (e.g. allocator crates can't depend on liballoc).
compiler. Binaries and Rust dylibs will use jemalloc by default where
available and staticlibs/other dylibs will use the system allocator by
default.
Two allocators are provided by the distribution by default,
alloc_systemandalloc_jemallocwhich operate as advertised.Closes #27389