From 417d62bc976aec34ec729bd391cb66f837bd0eb8 Mon Sep 17 00:00:00 2001 From: Tushar Mathur Date: Sun, 8 Oct 2023 07:43:11 +0530 Subject: [PATCH 01/13] Update README.md (#64) Signed-off-by: Tushar Mathur --- jemallocator/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jemallocator/README.md b/jemallocator/README.md index e9e13e66d..a7702bbbe 100644 --- a/jemallocator/README.md +++ b/jemallocator/README.md @@ -36,7 +36,7 @@ tikv-jemallocator = "0.5" To set `tikv_jemallocator::Jemalloc` as the global allocator add this to your project: ```rust -# main.rs +// main.rs #[cfg(not(target_env = "msvc"))] use tikv_jemallocator::Jemalloc; From f7adfca5aff272b43fd3ad896252b57fbbd9c72a Mon Sep 17 00:00:00 2001 From: Jack Kleeman Date: Tue, 30 Jan 2024 03:08:40 +0000 Subject: [PATCH 02/13] Allow unprefixed jemalloc on musl targets (#70) Signed-off-by: Jack Kleeman --- jemalloc-sys/src/env.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/jemalloc-sys/src/env.rs b/jemalloc-sys/src/env.rs index f4d3e8e1d..2053ad306 100644 --- a/jemalloc-sys/src/env.rs +++ b/jemalloc-sys/src/env.rs @@ -19,7 +19,6 @@ pub static NO_BG_THREAD_TARGETS: &[&str] = &["musl"]; // (not jemalloc malloc), and then the standard library would free with jemalloc free, // causing a segfault.” // https://github.com/rust-lang/rust/commit/e3b414d8612314e74e2b0ebde1ed5c6997d28e8d -// https://github.com/rust-lang/rust/commit/536011d929ecbd1170baf34e09580e567c971f95 // https://github.com/rust-lang/rust/commit/9f3de647326fbe50e0e283b9018ab7c41abccde3 // https://github.com/rust-lang/rust/commit/ed015456a114ae907a36af80c06f81ea93182a24 -pub static NO_UNPREFIXED_MALLOC_TARGETS: &[&str] = &["android", "dragonfly", "musl", "darwin"]; +pub static NO_UNPREFIXED_MALLOC_TARGETS: &[&str] = &["android", "dragonfly", "darwin"]; From b913c24fdd4841bb4028a00207dfeb76832c806b Mon Sep 17 00:00:00 2001 From: Marvin Schmidt Date: Tue, 30 Jan 2024 11:59:16 +0100 Subject: [PATCH 03/13] build: Fix build on riscv64gc-unknown-linux-musl (#67) The configure step for jemalloc fails to recognize the rustc target `riscv64gc-unknown-linux-musl`: ``` --- stderr Invalid configuration `riscv64gc-unknown-linux-musl': machine `riscv64gc-unknown' not recognized configure: error: /bin/sh build-aux/config.sub riscv64gc-unknown-linux-musl failed thread 'main' panicked at /home/marv/.cargo/registry/src/index.crates.io-6f17d22bba15001f/jemalloc-sys-0.5.4+5.3.0-patched/build.rs:351:9: command did not execute successfully: cd "/mnt/data/devel/ripgrep/target/release/build/jemalloc-sys-eb3f9d51d93e319f/out/build" && CC="cc" CFLAGS="-O3 -ffunction-sections -fdata-sections -fPIC -gdwarf-4 -fno-omit-frame-pointer -march=rv64gc -mabi=lp64d -mcmodel=medany -Wall -g -ggdb3 -O0" CPPFLAGS="-O3 -ffunction-sections -fdata-sections -fPIC -gdwarf-4 -fno-omit-frame-pointer -march=rv64gc -mabi=lp64d -mcmodel=medany -Wall -g -ggdb3 -O0" LDFLAGS="-O3 -ffunction-sections -fdata-sections -fPIC -gdwarf-4 -fno-omit-frame-pointer -march=rv64gc -mabi=lp64d -mcmodel=medany -Wall -g -ggdb3 -O0" "sh" "/mnt/data/devel/ripgrep/target/release/build/jemalloc-sys-eb3f9d51d93e319f/out/build/configure" "--disable-cxx" "--enable-doc=no" "--enable-shared=no" "--with-jemalloc-prefix=_rjem_" "--with-private-namespace=_rjem_" "--host=riscv64gc-unknown-linux-musl" "--build=riscv64gc-unknown-linux-musl" "--prefix=/mnt/data/devel/ripgrep/target/release/build/jemalloc-sys-eb3f9d51d93e319f/out" expected success, got: exit status: 1 ``` Add an entry to build.rs to translate between the GNU target and rustc target in order to work around the mismatch Signed-off-by: Marvin Schmidt --- jemalloc-sys/build.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/jemalloc-sys/build.rs b/jemalloc-sys/build.rs index cf1ff4533..094847e15 100644 --- a/jemalloc-sys/build.rs +++ b/jemalloc-sys/build.rs @@ -364,6 +364,7 @@ fn gnu_target(target: &str) -> String { "x86_64-pc-windows-gnu" => "x86_64-w64-mingw32".to_string(), "armv7-linux-androideabi" => "arm-linux-androideabi".to_string(), "riscv64gc-unknown-linux-gnu" => "riscv64-linux-gnu".to_string(), + "riscv64gc-unknown-linux-musl" => "riscv64-linux-musl".to_string(), s => s.to_string(), } } From af6e6529c087dc1d0ac159372111a859031269f6 Mon Sep 17 00:00:00 2001 From: Val Packett Date: Mon, 19 Feb 2024 08:10:03 -0300 Subject: [PATCH 04/13] Add Chimera Linux to gmake targets (#73) Signed-off-by: Val Packett --- jemalloc-sys/build.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/jemalloc-sys/build.rs b/jemalloc-sys/build.rs index 094847e15..fd11cf652 100644 --- a/jemalloc-sys/build.rs +++ b/jemalloc-sys/build.rs @@ -370,7 +370,14 @@ fn gnu_target(target: &str) -> String { } fn make_cmd(host: &str) -> &'static str { - const GMAKE_HOSTS: &[&str] = &["bitrig", "dragonfly", "freebsd", "netbsd", "openbsd"]; + const GMAKE_HOSTS: &[&str] = &[ + "bitrig", + "dragonfly", + "freebsd", + "netbsd", + "openbsd", + "chimera-linux", + ]; if GMAKE_HOSTS.iter().any(|i| host.contains(i)) { "gmake" } else if host.contains("windows") { From 802969384ae0c581255f3375ee2ba774c8d2a754 Mon Sep 17 00:00:00 2001 From: Jack Kleeman Date: Fri, 1 Mar 2024 06:26:01 +0000 Subject: [PATCH 05/13] Use tikv jemalloc fork (#75) As otherwise the commit doesn't reliably download on new checkout Signed-off-by: Jack Kleeman --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 04dd40a57..ca215355e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "jemalloc-sys/jemalloc"] path = jemalloc-sys/jemalloc - url = https://github.com/jemalloc/jemalloc + url = https://github.com/tikv/jemalloc From 714705e15f6d38424c6645abe2eef877ec828967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20=C3=81vila=20de=20Esp=C3=ADndola?= Date: Mon, 1 Apr 2024 03:28:04 +0000 Subject: [PATCH 06/13] Use --with-version when configuring jemalloc (#77) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Use --with-version when configuring jemalloc This also changes the metadata of the version so that jemalloc still reports the same version as before. Fixes tikv/jemallocator#76 Signed-off-by: Rafael Ávila de Espíndola --- jemalloc-sys/Cargo.toml | 2 +- jemalloc-sys/build.rs | 18 ++++++++++++++---- jemalloc-sys/configure/VERSION | 1 - 3 files changed, 15 insertions(+), 6 deletions(-) delete mode 100644 jemalloc-sys/configure/VERSION diff --git a/jemalloc-sys/Cargo.toml b/jemalloc-sys/Cargo.toml index 0e854dd8f..4c30478a1 100644 --- a/jemalloc-sys/Cargo.toml +++ b/jemalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tikv-jemalloc-sys" -version = "0.5.4+5.3.0-patched" +version = "0.5.4+5.3.0-1-ge13ca993e8ccb9ba9847cc330696e02839f328f7" authors = [ "Alex Crichton ", "Gonzalo Brito Gadeschi ", diff --git a/jemalloc-sys/build.rs b/jemalloc-sys/build.rs index fd11cf652..dc07fc35d 100644 --- a/jemalloc-sys/build.rs +++ b/jemalloc-sys/build.rs @@ -55,14 +55,23 @@ fn copy_recursively(src: &Path, dst: &Path) -> io::Result<()> { Ok(()) } +fn expect_env(name: &str) -> String { + env::var(name).unwrap_or_else(|_| panic!("{} was not set", name)) +} + // TODO: split main functions and remove following allow. #[allow(clippy::cognitive_complexity)] fn main() { - let target = env::var("TARGET").expect("TARGET was not set"); - let host = env::var("HOST").expect("HOST was not set"); - let num_jobs = env::var("NUM_JOBS").expect("NUM_JOBS was not set"); + let target = expect_env("TARGET"); + let host = expect_env("HOST"); + let num_jobs = expect_env("NUM_JOBS"); let out_dir = PathBuf::from(env::var_os("OUT_DIR").expect("OUT_DIR was not set")); let src_dir = env::current_dir().expect("failed to get current directory"); + let version = expect_env("CARGO_PKG_VERSION"); + let je_version = version + .split_once('+') + .expect("jemalloc version is missing") + .1; info!("TARGET={}", target); info!("HOST={}", host); @@ -147,7 +156,7 @@ fn main() { assert!(build_dir.exists()); // Configuration files - let config_files = ["configure", "VERSION"]; + let config_files = ["configure"]; // Copy the configuration files to jemalloc's source directory for f in &config_files { @@ -170,6 +179,7 @@ fn main() { .env("CFLAGS", cflags.clone()) .env("LDFLAGS", cflags.clone()) .env("CPPFLAGS", cflags) + .arg(format!("--with-version={je_version}")) .arg("--disable-cxx") .arg("--enable-doc=no") .arg("--enable-shared=no"); diff --git a/jemalloc-sys/configure/VERSION b/jemalloc-sys/configure/VERSION deleted file mode 100644 index 1dcfea03f..000000000 --- a/jemalloc-sys/configure/VERSION +++ /dev/null @@ -1 +0,0 @@ -5.3.0-0-g54eaed1d8b56b1aa528be3bdd1877e59c56fa90c From 4f35ea85e25b4f9e304b8d9ce163f5f648a12311 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Tue, 2 Apr 2024 08:24:58 -0400 Subject: [PATCH 07/13] feat: add profiling options (#74) - add m1 macos ci target - feat: add profiling options Signed-off-by: Dan Cline <6798349+Rjected@users.noreply.github.com> --- .github/workflows/main.yml | 7 +- jemalloc-ctl/Cargo.toml | 1 + jemalloc-ctl/src/lib.rs | 2 + jemalloc-ctl/src/profiling.rs | 155 ++++++++++++++++++++++++++++++++++ 4 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 jemalloc-ctl/src/profiling.rs diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 58ea088d0..673506365 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,7 +2,7 @@ name: CI on: pull_request: - branches: + branches: - 'master' - 'main' push: @@ -21,6 +21,11 @@ jobs: nobgt: 0 no_tests: 1 tag: arm64 + - name: aarch64-apple-darwin + target: aarch64-apple-darwin + nobgt: 0 + no_tests: 1 + tag: macos-14 - name: x86_64-unknown-linux-gnu (nightly) target: x86_64-unknown-linux-gnu nobgt: 0 diff --git a/jemalloc-ctl/Cargo.toml b/jemalloc-ctl/Cargo.toml index 0375ef526..f477ce754 100644 --- a/jemalloc-ctl/Cargo.toml +++ b/jemalloc-ctl/Cargo.toml @@ -35,6 +35,7 @@ tikv-jemallocator = { path = "../jemallocator", version = "0.5.0" } [features] default = [] +profiling = ["tikv-jemalloc-sys/profiling"] use_std = [ "libc/use_std" ] disable_initial_exec_tls = ["tikv-jemalloc-sys/disable_initial_exec_tls"] diff --git a/jemalloc-ctl/src/lib.rs b/jemalloc-ctl/src/lib.rs index a5aef998a..c5aea8ad7 100644 --- a/jemalloc-ctl/src/lib.rs +++ b/jemalloc-ctl/src/lib.rs @@ -88,6 +88,8 @@ pub mod config; mod error; mod keys; pub mod opt; +#[cfg(feature = "profiling")] +pub mod profiling; pub mod raw; pub mod stats; #[cfg(feature = "use_std")] diff --git a/jemalloc-ctl/src/profiling.rs b/jemalloc-ctl/src/profiling.rs new file mode 100644 index 000000000..306ab1a8e --- /dev/null +++ b/jemalloc-ctl/src/profiling.rs @@ -0,0 +1,155 @@ +//! `jemalloc`'s run-time configuration for profiling-specific settings. +//! +//! These settings are controlled by the `MALLOC_CONF` environment variable. + +option! { + lg_prof_interval[ str: b"opt.lg_prof_interval\0", non_str: 2 ] => libc::ssize_t | + ops: r | + docs: + /// Average interval (log base 2) between memory profile dumps, as measured in bytes of + /// allocation activity. + /// + /// The actual interval between dumps may be sporadic because + /// decentralized allocation counters are used to avoid synchronization bottlenecks. + /// + /// Profiles are dumped to files named according to the pattern + /// \.\.\.i\.heap, where \ is controlled by the + /// opt.prof_prefix and prof.prefix options. By default, interval-triggered profile dumping is + /// disabled (encoded as -1). + /// + /// # Examples + /// + /// ``` + /// # #[global_allocator] + /// # static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; + /// # + /// # fn main() { + /// use tikv_jemalloc_ctl::profiling; + /// let lg_prof_interval = profiling::lg_prof_interval::read().unwrap(); + /// println!("average interval between memory profile dumps: {}", lg_prof_interval); + /// # } + /// ``` + mib_docs: /// See [`lg_prof_interval`]. +} + +option! { + lg_prof_sample[ str: b"opt.lg_prof_sample\0", non_str: 2 ] => libc::size_t | + ops: r | + docs: + /// Average interval (log base 2) between allocation samples, as measured in bytes of + /// allocation activity. Increasing the sampling interval decreases profile fidelity, but also + /// decreases the computational overhead. + /// + /// The default sample interval is 512 KiB (2^19 B). + /// + /// # Examples + /// + /// ``` + /// # #[global_allocator] + /// # static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; + /// # + /// # fn main() { + /// use tikv_jemalloc_ctl::profiling; + /// let lg_prof_sample = profiling::lg_prof_sample::read().unwrap(); + /// println!("average interval between allocation samples: {}", lg_prof_sample); + /// # } + /// ``` + mib_docs: /// See [`lg_prof_sample`]. +} + +option! { + prof_final[ str: b"opt.prof_final\0", non_str: 2 ] => bool | + ops: r | + docs: + /// Use an atexit(3) function to dump final memory usage to a file named according to the + /// pattern \.\.\.f.heap, where \ is controlled by the opt.prof_prefix + /// and prof.prefix options. + /// + /// Note that atexit() may allocate memory during application initialization and then deadlock + /// internally when jemalloc in turn calls `atexit()`, so this option is not universally usable + /// (though the application can register its own `atexit()` function with equivalent + /// functionality). + /// + /// This option is disabled by default. + /// + /// # Examples + /// + /// ``` + /// # #[global_allocator] + /// # static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; + /// # + /// # fn main() { + /// use tikv_jemalloc_ctl::profiling; + /// let prof_final = profiling::prof_final::read().unwrap(); + /// println!("dump final memory usage to file: {}", prof_final); + /// # } + /// ``` + mib_docs: /// See [`prof_final`]. +} + +option! { + prof[ str: b"opt.prof\0", non_str: 2 ] => bool | + ops: r | + docs: + /// Memory profiling enabled/disabled. + /// + /// If enabled, profile memory allocation activity. + /// + /// See the `opt.prof_active` option for on-the-fly activation/deactivation. + /// + /// See the `opt.lg_prof_sample` option for probabilistic sampling control. + /// + /// See the `opt.prof_accum` option for control of cumulative sample reporting. + /// + /// See the `opt.lg_prof_interval` option for information on interval-triggered profile + /// dumping, the `opt.prof_gdump` option for information on high-water-triggered profile + /// dumping, and the `opt.prof_final` option for final profile dumping. + /// + /// Profile output is compatible with the jeprof command, which is based on the pprof that is + /// developed as part of the gperftools package. See `HEAP PROFILE FORMAT` for heap profile + /// format documentation. + /// + /// # Examples + /// + /// ``` + /// # #[global_allocator] + /// # static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; + /// # + /// # fn main() { + /// use tikv_jemalloc_ctl::profiling; + /// let prof = profiling::prof::read().unwrap(); + /// println!("is memory profiling enabled: {}", prof); + /// # } + /// ``` + mib_docs: /// See [`prof`]. +} + +option! { + prof_leak[ str: b"opt.prof_leak\0", non_str: 2 ] => bool | + ops: r | + docs: + /// Leak reporting enabled/disabled. + /// + /// If enabled, use an `atexit(3)` function to report memory leaks detected by allocation + /// sampling. + /// + /// See the opt.prof option for information on analyzing heap profile output. + /// + /// Works only when combined with `opt.prof_final`, otherwise does nothing. + /// + /// This option is disabled by default. + /// + /// # Examples + /// + /// ``` + /// # #[global_allocator] + /// # static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; + /// # + /// # fn main() { + /// use tikv_jemalloc_ctl::profiling; + /// let prof_leak = profiling::prof_leak::read().unwrap(); + /// println!("is leak reporting enabled: {}", prof_leak); + /// # } + /// ``` + mib_docs: /// See [`prof_leak`]. +} From 805804ac837821408167afd2dd6d93c96c13a82d Mon Sep 17 00:00:00 2001 From: fys <40801205+fengys1996@users.noreply.github.com> Date: Sun, 5 May 2024 16:45:27 +0800 Subject: [PATCH 08/13] fix: compile aarch64-linux-android binary on linux when enable lto. (#83) Close #81. Signed-off-by: fys --- jemalloc-sys/build.rs | 10 ++++++++++ jemalloc-sys/src/lib.rs | 14 -------------- jemalloc-sys/src/pthread_atfork.c | 11 +++++++++++ 3 files changed, 21 insertions(+), 14 deletions(-) create mode 100644 jemalloc-sys/src/pthread_atfork.c diff --git a/jemalloc-sys/build.rs b/jemalloc-sys/build.rs index dc07fc35d..12daa04d4 100644 --- a/jemalloc-sys/build.rs +++ b/jemalloc-sys/build.rs @@ -338,6 +338,16 @@ fn main() { println!("cargo:rustc-link-lib=atomic"); } println!("cargo:rerun-if-changed=jemalloc"); + + if target.contains("android") { + // These symbols are used by jemalloc on android but the really old android + // we're building on doesn't have them defined, so just make sure the symbols + // are available. + cc::Build::new() + .file("src/pthread_atfork.c") + .compile("pthread_atfork"); + println!("cargo:rerun-if-changed=src/pthread_atfork.c"); + } } fn run_and_log(cmd: &mut Command, log_file: &Path) { diff --git a/jemalloc-sys/src/lib.rs b/jemalloc-sys/src/lib.rs index 58010afdc..5ad550772 100644 --- a/jemalloc-sys/src/lib.rs +++ b/jemalloc-sys/src/lib.rs @@ -890,20 +890,6 @@ pub type extent_merge_t = unsafe extern "C" fn( arena_ind: c_uint, ) -> c_bool; -// These symbols are used by jemalloc on android but the really old android -// we're building on doesn't have them defined, so just make sure the symbols -// are available. -#[no_mangle] -#[cfg(target_os = "android")] -#[doc(hidden)] -pub extern "C" fn pthread_atfork( - _prefork: *mut u8, - _postfork_parent: *mut u8, - _postfork_child: *mut u8, -) -> i32 { - 0 -} - #[allow(missing_docs)] mod env; diff --git a/jemalloc-sys/src/pthread_atfork.c b/jemalloc-sys/src/pthread_atfork.c new file mode 100644 index 000000000..254443d20 --- /dev/null +++ b/jemalloc-sys/src/pthread_atfork.c @@ -0,0 +1,11 @@ +/* + * These symbols are used by jemalloc on android but the really old android + * we're building on doesn't have them defined, so just make sure the symbols + * are available. + */ +__attribute__((weak)) int +pthread_atfork(void (*prepare)(void) __attribute__((unused)), + void (*parent)(void) __attribute__((unused)), + void (*child)(void) __attribute__((unused))) { + return 0; +} From 86e924870d6d90ac85607466a9b30c99a33497f5 Mon Sep 17 00:00:00 2001 From: June Date: Thu, 9 May 2024 22:41:40 -0400 Subject: [PATCH 09/13] set `--disable-stats` if `stats` feature is not enabled (#82) jemalloc defaults to enabling stats if `--enable-stats` is not present and `--disable-stats` was not set: https://github.com/jemalloc/jemalloc/blob/fa451de17fff73cc03c31ec8cd817d62927d1ff9/configure.ac#L1331-L1333 the stats feature was always enabled by default and never respected if someone were to remove the stats feature as no logic was added for setting `--disable-stats`. to avoid breaking other user's setups who are relying on this behaviour, set stats as a default feature. Signed-off-by: strawberry --- jemalloc-sys/Cargo.toml | 2 +- jemalloc-sys/build.rs | 3 +++ jemallocator/Cargo.toml | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/jemalloc-sys/Cargo.toml b/jemalloc-sys/Cargo.toml index 4c30478a1..7f716427a 100644 --- a/jemalloc-sys/Cargo.toml +++ b/jemalloc-sys/Cargo.toml @@ -32,7 +32,7 @@ libc = { version = "^0.2.8", default-features = false } cc = "^1.0.13" [features] -default = ["background_threads_runtime_support"] +default = ["stats", "background_threads_runtime_support"] profiling = [] debug = [] background_threads_runtime_support = [] diff --git a/jemalloc-sys/build.rs b/jemalloc-sys/build.rs index 12daa04d4..b1065897f 100644 --- a/jemalloc-sys/build.rs +++ b/jemalloc-sys/build.rs @@ -265,6 +265,9 @@ fn main() { if env::var("CARGO_FEATURE_STATS").is_ok() { info!("CARGO_FEATURE_STATS set"); cmd.arg("--enable-stats"); + } else { + info!("CARGO_FEATURE_STATS not set"); + cmd.arg("--disable-stats"); } if env::var("CARGO_FEATURE_DISABLE_INITIAL_EXEC_TLS").is_ok() { diff --git a/jemallocator/Cargo.toml b/jemallocator/Cargo.toml index 010b99c6f..58954543f 100644 --- a/jemallocator/Cargo.toml +++ b/jemallocator/Cargo.toml @@ -41,7 +41,7 @@ paste = "1" tikv-jemalloc-ctl = { path = "../jemalloc-ctl", version = "0.5.0" } [features] -default = ["background_threads_runtime_support"] +default = ["stats", "background_threads_runtime_support"] alloc_trait = [] profiling = ["tikv-jemalloc-sys/profiling"] debug = ["tikv-jemalloc-sys/debug"] From e9692ae34cd2e8d888f416c26eb1664a093807d9 Mon Sep 17 00:00:00 2001 From: YEUNG King On Date: Mon, 13 May 2024 17:01:04 +0800 Subject: [PATCH 10/13] Revise CI runner platform on macOS (#86) macos-latest has been switched from x86_64 to aarch64 (https://github.com/actions/runner-images/blob/main/README.md) Signed-off-by: YEUNG King On --- .github/workflows/main.yml | 10 +++++----- jemallocator/README.md | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 673506365..659aec53f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,11 +21,11 @@ jobs: nobgt: 0 no_tests: 1 tag: arm64 - - name: aarch64-apple-darwin - target: aarch64-apple-darwin + - name: x86_64-apple-darwin + target: x86_64-apple-darwin nobgt: 0 no_tests: 1 - tag: macos-14 + tag: macos-13 - name: x86_64-unknown-linux-gnu (nightly) target: x86_64-unknown-linux-gnu nobgt: 0 @@ -43,8 +43,8 @@ jobs: nobgt: 1 no_tests: 1 tag: ubuntu-latest - - name: x86_64-apple-darwin (stable) - target: x86_64-apple-darwin + - name: aarch64-apple-darwin (stable) + target: aarch64-apple-darwin nobgt: 0 no_tests: 1 tag: macos-latest diff --git a/jemallocator/README.md b/jemallocator/README.md index a7702bbbe..7315a14c2 100644 --- a/jemallocator/README.md +++ b/jemallocator/README.md @@ -65,7 +65,7 @@ other targets are only tested on Rust nightly. | `powerpc64le-unknown-linux-gnu` | ✓ | ✓ | ✗ | | `x86_64-unknown-linux-gnu` (tier 1) | ✓ | ✓ | ✓ | | **MacOSX targets:** | **build** | **run** | **jemalloc** | -| `x86_64-apple-darwin` (tier 1) | ✓ | ✓ | ✗ | +| `aarch64-apple-darwin` | ✓ | ✓ | ✗ | ## Features From 5a82b9d435f4f432174ed1e055bd2bb3288775b8 Mon Sep 17 00:00:00 2001 From: Jay Date: Sun, 14 Jul 2024 14:25:29 +0800 Subject: [PATCH 11/13] remove outdated clippy allows (#94) Signed-off-by: Jay Lee --- jemalloc-ctl/src/error.rs | 4 ---- jemalloc-ctl/src/lib.rs | 1 - jemalloc-sys/src/lib.rs | 4 ---- 3 files changed, 9 deletions(-) diff --git a/jemalloc-ctl/src/error.rs b/jemalloc-ctl/src/error.rs index 46f792514..168744d62 100644 --- a/jemalloc-ctl/src/error.rs +++ b/jemalloc-ctl/src/error.rs @@ -1,8 +1,4 @@ //! Error type -#![cfg_attr( - feature = "cargo-clippy", - allow(clippy::cast_sign_loss, clippy::cast_possible_wrap) -)] use crate::{fmt, num, result}; use libc::c_int; diff --git a/jemalloc-ctl/src/lib.rs b/jemalloc-ctl/src/lib.rs index c5aea8ad7..e0abb991b 100644 --- a/jemalloc-ctl/src/lib.rs +++ b/jemalloc-ctl/src/lib.rs @@ -68,7 +68,6 @@ #![allow(renamed_and_removed_lints)] #![deny(missing_docs, broken_intra_doc_links)] #![cfg_attr(not(feature = "use_std"), no_std)] -#![cfg_attr(feature = "cargo-clippy", allow(clippy::module_name_repetitions))] #[cfg(test)] #[global_allocator] diff --git a/jemalloc-sys/src/lib.rs b/jemalloc-sys/src/lib.rs index 5ad550772..79096a0f8 100644 --- a/jemalloc-sys/src/lib.rs +++ b/jemalloc-sys/src/lib.rs @@ -41,10 +41,6 @@ //! [jemalloc_mallctl]: http://jemalloc.net/jemalloc.3.html#mallctl_namespace #![no_std] #![allow(non_snake_case, non_camel_case_types)] -#![cfg_attr( - feature = "cargo-clippy", - allow(clippy::cast_possible_truncation, clippy::cast_possible_wrap) -)] // TODO: rename the following lint on next minor bump #![allow(renamed_and_removed_lints)] #![deny(missing_docs, broken_intra_doc_links)] From 2fde3d8150795792c8e04ec67b5962c2a50aaeb6 Mon Sep 17 00:00:00 2001 From: Torrekie Gen <31795847+Torrekie@users.noreply.github.com> Date: Sun, 14 Jul 2024 15:23:49 +0800 Subject: [PATCH 12/13] allow per-target env detection (#91) Signed-off-by: Torrekie <31795847+Torrekie@users.noreply.github.com> --- jemalloc-sys/build.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/jemalloc-sys/build.rs b/jemalloc-sys/build.rs index b1065897f..b91d3e3d6 100644 --- a/jemalloc-sys/build.rs +++ b/jemalloc-sys/build.rs @@ -28,14 +28,28 @@ macro_rules! warning { } } +fn read_and_watch_env_impl(name: &str, env_getter: F) -> Option +where + F: Fn(&str) -> Option, +{ + let prefix = env::var("TARGET").unwrap().to_uppercase().replace('-', "_"); + let prefixed_name = format!("{}_{}", prefix, name); + + println!("cargo:rerun-if-env-changed={}", prefixed_name); + if let Some(value) = env_getter(&prefixed_name) { + return Some(value); + } + + println!("cargo:rerun-if-env-changed={}", name); + env_getter(name) +} + fn read_and_watch_env(name: &str) -> Result { - println!("cargo:rerun-if-env-changed={name}"); - env::var(name) + read_and_watch_env_impl(name, |n| env::var(n).ok()).ok_or(env::VarError::NotPresent) } fn read_and_watch_env_os(name: &str) -> Option { - println!("cargo:rerun-if-env-changed={name}"); - env::var_os(name) + read_and_watch_env_impl(name, |n| env::var_os(n)) } fn copy_recursively(src: &Path, dst: &Path) -> io::Result<()> { From f260a80f21b7f9eb1212809720d9a5f7f0cf0e8b Mon Sep 17 00:00:00 2001 From: Jay Date: Sun, 14 Jul 2024 23:34:47 +0800 Subject: [PATCH 13/13] *: bump 0.6.0 (#95) Signed-off-by: Jay Lee --- .github/workflows/main.yml | 16 +++-- CHANGELOG.md | 17 ++++++ jemalloc-ctl/Cargo.toml | 8 ++- jemalloc-ctl/src/lib.rs | 108 +++++++++++++++++---------------- jemalloc-sys/Cargo.toml | 5 +- jemallocator-global/Cargo.toml | 6 +- jemallocator-global/README.md | 2 +- jemallocator-global/src/lib.rs | 2 +- jemallocator/Cargo.toml | 12 ++-- jemallocator/README.md | 2 +- 10 files changed, 106 insertions(+), 72 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 659aec53f..721e5d089 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,11 +16,6 @@ jobs: strategy: matrix: include: - - name: aarch64-unknown-linux-gnu - target: aarch64-unknown-linux-gnu - nobgt: 0 - no_tests: 1 - tag: arm64 - name: x86_64-apple-darwin target: x86_64-apple-darwin nobgt: 0 @@ -48,6 +43,12 @@ jobs: nobgt: 0 no_tests: 1 tag: macos-latest + - name: x86_64-unknown-linux-gnu (msrv) + target: x86_64-unknown-linux-gnu + nobgt: 0 + no_tests: 0 + rust: msrv + tag: ubuntu-latest runs-on: ${{ matrix.tag }} env: TARGET: ${{ matrix.target }} @@ -62,6 +63,9 @@ jobs: if [[ "${{ matrix.rust }}" == "nightly" ]]; then rustup default nightly fi + if [[ "${{ matrix.rust }}" == "msrv" ]]; then + rustup default `grep rust-version jemalloc-sys/Cargo.toml | cut -d '"' -f 2` + fi rustup target add ${{ matrix.target }} if [[ "$TARGET" == "x86_64-unknown-linux-musl" ]]; then sudo apt install -y musl-tools @@ -90,5 +94,5 @@ jobs: - run: cargo clippy -p tikv-jemallocator -- -D clippy::all - run: cargo clippy -p tikv-jemallocator-global -- -D clippy::all - run: cargo clippy -p tikv-jemalloc-ctl -- -D clippy::all - - run: env RUSTDOCFLAGS="--cfg jemallocator_docs" cargo doc + - run: env RUSTDOCFLAGS="--cfg jemallocator_docs" cargo doc --features stats,profiling,use_std - run: shellcheck ci/*.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index bcd561ba1..e160b5d17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,20 @@ +# 0.6.0 - 2024-07-14 + +- Fix build on riscv64gc-unknown-linux-musl (#67) (#75) +- Allow jemalloc-sys to be the default allocator on musl linux (#70) +- Add Chimera Linux to gmake targets (#73) +- Add profiling options to jemalloc-ctl (#74) +- Fix jemalloc version not shown in API (#77) +- Fix jemalloc stats is still enabled when stats feature is disabled (#82) +- Fix duplicated symbol when build and link on aarch64-linux-android (#83) +- Revise CI runner platform on macOS (#86) +- Allow setting per-target env (#91) +- Remove outdated clippy allows (#94) +- Set MSRV to 1.71.0 (#95) + +Note since 0.6.0, if you want to use jemalloc stats, you have to enable the +feature explicitly. + # 0.5.4 - 2023-07-22 - Add disable_initial_exec_tls feature for jemalloc-ctl (#59) diff --git a/jemalloc-ctl/Cargo.toml b/jemalloc-ctl/Cargo.toml index f477ce754..a1e450c58 100644 --- a/jemalloc-ctl/Cargo.toml +++ b/jemalloc-ctl/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tikv-jemalloc-ctl" -version = "0.5.4" +version = "0.6.0" authors = [ "Steven Fackler ", "Gonzalo Brito Gadeschi ", @@ -26,18 +26,20 @@ is-it-maintained-open-issues = { repository = "tikv/jemallocator" } maintenance = { status = "actively-developed" } [dependencies] -tikv-jemalloc-sys = { path = "../jemalloc-sys", version = "0.5.0" } +tikv-jemalloc-sys = { path = "../jemalloc-sys", version = "0.6.0" } libc = { version = "0.2", default-features = false } paste = "1" [dev-dependencies] -tikv-jemallocator = { path = "../jemallocator", version = "0.5.0" } +tikv-jemallocator = { path = "../jemallocator", version = "0.6.0" } [features] default = [] +stats = ["tikv-jemalloc-sys/stats"] profiling = ["tikv-jemalloc-sys/profiling"] use_std = [ "libc/use_std" ] disable_initial_exec_tls = ["tikv-jemalloc-sys/disable_initial_exec_tls"] [package.metadata.docs.rs] rustdoc-args = [ "--cfg", "jemallocator_docs" ] +features = ["stats", "profiling", "use_std"] diff --git a/jemalloc-ctl/src/lib.rs b/jemalloc-ctl/src/lib.rs index e0abb991b..487f719fe 100644 --- a/jemalloc-ctl/src/lib.rs +++ b/jemalloc-ctl/src/lib.rs @@ -13,57 +13,62 @@ //! `$op::{read(), write(x), update(x)}` on the type calls `mallctl` with the //! string-based API. If the operation will be repeatedly performed, a MIB for //! the operation can be obtained using `$op.mib()`. -//! -//! # Examples -//! -//! Repeatedly printing allocation statistics: -//! -//! ```no_run -//! use std::thread; -//! use std::time::Duration; -//! use tikv_jemalloc_ctl::{stats, epoch}; -//! -//! #[global_allocator] -//! static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; -//! -//! fn main() { -//! loop { -//! // many statistics are cached and only updated when the epoch is advanced. -//! epoch::advance().unwrap(); -//! -//! let allocated = stats::allocated::read().unwrap(); -//! let resident = stats::resident::read().unwrap(); -//! println!("{} bytes allocated/{} bytes resident", allocated, resident); -//! thread::sleep(Duration::from_secs(10)); -//! } -//! } -//! ``` -//! -//! Doing the same with the MIB-based API: -//! -//! ```no_run -//! use std::thread; -//! use std::time::Duration; -//! use tikv_jemalloc_ctl::{stats, epoch}; -//! -//! #[global_allocator] -//! static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; -//! -//! fn main() { -//! let e = epoch::mib().unwrap(); -//! let allocated = stats::allocated::mib().unwrap(); -//! let resident = stats::resident::mib().unwrap(); -//! loop { -//! // many statistics are cached and only updated when the epoch is advanced. -//! e.advance().unwrap(); -//! -//! let allocated = allocated.read().unwrap(); -//! let resident = resident.read().unwrap(); -//! println!("{} bytes allocated/{} bytes resident", allocated, resident); -//! thread::sleep(Duration::from_secs(10)); -//! } -//! } -//! ``` +#![cfg_attr( + feature = "stats", + doc = r##" + +# Examples + +Repeatedly printing allocation statistics: + +```no_run +use std::thread; +use std::time::Duration; +use tikv_jemalloc_ctl::{stats, epoch}; + +#[global_allocator] +static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; + +fn main() { + loop { + // many statistics are cached and only updated when the epoch is advanced. + epoch::advance().unwrap(); + + let allocated = stats::allocated::read().unwrap(); + let resident = stats::resident::read().unwrap(); + println!("{} bytes allocated/{} bytes resident", allocated, resident); + thread::sleep(Duration::from_secs(10)); + } +} +``` + +Doing the same with the MIB-based API: + +```no_run +use std::thread; +use std::time::Duration; +use tikv_jemalloc_ctl::{stats, epoch}; + +#[global_allocator] +static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; + +fn main() { + let e = epoch::mib().unwrap(); + let allocated = stats::allocated::mib().unwrap(); + let resident = stats::resident::mib().unwrap(); + loop { + // many statistics are cached and only updated when the epoch is advanced. + e.advance().unwrap(); + + let allocated = allocated.read().unwrap(); + let resident = resident.read().unwrap(); + println!("{} bytes allocated/{} bytes resident", allocated, resident); + thread::sleep(Duration::from_secs(10)); + } +} +``` +"## +)] // TODO: rename the following lint on next minor bump #![allow(renamed_and_removed_lints)] #![deny(missing_docs, broken_intra_doc_links)] @@ -90,6 +95,7 @@ pub mod opt; #[cfg(feature = "profiling")] pub mod profiling; pub mod raw; +#[cfg(feature = "stats")] pub mod stats; #[cfg(feature = "use_std")] pub mod stats_print; diff --git a/jemalloc-sys/Cargo.toml b/jemalloc-sys/Cargo.toml index 7f716427a..220a6b8d0 100644 --- a/jemalloc-sys/Cargo.toml +++ b/jemalloc-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tikv-jemalloc-sys" -version = "0.5.4+5.3.0-1-ge13ca993e8ccb9ba9847cc330696e02839f328f7" +version = "0.6.0+5.3.0-1-ge13ca993e8ccb9ba9847cc330696e02839f328f7" authors = [ "Alex Crichton ", "Gonzalo Brito Gadeschi ", @@ -18,6 +18,7 @@ description = """ Rust FFI bindings to jemalloc """ edition = "2018" +rust-version = "1.71.0" [badges] codecov = { repository = "tikv/jemallocator" } @@ -32,7 +33,7 @@ libc = { version = "^0.2.8", default-features = false } cc = "^1.0.13" [features] -default = ["stats", "background_threads_runtime_support"] +default = ["background_threads_runtime_support"] profiling = [] debug = [] background_threads_runtime_support = [] diff --git a/jemallocator-global/Cargo.toml b/jemallocator-global/Cargo.toml index 31cfc9519..492f1f8fc 100644 --- a/jemallocator-global/Cargo.toml +++ b/jemallocator-global/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "tikv-jemallocator-global" # Make sure to update the version in the readme as well: -version = "0.5.0" +version = "0.6.0" authors = [ "Gonzalo Brito Gadeschi ", "The TiKV Project Developers", @@ -26,7 +26,7 @@ is-it-maintained-open-issues = { repository = "tikv/jemallocator" } maintenance = { status = "actively-developed" } [dependencies] -tikv-jemallocator = { version = "0.5.0", path = "../jemallocator", optional = true } +tikv-jemallocator = { version = "0.6.0", path = "../jemallocator", optional = true } cfg-if = "0.1" [features] @@ -38,7 +38,7 @@ force_global_jemalloc = [ "tikv-jemallocator" ] # for a particular target, white-list the target explicitly here: [target.'cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))'.dependencies] -tikv-jemallocator = { version = "0.5.0", path = "../jemallocator", optional = false } +tikv-jemallocator = { version = "0.6.0", path = "../jemallocator", optional = false } # FIXME: https://github.com/gnzlbg/jemallocator/issues/91 # [target.'cfg(target_os = "windows")'.dependencies] diff --git a/jemallocator-global/README.md b/jemallocator-global/README.md index 51f7d06af..dbf26c6c5 100644 --- a/jemallocator-global/README.md +++ b/jemallocator-global/README.md @@ -11,7 +11,7 @@ Add it as a dependency: ```toml # Cargo.toml [dependencies] -tikv-jemallocator-global = "0.5.0" +tikv-jemallocator-global = "0.6.0" ``` and `jemalloc` will be used as the `#[global_allocator]` on targets that support diff --git a/jemallocator-global/src/lib.rs b/jemallocator-global/src/lib.rs index 424404463..e6f77678b 100644 --- a/jemallocator-global/src/lib.rs +++ b/jemallocator-global/src/lib.rs @@ -5,7 +5,7 @@ //! ```toml //! # Cargo.toml //! [dependencies] -//! jemallocator-global = "0.5.0" +//! jemallocator-global = "0.6.0" //! ``` //! //! and `jemalloc` will be used as the `#[global_allocator]` on targets that diff --git a/jemallocator/Cargo.toml b/jemallocator/Cargo.toml index 58954543f..a8a46b13c 100644 --- a/jemallocator/Cargo.toml +++ b/jemallocator/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "tikv-jemallocator" # Make sure to update the version in the README as well: -version = "0.5.4" +version = "0.6.0" authors = [ "Alex Crichton ", "Gonzalo Brito Gadeschi ", @@ -32,16 +32,20 @@ maintenance = { status = "actively-developed" } test = false bench = false +[[test]] +name = "ffi" +required-features = ["stats"] + [dependencies] -tikv-jemalloc-sys = { path = "../jemalloc-sys", version = "0.5.0", default-features = false } +tikv-jemalloc-sys = { path = "../jemalloc-sys", version = "0.6.0", default-features = false } libc = { version = "^0.2.8", default-features = false } [dev-dependencies] paste = "1" -tikv-jemalloc-ctl = { path = "../jemalloc-ctl", version = "0.5.0" } +tikv-jemalloc-ctl = { path = "../jemalloc-ctl", version = "0.6.0" } [features] -default = ["stats", "background_threads_runtime_support"] +default = ["background_threads_runtime_support"] alloc_trait = [] profiling = ["tikv-jemalloc-sys/profiling"] debug = ["tikv-jemalloc-sys/debug"] diff --git a/jemallocator/README.md b/jemallocator/README.md index 7315a14c2..43e00d106 100644 --- a/jemallocator/README.md +++ b/jemallocator/README.md @@ -30,7 +30,7 @@ To use `tikv-jemallocator` add it as a dependency: [dependencies] [target.'cfg(not(target_env = "msvc"))'.dependencies] -tikv-jemallocator = "0.5" +tikv-jemallocator = "0.6" ``` To set `tikv_jemallocator::Jemalloc` as the global allocator add this to your project: