From: Xuehan Xu Date: Wed, 16 Jul 2025 03:01:27 +0000 (+0800) Subject: crimson/os/seastore/async_cleaner: make gc_formula configurable X-Git-Tag: v21.0.0~256^2~102^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=eb406df08cb3efed7f8466eb340c82450f7f0721;p=ceph.git crimson/os/seastore/async_cleaner: make gc_formula configurable Signed-off-by: Xuehan Xu --- diff --git a/src/common/options/crimson.yaml.in b/src/common/options/crimson.yaml.in index 1d26d42c706..8f79a6bebb2 100644 --- a/src/common/options/crimson.yaml.in +++ b/src/common/options/crimson.yaml.in @@ -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 diff --git a/src/crimson/os/seastore/async_cleaner.cc b/src/crimson/os/seastore/async_cleaner.cc index 52ed20415c7..45467025b21 100644 --- a/src/crimson/os/seastore/async_cleaner.cc +++ b/src/crimson/os/seastore/async_cleaner.cc @@ -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( + "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::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"); diff --git a/src/crimson/os/seastore/async_cleaner.h b/src/crimson/os/seastore/async_cleaner.h index 7e99dda95e7..11011bdd155 100644 --- a/src/crimson/os/seastore/async_cleaner.h +++ b/src/crimson/os/seastore/async_cleaner.h @@ -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;