From 9265e8e46c3e3b71a7a665f238b3c96e0b70f36e Mon Sep 17 00:00:00 2001 From: Georgios Konstantopoulos Date: Sun, 15 Feb 2026 22:13:24 -0800 Subject: [PATCH] chore: remove reserved_cpu_cores from rayon thread pools (#22221) Co-authored-by: Amp --- crates/node/builder/src/launch/common.rs | 8 +++++--- crates/tasks/src/runtime.rs | 10 +++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/crates/node/builder/src/launch/common.rs b/crates/node/builder/src/launch/common.rs index 1cc3ed125f..9605ccae99 100644 --- a/crates/node/builder/src/launch/common.rs +++ b/crates/node/builder/src/launch/common.rs @@ -85,7 +85,7 @@ use reth_tracing::{ }; use reth_transaction_pool::TransactionPool; use reth_trie_db::ChangesetCache; -use std::{sync::Arc, thread::available_parallelism, time::Duration}; +use std::{num::NonZeroUsize, sync::Arc, thread::available_parallelism, time::Duration}; use tokio::sync::{ mpsc::{unbounded_channel, UnboundedSender}, oneshot, watch, @@ -228,8 +228,10 @@ impl LaunchContext { } // Configure the implicit global rayon pool for `par_iter` usage. - let num_threads = available_parallelism() - .map_or(0, |num| num.get().saturating_sub(reserved_cpu_cores).max(1)); + // TODO: reserved_cpu_cores is currently ignored because subtracting from thread pool + // sizes doesn't actually reserve CPU cores for other processes. + let _ = reserved_cpu_cores; + let num_threads = available_parallelism().map_or(1, NonZeroUsize::get); if let Err(err) = ThreadPoolBuilder::new() .num_threads(num_threads) .thread_name(|i| format!("rayon-{i:02}")) diff --git a/crates/tasks/src/runtime.rs b/crates/tasks/src/runtime.rs index e6c1653510..f5f8acdb91 100644 --- a/crates/tasks/src/runtime.rs +++ b/crates/tasks/src/runtime.rs @@ -18,7 +18,7 @@ use futures_util::{ Future, FutureExt, TryFutureExt, }; #[cfg(feature = "rayon")] -use std::thread::available_parallelism; +use std::{num::NonZeroUsize, thread::available_parallelism}; use std::{ pin::pin, sync::{ @@ -183,10 +183,10 @@ impl RayonConfig { /// Compute the default number of threads based on available parallelism. fn default_thread_count(&self) -> usize { - self.cpu_threads.unwrap_or_else(|| { - available_parallelism() - .map_or(1, |num| num.get().saturating_sub(self.reserved_cpu_cores).max(1)) - }) + // TODO: reserved_cpu_cores is currently ignored because subtracting from thread pool + // sizes doesn't actually reserve CPU cores for other processes. + let _ = self.reserved_cpu_cores; + self.cpu_threads.unwrap_or_else(|| available_parallelism().map_or(1, NonZeroUsize::get)) } }