Join jemalloc background threads prior to exit.

Co-authored-by: Jade Ellis <jade@ellis.link>
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2025-04-22 06:29:30 +00:00 committed by magmaus3
parent d9d4e6a67a
commit 39938fa7e6
Signed by: magmaus3
GPG key ID: C8AABFABFA2FAF66
2 changed files with 16 additions and 7 deletions

View file

@ -274,6 +274,10 @@ pub fn set_dirty_decay<I: Into<Option<usize>>>(arena: I, decay_ms: isize) -> Res
} }
} }
pub fn background_thread_enable(enable: bool) -> Result<bool> {
set::<u8>(&mallctl!("background_thread"), enable.into()).map(is_nonzero!())
}
#[inline] #[inline]
#[must_use] #[must_use]
pub fn is_affine_arena() -> bool { is_percpu_arena() || is_phycpu_arena() } pub fn is_affine_arena() -> bool { is_percpu_arena() || is_phycpu_arena() }

View file

@ -98,12 +98,7 @@ pub(super) fn shutdown(server: &Arc<Server>, runtime: tokio::runtime::Runtime) {
Level::INFO Level::INFO
}; };
debug!( wait_shutdown(server, runtime);
timeout = ?SHUTDOWN_TIMEOUT,
"Waiting for runtime..."
);
runtime.shutdown_timeout(SHUTDOWN_TIMEOUT);
let runtime_metrics = server.server.metrics.runtime_interval().unwrap_or_default(); let runtime_metrics = server.server.metrics.runtime_interval().unwrap_or_default();
event!(LEVEL, ?runtime_metrics, "Final runtime metrics"); event!(LEVEL, ?runtime_metrics, "Final runtime metrics");
@ -111,13 +106,23 @@ pub(super) fn shutdown(server: &Arc<Server>, runtime: tokio::runtime::Runtime) {
#[cfg(not(tokio_unstable))] #[cfg(not(tokio_unstable))]
#[tracing::instrument(name = "stop", level = "info", skip_all)] #[tracing::instrument(name = "stop", level = "info", skip_all)]
pub(super) fn shutdown(_server: &Arc<Server>, runtime: tokio::runtime::Runtime) { pub(super) fn shutdown(server: &Arc<Server>, runtime: tokio::runtime::Runtime) {
wait_shutdown(server, runtime);
}
fn wait_shutdown(_server: &Arc<Server>, runtime: tokio::runtime::Runtime) {
debug!( debug!(
timeout = ?SHUTDOWN_TIMEOUT, timeout = ?SHUTDOWN_TIMEOUT,
"Waiting for runtime..." "Waiting for runtime..."
); );
runtime.shutdown_timeout(SHUTDOWN_TIMEOUT); runtime.shutdown_timeout(SHUTDOWN_TIMEOUT);
// Join any jemalloc threads so they don't appear in use at exit.
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))]
conduwuit_core::alloc::je::background_thread_enable(false)
.log_debug_err()
.ok();
} }
#[tracing::instrument( #[tracing::instrument(