From 2c7ebfd62fd181322404fa60f217534200424e91 Mon Sep 17 00:00:00 2001 From: Yingxin Cheng Date: Wed, 3 Aug 2022 10:52:27 +0800 Subject: [PATCH] crimson/os/seastore/cache: backref related renames Signed-off-by: Yingxin Cheng --- src/crimson/os/seastore/async_cleaner.cc | 8 +- src/crimson/os/seastore/async_cleaner.h | 4 +- .../seastore/backref/btree_backref_manager.cc | 52 +++++------ .../seastore/backref/btree_backref_manager.h | 7 +- src/crimson/os/seastore/backref_manager.h | 7 +- src/crimson/os/seastore/cache.cc | 20 ++-- src/crimson/os/seastore/cache.h | 92 +++++++++---------- 7 files changed, 91 insertions(+), 99 deletions(-) diff --git a/src/crimson/os/seastore/async_cleaner.cc b/src/crimson/os/seastore/async_cleaner.cc index f25bfc43afc..35b8b0ed7e5 100644 --- a/src/crimson/os/seastore/async_cleaner.cc +++ b/src/crimson/os/seastore/async_cleaner.cc @@ -867,8 +867,8 @@ AsyncCleaner::retrieve_live_extents_ret AsyncCleaner::_retrieve_live_extents( Transaction &t, std::set< - backref_buf_entry_t, - backref_buf_entry_t::cmp_t> &&backrefs, + backref_entry_t, + backref_entry_t::cmp_t> &&backrefs, std::vector &extents) { return seastar::do_with( @@ -984,8 +984,8 @@ AsyncCleaner::gc_reclaim_space_ret AsyncCleaner::gc_reclaim_space() backref_manager.get_cached_backref_entries_in_range( reclaim_state->start_pos, reclaim_state->end_pos); std::set< - backref_buf_entry_t, - backref_buf_entry_t::cmp_t> backrefs; + backref_entry_t, + backref_entry_t::cmp_t> backrefs; for (auto &pin : pin_list) { backrefs.emplace(pin->get_key(), pin->get_val(), pin->get_length(), pin->get_type(), journal_seq_t()); diff --git a/src/crimson/os/seastore/async_cleaner.h b/src/crimson/os/seastore/async_cleaner.h index 8e9c7b33fad..a107694a55c 100644 --- a/src/crimson/os/seastore/async_cleaner.h +++ b/src/crimson/os/seastore/async_cleaner.h @@ -1160,8 +1160,8 @@ private: retrieve_live_extents_ret _retrieve_live_extents( Transaction &t, std::set< - backref_buf_entry_t, - backref_buf_entry_t::cmp_t> &&backrefs, + backref_entry_t, + backref_entry_t::cmp_t> &&backrefs, std::vector &extents); using retrieve_backref_mappings_ertr = work_ertr; diff --git a/src/crimson/os/seastore/backref/btree_backref_manager.cc b/src/crimson/os/seastore/backref/btree_backref_manager.cc index c0996272e81..2f50d13768b 100644 --- a/src/crimson/os/seastore/backref/btree_backref_manager.cc +++ b/src/crimson/os/seastore/backref/btree_backref_manager.cc @@ -353,33 +353,33 @@ BtreeBackrefManager::scan_mapped_space( ); }); }).si_then([this, &scan_visitor, c, FNAME, block_size] { - DEBUGT("scan backref cache", c.trans); - auto &backrefs = cache.get_backrefs(); - for (auto &backref : backrefs) { - if (backref.laddr == L_ADDR_NULL) { + auto &backref_entry_mset = cache.get_backref_entry_mset(); + DEBUGT("scan {} backref entries", c.trans, backref_entry_mset.size()); + for (auto &backref_entry : backref_entry_mset) { + if (backref_entry.laddr == L_ADDR_NULL) { TRACET("backref entry {}~{} {} free", c.trans, - backref.paddr, - backref.len, - backref.type); + backref_entry.paddr, + backref_entry.len, + backref_entry.type); } else { TRACET("backref entry {}~{} {}~{} {} used", c.trans, - backref.paddr, - backref.len, - backref.laddr, - backref.len, - backref.type); + backref_entry.paddr, + backref_entry.len, + backref_entry.laddr, + backref_entry.len, + backref_entry.type); } - ceph_assert(backref.paddr.is_absolute()); - ceph_assert(backref.len > 0 && - backref.len % block_size == 0); - ceph_assert(!is_backref_node(backref.type)); + ceph_assert(backref_entry.paddr.is_absolute()); + ceph_assert(backref_entry.len > 0 && + backref_entry.len % block_size == 0); + ceph_assert(!is_backref_node(backref_entry.type)); scan_visitor( - backref.paddr, - backref.len, - backref.type, - backref.laddr); + backref_entry.paddr, + backref_entry.len, + backref_entry.type, + backref_entry.laddr); } }); }); @@ -497,7 +497,7 @@ void BtreeBackrefManager::complete_transaction( } } -Cache::backref_buf_entry_query_set_t +Cache::backref_entry_query_mset_t BtreeBackrefManager::get_cached_backref_entries_in_range( paddr_t start, paddr_t end) @@ -505,13 +505,7 @@ BtreeBackrefManager::get_cached_backref_entries_in_range( return cache.get_backref_entries_in_range(start, end); } -const backref_set_t& -BtreeBackrefManager::get_cached_backrefs() -{ - return cache.get_backrefs(); -} - -Cache::backref_extent_buf_entry_query_set_t +Cache::backref_extent_entry_query_set_t BtreeBackrefManager::get_cached_backref_extents_in_range( paddr_t start, paddr_t end) @@ -529,7 +523,7 @@ void BtreeBackrefManager::cache_new_backref_extent( BtreeBackrefManager::retrieve_backref_extents_ret BtreeBackrefManager::retrieve_backref_extents( Transaction &t, - Cache::backref_extent_buf_entry_query_set_t &&backref_extents, + Cache::backref_extent_entry_query_set_t &&backref_extents, std::vector &extents) { return trans_intr::parallel_for_each( diff --git a/src/crimson/os/seastore/backref/btree_backref_manager.h b/src/crimson/os/seastore/backref/btree_backref_manager.h index 2ad34295a7e..03fa7e11521 100644 --- a/src/crimson/os/seastore/backref/btree_backref_manager.h +++ b/src/crimson/os/seastore/backref/btree_backref_manager.h @@ -97,20 +97,19 @@ public: pin_set.retire(bpin->get_range_pin()); } - Cache::backref_buf_entry_query_set_t + Cache::backref_entry_query_mset_t get_cached_backref_entries_in_range( paddr_t start, paddr_t end) final; - const backref_set_t& get_cached_backrefs() final; - Cache::backref_extent_buf_entry_query_set_t + Cache::backref_extent_entry_query_set_t get_cached_backref_extents_in_range( paddr_t start, paddr_t end) final; retrieve_backref_extents_ret retrieve_backref_extents( Transaction &t, - Cache::backref_extent_buf_entry_query_set_t &&backref_extents, + Cache::backref_extent_entry_query_set_t &&backref_extents, std::vector &extents) final; void cache_new_backref_extent(paddr_t paddr, extent_types_t type) final; diff --git a/src/crimson/os/seastore/backref_manager.h b/src/crimson/os/seastore/backref_manager.h index 1a9d07dfae6..e4d6890b7d5 100644 --- a/src/crimson/os/seastore/backref_manager.h +++ b/src/crimson/os/seastore/backref_manager.h @@ -82,13 +82,12 @@ public: Transaction &t, CachedExtentRef e) = 0; - virtual Cache::backref_buf_entry_query_set_t + virtual Cache::backref_entry_query_mset_t get_cached_backref_entries_in_range( paddr_t start, paddr_t end) = 0; - virtual const backref_set_t& get_cached_backrefs() = 0; - virtual Cache::backref_extent_buf_entry_query_set_t + virtual Cache::backref_extent_entry_query_set_t get_cached_backref_extents_in_range( paddr_t start, paddr_t end) = 0; @@ -101,7 +100,7 @@ public: retrieve_backref_extents_iertr::future<>; virtual retrieve_backref_extents_ret retrieve_backref_extents( Transaction &t, - Cache::backref_extent_buf_entry_query_set_t &&backref_extents, + Cache::backref_extent_entry_query_set_t &&backref_extents, std::vector &extents) = 0; virtual void cache_new_backref_extent(paddr_t paddr, extent_types_t type) = 0; diff --git a/src/crimson/os/seastore/cache.cc b/src/crimson/os/seastore/cache.cc index f4d55d41a66..e1678dc7f09 100644 --- a/src/crimson/os/seastore/cache.cc +++ b/src/crimson/os/seastore/cache.cc @@ -28,8 +28,8 @@ SET_SUBSYS(seastore_cache); namespace crimson::os::seastore { -std::ostream &operator<<(std::ostream &out, const backref_buf_entry_t &ent) { - return out << "backref_buf_entry_t{" +std::ostream &operator<<(std::ostream &out, const backref_entry_t &ent) { + return out << "backref_entry_t{" << ent.paddr << "~" << ent.len << ", " << "laddr: " << ent.laddr << ", " << "type: " << ent.type << ", " @@ -1385,7 +1385,7 @@ record_t Cache::prepare_record( } void Cache::backref_batch_update( - std::vector &&list, + std::vector &&list, const journal_seq_t &seq) { LOG_PREFIX(Cache::backref_batch_update); @@ -1393,7 +1393,7 @@ void Cache::backref_batch_update( ceph_assert(seq != JOURNAL_SEQ_NULL); for (auto &ent : list) { - backref_set.insert(*ent); + backref_entry_mset.insert(*ent); } auto iter = backref_entryrefs_by_seq.find(seq); @@ -1417,7 +1417,7 @@ void Cache::complete_commit( SUBTRACET(seastore_t, "final_block_start={}, start_seq={}", t, final_block_start, start_seq); - std::vector backref_list; + std::vector backref_list; t.for_each_fresh_block([&](const CachedExtentRef &i) { bool is_inline = false; if (i->is_inline()) { @@ -1444,7 +1444,7 @@ void Cache::complete_commit( i->get_paddr(), i->get_length()); backref_list.emplace_back( - std::make_unique( + std::make_unique( i->get_paddr(), i->is_logical() ? i->cast()->get_laddr() @@ -1514,7 +1514,7 @@ void Cache::complete_commit( i->get_paddr(), i->get_length()); backref_list.emplace_back( - std::make_unique( + std::make_unique( i->get_paddr(), L_ADDR_NULL, i->get_length(), @@ -1547,7 +1547,7 @@ void Cache::complete_commit( i->get_paddr(), i->get_length()); backref_list.emplace_back( - std::make_unique( + std::make_unique( i->get_paddr(), i->cast()->get_laddr(), i->get_length(), @@ -1651,7 +1651,7 @@ Cache::replay_delta( alloc_delta_t alloc_delta; decode(alloc_delta, delta.bl); - std::vector backref_list; + std::vector backref_list; for (auto &alloc_blk : alloc_delta.alloc_blk_ranges) { if (alloc_blk.paddr.is_relative()) { assert(alloc_blk.paddr.is_record_relative()); @@ -1660,7 +1660,7 @@ Cache::replay_delta( DEBUG("replay alloc_blk {}~{} {}, journal_seq: {}", alloc_blk.paddr, alloc_blk.len, alloc_blk.laddr, journal_seq); backref_list.emplace_back( - std::make_unique( + std::make_unique( alloc_blk.paddr, alloc_blk.laddr, alloc_blk.len, diff --git a/src/crimson/os/seastore/cache.h b/src/crimson/os/seastore/cache.h index a06aa0bde6b..4a4a280bcde 100644 --- a/src/crimson/os/seastore/cache.h +++ b/src/crimson/os/seastore/cache.h @@ -28,8 +28,8 @@ namespace crimson::os::seastore { class BackrefManager; class AsyncCleaner; -struct backref_buf_entry_t { - backref_buf_entry_t( +struct backref_entry_t { + backref_entry_t( const paddr_t paddr, const laddr_t laddr, const extent_len_t len, @@ -41,7 +41,7 @@ struct backref_buf_entry_t { type(type), seq(seq) {} - backref_buf_entry_t(alloc_blk_t alloc_blk) + backref_entry_t(alloc_blk_t alloc_blk) : paddr(alloc_blk.paddr), laddr(alloc_blk.laddr), len(alloc_blk.len), @@ -54,18 +54,18 @@ struct backref_buf_entry_t { extent_types_t::ROOT; journal_seq_t seq; friend bool operator< ( - const backref_buf_entry_t &l, - const backref_buf_entry_t &r) { + const backref_entry_t &l, + const backref_entry_t &r) { return l.paddr < r.paddr; } friend bool operator> ( - const backref_buf_entry_t &l, - const backref_buf_entry_t &r) { + const backref_entry_t &l, + const backref_entry_t &r) { return l.paddr > r.paddr; } friend bool operator== ( - const backref_buf_entry_t &l, - const backref_buf_entry_t &r) { + const backref_entry_t &l, + const backref_entry_t &r) { return l.paddr == r.paddr; } @@ -75,35 +75,35 @@ struct backref_buf_entry_t { boost::intrusive::auto_unlink>>; set_hook_t backref_set_hook; using backref_set_member_options = boost::intrusive::member_hook< - backref_buf_entry_t, + backref_entry_t, set_hook_t, - &backref_buf_entry_t::backref_set_hook>; - using set_t = boost::intrusive::multiset< - backref_buf_entry_t, + &backref_entry_t::backref_set_hook>; + using multiset_t = boost::intrusive::multiset< + backref_entry_t, backref_set_member_options, boost::intrusive::constant_time_size>; struct cmp_t { using is_transparent = paddr_t; bool operator()( - const backref_buf_entry_t &l, - const backref_buf_entry_t &r) const { + const backref_entry_t &l, + const backref_entry_t &r) const { return l.paddr < r.paddr; } - bool operator()(const paddr_t l, const backref_buf_entry_t &r) const { + bool operator()(const paddr_t l, const backref_entry_t &r) const { return l < r.paddr; } - bool operator()(const backref_buf_entry_t &l, const paddr_t r) const { + bool operator()(const backref_entry_t &l, const paddr_t r) const { return l.paddr < r; } }; }; -std::ostream &operator<<(std::ostream &out, const backref_buf_entry_t &ent); +std::ostream &operator<<(std::ostream &out, const backref_entry_t &ent); -using backref_buf_entry_ref = std::unique_ptr; -using backref_set_t = backref_buf_entry_t::set_t; -using backref_entry_refs_t = std::vector; +using backref_entry_ref = std::unique_ptr; +using backref_entry_mset_t = backref_entry_t::multiset_t; +using backref_entry_refs_t = std::vector; using backref_entryrefs_by_seq_t = std::map; /** @@ -535,23 +535,23 @@ private: } backref_entryrefs_by_seq_t backref_entryrefs_by_seq; - backref_set_t backref_set; // in cache backrefs indexed by paddr_t + backref_entry_mset_t backref_entry_mset; - using backref_buf_entry_query_set_t = + using backref_entry_query_mset_t = std::multiset< - backref_buf_entry_t, - backref_buf_entry_t::cmp_t>; + backref_entry_t, + backref_entry_t::cmp_t>; - backref_buf_entry_query_set_t get_backref_entries_in_range( + backref_entry_query_mset_t get_backref_entries_in_range( paddr_t start, paddr_t end) { - auto start_iter = backref_set.lower_bound( + auto start_iter = backref_entry_mset.lower_bound( start, - backref_buf_entry_t::cmp_t()); - auto end_iter = backref_set.lower_bound( + backref_entry_t::cmp_t()); + auto end_iter = backref_entry_mset.lower_bound( end, - backref_buf_entry_t::cmp_t()); - backref_buf_entry_query_set_t res; + backref_entry_t::cmp_t()); + backref_entry_query_mset_t res; for (auto it = start_iter; it != end_iter; it++) { @@ -560,8 +560,8 @@ private: return res; } - const backref_set_t& get_backrefs() { - return backref_set; + const backref_entry_mset_t& get_backref_entry_mset() { + return backref_entry_mset; } backref_entryrefs_by_seq_t& get_backref_entryrefs_by_seq() { @@ -902,8 +902,8 @@ public: /// Dump live extents void dump_contents(); - struct backref_extent_buf_entry_t { - backref_extent_buf_entry_t( + struct backref_extent_entry_t { + backref_extent_entry_t( paddr_t paddr, extent_types_t type) : paddr(paddr), type(type) {} @@ -912,17 +912,17 @@ public: struct cmp_t { using is_transparent = paddr_t; bool operator()( - const backref_extent_buf_entry_t &l, - const backref_extent_buf_entry_t &r) const { + const backref_extent_entry_t &l, + const backref_extent_entry_t &r) const { return l.paddr < r.paddr; } bool operator()( const paddr_t &l, - const backref_extent_buf_entry_t &r) const { + const backref_extent_entry_t &r) const { return l < r.paddr; } bool operator()( - const backref_extent_buf_entry_t &l, + const backref_extent_entry_t &l, const paddr_t &r) const { return l.paddr < r; } @@ -975,11 +975,11 @@ private: */ CachedExtent::list dirty; - using backref_extent_buf_entry_query_set_t = + using backref_extent_entry_query_set_t = std::set< - backref_extent_buf_entry_t, - backref_extent_buf_entry_t::cmp_t>; - backref_extent_buf_entry_query_set_t backref_extents; + backref_extent_entry_t, + backref_extent_entry_t::cmp_t>; + backref_extent_entry_query_set_t backref_extents; void add_backref_extent(paddr_t paddr, extent_types_t type) { assert(!paddr.is_relative()); @@ -994,12 +994,12 @@ private: backref_extents.erase(iter); } - backref_extent_buf_entry_query_set_t get_backref_extents_in_range( + backref_extent_entry_query_set_t get_backref_extents_in_range( paddr_t start, paddr_t end) { auto start_iter = backref_extents.lower_bound(start); auto end_iter = backref_extents.upper_bound(end); - backref_extent_buf_entry_query_set_t res; + backref_extent_entry_query_set_t res; res.insert(start_iter, end_iter); return res; } @@ -1250,7 +1250,7 @@ private: } void backref_batch_update( - std::vector &&, + std::vector &&, const journal_seq_t &); /// Add extent to extents handling dirty and refcounting -- 2.39.5