From: myoungwon oh Date: Thu, 16 Mar 2023 06:35:59 +0000 (+0900) Subject: crimson/os/seastore/rbm: implement get_stat() X-Git-Tag: v19.0.0~1519^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F50555%2Fhead;p=ceph.git crimson/os/seastore/rbm: implement get_stat() Signed-off-by: Myoungwon Oh --- diff --git a/src/crimson/os/seastore/async_cleaner.cc b/src/crimson/os/seastore/async_cleaner.cc index 508f0dda8bbf..e51e499ef8c7 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 cc7dfb0a1243..fb8e03bb4bcf 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 f94ee6e235c1..0478f5d0e5a6 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 ab57589b58a0..5db46b2370ed 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