mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-30 00:47:13 +00:00
perf(runtime): mark Tokio threads as mimalloc threadpool (#6646)
Upgrade rustfs-mimalloc and rustfs-mimalloc-sys to 0.5.1, then call the new safe wrapper from Tokio worker thread startup so mimalloc can treat runtime threads as threadpool workers. Keep the hint no-op on Windows, matching RustFS allocator platform boundaries. Co-authored-by: heihutu <heihutu@gmail.com>
This commit is contained in:
@@ -30,6 +30,12 @@ fn compute_default_thread_stack_size() -> usize {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn mark_allocator_threadpool_thread() {
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
rustfs_mimalloc::set_current_thread_in_threadpool();
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -160,15 +166,19 @@ pub fn tokio_runtime_builder() -> tokio::runtime::Builder {
|
||||
rustfs_utils::get_env_usize(rustfs_config::ENV_MAX_IO_EVENTS_PER_TICK, rustfs_config::DEFAULT_MAX_IO_EVENTS_PER_TICK);
|
||||
builder.enable_all().max_io_events_per_tick(max_io_events_per_tick);
|
||||
|
||||
// Optional: Simple log of thread start/stop
|
||||
if print_tokio_thread_enable() {
|
||||
builder
|
||||
.on_thread_start(|| {
|
||||
tracing::trace!(thread_id = ?std::thread::current().id(), "worker thread started");
|
||||
})
|
||||
.on_thread_stop(|| {
|
||||
tracing::trace!(thread_id = ?std::thread::current().id(), "worker thread stopped");
|
||||
});
|
||||
let print_tokio_threads = print_tokio_thread_enable();
|
||||
builder.on_thread_start(move || {
|
||||
mark_allocator_threadpool_thread();
|
||||
if print_tokio_threads {
|
||||
tracing::trace!(thread_id = ?std::thread::current().id(), "worker thread started");
|
||||
}
|
||||
});
|
||||
|
||||
// Optional: Simple log of thread stop
|
||||
if print_tokio_threads {
|
||||
builder.on_thread_stop(|| {
|
||||
tracing::trace!(thread_id = ?std::thread::current().id(), "worker thread stopped");
|
||||
});
|
||||
}
|
||||
if !rustfs_obs::is_production_environment() {
|
||||
println!(
|
||||
|
||||
Reference in New Issue
Block a user