From: Ronen Friedman Date: Sun, 10 Sep 2023 17:55:59 +0000 (-0500) Subject: osd/scrub: moving the resources counters code into a separate file X-Git-Tag: v19.0.0~438^2~18 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=de273640fbc05df3044f3f20c0d0bd39347e12b5;p=ceph.git osd/scrub: moving the resources counters code into a separate file No code changes in this commit. Signed-off-by: Ronen Friedman --- diff --git a/src/osd/CMakeLists.txt b/src/osd/CMakeLists.txt index ed13eb0a1379..75f91fb53742 100644 --- a/src/osd/CMakeLists.txt +++ b/src/osd/CMakeLists.txt @@ -26,6 +26,7 @@ set(osd_srcs scrubber/osd_scrub_sched.cc scrubber/PrimaryLogScrub.cc scrubber/scrub_machine.cc + scrubber/scrub_resources.cc scrubber/ScrubStore.cc scrubber/scrub_backend.cc Watch.cc diff --git a/src/osd/scrubber/osd_scrub_sched.cc b/src/osd/scrubber/osd_scrub_sched.cc index 674bd8913a27..64b44e0dc323 100644 --- a/src/osd/scrubber/osd_scrub_sched.cc +++ b/src/osd/scrubber/osd_scrub_sched.cc @@ -600,83 +600,6 @@ ScrubQueue::ScrubQContainer ScrubQueue::list_registered_jobs() const return all_jobs; } -// ////////////////////////////////////////////////////////////////////////// // -// ScrubQueue - scrub resource management - -bool ScrubQueue::can_inc_scrubs() const -{ - // consider removing the lock here. Caller already handles delayed - // inc_scrubs_local() failures - std::lock_guard lck{resource_lock}; - - if (scrubs_local + scrubs_remote < conf()->osd_max_scrubs) { - return true; - } - - dout(20) << " == false. " << scrubs_local << " local + " << scrubs_remote - << " remote >= max " << conf()->osd_max_scrubs << dendl; - return false; -} - -bool ScrubQueue::inc_scrubs_local() -{ - std::lock_guard lck{resource_lock}; - - if (scrubs_local + scrubs_remote < conf()->osd_max_scrubs) { - ++scrubs_local; - return true; - } - - dout(20) << ": " << scrubs_local << " local + " << scrubs_remote - << " remote >= max " << conf()->osd_max_scrubs << dendl; - return false; -} - -void ScrubQueue::dec_scrubs_local() -{ - std::lock_guard lck{resource_lock}; - dout(20) << ": " << scrubs_local << " -> " << (scrubs_local - 1) << " (max " - << conf()->osd_max_scrubs << ", remote " << scrubs_remote << ")" - << dendl; - - --scrubs_local; - ceph_assert(scrubs_local >= 0); -} - -bool ScrubQueue::inc_scrubs_remote() -{ - std::lock_guard lck{resource_lock}; - - if (scrubs_local + scrubs_remote < conf()->osd_max_scrubs) { - dout(20) << ": " << scrubs_remote << " -> " << (scrubs_remote + 1) - << " (max " << conf()->osd_max_scrubs << ", local " - << scrubs_local << ")" << dendl; - ++scrubs_remote; - return true; - } - - dout(20) << ": " << scrubs_local << " local + " << scrubs_remote - << " remote >= max " << conf()->osd_max_scrubs << dendl; - return false; -} - -void ScrubQueue::dec_scrubs_remote() -{ - std::lock_guard lck{resource_lock}; - dout(20) << ": " << scrubs_remote << " -> " << (scrubs_remote - 1) << " (max " - << conf()->osd_max_scrubs << ", local " << scrubs_local << ")" - << dendl; - --scrubs_remote; - ceph_assert(scrubs_remote >= 0); -} - -void ScrubQueue::dump_scrub_reservations(ceph::Formatter* f) const -{ - std::lock_guard lck{resource_lock}; - f->dump_int("scrubs_local", scrubs_local); - f->dump_int("scrubs_remote", scrubs_remote); - f->dump_int("osd_max_scrubs", conf()->osd_max_scrubs); -} void ScrubQueue::clear_pg_scrub_blocked(spg_t blocked_pg) { diff --git a/src/osd/scrubber/scrub_resources.cc b/src/osd/scrubber/scrub_resources.cc new file mode 100644 index 000000000000..a324234721be --- /dev/null +++ b/src/osd/scrubber/scrub_resources.cc @@ -0,0 +1,91 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include "./osd_scrub_sched.h" + + +// ////////////////////////////////////////////////////////////////////////// // +// ScrubQueue - scrub resource management + +#define dout_subsys ceph_subsys_osd +#undef dout_context +#define dout_context (cct) +#undef dout_prefix +#define dout_prefix \ + *_dout << "osd." << osd_service.get_nodeid() << " scrub-queue::" << __func__ \ + << " " + +bool ScrubQueue::can_inc_scrubs() const +{ + // consider removing the lock here. Caller already handles delayed + // inc_scrubs_local() failures + std::lock_guard lck{resource_lock}; + + if (scrubs_local + scrubs_remote < conf()->osd_max_scrubs) { + return true; + } + + dout(20) << " == false. " << scrubs_local << " local + " << scrubs_remote + << " remote >= max " << conf()->osd_max_scrubs << dendl; + return false; +} + +bool ScrubQueue::inc_scrubs_local() +{ + std::lock_guard lck{resource_lock}; + + if (scrubs_local + scrubs_remote < conf()->osd_max_scrubs) { + ++scrubs_local; + return true; + } + + dout(20) << ": " << scrubs_local << " local + " << scrubs_remote + << " remote >= max " << conf()->osd_max_scrubs << dendl; + return false; +} + +void ScrubQueue::dec_scrubs_local() +{ + std::lock_guard lck{resource_lock}; + dout(20) << ": " << scrubs_local << " -> " << (scrubs_local - 1) << " (max " + << conf()->osd_max_scrubs << ", remote " << scrubs_remote << ")" + << dendl; + + --scrubs_local; + ceph_assert(scrubs_local >= 0); +} + +bool ScrubQueue::inc_scrubs_remote() +{ + std::lock_guard lck{resource_lock}; + + if (scrubs_local + scrubs_remote < conf()->osd_max_scrubs) { + dout(20) << ": " << scrubs_remote << " -> " << (scrubs_remote + 1) + << " (max " << conf()->osd_max_scrubs << ", local " + << scrubs_local << ")" << dendl; + ++scrubs_remote; + return true; + } + + dout(20) << ": " << scrubs_local << " local + " << scrubs_remote + << " remote >= max " << conf()->osd_max_scrubs << dendl; + return false; +} + +void ScrubQueue::dec_scrubs_remote() +{ + std::lock_guard lck{resource_lock}; + dout(20) << ": " << scrubs_remote << " -> " << (scrubs_remote - 1) << " (max " + << conf()->osd_max_scrubs << ", local " << scrubs_local << ")" + << dendl; + --scrubs_remote; + ceph_assert(scrubs_remote >= 0); +} + +void ScrubQueue::dump_scrub_reservations(ceph::Formatter* f) const +{ + std::lock_guard lck{resource_lock}; + f->dump_int("scrubs_local", scrubs_local); + f->dump_int("scrubs_remote", scrubs_remote); + f->dump_int("osd_max_scrubs", conf()->osd_max_scrubs); +}