From cf85a005dc797d477988f19c307ad11332975f61 Mon Sep 17 00:00:00 2001 From: Ronen Friedman Date: Sat, 17 May 2025 02:17:42 -0500 Subject: [PATCH] osd/scrub: minimize calls to sysconf() in scrub_load_below_threshold() Return an 'all is OK' value if the 1min CPU load - even before being divided by the number of CPUs - is below the configured threshold. This is a very common case, and avoids the need to call sysconf() to get the number of CPUs. Signed-off-by: Ronen Friedman (cherry picked from commit 3392bc0f506768b6b3e2d65d549fa2e3b704fd6e) --- src/osd/scrubber/osd_scrub.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/osd/scrubber/osd_scrub.cc b/src/osd/scrubber/osd_scrub.cc index 6ce087ad9546f..f730198fe524a 100644 --- a/src/osd/scrubber/osd_scrub.cc +++ b/src/osd/scrubber/osd_scrub.cc @@ -306,7 +306,18 @@ std::optional OsdScrub::LoadTracker::update_load_average() bool OsdScrub::LoadTracker::scrub_load_below_threshold() const { - // allow scrub if below configured threshold + // if the 1-min load average - even before dividing by the number of CPUs - + // is below the configured threshold, scrubs are allowed. No need to call + // sysconf(). + if (loadavg_1min < conf->osd_scrub_load_threshold) { + dout(20) << fmt::format( + "loadavg {:.3f} < max {:.3f} = yes", + loadavg_1min, conf->osd_scrub_load_threshold) + << dendl; + return true; + } + + // check the load per CPU const long cpus = sysconf(_SC_NPROCESSORS_ONLN); const double loadavg_per_cpu = cpus > 0 ? loadavg_1min / cpus : loadavg_1min; if (loadavg_per_cpu < conf->osd_scrub_load_threshold) { -- 2.39.5