Skip to content

Commit 851e140

Browse files
committed
Auto merge of #148925 - madsmtm:jemalloc-perf, r=Kobzol
Simplify `jemalloc` setup (without perf regression) Reland rust-lang/rust#146627 after fixing [the performance regression](rust-lang/rust#148851 (comment)) that caused it to be reverted in rust-lang/rust#148896. This avoids 65f0b7a (second commit in the initial PR), and adds a comment explaining why `extern crate` is needed here instead of `use` (we need to load `tikv_jemalloc_sys` from the sysroot because of rust-lang/cc-rs#1613). r? Kobzol
2 parents 9282c72 + e16034b commit 851e140

File tree

2 files changed

+7
-43
lines changed

2 files changed

+7
-43
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ serde_json = { version = "1.0", optional = true }
3333
# But only for some targets, it fails for others. Rustc configures this in its CI, but we can't
3434
# easily use that since we support of-tree builds.
3535
[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies.tikv-jemalloc-sys]
36-
version = "0.6.0"
37-
features = ['unprefixed_malloc_on_supported_platforms']
36+
version = "0.6.1"
37+
features = ['override_allocator_on_supported_platforms']
3838

3939
[target.'cfg(unix)'.dependencies]
4040
libc = "0.2"

src/bin/miri.rs

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ extern crate rustc_middle;
2020
extern crate rustc_session;
2121
extern crate rustc_span;
2222

23+
/// See docs in https://github.com/rust-lang/rust/blob/HEAD/compiler/rustc/src/main.rs
24+
/// and https://github.com/rust-lang/rust/pull/146627 for why we need this `use` statement.
25+
#[cfg(any(target_os = "linux", target_os = "macos"))]
26+
use tikv_jemalloc_sys as _;
27+
2328
mod log;
2429

2530
use std::env;
@@ -395,48 +400,7 @@ fn parse_range(val: &str) -> Result<Range<u32>, &'static str> {
395400
Ok(from..to)
396401
}
397402

398-
#[cfg(any(target_os = "linux", target_os = "macos"))]
399-
fn jemalloc_magic() {
400-
// These magic runes are copied from
401-
// <https://github.com/rust-lang/rust/blob/e89bd9428f621545c979c0ec686addc6563a394e/compiler/rustc/src/main.rs#L39>.
402-
// See there for further comments.
403-
use std::os::raw::{c_int, c_void};
404-
405-
use tikv_jemalloc_sys as jemalloc_sys;
406-
407-
#[used]
408-
static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::calloc;
409-
#[used]
410-
static _F2: unsafe extern "C" fn(*mut *mut c_void, usize, usize) -> c_int =
411-
jemalloc_sys::posix_memalign;
412-
#[used]
413-
static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::aligned_alloc;
414-
#[used]
415-
static _F4: unsafe extern "C" fn(usize) -> *mut c_void = jemalloc_sys::malloc;
416-
#[used]
417-
static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = jemalloc_sys::realloc;
418-
#[used]
419-
static _F6: unsafe extern "C" fn(*mut c_void) = jemalloc_sys::free;
420-
421-
// On OSX, jemalloc doesn't directly override malloc/free, but instead
422-
// registers itself with the allocator's zone APIs in a ctor. However,
423-
// the linker doesn't seem to consider ctors as "used" when statically
424-
// linking, so we need to explicitly depend on the function.
425-
#[cfg(target_os = "macos")]
426-
{
427-
unsafe extern "C" {
428-
fn _rjem_je_zone_register();
429-
}
430-
431-
#[used]
432-
static _F7: unsafe extern "C" fn() = _rjem_je_zone_register;
433-
}
434-
}
435-
436403
fn main() {
437-
#[cfg(any(target_os = "linux", target_os = "macos"))]
438-
jemalloc_magic();
439-
440404
let early_dcx = EarlyDiagCtxt::new(ErrorOutputType::default());
441405

442406
// Snapshot a copy of the environment before `rustc` starts messing with it.

0 commit comments

Comments
 (0)