Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 2 additions & 1 deletion jemalloc-sys/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions jemalloc-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,18 @@ impl BackgroundThreadSupport {
"`background_threads_runtime_support` not supported for `{}`",
target
);
if always_enabled {
Comment thread
BusyJay marked this conversation as resolved.
// 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 })
Expand Down
5 changes: 3 additions & 2 deletions jemalloc-sys/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion jemallocator/tests/background_thread_defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
1 change: 0 additions & 1 deletion jemallocator/tests/background_thread_enabled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading