]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osd/PG: Add helper method to get the average size of objects in a PG.
authorSridhar Seshasayee <sseshasa@redhat.com>
Mon, 20 Nov 2023 12:46:31 +0000 (18:16 +0530)
committerSridhar Seshasayee <sseshasa@redhat.com>
Tue, 2 Jan 2024 07:44:21 +0000 (13:14 +0530)
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 <sseshasa@redhat.com>
(cherry picked from commit 08b2255c345b0614cb1e1e4e3435910235c677cd)

src/osd/PG.cc
src/osd/PG.h

index fa49038ed27e620e32a1e2ae73490e7519b1d9de..245aa8d0079ae54bd3ef7ebdb4ab7781438ba3a8 100644 (file)
@@ -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<uint64_t>(
-      std::max<int64_t>(
-       0, // ensure bytes is non-negative
-       info.stats.stats.sum.num_bytes));
-    auto num_objects = static_cast<uint64_t>(
-      std::max<int64_t>(
-       1, // ensure objects is non-negative and non-zero
-       info.stats.stats.sum.num_objects));
-    uint64_t cost_per_object = std::max<uint64_t>(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()
     );
index 88c893b350db393736937ba6764b1ef181e7479c..2f8b590617a169e5bd4ae61e09b6f9e014a2d2a7 100644 (file)
@@ -1019,6 +1019,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<uint64_t>(
+      std::max<int64_t>(
+        0, // ensure bytes is non-negative
+        info.stats.stats.sum.num_bytes));
+    auto num_objects = static_cast<uint64_t>(
+      std::max<int64_t>(
+        1, // ensure objects is non-negative and non-zero
+        info.stats.stats.sum.num_objects));
+    return std::max<uint64_t>(num_bytes / num_objects, 1);
+  }
+
 protected:
 
   /*