Skip to content

Commit 08b2255

Browse files
committed
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 <[email protected]>
1 parent 2139231 commit 08b2255

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/osd/PG.cc

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -420,15 +420,7 @@ void PG::queue_recovery()
420420
dout(10) << "queue_recovery -- queuing" << dendl;
421421
recovery_queued = true;
422422
// Let cost per object be the average object size
423-
auto num_bytes = static_cast<uint64_t>(
424-
std::max<int64_t>(
425-
0, // ensure bytes is non-negative
426-
info.stats.stats.sum.num_bytes));
427-
auto num_objects = static_cast<uint64_t>(
428-
std::max<int64_t>(
429-
1, // ensure objects is non-negative and non-zero
430-
info.stats.stats.sum.num_objects));
431-
uint64_t cost_per_object = std::max<uint64_t>(num_bytes / num_objects, 1);
423+
uint64_t cost_per_object = get_average_object_size();
432424
osd->queue_for_recovery(
433425
this, cost_per_object, recovery_state.get_recovery_op_priority()
434426
);

src/osd/PG.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,19 @@ class PG : public DoutPrefixProvider,
10241024
return num_bytes;
10251025
}
10261026

1027+
uint64_t get_average_object_size() {
1028+
ceph_assert(ceph_mutex_is_locked_by_me(_lock));
1029+
auto num_bytes = static_cast<uint64_t>(
1030+
std::max<int64_t>(
1031+
0, // ensure bytes is non-negative
1032+
info.stats.stats.sum.num_bytes));
1033+
auto num_objects = static_cast<uint64_t>(
1034+
std::max<int64_t>(
1035+
1, // ensure objects is non-negative and non-zero
1036+
info.stats.stats.sum.num_objects));
1037+
return std::max<uint64_t>(num_bytes / num_objects, 1);
1038+
}
1039+
10271040
protected:
10281041

10291042
/*

0 commit comments

Comments
 (0)