Auto merge of #155726 - Zoxc:global-jemalloc-only, r=<try>
[TEST] Use only global Rust jemalloc
This commit is contained in:
14
Cargo.lock
14
Cargo.lock
@@ -756,7 +756,7 @@ checksum = "af491d569909a7e4dee0ad7db7f5341fef5c614d5b8ec8cf765732aba3cff681"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
"termcolor",
|
"termcolor",
|
||||||
"unicode-width 0.1.14",
|
"unicode-width 0.2.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3429,7 +3429,6 @@ dependencies = [
|
|||||||
"rustc_public",
|
"rustc_public",
|
||||||
"rustc_public_bridge",
|
"rustc_public_bridge",
|
||||||
"rustc_windows_rc",
|
"rustc_windows_rc",
|
||||||
"tikv-jemalloc-sys",
|
|
||||||
"wasi 0.14.2+wasi-0.2.4",
|
"wasi 0.14.2+wasi-0.2.4",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -3837,6 +3836,7 @@ dependencies = [
|
|||||||
"rustc_target",
|
"rustc_target",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"shlex",
|
"shlex",
|
||||||
|
"tikv-jemallocator",
|
||||||
"tracing",
|
"tracing",
|
||||||
"windows 0.61.3",
|
"windows 0.61.3",
|
||||||
]
|
]
|
||||||
@@ -5551,6 +5551,16 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tikv-jemallocator"
|
||||||
|
version = "0.6.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0359b4327f954e0567e69fb191cf1436617748813819c94b8cd4a431422d053a"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"tikv-jemalloc-sys",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tinystr"
|
name = "tinystr"
|
||||||
version = "0.8.2"
|
version = "0.8.2"
|
||||||
|
|||||||
@@ -26,16 +26,10 @@ rustc_public_bridge = { path = "../rustc_public_bridge" }
|
|||||||
getrandom = "=0.3.3"
|
getrandom = "=0.3.3"
|
||||||
wasi = "=0.14.2"
|
wasi = "=0.14.2"
|
||||||
|
|
||||||
|
|
||||||
[dependencies.tikv-jemalloc-sys]
|
|
||||||
version = "0.6.1"
|
|
||||||
optional = true
|
|
||||||
features = ['override_allocator_on_supported_platforms']
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
# tidy-alphabetical-start
|
# tidy-alphabetical-start
|
||||||
check_only = ['rustc_driver_impl/check_only']
|
check_only = ['rustc_driver_impl/check_only']
|
||||||
jemalloc = ['dep:tikv-jemalloc-sys']
|
jemalloc = ['rustc_driver_impl/jemalloc']
|
||||||
llvm = ['rustc_driver_impl/llvm']
|
llvm = ['rustc_driver_impl/llvm']
|
||||||
llvm_enzyme = ['rustc_driver_impl/llvm_enzyme']
|
llvm_enzyme = ['rustc_driver_impl/llvm_enzyme']
|
||||||
llvm_offload = ['rustc_driver_impl/llvm_offload']
|
llvm_offload = ['rustc_driver_impl/llvm_offload']
|
||||||
|
|||||||
@@ -5,41 +5,6 @@
|
|||||||
|
|
||||||
use std::process::ExitCode;
|
use std::process::ExitCode;
|
||||||
|
|
||||||
// A note about jemalloc: rustc uses jemalloc when built for CI and
|
|
||||||
// distribution. The obvious way to do this is with the `#[global_allocator]`
|
|
||||||
// mechanism. However, for complicated reasons (see
|
|
||||||
// https://github.com/rust-lang/rust/pull/81782#issuecomment-784438001 for some
|
|
||||||
// details) that mechanism doesn't work here. Also, we'd like to use a
|
|
||||||
// consistent allocator across the rustc <-> llvm boundary, and
|
|
||||||
// `#[global_allocator]` wouldn't provide that.
|
|
||||||
//
|
|
||||||
// Instead, we use a lower-level mechanism, namely the
|
|
||||||
// `"override_allocator_on_supported_platforms"` Cargo feature of jemalloc-sys.
|
|
||||||
//
|
|
||||||
// This makes jemalloc-sys override the libc/system allocator's implementation
|
|
||||||
// of `malloc`, `free`, etc.. This means that Rust's `System` allocator, which
|
|
||||||
// calls `libc::malloc()` et al., is actually calling into jemalloc.
|
|
||||||
//
|
|
||||||
// A consequence of not using `GlobalAlloc` (and the `tikv-jemallocator` crate
|
|
||||||
// provides an impl of that trait, which is called `Jemalloc`) is that we
|
|
||||||
// cannot use the sized deallocation APIs (`sdallocx`) that jemalloc provides.
|
|
||||||
// It's unclear how much performance is lost because of this.
|
|
||||||
//
|
|
||||||
// NOTE: Even though Cargo passes `--extern` with `tikv_jemalloc_sys`, we still need to `use` the
|
|
||||||
// crate for the compiler to see the `#[used]`, see https://github.com/rust-lang/rust/issues/64402.
|
|
||||||
// This is similarly required if we used a crate with `#[global_allocator]`.
|
|
||||||
//
|
|
||||||
// NOTE: if you are reading this comment because you want to set a custom `global_allocator` for
|
|
||||||
// benchmarking, consider using the benchmarks in the `rustc-perf` collector suite instead:
|
|
||||||
// https://github.com/rust-lang/rustc-perf/blob/master/collector/README.md#profiling
|
|
||||||
//
|
|
||||||
// NOTE: if you are reading this comment because you want to replace jemalloc with another allocator
|
|
||||||
// to compare their performance, see
|
|
||||||
// https://github.com/rust-lang/rust/commit/b90cfc887c31c3e7a9e6d462e2464db1fe506175#diff-43914724af6e464c1da2171e4a9b6c7e607d5bc1203fa95c0ab85be4122605ef
|
|
||||||
// for an example of how to do so.
|
|
||||||
#[cfg(feature = "jemalloc")]
|
|
||||||
use tikv_jemalloc_sys as _;
|
|
||||||
|
|
||||||
fn main() -> ExitCode {
|
fn main() -> ExitCode {
|
||||||
rustc_driver::main()
|
rustc_driver::main()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,9 +55,14 @@ features = [
|
|||||||
ctrlc = "3.4.4"
|
ctrlc = "3.4.4"
|
||||||
# tidy-alphabetical-end
|
# tidy-alphabetical-end
|
||||||
|
|
||||||
|
[dependencies.tikv-jemallocator]
|
||||||
|
version = "0.6.1"
|
||||||
|
optional = true
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
# tidy-alphabetical-start
|
# tidy-alphabetical-start
|
||||||
check_only = ['rustc_interface/check_only']
|
check_only = ['rustc_interface/check_only']
|
||||||
|
jemalloc = ['dep:tikv-jemallocator']
|
||||||
llvm = ['rustc_interface/llvm']
|
llvm = ['rustc_interface/llvm']
|
||||||
llvm_enzyme = ['rustc_interface/llvm_enzyme']
|
llvm_enzyme = ['rustc_interface/llvm_enzyme']
|
||||||
llvm_offload = ['rustc_interface/llvm_offload']
|
llvm_offload = ['rustc_interface/llvm_offload']
|
||||||
|
|||||||
@@ -63,6 +63,10 @@ use rustc_target::json::ToJson;
|
|||||||
use rustc_target::spec::{Target, TargetTuple};
|
use rustc_target::spec::{Target, TargetTuple};
|
||||||
use tracing::trace;
|
use tracing::trace;
|
||||||
|
|
||||||
|
#[cfg(feature = "jemalloc")]
|
||||||
|
#[global_allocator]
|
||||||
|
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
|
||||||
|
|
||||||
#[allow(unused_macros)]
|
#[allow(unused_macros)]
|
||||||
macro do_not_use_print($($t:tt)*) {
|
macro do_not_use_print($($t:tt)*) {
|
||||||
std::compile_error!(
|
std::compile_error!(
|
||||||
|
|||||||
@@ -56,15 +56,6 @@ extern crate rustc_target;
|
|||||||
extern crate rustc_trait_selection;
|
extern crate rustc_trait_selection;
|
||||||
extern crate test;
|
extern crate test;
|
||||||
|
|
||||||
/// See docs in https://github.com/rust-lang/rust/blob/HEAD/compiler/rustc/src/main.rs
|
|
||||||
/// and https://github.com/rust-lang/rust/pull/146627 for why we need this.
|
|
||||||
///
|
|
||||||
/// FIXME(madsmtm): This is loaded from the sysroot that was built with the other `rustc` crates
|
|
||||||
/// above, instead of via Cargo as you'd normally do. This is currently needed for LTO due to
|
|
||||||
/// https://github.com/rust-lang/cc-rs/issues/1613.
|
|
||||||
#[cfg(feature = "jemalloc")]
|
|
||||||
extern crate tikv_jemalloc_sys as _;
|
|
||||||
|
|
||||||
use std::env::{self, VarError};
|
use std::env::{self, VarError};
|
||||||
use std::io::{self, IsTerminal};
|
use std::io::{self, IsTerminal};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|||||||
@@ -11,15 +11,6 @@ extern crate rustc_interface;
|
|||||||
extern crate rustc_session;
|
extern crate rustc_session;
|
||||||
extern crate rustc_span;
|
extern crate rustc_span;
|
||||||
|
|
||||||
/// See docs in <https://github.com/rust-lang/rust/blob/HEAD/compiler/rustc/src/main.rs>
|
|
||||||
/// and <https://github.com/rust-lang/rust/pull/146627> for why we need this.
|
|
||||||
///
|
|
||||||
/// FIXME(madsmtm): This is loaded from the sysroot that was built with the other `rustc` crates
|
|
||||||
/// above, instead of via Cargo as you'd normally do. This is currently needed for LTO due to
|
|
||||||
/// <https://github.com/rust-lang/cc-rs/issues/1613>.
|
|
||||||
#[cfg(feature = "jemalloc")]
|
|
||||||
extern crate tikv_jemalloc_sys as _;
|
|
||||||
|
|
||||||
use clippy_utils::sym;
|
use clippy_utils::sym;
|
||||||
use declare_clippy_lint::LintListBuilder;
|
use declare_clippy_lint::LintListBuilder;
|
||||||
use rustc_interface::interface;
|
use rustc_interface::interface;
|
||||||
|
|||||||
@@ -18,20 +18,6 @@ extern crate rustc_middle;
|
|||||||
extern crate rustc_session;
|
extern crate rustc_session;
|
||||||
extern crate rustc_span;
|
extern crate rustc_span;
|
||||||
|
|
||||||
/// See docs in https://github.com/rust-lang/rust/blob/HEAD/compiler/rustc/src/main.rs
|
|
||||||
/// and https://github.com/rust-lang/rust/pull/146627 for why we need this.
|
|
||||||
///
|
|
||||||
/// FIXME(madsmtm): This is loaded from the sysroot that was built with the other `rustc` crates
|
|
||||||
/// above, instead of via Cargo as you'd normally do. This is currently needed for LTO due to
|
|
||||||
/// https://github.com/rust-lang/cc-rs/issues/1613.
|
|
||||||
#[cfg(feature = "jemalloc")]
|
|
||||||
// Make sure `--all-features` works: only Linux and macOS actually use jemalloc, and not on arm32.
|
|
||||||
#[cfg(all(
|
|
||||||
any(target_os = "linux", target_os = "macos"),
|
|
||||||
any(target_arch = "x86_64", target_arch = "x86", target_arch = "aarch64"),
|
|
||||||
))]
|
|
||||||
extern crate tikv_jemalloc_sys as _;
|
|
||||||
|
|
||||||
mod log;
|
mod log;
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|||||||
@@ -442,6 +442,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
|
|||||||
"thorin-dwp",
|
"thorin-dwp",
|
||||||
"thread_local",
|
"thread_local",
|
||||||
"tikv-jemalloc-sys",
|
"tikv-jemalloc-sys",
|
||||||
|
"tikv-jemallocator",
|
||||||
"tinystr",
|
"tinystr",
|
||||||
"tinyvec",
|
"tinyvec",
|
||||||
"tinyvec_macros",
|
"tinyvec_macros",
|
||||||
|
|||||||
Reference in New Issue
Block a user