diff --git a/CHANGELOG.md b/CHANGELOG.md index ddd5ea6fe..c3a853191 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Unreleased +- tikv-jemalloc-sys: the `background_threads` feature no longer puts + `background_thread:true` into the default `malloc_conf` on targets that + don't support background threads, which now include Apple targets. jemalloc + rejected the option there, its initialization never completed, and every + allocation took a global lock. - tikv-jemalloc-sys: expose the jemalloc 5.4.0 extent-allocation hook flags `EXTENT_ALLOC_FLAG_PINNED` and `EXTENT_ALLOC_FLAG_MASK`, documenting the low-bit protocol of the pointer returned from `extent_alloc_t` hooks. diff --git a/jemalloc-sys/README.md b/jemalloc-sys/README.md index b3fe497ae..7bc92a759 100644 --- a/jemalloc-sys/README.md +++ b/jemalloc-sys/README.md @@ -94,7 +94,8 @@ This crate provides following cargo feature flags: process will be disabled regardless the state in parent process. See `stats.background_thread` for related stats. `opt.background_thread` can be used to set the default option. The background thread is only available on - selected pthread-based platforms. + selected pthread-based platforms; on targets where it is not supported (Apple + targets) this feature has no effect. * `unprefixed_malloc_on_supported_platforms`: when disabled, configure `jemalloc` with `--with-jemalloc-prefix=_rjem_`. Enabling this causes symbols diff --git a/jemalloc-sys/build.rs b/jemalloc-sys/build.rs index 1cc133163..b6c4a4772 100644 --- a/jemalloc-sys/build.rs +++ b/jemalloc-sys/build.rs @@ -509,6 +509,18 @@ impl BackgroundThreadSupport { "`background_threads_runtime_support` not supported for `{}`", target ); + if always_enabled { + // jemalloc rejects `background_thread:true` on these targets + // and its initialization never completes, so don't put it in + // the default `malloc_conf`. + warning!( + "`background_threads` not supported for `{}`; not enabling background threads by default", + target + ); + } + return Some(Self { + always_enabled: false, + }); } Some(Self { always_enabled }) diff --git a/jemalloc-sys/src/env.rs b/jemalloc-sys/src/env.rs index 88703d359..ab23385c7 100644 --- a/jemalloc-sys/src/env.rs +++ b/jemalloc-sys/src/env.rs @@ -11,8 +11,9 @@ pub static UNSUPPORTED_TARGETS: &[&str] = &[ /// `jemalloc-sys` is not tested on these targets in CI: pub static UNTESTED_TARGETS: &[&str] = &["openbsd", "msvc"]; -/// `jemalloc`'s background_thread support is known not to work on these targets: -pub static NO_BG_THREAD_TARGETS: &[&str] = &["musl"]; +/// `jemalloc`'s background_thread support is known not to work on these targets +/// (jemalloc's `configure` never enables it on Apple targets): +pub static NO_BG_THREAD_TARGETS: &[&str] = &["apple"]; /// targets that don't support unprefixed `malloc` // “it was found that the `realpath` function in libc would allocate with libc malloc diff --git a/jemallocator/tests/background_thread_defaults.rs b/jemallocator/tests/background_thread_defaults.rs index 0fa7798c8..af5710641 100644 --- a/jemallocator/tests/background_thread_defaults.rs +++ b/jemallocator/tests/background_thread_defaults.rs @@ -19,5 +19,10 @@ fn background_threads_runtime_defaults() { return; } - assert_eq!(background_threads(), cfg!(feature = "background_threads")); + // `background_threads` is ignored on targets in `NO_BG_THREAD_TARGETS`. + let supported = !cfg!(target_vendor = "apple"); + assert_eq!( + background_threads(), + cfg!(feature = "background_threads") && supported + ); } diff --git a/jemallocator/tests/background_thread_enabled.rs b/jemallocator/tests/background_thread_enabled.rs index 76d286d6d..c61e706e3 100644 --- a/jemallocator/tests/background_thread_enabled.rs +++ b/jemallocator/tests/background_thread_enabled.rs @@ -2,7 +2,6 @@ //! library was compiled with background thread run-time support. #![cfg(feature = "background_threads_runtime_support")] #![cfg(not(feature = "unprefixed_malloc_on_supported_platforms"))] -#![cfg(not(target_env = "musl"))] use tikv_jemallocator::Jemalloc;