]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/os/seastore/cache: add hit ratio metric
authorZhang Song <zhangsong02@qianxin.com>
Wed, 3 Sep 2025 08:06:54 +0000 (16:06 +0800)
committerXuehan Xu <xuxuehan@qianxin.com>
Fri, 31 Jul 2026 01:40:19 +0000 (09:40 +0800)
Signed-off-by: Zhang Song <zhangsong02@qianxin.com>
Signed-off-by: Xuehan Xu <xuxuehan@qianxin.com>
src/crimson/os/seastore/cache.cc
src/crimson/os/seastore/cache.h
src/crimson/os/seastore/object_data_handler.cc
src/crimson/os/seastore/transaction.h
src/crimson/os/seastore/transaction_manager.h

index 10db3a0732bf67c51b72bf49510100e51595d773..02fbe9a59b436231177475b1a82177dae0ac4c67 100644 (file)
@@ -231,6 +231,29 @@ void Cache::register_metrics(store_index_t store_index)
     }
   );
 
+  metrics.add_group("cache", {
+    sm::make_counter(
+      "write_hit_hot",
+      stats.write_hit_hot,
+      sm::description("the number of the lbc hits of data writes"),
+      {sm::label_instance("shard_store_index", std::to_string(store_index))}),
+    sm::make_counter(
+      "write_hit_cold",
+      stats.write_hit_cold,
+      sm::description("the number of the lbc misses of data writes"),
+      {sm::label_instance("shard_store_index", std::to_string(store_index))}),
+    sm::make_counter(
+      "read_hit_hot",
+      stats.read_hit_hot,
+      sm::description("the number of the lbc hits of data reads"),
+      {sm::label_instance("shard_store_index", std::to_string(store_index))}),
+    sm::make_counter(
+      "read_hit_cold",
+      stats.read_hit_cold,
+      sm::description("the number of the lbc misses of data reads"),
+      {sm::label_instance("shard_store_index", std::to_string(store_index))}),
+  });
+
   {
     /*
      * efforts discarded/committed
@@ -2181,6 +2204,9 @@ void Cache::complete_commit(
         i->set_invalid(t);
     }
   }
+
+  stats.write_hit_hot += t.write_hit_hot;
+  stats.write_hit_cold += t.write_hit_cold;
 }
 
 void Cache::init()
index df3fdf90e98b7edb5842b2c922338ea398ac1730..0b67f16ccc20a3f9d354ed49416a4b531d8b49c2 100644 (file)
@@ -761,6 +761,11 @@ public:
     return epm.is_pure_rbm();
   }
 
+  void update_read_ratio(Transaction &t) {
+    stats.read_hit_hot += t.read_hit_hot;
+    stats.read_hit_cold += t.read_hit_cold;
+  }
+
 private:
   using get_extent_ertr = base_ertr;
   template <typename T>
@@ -1868,6 +1873,11 @@ private:
     std::array<uint64_t, NUM_SRC_COMB> trans_conflicts_by_srcs;
     counter_by_src_t<uint64_t> trans_conflicts_by_unknown;
 
+    uint64_t write_hit_hot = 0;
+    uint64_t write_hit_cold = 0;
+    uint64_t read_hit_hot = 0;
+    uint64_t read_hit_cold = 0;
+
     rewrite_stats_t trim_rewrites;
     rewrite_stats_t reclaim_rewrites;
   } stats;
index 8a0d683c065d4e69820e585caa935a5b59092c28..28d1a7b0ef4a154eceacaf5ba1f669053283ee30 100644 (file)
@@ -1578,6 +1578,7 @@ ObjectDataHandler::read_ret ObjectDataHandler::read(
       read_len,
       pin_start,
       pin_len);
+
     rpins.emplace_back(
       pin, read_start_aligned, read_len_aligned,
       unalign_start_offset, read_len);
@@ -1613,11 +1614,17 @@ ObjectDataHandler::read_ret ObjectDataHandler::read(
     DEBUGT("got extent: {}", ctx.t, *maybe_indirect_extent.extent);
     auto paddr = maybe_indirect_extent.extent->get_paddr();
     all_cold &= ctx.tm.is_cold_device(paddr.get_device_id());
+
+    if (paddr.is_absolute()) {
+      ctx.tm.update_read_ratio(ctx.t, paddr.get_device_id());
+    }
+
   }
   if (!all_cold) {
     assert(ctx.tm.is_prefix_cached(prefix));
     ctx.tm.update_logical_bucket_for_read(prefix);
   }
+  ctx.tm.submit_read_ratio(ctx.t);
   co_return std::move(ret);
 }
 
index 73beb38d0f24adc4ae72232dc00fd2f14888766c..aee350944495fe882b5ad22cc7c0021e378d4cd4 100644 (file)
@@ -540,7 +540,16 @@ public:
   friend class crimson::os::seastore::SeaStore;
   friend class TransactionConflictCondition;
 
+  uint64_t write_hit_hot = 0;
+  uint64_t write_hit_cold = 0;
+  uint64_t read_hit_hot = 0;
+  uint64_t read_hit_cold = 0;
+
   void reset_preserve_handle() {
+    write_hit_hot = 0;
+    write_hit_cold = 0;
+    read_hit_hot = 0;
+    read_hit_cold = 0;
     root.reset();
     offset = 0;
     delayed_temp_offset = 0;
index 53272f5a6f43a3998e98cf2cefc2b8ee09b739f7..3c576d78b239cb15a399f74aae976ee5ee241e97 100644 (file)
@@ -245,6 +245,28 @@ public:
     }
   };
 
+  void update_hit_ratio(Transaction& t, device_id_t id) {
+    if (epm->is_cold_device(id)) {
+      t.write_hit_cold++;
+    } else {
+      t.write_hit_hot++;
+    }
+  }
+
+  void update_read_ratio(Transaction& t, device_id_t id) {
+    if (epm->is_cold_device(id)) {
+      t.read_hit_cold++;
+    } else {
+      t.read_hit_hot++;
+    }
+  }
+
+  void submit_read_ratio(Transaction& t) {
+    if (cache) {
+      cache->update_read_ratio(t);
+    }
+  }
+
   template <typename T>
   using lextent_init_func_t = std::function<void (T&)>;
   /**
@@ -1223,6 +1245,9 @@ public:
       return cut_mapping<T>(
        t, (laddr + aligned_len).checked_to_laddr(), std::move(mapping), false);
     } else {
+      if (mapping.is_linked_direct() && mapping.get_val().is_absolute()) {
+       update_hit_ratio(t, mapping.get_val().get_device_id());
+      }
       return remove(t, std::move(mapping)
       ).handle_error_interruptible(
        punch_mappings_iertr::pass_further{},