]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/os/seastore/async_cleaner: make gc_formula configurable 64452/head
authorXuehan Xu <xuxuehan@qianxin.com>
Wed, 16 Jul 2025 03:01:27 +0000 (11:01 +0800)
committerXuehan Xu <xuxuehan@qianxin.com>
Fri, 18 Jul 2025 07:28:49 +0000 (15:28 +0800)
Signed-off-by: Xuehan Xu <xuxuehan@qianxin.com>
src/common/options/crimson.yaml.in
src/crimson/os/seastore/async_cleaner.cc
src/crimson/os/seastore/async_cleaner.h

index 1d26d42c706957fc912d8cab2ae8a6d735c43d8d..8f79a6bebb29c9b790a4838e57cc9b056dfd7ba9 100644 (file)
@@ -199,6 +199,15 @@ options:
   level: advanced
   desc: The number of generations in the cold tier if it exists.
   default: 3
+- name: seastore_segment_cleaner_gc_formula
+  type: str
+  level: advanced
+  desc: The algorithm that SegmentCleaner will use to select segments to reclaim
+  default: cost_benefit
+  enum_values:
+  - greedy
+  - cost_benefit
+  - benefit
 - name: seastore_data_delta_based_overwrite
   type: size
   level: dev
index 52ed20415c7db0cc4df757e611819aaaf7e6d85f..45467025b219005f0cd83156d6fd74dbcdde2c7e 100644 (file)
@@ -14,13 +14,6 @@ SET_SUBSYS(seastore_cleaner);
 
 namespace {
 
-enum class gc_formula_t {
-  GREEDY,
-  BENEFIT,
-  COST_BENEFIT,
-};
-constexpr auto gc_formula = gc_formula_t::COST_BENEFIT;
-
 }
 
 namespace crimson::os::seastore {
@@ -925,6 +918,19 @@ SegmentCleaner::SegmentCleaner(
     ool_segment_seq_allocator(segment_seq_allocator),
     max_rewrite_generation(max_rewrite_generation)
 {
+  LOG_PREFIX(SegmentCleaner::SegmentCleaner);
+  auto formula = crimson::common::get_conf<std::string>(
+    "seastore_segment_cleaner_gc_formula");
+  INFO("gc_formula={}, max_rewrite_generation={}",
+    formula, max_rewrite_generation);
+  if (formula == "greedy") {
+    gc_formula = gc_formula_t::GREEDY;
+  } else if (formula == "cost_benefit") {
+    gc_formula = gc_formula_t::COST_BENEFIT;
+  } else {
+    assert(formula == "benefit");
+    gc_formula = gc_formula_t::BENEFIT;
+  }
   config.validate();
 }
 
@@ -1105,11 +1111,11 @@ double SegmentCleaner::calc_gc_benefit_cost(
 {
   double util = calc_utilization(id);
   ceph_assert(util >= 0 && util < 1);
-  if constexpr (gc_formula == gc_formula_t::GREEDY) {
+  if (gc_formula == gc_formula_t::GREEDY) {
     return 1 - util;
   }
 
-  if constexpr (gc_formula == gc_formula_t::COST_BENEFIT) {
+  if (gc_formula == gc_formula_t::COST_BENEFIT) {
     if (util == 0) {
       return std::numeric_limits<double>::max();
     }
@@ -1676,13 +1682,13 @@ segment_id_t SegmentCleaner::get_next_reclaim_segment() const
   segment_id_t id = NULL_SEG_ID;
   double max_benefit_cost = 0;
   sea_time_point now_time;
-  if constexpr (gc_formula != gc_formula_t::GREEDY) {
+  if (gc_formula != gc_formula_t::GREEDY) {
     now_time = seastar::lowres_system_clock::now();
   } else {
     now_time = NULL_TIME;
   }
   sea_time_point bound_time;
-  if constexpr (gc_formula == gc_formula_t::BENEFIT) {
+  if (gc_formula == gc_formula_t::BENEFIT) {
     bound_time = segments.get_time_bound();
     if (bound_time == NULL_TIME) {
       WARN("BENEFIT -- bound_time is NULL_TIME");
index 7e99dda95e721053647c802a345c964ef80ccd70..11011bdd15579bf3537b2509942b86b240b04faf 100644 (file)
@@ -1673,6 +1673,13 @@ private:
   // TODO: drop once paddr->journal_seq_t is introduced
   SegmentSeqAllocator &ool_segment_seq_allocator;
   const rewrite_gen_t max_rewrite_generation = NULL_GENERATION;
+
+  enum class gc_formula_t {
+    GREEDY,
+    BENEFIT,
+    COST_BENEFIT,
+  };
+  gc_formula_t gc_formula;
 };
 
 class RBMCleaner;