From: Yingxin Cheng Date: Wed, 21 Aug 2024 06:22:04 +0000 (+0800) Subject: crimson/os/cache: simplify lru stats data structures X-Git-Tag: v20.0.0~1175^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=344202582afc405488fa88aa7ab445e7cf237abc;p=ceph.git crimson/os/cache: simplify lru stats data structures Signed-off-by: Yingxin Cheng --- diff --git a/src/crimson/os/seastore/cache.cc b/src/crimson/os/seastore/cache.cc index 2939a0f9d8a1..243694084a5d 100644 --- a/src/crimson/os/seastore/cache.cc +++ b/src/crimson/os/seastore/cache.cc @@ -2355,15 +2355,10 @@ void Cache::LRU::get_stats( stats.lru_io.minus(last_overall_io); if (report_detail && seconds != 0) { - cache_io_stats_t _trans_io = trans_io; - _trans_io.minus(last_trans_io); - - cache_io_stats_t other_io = stats.lru_io; - other_io.minus(_trans_io); - counter_by_src_t > _trans_io_by_src_ext = trans_io_by_src_ext; counter_by_src_t trans_io_by_src; + cache_io_stats_t trans_io; for (uint8_t _src=0; _src(_src); auto& io_by_ext = get_by_src(_trans_io_by_src_ext, src); @@ -2376,7 +2371,10 @@ void Cache::LRU::get_stats( extent_io.minus(last_extent_io); trans_io_per_src.add(extent_io); } + trans_io.add(trans_io_per_src); } + cache_io_stats_t other_io = stats.lru_io; + other_io.minus(trans_io); std::ostringstream oss; oss << "\nlru total" << stats.lru_sizes; @@ -2385,7 +2383,7 @@ void Cache::LRU::get_stats( cache_size_stats_t phys_sizes; for (uint8_t _ext=0; _ext(_ext); - const auto extent_sizes = get_by_ext(sizes_by_ext, ext); + const auto& extent_sizes = get_by_ext(sizes_by_ext, ext); if (is_data_type(ext)) { data_sizes.add(extent_sizes); } else if (is_logical_metadata_type(ext)) { @@ -2399,7 +2397,7 @@ void Cache::LRU::get_stats( << "\n phys" << phys_sizes; oss << "\nlru io: trans-" - << cache_io_stats_printer_t{seconds, _trans_io} + << cache_io_stats_printer_t{seconds, trans_io} << "; other-" << cache_io_stats_printer_t{seconds, other_io}; for (uint8_t _src=0; _src sizes_by_ext; cache_io_stats_t overall_io; - cache_io_stats_t trans_io; counter_by_src_t > trans_io_by_src_ext; @@ -1459,12 +1458,12 @@ private: lru.erase(lru.s_iterator_to(extent)); current_size -= extent_length; get_by_ext(sizes_by_ext, extent.get_type()).account_out(extent_length); - overall_io.account_out(extent_length); + overall_io.out_sizes.account_in(extent_length); if (p_src) { - trans_io.account_out(extent_length); get_by_ext( get_by_src(trans_io_by_src_ext, *p_src), - extent.get_type()).account_out(extent_length); + extent.get_type() + ).out_sizes.account_in(extent_length); } intrusive_ptr_release(&extent); } @@ -1513,12 +1512,12 @@ private: // absent, add to top (back) current_size += extent_length; get_by_ext(sizes_by_ext, extent.get_type()).account_in(extent_length); - overall_io.account_in(extent_length); + overall_io.in_sizes.account_in(extent_length); if (p_src) { - trans_io.account_in(extent_length); get_by_ext( get_by_src(trans_io_by_src_ext, *p_src), - extent.get_type()).account_in(extent_length); + extent.get_type() + ).in_sizes.account_in(extent_length); } intrusive_ptr_add_ref(&extent); lru.push_back(extent); diff --git a/src/crimson/os/seastore/seastore.cc b/src/crimson/os/seastore/seastore.cc index b08e9086d6dd..9fb7fac1a3b8 100644 --- a/src/crimson/os/seastore/seastore.cc +++ b/src/crimson/os/seastore/seastore.cc @@ -710,10 +710,10 @@ seastar::future<> SeaStore::report_stats() lru_sizes_ps.size /= seastar::smp::count; lru_sizes_ps.num_extents /= seastar::smp::count; cache_io_stats_t lru_io_ps = cache_total.lru_io; - lru_io_ps.in_size /= seastar::smp::count; - lru_io_ps.in_num_extents /= seastar::smp::count; - lru_io_ps.out_size /= seastar::smp::count; - lru_io_ps.out_num_extents /= seastar::smp::count; + lru_io_ps.in_sizes.size /= seastar::smp::count; + lru_io_ps.in_sizes.num_extents /= seastar::smp::count; + lru_io_ps.out_sizes.size /= seastar::smp::count; + lru_io_ps.out_sizes.num_extents /= seastar::smp::count; INFO("cache lru: total{} {}; per-shard: total{} {}", cache_total.lru_sizes, cache_io_stats_printer_t{seconds, cache_total.lru_io}, diff --git a/src/crimson/os/seastore/seastore_types.cc b/src/crimson/os/seastore/seastore_types.cc index 5ba9f67dae82..bb3bfa5248e0 100644 --- a/src/crimson/os/seastore/seastore_types.cc +++ b/src/crimson/os/seastore/seastore_types.cc @@ -980,25 +980,6 @@ std::ostream& operator<<(std::ostream& out, const writer_stats_printer_t& p) return out; } -std::ostream& operator<<(std::ostream& out, const cache_io_stats_printer_t& p) -{ - constexpr const char* dfmt = "{:.2f}"; - out << "in(" - << fmt::format(dfmt, p.stats.get_in_mbs(p.seconds)) - << "MiB/s," - << fmt::format(dfmt, p.stats.get_in_avg_kb()) - << "KiB," - << fmt::format(dfmt, p.stats.in_num_extents/p.seconds) - << "ps) out(" - << fmt::format(dfmt, p.stats.get_out_mbs(p.seconds)) - << "MiB/s," - << fmt::format(dfmt, p.stats.get_out_avg_kb()) - << "KiB," - << fmt::format(dfmt, p.stats.out_num_extents/p.seconds) - << "ps)"; - return out; -} - std::ostream& operator<<(std::ostream& out, const cache_size_stats_t& p) { constexpr const char* dfmt = "{:.2f}"; @@ -1025,6 +1006,15 @@ std::ostream& operator<<(std::ostream& out, const cache_size_stats_printer_t& p) return out; } +std::ostream& operator<<(std::ostream& out, const cache_io_stats_printer_t& p) +{ + out << "in" + << cache_size_stats_printer_t{p.seconds, p.stats.in_sizes} + << " out" + << cache_size_stats_printer_t{p.seconds, p.stats.out_sizes}; + return out; +} + std::ostream& operator<<(std::ostream& out, const dirty_io_stats_printer_t& p) { constexpr const char* dfmt = "{:.2f}"; diff --git a/src/crimson/os/seastore/seastore_types.h b/src/crimson/os/seastore/seastore_types.h index bc6c22333158..cd6ad671c4fc 100644 --- a/src/crimson/os/seastore/seastore_types.h +++ b/src/crimson/os/seastore/seastore_types.h @@ -2557,62 +2557,6 @@ struct shard_stats_t { } }; -struct cache_io_stats_t { - uint64_t in_size = 0; - uint64_t in_num_extents = 0; - uint64_t out_size = 0; - uint64_t out_num_extents = 0; - - bool is_empty() const { - return in_num_extents == 0 && out_num_extents == 0; - } - - double get_in_mbs(double seconds) const { - return (in_size>>12)/(seconds*256); - } - - double get_in_avg_kb() const { - return (in_size>>10)/static_cast(in_num_extents); - } - - double get_out_mbs(double seconds) const { - return (out_size>>12)/(seconds*256); - } - - double get_out_avg_kb() const { - return (out_size>>10)/static_cast(out_num_extents); - } - - void account_in(extent_len_t size) { - in_size += size; - ++in_num_extents; - } - - void account_out(extent_len_t size) { - out_size += size; - ++out_num_extents; - } - - void minus(const cache_io_stats_t& o) { - in_size -= o.in_size; - in_num_extents -= o.in_num_extents; - out_size -= o.out_size; - out_num_extents -= o.out_num_extents; - } - - void add(const cache_io_stats_t& o) { - in_size += o.in_size; - in_num_extents += o.in_num_extents; - out_size += o.out_size; - out_num_extents += o.out_num_extents; - } -}; -struct cache_io_stats_printer_t { - double seconds; - const cache_io_stats_t &stats; -}; -std::ostream& operator<<(std::ostream&, const cache_io_stats_printer_t&); - struct cache_size_stats_t { uint64_t size = 0; uint64_t num_extents = 0; @@ -2658,6 +2602,30 @@ struct cache_size_stats_printer_t { }; std::ostream& operator<<(std::ostream&, const cache_size_stats_printer_t&); +struct cache_io_stats_t { + cache_size_stats_t in_sizes; + cache_size_stats_t out_sizes; + + bool is_empty() const { + return in_sizes.is_empty() && out_sizes.is_empty(); + } + + void add(const cache_io_stats_t& o) { + in_sizes.add(o.in_sizes); + out_sizes.add(o.out_sizes); + } + + void minus(const cache_io_stats_t& o) { + in_sizes.minus(o.in_sizes); + out_sizes.minus(o.out_sizes); + } +}; +struct cache_io_stats_printer_t { + double seconds; + const cache_io_stats_t& stats; +}; +std::ostream& operator<<(std::ostream&, const cache_io_stats_printer_t&); + struct dirty_io_stats_t { cache_size_stats_t in_sizes; uint64_t num_replace = 0;