From be00314b93c4a1334f53596d99bf32fa8e43dda3 Mon Sep 17 00:00:00 2001 From: Yingxin Cheng Date: Wed, 18 Dec 2024 17:03:37 +0800 Subject: [PATCH] crimson/os/seastore/cache: rework backref_batch_update() Leverage the fact that seq won't go backwards. Signed-off-by: Yingxin Cheng --- src/crimson/os/seastore/cache.cc | 44 +++++++++++++++++++------------- src/crimson/os/seastore/cache.h | 6 ++--- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/crimson/os/seastore/cache.cc b/src/crimson/os/seastore/cache.cc index a08b8698c90fa..2d8243a25ae8d 100644 --- a/src/crimson/os/seastore/cache.cc +++ b/src/crimson/os/seastore/cache.cc @@ -1636,26 +1636,38 @@ record_t Cache::prepare_record( return record; } -void Cache::backref_batch_update( +void Cache::commit_backref_entries( backref_entry_refs_t&& backref_entries, const journal_seq_t& seq) { - LOG_PREFIX(Cache::backref_batch_update); - DEBUG("inserting {} entries at {}", backref_entries.size(), seq); - ceph_assert(seq != JOURNAL_SEQ_NULL); - + LOG_PREFIX(Cache::commit_backref_entries); + DEBUG("backref_entry apply {} entries at {}", + backref_entries.size(), seq); + assert(seq != JOURNAL_SEQ_NULL); + if (backref_entries.empty()) { + return; + } for (auto &entry : backref_entries) { backref_entry_mset.insert(*entry); } - - auto iter = backref_entryrefs_by_seq.find(seq); - if (iter == backref_entryrefs_by_seq.end()) { - backref_entryrefs_by_seq.emplace(seq, std::move(backref_entries)); - } else { - iter->second.insert( - iter->second.end(), + if (backref_entryrefs_by_seq.empty()) { + backref_entryrefs_by_seq.insert( + backref_entryrefs_by_seq.end(), + {seq, std::move(backref_entries)}); + return; + } + auto last = backref_entryrefs_by_seq.rbegin(); + assert(last->first <= seq); + if (last->first == seq) { + last->second.insert( + last->second.end(), std::make_move_iterator(backref_entries.begin()), std::make_move_iterator(backref_entries.end())); + } else { + assert(last->first < seq); + backref_entryrefs_by_seq.insert( + backref_entryrefs_by_seq.end(), + {seq, std::move(backref_entries)}); } } @@ -1823,9 +1835,7 @@ void Cache::complete_commit( } } } - if (!backref_entries.empty()) { - backref_batch_update(std::move(backref_entries), start_seq); - } + commit_backref_entries(std::move(backref_entries), start_seq); for (auto &i: t.pre_alloc_list) { if (!i->is_valid()) { @@ -1959,9 +1969,7 @@ Cache::replay_delta( backref_entries.emplace_back( backref_entry_t::create(alloc_blk)); } - if (!backref_entries.empty()) { - backref_batch_update(std::move(backref_entries), journal_seq); - } + commit_backref_entries(std::move(backref_entries), journal_seq); return replay_delta_ertr::make_ready_future>( std::make_pair(true, nullptr)); } diff --git a/src/crimson/os/seastore/cache.h b/src/crimson/os/seastore/cache.h index acba71b9ec6fa..7fbb197276fb1 100644 --- a/src/crimson/os/seastore/cache.h +++ b/src/crimson/os/seastore/cache.h @@ -1925,9 +1925,9 @@ private: seastar::metrics::metric_group metrics; void register_metrics(); - void backref_batch_update( - backref_entry_refs_t &&, - const journal_seq_t &); + void commit_backref_entries( + backref_entry_refs_t&& backref_entries, + const journal_seq_t& seq); /// Add extent to extents handling dirty and refcounting /// -- 2.39.5