From 8c6cedea0af0c6aa10ac09778c9113aff85ada86 Mon Sep 17 00:00:00 2001 From: Yingxin Cheng Date: Mon, 5 Aug 2024 16:04:26 +0800 Subject: [PATCH] crimson/os/seastore/cache: introduce maybe_add_to_read_set() And only touch extent if it is absent in transaction. Signed-off-by: Yingxin Cheng --- src/crimson/os/seastore/cache.h | 5 +++-- src/crimson/os/seastore/transaction.h | 27 +++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/crimson/os/seastore/cache.h b/src/crimson/os/seastore/cache.h index 779df4f6f524b..4441df86d4e95 100644 --- a/src/crimson/os/seastore/cache.h +++ b/src/crimson/os/seastore/cache.h @@ -494,8 +494,9 @@ public: } else { // stable from trans-view assert(!p_extent->is_pending_in_trans(t.get_trans_id())); - t.add_to_read_set(p_extent); - touch_extent(*p_extent); + if (t.maybe_add_to_read_set(p_extent)) { + touch_extent(*p_extent); + } } } else { assert(!extent->is_stable_writting()); diff --git a/src/crimson/os/seastore/transaction.h b/src/crimson/os/seastore/transaction.h index d7cdb30098a0f..2fa468fb48e07 100644 --- a/src/crimson/os/seastore/transaction.h +++ b/src/crimson/os/seastore/transaction.h @@ -137,14 +137,37 @@ public: } } + // Returns true if added, false if already added or weak + bool maybe_add_to_read_set(CachedExtentRef ref) { + if (is_weak()) { + return false; + } + + assert(ref->is_valid()); + + auto it = ref->transactions.lower_bound( + this, read_set_item_t::trans_cmp_t()); + if (it != ref->transactions.end() && it->t == this) { + return false; + } + + auto [iter, inserted] = read_set.emplace(this, ref); + ceph_assert(inserted); + ref->transactions.insert_before( + it, const_cast&>(*iter)); + return true; + } + void add_to_read_set(CachedExtentRef ref) { - if (is_weak()) return; + if (is_weak()) { + return; + } assert(ref->is_valid()); auto it = ref->transactions.lower_bound( this, read_set_item_t::trans_cmp_t()); - if (it != ref->transactions.end() && it->t == this) return; + assert(it == ref->transactions.end() || it->t != this); auto [iter, inserted] = read_set.emplace(this, ref); ceph_assert(inserted); -- 2.39.5