Skip to content

Commit

Permalink
Mimalloc support as a separate config.toml option.
Browse files Browse the repository at this point in the history
Remove misleading OSX from config.toml option comments as
it is not really supported.
  • Loading branch information
jq-rs committed Feb 9, 2021
1 parent 35d9352 commit 22f306c
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 9 deletions.
18 changes: 18 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,12 @@ dependencies = [
"rustc-std-workspace-core",
]

[[package]]
name = "fs_extra"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394"

[[package]]
name = "fst"
version = "0.3.5"
Expand Down Expand Up @@ -1612,6 +1618,17 @@ version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"

[[package]]
name = "jemalloc-sys"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d3b9f3f5c9b31aa0f5ed3260385ac205db665baa41d49bb8338008ae94ede45"
dependencies = [
"cc",
"fs_extra",
"libc",
]

[[package]]
name = "jobserver"
version = "0.1.21"
Expand Down Expand Up @@ -3405,6 +3422,7 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
name = "rustc-main"
version = "0.0.0"
dependencies = [
"jemalloc-sys",
"libmimalloc-sys",
"rustc_codegen_ssa",
"rustc_driver",
Expand Down
15 changes: 8 additions & 7 deletions compiler/rustc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ rustc_driver = { path = "../rustc_driver" }
# crate is intended to be used by codegen backends, which may not be in-tree.
rustc_codegen_ssa = { path = "../rustc_codegen_ssa" }

#[dependencies.jemalloc-sys]
#version = '0.3.0'
#optional = true
#features = ['unprefixed_malloc_on_supported_platforms']
[dependencies.jemalloc-sys]
version = '0.3.0'
optional = true
features = ['unprefixed_malloc_on_supported_platforms']

[dependencies.libmimalloc-sys]
version = "0.1.20"
version = '0.1.20'
optional = true
default-features = false
features = ["extended", "override"]
features = ['extended', 'override']

[features]
jemalloc = ['libmimalloc-sys']
jemalloc = ['jemalloc-sys']
mimalloc = ['libmimalloc-sys']
llvm = ['rustc_driver/llvm']
max_level_info = ['rustc_driver/max_level_info']
27 changes: 27 additions & 0 deletions compiler/rustc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,33 @@ fn main() {
// dynamic libraries. That means to pull in jemalloc we need to actually
// reference allocation symbols one way or another (as this file is the only
// object code in the rustc executable).
#[cfg(feature = "jemalloc-sys")]
{
use std::os::raw::{c_int, c_void};

#[used]
static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::calloc;
#[used]
static _F2: unsafe extern "C" fn(*mut *mut c_void, usize, usize) -> c_int =
jemalloc_sys::posix_memalign;
#[used]
static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::aligned_alloc;
#[used]
static _F4: unsafe extern "C" fn(usize) -> *mut c_void = jemalloc_sys::malloc;
#[used]
static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = jemalloc_sys::realloc;
#[used]
static _F6: unsafe extern "C" fn(*mut c_void) = jemalloc_sys::free;
}

// Pull in mimalloc when enabled.
//
// Note that we're pulling in a static copy of mimalloc which means that to
// pull it in we need to actually reference its symbols for it to get
// linked. The two crates we link to here, std and rustc_driver, are both
// dynamic libraries. That means to pull in mimalloc we need to actually
// reference allocation symbols one way or another (as this file is the only
// object code in the rustc executable).
#[cfg(feature = "libmimalloc-sys")]
{
use std::os::raw::{c_int, c_void};
Expand Down
8 changes: 6 additions & 2 deletions config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,13 @@ 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
# override the default allocator for rustc and LLVM.
# Link the compiler against `jemalloc`, where on Linux it should override
# the default allocator for rustc and LLVM.
#jemalloc = false
#
# Link the compiler against `mimalloc`, where on Linux it should override
# the default allocator for rustc and LLVM.
#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
Expand Down
3 changes: 3 additions & 0 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ pub struct Config {
pub targets: Vec<TargetSelection>,
pub local_rebuild: bool,
pub jemalloc: bool,
pub mimalloc: bool,
pub control_flow_guard: bool,

// dist misc
Expand Down Expand Up @@ -497,6 +498,7 @@ struct Rust {
thin_lto_import_instr_limit: Option<u32>,
remap_debuginfo: Option<bool>,
jemalloc: Option<bool>,
mimalloc: Option<bool>,
test_compare_mode: Option<bool>,
llvm_libunwind: Option<String>,
control_flow_guard: Option<bool>,
Expand Down Expand Up @@ -849,6 +851,7 @@ impl Config {
set(&mut config.codegen_tests, rust.codegen_tests);
set(&mut config.rust_rpath, rust.rpath);
set(&mut config.jemalloc, rust.jemalloc);
set(&mut config.mimalloc, rust.mimalloc);
set(&mut config.test_compare_mode, rust.test_compare_mode);
config.llvm_libunwind = rust
.llvm_libunwind
Expand Down
3 changes: 3 additions & 0 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,9 @@ impl Build {
if self.config.jemalloc {
features.push_str("jemalloc");
}
if self.config.mimalloc {
features.push_str("mimalloc");
}
if self.config.llvm_enabled() {
features.push_str(" llvm");
}
Expand Down

0 comments on commit 22f306c

Please sign in to comment.