From a8a1010365e30d70bcfbce5f087c21848b9aee37 Mon Sep 17 00:00:00 2001 From: Yingxin Cheng Date: Wed, 7 Jul 2021 09:46:32 +0800 Subject: [PATCH] crimson/os/seastore/cache: count invalidated transactions Labeled by source and extent-type. Signed-off-by: Yingxin Cheng --- src/crimson/os/seastore/cache.cc | 76 +++++++++++++++++++++++- src/crimson/os/seastore/cache.h | 15 ++++- src/crimson/os/seastore/seastore_types.h | 12 ++++ 3 files changed, 101 insertions(+), 2 deletions(-) diff --git a/src/crimson/os/seastore/cache.cc b/src/crimson/os/seastore/cache.cc index a9482f195fd..fdf88d9f27b 100644 --- a/src/crimson/os/seastore/cache.cc +++ b/src/crimson/os/seastore/cache.cc @@ -96,6 +96,22 @@ void Cache::register_metrics() {src_t::CLEANER, src_label("CLEANER")}, }; + auto ext_label = sm::label("ext"); + std::map labels_by_ext { + {extent_types_t::ROOT, ext_label("ROOT")}, + {extent_types_t::LADDR_INTERNAL, ext_label("LADDR_INTERNAL")}, + {extent_types_t::LADDR_LEAF, ext_label("LADDR_LEAF")}, + {extent_types_t::OMAP_INNER, ext_label("OMAP_INNER")}, + {extent_types_t::OMAP_LEAF, ext_label("OMAP_LEAF")}, + {extent_types_t::ONODE_BLOCK_STAGED, ext_label("ONODE_BLOCK_STAGED")}, + {extent_types_t::COLL_BLOCK, ext_label("COLL_BLOCK")}, + {extent_types_t::OBJECT_DATA_BLOCK, ext_label("OBJECT_DATA_BLOCK")}, + {extent_types_t::RETIRED_PLACEHOLDER, ext_label("RETIRED_PLACEHOLDER")}, + {extent_types_t::RBM_ALLOC_INFO, ext_label("RBM_ALLOC_INFO")}, + {extent_types_t::TEST_BLOCK, ext_label("TEST_BLOCK")}, + {extent_types_t::TEST_BLOCK_PHYSICAL, ext_label("TEST_BLOCK_PHYSICAL")} + }; + /* * trans_created */ @@ -181,6 +197,54 @@ void Cache::register_metrics() ), } ); + + /* + * trans_invalidated + */ + auto register_trans_invalidated = + [this, &labels_by_src, &labels_by_ext](src_t src, extent_types_t ext) { + auto m_key = std::make_pair(src, ext); + stats.trans_invalidated[m_key] = 0; + std::ostringstream oss_desc; + oss_desc << "total number of transaction invalidated (src=" + << src << ", ext=" + << ext << ")"; + metrics.add_group( + "cache", + { + sm::make_counter( + "trans_invalidated", + stats.trans_invalidated.find(m_key)->second, + sm::description(oss_desc.str()), + {labels_by_src.find(src)->second, + labels_by_ext.find(ext)->second} + ), + } + ); + }; + for (auto& [src, label] : labels_by_src) { + for (auto& [ext, _label] : labels_by_ext) { + register_trans_invalidated(src, ext); + } + } + + metrics.add_group( + "cache", + { + sm::make_counter( + "trans_invalidated", + [this] { + uint64_t total = 0; + for (auto& [k, v] : stats.trans_invalidated) { + total += v; + } + return total; + }, + sm::description("total number of transaction invalidated"), + {src_label("ALL")} + ), + } + ); } void Cache::add_extent(CachedExtentRef ref) @@ -283,9 +347,19 @@ void Cache::replace_extent(CachedExtentRef next, CachedExtentRef prev) } void Cache::invalidate(CachedExtent &extent) { + LOG_PREFIX(Cache::invalidate); + DEBUG("invalidate begin -- extent {}", extent); for (auto &&i: extent.transactions) { - i.t->conflicted = true; + if (!i.t->conflicted) { + DEBUGT("", i.t); + i.t->conflicted = true; + assert(!i.t->is_weak()); + auto m_key = std::make_pair(i.t->get_src(), extent.get_type()); + assert(stats.trans_invalidated.count(m_key)); + ++(stats.trans_invalidated[m_key]); + } } + DEBUG("invalidate end"); extent.state = CachedExtent::extent_state_t::INVALID; } diff --git a/src/crimson/os/seastore/cache.h b/src/crimson/os/seastore/cache.h index 897dc3d7ff3..452fff7dccb 100644 --- a/src/crimson/os/seastore/cache.h +++ b/src/crimson/os/seastore/cache.h @@ -296,9 +296,14 @@ public: return trans_intr::make_interruptible( get_extent(offset, length) ).si_then( - [&t](auto ref) mutable { + [&t, this](auto ref) { if (!ref->is_valid()) { + LOG_PREFIX(Cache::get_extent); + DEBUGT("got invalid extent: {}", t, ref); t.conflicted = true; + auto m_key = std::make_pair(t.get_src(), T::TYPE); + assert(stats.trans_invalidated.count(m_key)); + ++(stats.trans_invalidated[m_key]); return get_extent_iertr::make_ready_future>(); } else { t.add_to_read_set(ref); @@ -343,7 +348,12 @@ public: get_extent_by_type(type, offset, laddr, length) ).si_then([=, &t](CachedExtentRef ret) { if (!ret->is_valid()) { + LOG_PREFIX(Cache::get_extent_by_type); + DEBUGT("got invalid extent: {}", t, ret); t.conflicted = true; + auto m_key = std::make_pair(t.get_src(), type); + assert(stats.trans_invalidated.count(m_key)); + ++(stats.trans_invalidated[m_key]); return get_extent_ertr::make_ready_future(); } else { t.add_to_read_set(ret); @@ -572,9 +582,12 @@ private: */ CachedExtent::list dirty; + using src_ext_t = std::pair; struct { std::array trans_created_by_src; std::array trans_committed_by_src; + std::unordered_map> trans_invalidated; } stats; uint64_t& get_counter( std::array& counters_by_src, diff --git a/src/crimson/os/seastore/seastore_types.h b/src/crimson/os/seastore/seastore_types.h index 5a7a11a5f25..53316be75c8 100644 --- a/src/crimson/os/seastore/seastore_types.h +++ b/src/crimson/os/seastore/seastore_types.h @@ -713,6 +713,18 @@ struct rbm_alloc_delta_t { } +namespace std { + +template<> +struct hash<::crimson::os::seastore::extent_types_t> { + std::size_t operator()( + const ::crimson::os::seastore::extent_types_t& type) const noexcept { + return std::hash{}((uint8_t)type); + } +}; + +} + WRITE_CLASS_DENC_BOUNDED(crimson::os::seastore::seastore_meta_t) WRITE_CLASS_DENC_BOUNDED(crimson::os::seastore::paddr_t) WRITE_CLASS_DENC_BOUNDED(crimson::os::seastore::journal_seq_t) -- 2.39.5