From: Sridhar Seshasayee Date: Mon, 20 Nov 2023 12:46:31 +0000 (+0530) Subject: osd/PG: Add helper method to get the average size of objects in a PG. X-Git-Tag: v19.3.0~320^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=08b2255c345b0614cb1e1e4e3435910235c677cd;p=ceph.git osd/PG: Add helper method to get the average size of objects in a PG. Factor out the code in PG::queue_recovery() that determines the average object size in a PG to PG::get_average_object_size(). This is used to determine the cost of a background operation for e.g., recovery, snaptrim in case mClock scheduler is employed. Signed-off-by: Sridhar Seshasayee --- diff --git a/src/osd/PG.cc b/src/osd/PG.cc index d2f97a129a24..11af6c2b3ca8 100644 --- a/src/osd/PG.cc +++ b/src/osd/PG.cc @@ -420,15 +420,7 @@ void PG::queue_recovery() dout(10) << "queue_recovery -- queuing" << dendl; recovery_queued = true; // Let cost per object be the average object size - auto num_bytes = static_cast( - std::max( - 0, // ensure bytes is non-negative - info.stats.stats.sum.num_bytes)); - auto num_objects = static_cast( - std::max( - 1, // ensure objects is non-negative and non-zero - info.stats.stats.sum.num_objects)); - uint64_t cost_per_object = std::max(num_bytes / num_objects, 1); + uint64_t cost_per_object = get_average_object_size(); osd->queue_for_recovery( this, cost_per_object, recovery_state.get_recovery_op_priority() ); diff --git a/src/osd/PG.h b/src/osd/PG.h index 2e82e74ab012..0cfd33d484ee 100644 --- a/src/osd/PG.h +++ b/src/osd/PG.h @@ -1024,6 +1024,19 @@ public: return num_bytes; } + uint64_t get_average_object_size() { + ceph_assert(ceph_mutex_is_locked_by_me(_lock)); + auto num_bytes = static_cast( + std::max( + 0, // ensure bytes is non-negative + info.stats.stats.sum.num_bytes)); + auto num_objects = static_cast( + std::max( + 1, // ensure objects is non-negative and non-zero + info.stats.stats.sum.num_objects)); + return std::max(num_bytes / num_objects, 1); + } + protected: /*