From: Ronen Friedman Date: Sat, 17 May 2025 07:17:42 +0000 (-0500) Subject: osd/scrub: minimize calls to sysconf() in scrub_load_below_threshold() X-Git-Tag: v20.1.0~289^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F63349%2Fhead;p=ceph.git 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) --- diff --git a/src/osd/scrubber/osd_scrub.cc b/src/osd/scrubber/osd_scrub.cc index 6ce087ad9546..f730198fe524 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) {