]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/os/seastore/rbm: implement get_stat() 50555/head
authormyoungwon oh <ohmyoungwon@gmail.com>
Thu, 16 Mar 2023 06:35:59 +0000 (15:35 +0900)
committermyoungwon oh <ohmyoungwon@gmail.com>
Thu, 23 Mar 2023 07:06:05 +0000 (07:06 +0000)
Signed-off-by: Myoungwon Oh <myoungwon.oh@samsung.com>
src/crimson/os/seastore/async_cleaner.cc
src/crimson/os/seastore/async_cleaner.h
src/crimson/os/seastore/random_block_manager.h
src/crimson/os/seastore/random_block_manager/block_rb_manager.h

index 508f0dda8bbf988637677ddbebf50f33e4a6c5be..e51e499ef8c76512244646b1432e53dc31817478 100644 (file)
@@ -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")),
+  });
+}
+
 }
index cc7dfb0a1243bc44737785e2de3ad4c7f54a29b6..fb8e03bb4bcf8ae1e2c75005ebfd351b5ab7a290 100644 (file)
@@ -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;
index f94ee6e235c194fc336bdd080e96646ae7c699a2..0478f5d0e5a633efe10e2a310f4e3e45a09f73b6 100644 (file)
@@ -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<RandomBlockManager>;
index ab57589b58a0767814509cb517e5aad73041ec02..5db46b2370ed07017a4e68449cad64aaec265f00 100644 (file)
@@ -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