From 5e4908a02d8a42cbdbb9a7876fd35621f811eb08 Mon Sep 17 00:00:00 2001 From: Ronen Friedman Date: Wed, 29 Apr 2026 04:14:23 +0000 Subject: [PATCH] crimson/osd: collect total snap-trim queueus length Periodically collect the total snap-trim queue length across all PGs. Expose it through OSDService::get_snap_trim_queue_total(). Signed-off-by: Ronen Friedman --- src/crimson/osd/osd.cc | 10 ++++++++++ src/crimson/osd/osd.h | 4 ++++ src/crimson/osd/pg_shard_manager.cc | 12 ++++++++++++ src/crimson/osd/pg_shard_manager.h | 2 ++ 4 files changed, 28 insertions(+) diff --git a/src/crimson/osd/osd.cc b/src/crimson/osd/osd.cc index 1ba7669fef6..77b8f85fb9c 100644 --- a/src/crimson/osd/osd.cc +++ b/src/crimson/osd/osd.cc @@ -69,6 +69,7 @@ SET_SUBSYS(osd); namespace { static constexpr int TICK_INTERVAL = 1; + static constexpr int TRIM_QLENGTHS_UPDATE_PERIOD = 5; } using std::make_unique; @@ -122,6 +123,15 @@ OSD::OSD(int id, uint32_t nonce, ).then([this] { update_stats(); mgrc->update_daemon_health(get_health_metrics()); + if (++trim_queue_length_countdown >= TRIM_QLENGTHS_UPDATE_PERIOD) { + trim_queue_length_countdown = 0; + std::ignore = pg_shard_manager.calc_snap_trim_queue_total( + ).then([this](uint64_t total) { + LOG_PREFIX(OSD::tick); + snap_trim_queue_total = total; + DEBUG("snap_trim_queue_total: {}", total); + }); + } tick_timer.arm( std::chrono::seconds(TICK_INTERVAL)); }); diff --git a/src/crimson/osd/osd.h b/src/crimson/osd/osd.h index 730336e6bff..703ccd3ae5e 100644 --- a/src/crimson/osd/osd.h +++ b/src/crimson/osd/osd.h @@ -127,6 +127,10 @@ class OSD final : public crimson::net::Dispatcher, std::unique_ptr heartbeat; seastar::timer tick_timer; + uint_fast16_t trim_queue_length_countdown = 0; + /// caching the total snap trim queue length across all PGs, + /// updated periodically by the tick_timer + uint64_t snap_trim_queue_total = 0; seastar::timer stats_timer; std::vector shard_stats; diff --git a/src/crimson/osd/pg_shard_manager.cc b/src/crimson/osd/pg_shard_manager.cc index e9563e63b68..6467f221a08 100644 --- a/src/crimson/osd/pg_shard_manager.cc +++ b/src/crimson/osd/pg_shard_manager.cc @@ -117,4 +117,16 @@ seastar::future<> PGShardManager::set_superblock(OSDSuperblock superblock) { }); } +seastar::future +PGShardManager::calc_snap_trim_queue_total() const +{ + uint64_t total = 0; + co_await for_each_pg([&total](const auto&, const auto &pg) { + if (pg->is_primary()) { + total += pg->get_snap_trimq_size(); + } + }); + co_return total; +} + } diff --git a/src/crimson/osd/pg_shard_manager.h b/src/crimson/osd/pg_shard_manager.h index 04ab77ee5d0..fcc16ef1ec5 100644 --- a/src/crimson/osd/pg_shard_manager.h +++ b/src/crimson/osd/pg_shard_manager.h @@ -337,6 +337,8 @@ public: }); } + seastar::future calc_snap_trim_queue_total() const; + /** * for_each_pgid * -- 2.47.3