diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 99a0c0b4b85de..be9ce644fa3c8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -279,7 +279,7 @@ jobs: - name: dist-x86_64-apple env: SCRIPT: "./x.py dist" - RUST_CONFIGURE_ARGS: "--host=x86_64-apple-darwin --target=x86_64-apple-darwin,aarch64-apple-ios,x86_64-apple-ios --enable-full-tools --enable-sanitizers --enable-profiler --set rust.jemalloc --set llvm.ninja=false" + RUST_CONFIGURE_ARGS: "--host=x86_64-apple-darwin --target=x86_64-apple-darwin,aarch64-apple-ios,x86_64-apple-ios --enable-full-tools --enable-sanitizers --enable-profiler --set llvm.ninja=false" RUSTC_RETRY_LINKER_ON_SEGFAULT: 1 MACOSX_DEPLOYMENT_TARGET: 10.7 NO_LLVM_ASSERTIONS: 1 @@ -289,7 +289,7 @@ jobs: - name: dist-x86_64-apple-alt env: SCRIPT: "./x.py dist" - RUST_CONFIGURE_ARGS: "--enable-extended --enable-profiler --set rust.jemalloc --set llvm.ninja=false" + RUST_CONFIGURE_ARGS: "--enable-extended --enable-profiler --set llvm.ninja=false" RUSTC_RETRY_LINKER_ON_SEGFAULT: 1 MACOSX_DEPLOYMENT_TARGET: 10.7 NO_LLVM_ASSERTIONS: 1 @@ -298,7 +298,7 @@ jobs: - name: x86_64-apple env: SCRIPT: "./x.py --stage 2 test" - RUST_CONFIGURE_ARGS: "--build=x86_64-apple-darwin --enable-sanitizers --enable-profiler --set rust.jemalloc --set llvm.ninja=false" + RUST_CONFIGURE_ARGS: "--build=x86_64-apple-darwin --enable-sanitizers --enable-profiler --set llvm.ninja=false" RUSTC_RETRY_LINKER_ON_SEGFAULT: 1 MACOSX_DEPLOYMENT_TARGET: 10.8 MACOSX_STD_DEPLOYMENT_TARGET: 10.7 @@ -308,7 +308,7 @@ jobs: - name: dist-aarch64-apple env: SCRIPT: "./x.py dist --stage 2" - RUST_CONFIGURE_ARGS: "--build=x86_64-apple-darwin --host=aarch64-apple-darwin --target=aarch64-apple-darwin --enable-full-tools --enable-sanitizers --enable-profiler --set rust.jemalloc --set llvm.ninja=false" + RUST_CONFIGURE_ARGS: "--build=x86_64-apple-darwin --host=aarch64-apple-darwin --target=aarch64-apple-darwin --enable-full-tools --enable-sanitizers --enable-profiler --set llvm.ninja=false" RUSTC_RETRY_LINKER_ON_SEGFAULT: 1 SELECT_XCODE: /Applications/Xcode_12.2.app USE_XCODE_CLANG: 1 @@ -317,7 +317,6 @@ jobs: NO_LLVM_ASSERTIONS: 1 NO_DEBUG_ASSERTIONS: 1 DIST_REQUIRE_ALL_TOOLS: 1 - JEMALLOC_SYS_WITH_LG_PAGE: 14 os: macos-latest - name: x86_64-msvc-1 env: diff --git a/Cargo.lock b/Cargo.lock index 9e773c572cc41..b0ceddec933f7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -928,6 +928,12 @@ dependencies = [ "syn", ] +[[package]] +name = "cty" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7313c0d620d0cb4dbd9d019e461a4beb501071ff46ec0ab933efb4daa76d73e3" + [[package]] name = "curl" version = "0.4.34" @@ -1242,12 +1248,6 @@ dependencies = [ "rustc-std-workspace-core", ] -[[package]] -name = "fs_extra" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f2a4a2034423744d2cc7ca2068453168dcdb82c438419e639a26bd87839c674" - [[package]] name = "fst" version = "0.3.5" @@ -1735,17 +1735,6 @@ 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" @@ -1933,6 +1922,16 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "libmimalloc-sys" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e58f42b6424a0ed536678c65fd97cd64b4344bcf86251e284f7c0ce9eee40e64" +dependencies = [ + "cmake", + "cty", +] + [[package]] name = "libnghttp2-sys" version = "0.1.4+1.41.0" @@ -3533,7 +3532,7 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" name = "rustc-main" version = "0.0.0" dependencies = [ - "jemalloc-sys", + "libmimalloc-sys", "rustc_codegen_ssa", "rustc_driver", ] diff --git a/compiler/rustc/Cargo.toml b/compiler/rustc/Cargo.toml index 6e6c0c71a1f3b..53a374e7f70f6 100644 --- a/compiler/rustc/Cargo.toml +++ b/compiler/rustc/Cargo.toml @@ -11,12 +11,13 @@ 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' +[dependencies.libmimalloc-sys] +version = '0.1.20' optional = true -features = ['unprefixed_malloc_on_supported_platforms'] +default-features = false +features = ['extended', 'override'] [features] -jemalloc = ['jemalloc-sys'] +mimalloc = ['libmimalloc-sys'] llvm = ['rustc_driver/llvm'] max_level_info = ['rustc_driver/max_level_info'] diff --git a/compiler/rustc/src/main.rs b/compiler/rustc/src/main.rs index 0151973eccfda..ee87636015f81 100644 --- a/compiler/rustc/src/main.rs +++ b/compiler/rustc/src/main.rs @@ -1,29 +1,31 @@ fn main() { - // Pull in jemalloc when enabled. + // Pull in mimalloc when enabled. // - // Note that we're pulling in a static copy of jemalloc which means that to + // 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 jemalloc we actually need to + // dynamic libraries. That means to pull in mimalloc we actually need to // reference allocation symbols one way or another (as this file is the only // object code in the rustc executable). - #[cfg(feature = "jemalloc-sys")] + #[cfg(feature = "libmimalloc-sys")] { use std::os::raw::{c_int, c_void}; #[used] - static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::calloc; + static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = libmimalloc_sys::mi_calloc; #[used] static _F2: unsafe extern "C" fn(*mut *mut c_void, usize, usize) -> c_int = - jemalloc_sys::posix_memalign; + libmimalloc_sys::mi_posix_memalign; #[used] - static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::aligned_alloc; + static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void = + libmimalloc_sys::mi_aligned_alloc; #[used] - static _F4: unsafe extern "C" fn(usize) -> *mut c_void = jemalloc_sys::malloc; + static _F4: unsafe extern "C" fn(usize) -> *mut c_void = libmimalloc_sys::mi_malloc; #[used] - static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = jemalloc_sys::realloc; + static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = + libmimalloc_sys::mi_realloc; #[used] - static _F6: unsafe extern "C" fn(*mut c_void) = jemalloc_sys::free; + static _F6: unsafe extern "C" fn(*mut c_void) = libmimalloc_sys::mi_free; } rustc_driver::set_sigpipe_handler(); diff --git a/config.toml.example b/config.toml.example index 5c4392acca595..f67e85609fe58 100644 --- a/config.toml.example +++ b/config.toml.example @@ -547,9 +547,9 @@ 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. -#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 diff --git a/src/bootstrap/CHANGELOG.md b/src/bootstrap/CHANGELOG.md index f899f21080ebe..a118614181269 100644 --- a/src/bootstrap/CHANGELOG.md +++ b/src/bootstrap/CHANGELOG.md @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Changes since the last major version] +- `jemalloc` allocator `config.toml` option is replaced with `mimalloc` option for improved performance characteristics [#81782](https://github.com/rust-lang/rust/pull/81782) - `llvm-libunwind` now accepts `in-tree` (formerly true), `system` or `no` (formerly false) [#77703](https://github.com/rust-lang/rust/pull/77703) ### Non-breaking changes diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index b2af8e59b7c9f..237a5d4bba5a8 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -142,7 +142,7 @@ pub struct Config { pub hosts: Vec, pub targets: Vec, pub local_rebuild: bool, - pub jemalloc: bool, + pub mimalloc: bool, pub control_flow_guard: bool, // dist misc @@ -501,7 +501,7 @@ struct Rust { verify_llvm_ir: Option, thin_lto_import_instr_limit: Option, remap_debuginfo: Option, - jemalloc: Option, + mimalloc: Option, test_compare_mode: Option, llvm_libunwind: Option, control_flow_guard: Option, @@ -856,7 +856,7 @@ impl Config { set(&mut config.rust_optimize_tests, rust.optimize_tests); 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 diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 5d708d3b25c12..e5d8af0234efb 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -564,8 +564,8 @@ impl Build { /// Gets the space-separated set of activated features for the compiler. fn rustc_features(&self) -> String { let mut features = String::new(); - 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"); diff --git a/src/ci/docker/host-x86_64/disabled/dist-x86_64-haiku/Dockerfile b/src/ci/docker/host-x86_64/disabled/dist-x86_64-haiku/Dockerfile index 5ddd3f1803964..483de149fc559 100644 --- a/src/ci/docker/host-x86_64/disabled/dist-x86_64-haiku/Dockerfile +++ b/src/ci/docker/host-x86_64/disabled/dist-x86_64-haiku/Dockerfile @@ -43,7 +43,7 @@ RUN sh /scripts/sccache.sh ENV HOST=x86_64-unknown-haiku ENV TARGET=target.$HOST -ENV RUST_CONFIGURE_ARGS --disable-jemalloc \ +ENV RUST_CONFIGURE_ARGS \ --set=$TARGET.cc=x86_64-unknown-haiku-gcc \ --set=$TARGET.cxx=x86_64-unknown-haiku-g++ \ --set=$TARGET.llvm-config=/bin/llvm-config-haiku diff --git a/src/ci/docker/host-x86_64/dist-i686-linux/Dockerfile b/src/ci/docker/host-x86_64/dist-i686-linux/Dockerfile index 247b539652b15..e3ce4217a24f8 100644 --- a/src/ci/docker/host-x86_64/dist-i686-linux/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-i686-linux/Dockerfile @@ -96,7 +96,7 @@ ENV RUST_CONFIGURE_ARGS \ --set target.i686-unknown-linux-gnu.linker=clang \ --build=i686-unknown-linux-gnu \ --set llvm.ninja=false \ - --set rust.jemalloc + --set rust.mimalloc ENV SCRIPT python2.7 ../x.py dist --build $HOSTS --host $HOSTS --target $HOSTS ENV CARGO_TARGET_I686_UNKNOWN_LINUX_GNU_LINKER=clang diff --git a/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile b/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile index 4dd4378f19692..39d13b980f8c0 100644 --- a/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile @@ -101,7 +101,7 @@ ENV RUST_CONFIGURE_ARGS \ --set target.x86_64-unknown-linux-gnu.ranlib=/rustroot/bin/llvm-ranlib \ --set llvm.thin-lto=true \ --set llvm.ninja=false \ - --set rust.jemalloc + --set rust.mimalloc ENV SCRIPT ../src/ci/pgo.sh python2.7 ../x.py dist \ --host $HOSTS --target $HOSTS \ --include-default-paths \ diff --git a/src/ci/github-actions/ci.yml b/src/ci/github-actions/ci.yml index 7125b33699a0c..ba99bf58ae8bd 100644 --- a/src/ci/github-actions/ci.yml +++ b/src/ci/github-actions/ci.yml @@ -432,7 +432,7 @@ jobs: - name: dist-x86_64-apple env: SCRIPT: ./x.py dist - RUST_CONFIGURE_ARGS: --host=x86_64-apple-darwin --target=x86_64-apple-darwin,aarch64-apple-ios,x86_64-apple-ios --enable-full-tools --enable-sanitizers --enable-profiler --set rust.jemalloc --set llvm.ninja=false + RUST_CONFIGURE_ARGS: --host=x86_64-apple-darwin --target=x86_64-apple-darwin,aarch64-apple-ios,x86_64-apple-ios --enable-full-tools --enable-sanitizers --enable-profiler --set llvm.ninja=false RUSTC_RETRY_LINKER_ON_SEGFAULT: 1 MACOSX_DEPLOYMENT_TARGET: 10.7 NO_LLVM_ASSERTIONS: 1 @@ -443,7 +443,7 @@ jobs: - name: dist-x86_64-apple-alt env: SCRIPT: ./x.py dist - RUST_CONFIGURE_ARGS: --enable-extended --enable-profiler --set rust.jemalloc --set llvm.ninja=false + RUST_CONFIGURE_ARGS: --enable-extended --enable-profiler --set llvm.ninja=false RUSTC_RETRY_LINKER_ON_SEGFAULT: 1 MACOSX_DEPLOYMENT_TARGET: 10.7 NO_LLVM_ASSERTIONS: 1 @@ -453,7 +453,7 @@ jobs: - name: x86_64-apple env: SCRIPT: ./x.py --stage 2 test - RUST_CONFIGURE_ARGS: --build=x86_64-apple-darwin --enable-sanitizers --enable-profiler --set rust.jemalloc --set llvm.ninja=false + RUST_CONFIGURE_ARGS: --build=x86_64-apple-darwin --enable-sanitizers --enable-profiler --set llvm.ninja=false RUSTC_RETRY_LINKER_ON_SEGFAULT: 1 MACOSX_DEPLOYMENT_TARGET: 10.8 MACOSX_STD_DEPLOYMENT_TARGET: 10.7 @@ -472,7 +472,6 @@ jobs: --enable-full-tools --enable-sanitizers --enable-profiler - --set rust.jemalloc --set llvm.ninja=false RUSTC_RETRY_LINKER_ON_SEGFAULT: 1 SELECT_XCODE: /Applications/Xcode_12.2.app @@ -482,14 +481,6 @@ jobs: NO_LLVM_ASSERTIONS: 1 NO_DEBUG_ASSERTIONS: 1 DIST_REQUIRE_ALL_TOOLS: 1 - # Corresponds to 16K page size - # - # Shouldn't be needed if jemalloc-sys is updated to - # handle this platform like iOS or if we build on - # aarch64-apple-darwin itself. - # - # https://github.com/gnzlbg/jemallocator/blob/c27a859e98e3cb790dc269773d9da71a1e918458/jemalloc-sys/build.rs#L237 - JEMALLOC_SYS_WITH_LG_PAGE: 14 <<: *job-macos-xl ######################