diff --git a/jemalloc-ctl/Cargo.toml b/jemalloc-ctl/Cargo.toml index 90a7ed8e1..5eb49e178 100644 --- a/jemalloc-ctl/Cargo.toml +++ b/jemalloc-ctl/Cargo.toml @@ -37,6 +37,7 @@ tikv-jemallocator = { path = "../jemallocator", version = "0.6.1" } default = [] stats = ["tikv-jemalloc-sys/stats"] profiling = ["tikv-jemalloc-sys/profiling"] +profiling_libunwind = ["tikv-jemalloc-sys/profiling_libunwind", "profiling"] use_std = [ "libc/use_std" ] disable_initial_exec_tls = ["tikv-jemalloc-sys/disable_initial_exec_tls"] diff --git a/jemalloc-sys/Cargo.toml b/jemalloc-sys/Cargo.toml index b245cd0e1..9fb9bc795 100644 --- a/jemalloc-sys/Cargo.toml +++ b/jemalloc-sys/Cargo.toml @@ -41,6 +41,7 @@ cc = "^1.0.13" [features] default = ["background_threads_runtime_support"] profiling = [] +profiling_libunwind = ["profiling"] debug = [] background_threads_runtime_support = [] background_threads = [ "background_threads_runtime_support" ] diff --git a/jemalloc-sys/README.md b/jemalloc-sys/README.md index df871f458..bce9ae000 100644 --- a/jemalloc-sys/README.md +++ b/jemalloc-sys/README.md @@ -45,6 +45,15 @@ This crate provides following cargo feature flags: * `libgcc` (unless --disable-prof-libgcc) * `gcc intrinsics` (unless --disable-prof-gcc) +* `profiling_libunwind` (configure `jemalloc` with `--enable-prof-libunwind`): + Force jemalloc to use `libunwind` for backtracing during heap profiling + instead of the default gcc-based unwinding, which has a + [known livelock bug](https://github.com/jemalloc/jemalloc/issues/2282) in + multi-threaded programs using `_Unwind_Backtrace`. Enables `profiling` + automatically. On Linux, this requires `libunwind-dev` (or `libunwind-devel`) + to be installed. On macOS/iOS, unwind symbols are provided by the system and + no extra library is needed. + * `stats` (configure `jemalloc` with `--enable-stats`): Enable statistics gathering functionality. See the `jemalloc`'s "`opt.stats_print`" option documentation for usage details. diff --git a/jemalloc-sys/build.rs b/jemalloc-sys/build.rs index 3841d6bb6..d7e11f4fd 100644 --- a/jemalloc-sys/build.rs +++ b/jemalloc-sys/build.rs @@ -284,6 +284,17 @@ fn main() { cmd.arg("--enable-prof"); } + if env::var("CARGO_FEATURE_PROFILING_LIBUNWIND").is_ok() { + info!("CARGO_FEATURE_PROFILING_LIBUNWIND set"); + cmd.arg("--enable-prof-libunwind"); + // On Apple platforms unwind symbols live in libSystem, and on + // Windows libunwind is not available. Everywhere else (Linux, + // FreeBSD, etc.) we need to link it explicitly. + if !target.contains("apple") && !target.contains("windows") { + println!("cargo:rustc-link-lib=unwind"); + } + } + if env::var("CARGO_FEATURE_STATS").is_ok() { info!("CARGO_FEATURE_STATS set"); cmd.arg("--enable-stats"); diff --git a/jemallocator/Cargo.toml b/jemallocator/Cargo.toml index a2d01df57..90ca38763 100644 --- a/jemallocator/Cargo.toml +++ b/jemallocator/Cargo.toml @@ -48,6 +48,7 @@ tikv-jemalloc-ctl = { path = "../jemalloc-ctl", version = "0.6.1" } default = ["background_threads_runtime_support"] alloc_trait = [] profiling = ["tikv-jemalloc-sys/profiling"] +profiling_libunwind = ["tikv-jemalloc-sys/profiling_libunwind", "profiling"] debug = ["tikv-jemalloc-sys/debug"] stats = ["tikv-jemalloc-sys/stats"] background_threads_runtime_support = ["tikv-jemalloc-sys/background_threads_runtime_support"]