From 3c21cff441739a93d9936ed0d7b4fdc4a32ca51c Mon Sep 17 00:00:00 2001 From: myoungwon oh Date: Thu, 16 Mar 2023 15:35:59 +0900 Subject: [PATCH] crimson/os/seastore/rbm: implement get_stat() Signed-off-by: Myoungwon Oh --- src/crimson/os/seastore/async_cleaner.cc | 20 +++++++++++++ src/crimson/os/seastore/async_cleaner.h | 29 +++++++++++++++++-- .../os/seastore/random_block_manager.h | 1 + .../random_block_manager/block_rb_manager.h | 4 +++ 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/crimson/os/seastore/async_cleaner.cc b/src/crimson/os/seastore/async_cleaner.cc index 508f0dda8bbf9..e51e499ef8c76 100644 --- a/src/crimson/os/seastore/async_cleaner.cc +++ b/src/crimson/os/seastore/async_cleaner.cc @@ -1628,6 +1628,7 @@ void RBMCleaner::mark_space_used( if (addr.get_device_id() == rbm->get_device_id()) { if (rbm->get_start() <= addr) { INFO("allocate addr: {} len: {}", addr, len); + stats.used_bytes += len; rbm->mark_space_used(addr, len); } return; @@ -1646,6 +1647,8 @@ void RBMCleaner::mark_space_free( if (addr.get_device_id() == rbm->get_device_id()) { if (rbm->get_start() <= addr) { INFO("free addr: {} len: {}", addr, len); + ceph_assert(stats.used_bytes >= len); + stats.used_bytes -= len; rbm->mark_space_free(addr, len); } return; @@ -1690,6 +1693,7 @@ RBMCleaner::clean_space_ret RBMCleaner::clean_space() RBMCleaner::mount_ret RBMCleaner::mount() { stats = {}; + register_metrics(); return seastar::do_with( rb_group->get_rb_managers(), [](auto &rbs) { @@ -1783,4 +1787,20 @@ bool RBMCleaner::equals(const RBMSpaceTracker &_other) const return all_match; } +void RBMCleaner::register_metrics() +{ + namespace sm = seastar::metrics; + + metrics.add_group("rbm_cleaner", { + sm::make_counter("total_bytes", + [this] { return get_total_bytes(); }, + sm::description("the size of the space")), + sm::make_counter("available_bytes", + [this] { return get_total_bytes() - get_journal_bytes() - stats.used_bytes; }, + sm::description("the size of the space is available")), + sm::make_counter("used_bytes", stats.used_bytes, + sm::description("the size of the space occupied by live extents")), + }); +} + } diff --git a/src/crimson/os/seastore/async_cleaner.h b/src/crimson/os/seastore/async_cleaner.h index cc7dfb0a1243b..fb8e03bb4bcf8 100644 --- a/src/crimson/os/seastore/async_cleaner.h +++ b/src/crimson/os/seastore/async_cleaner.h @@ -1634,7 +1634,10 @@ public: store_statfs_t get_stat() const final { store_statfs_t st; - // TODO + st.total = get_total_bytes(); + st.available = get_total_bytes() - get_journal_bytes() - stats.used_bytes; + st.allocated = get_journal_bytes() + stats.used_bytes; + st.data_stored = get_journal_bytes() + stats.used_bytes; return st; } @@ -1687,7 +1690,27 @@ public: paddr_t alloc_paddr(extent_len_t length) { // TODO: implement allocation strategy (dirty metadata and multiple devices) auto rbs = rb_group->get_rb_managers(); - return rbs[0]->alloc_extent(length); + auto paddr = rbs[0]->alloc_extent(length); + stats.used_bytes += length; + return paddr; + } + + size_t get_total_bytes() const { + auto rbs = rb_group->get_rb_managers(); + size_t total = 0; + for (auto p : rbs) { + total += p->get_device()->get_available_size(); + } + return total; + } + + size_t get_journal_bytes() const { + auto rbs = rb_group->get_rb_managers(); + size_t total = 0; + for (auto p : rbs) { + total += p->get_journal_size(); + } + return total; } // Testing interfaces @@ -1722,6 +1745,8 @@ private: */ uint64_t projected_used_bytes = 0; } stats; + seastar::metrics::metric_group metrics; + void register_metrics(); ExtentCallbackInterface *extent_callback = nullptr; BackgroundListener *background_callback = nullptr; diff --git a/src/crimson/os/seastore/random_block_manager.h b/src/crimson/os/seastore/random_block_manager.h index f94ee6e235c19..0478f5d0e5a63 100644 --- a/src/crimson/os/seastore/random_block_manager.h +++ b/src/crimson/os/seastore/random_block_manager.h @@ -105,6 +105,7 @@ public: virtual Device* get_device() = 0; virtual paddr_t get_start() = 0; virtual rbm_extent_state_t get_extent_state(paddr_t addr, size_t size) = 0; + virtual size_t get_journal_size() const = 0; virtual ~RandomBlockManager() {} }; using RandomBlockManagerRef = std::unique_ptr; diff --git a/src/crimson/os/seastore/random_block_manager/block_rb_manager.h b/src/crimson/os/seastore/random_block_manager/block_rb_manager.h index ab57589b58a07..5db46b2370ed0 100644 --- a/src/crimson/os/seastore/random_block_manager/block_rb_manager.h +++ b/src/crimson/os/seastore/random_block_manager/block_rb_manager.h @@ -123,6 +123,10 @@ public: return allocator->get_extent_state(addr, size); } + size_t get_journal_size() const final { + return device->get_journal_size(); + } + private: /* * this contains the number of bitmap blocks, free blocks and -- 2.39.5