From: Yingxin Cheng Date: Tue, 27 Jul 2021 08:04:28 +0000 (+0800) Subject: crimson/os/seastore: measure cache hit ratio by src X-Git-Tag: v17.1.0~1254^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c7d58c05f4a995deb6fe3ff0e05616bc8849eaae;p=ceph.git crimson/os/seastore: measure cache hit ratio by src Remove excessive amount of cache hit/access metrics by extent type. Signed-off-by: Yingxin Cheng --- diff --git a/src/crimson/os/seastore/cache.cc b/src/crimson/os/seastore/cache.cc index 8966dc5a9e3e..9e6b26e1cfd3 100644 --- a/src/crimson/os/seastore/cache.cc +++ b/src/crimson/os/seastore/cache.cc @@ -275,73 +275,27 @@ void Cache::register_metrics() /* * cache_query: cache_access and cache_hit */ - auto register_cache_access = - [this, &labels_by_src, &labels_by_ext] - (src_t src, const sm::label_instance& src_label, - extent_types_t ext, const sm::label_instance& ext_label) { - auto m_key = std::make_pair(src, ext); - stats.cache_query[m_key] = {0, 0}; - { - metrics.add_group( - "cache", - { - sm::make_counter( - "cache_access", - stats.cache_query.find(m_key)->second.access, - sm::description("total number of cache accesses labeled by " - "transaction source and extent type"), - {src_label, ext_label} - ), - sm::make_counter( - "cache_hit", - stats.cache_query.find(m_key)->second.hit, - sm::description("total number of cache hits labeled by " - "transaction source and extent type"), - {src_label, ext_label} - ), - } - ); - } - }; - + stats.cache_query_by_src.fill({}); for (auto& [src, src_label] : labels_by_src) { - for (auto& [ext, ext_label] : labels_by_ext) { - if (ext != extent_types_t::RETIRED_PLACEHOLDER) { - register_cache_access(src, src_label, ext, ext_label); + metrics.add_group( + "cache", + { + sm::make_counter( + "cache_access", + get_counter(stats.cache_query_by_src, src).access, + sm::description("total number of cache accesses"), + {src_label} + ), + sm::make_counter( + "cache_hit", + get_counter(stats.cache_query_by_src, src).hit, + sm::description("total number of cache hits"), + {src_label} + ), } - } + ); } - metrics.add_group( - "cache", - { - sm::make_counter( - "cache_access", - [this] { - uint64_t total = 0; - for (auto& [k, v] : stats.cache_query) { - total += v.access; - } - return total; - }, - sm::description("total number of cache accesses"), - {src_label("ALL")} - ), - sm::make_counter( - "cache_hit", - [this] { - uint64_t total = 0; - for (auto& [k, v] : stats.cache_query) { - total += v.hit; - } - return total; - }, - sm::description("total number of cache hits"), - {src_label("ALL")} - ), - } - ); - { /* * efforts discarded/committed diff --git a/src/crimson/os/seastore/cache.h b/src/crimson/os/seastore/cache.h index 35d175360b2f..e4da2bd34b71 100644 --- a/src/crimson/os/seastore/cache.h +++ b/src/crimson/os/seastore/cache.h @@ -592,8 +592,8 @@ private: CachedExtent::list dirty; struct query_counters_t { - uint64_t access; - uint64_t hit; + uint64_t access = 0; + uint64_t hit = 0; }; /** @@ -662,8 +662,7 @@ private: std::unordered_map> trans_invalidated; std::array invalidated_efforts_by_src; - std::unordered_map> cache_query; + std::array cache_query_by_src; uint64_t read_transactions_successful; effort_t read_effort_successful; uint64_t dirty_bytes; @@ -758,8 +757,7 @@ private: const src_ext_t* p_metric_key) { query_counters_t* p_counters = nullptr; if (p_metric_key) { - assert(stats.cache_query.count(*p_metric_key)); - p_counters = &stats.cache_query[*p_metric_key]; + p_counters = &get_counter(stats.cache_query_by_src, p_metric_key->first); ++p_counters->access; } if (auto iter = extents.find_offset(offset);