From b195eb6c80c93d5e180a67e5351d497ab9f4cdc9 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 24 Feb 2025 14:38:16 +0100 Subject: [PATCH] Disable jemalloc decay in benches --- Cargo.toml | 3 +++ benches/accumulator.rs | 2 ++ benches/compare.rs | 2 ++ benches/incremental.rs | 2 ++ benches/shims/global_alloc_overwrite.rs | 29 +++++++++++++++++++++++++ 5 files changed, 38 insertions(+) create mode 100644 benches/shims/global_alloc_overwrite.rs diff --git a/Cargo.toml b/Cargo.toml index 67c3475dd..d6550b175 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,6 +50,9 @@ rustversion = "1.0" test-log = { version = "0.2.11", features = ["trace"] } trybuild = "1.0" +[target.'cfg(all(not(target_os = "windows"), not(target_os = "openbsd"), any(target_arch = "x86_64", target_arch = "aarch64", target_arch = "powerpc64")))'.dev-dependencies] +tikv-jemallocator = "0.6.0" + [[bench]] name = "compare" harness = false diff --git a/benches/accumulator.rs b/benches/accumulator.rs index b1a461e89..90c8781d2 100644 --- a/benches/accumulator.rs +++ b/benches/accumulator.rs @@ -3,6 +3,8 @@ use std::hint::black_box; use codspeed_criterion_compat::{criterion_group, criterion_main, BatchSize, Criterion}; use salsa::Accumulator; +include!("shims/global_alloc_overwrite.rs"); + #[salsa::input] struct Input { expressions: usize, diff --git a/benches/compare.rs b/benches/compare.rs index 6f8b7ee13..4e1cf73cd 100644 --- a/benches/compare.rs +++ b/benches/compare.rs @@ -6,6 +6,8 @@ use codspeed_criterion_compat::{ }; use salsa::Setter; +include!("shims/global_alloc_overwrite.rs"); + #[salsa::input] pub struct Input { #[return_ref] diff --git a/benches/incremental.rs b/benches/incremental.rs index 7fa992682..76796a5bf 100644 --- a/benches/incremental.rs +++ b/benches/incremental.rs @@ -3,6 +3,8 @@ use std::hint::black_box; use codspeed_criterion_compat::{criterion_group, criterion_main, BatchSize, Criterion}; use salsa::Setter; +include!("shims/global_alloc_overwrite.rs"); + #[salsa::input] struct Input { field: usize, diff --git a/benches/shims/global_alloc_overwrite.rs b/benches/shims/global_alloc_overwrite.rs new file mode 100644 index 000000000..e3b5ea74f --- /dev/null +++ b/benches/shims/global_alloc_overwrite.rs @@ -0,0 +1,29 @@ +#[cfg(all( + not(target_os = "windows"), + not(target_os = "openbsd"), + any( + target_arch = "x86_64", + target_arch = "aarch64", + target_arch = "powerpc64" + ) +))] +#[global_allocator] +static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; + +// Disable decay after 10s because it can show up as *random* slow allocations +// in benchmarks. We don't need purging in benchmarks because it isn't important +// to give unallocated pages back to the OS. +// https://jemalloc.net/jemalloc.3.html#opt.dirty_decay_ms +#[cfg(all( + not(target_os = "windows"), + not(target_os = "openbsd"), + any( + target_arch = "x86_64", + target_arch = "aarch64", + target_arch = "powerpc64" + ) +))] +#[allow(non_upper_case_globals)] +#[export_name = "_rjem_malloc_conf"] +#[allow(unsafe_code)] +pub static _rjem_malloc_conf: &[u8] = b"dirty_decay_ms:-1,muzzy_decay_ms:-1\0";