From: Yingxin Cheng Date: Mon, 5 Aug 2024 08:04:26 +0000 (+0800) Subject: crimson/os/seastore/cache: introduce maybe_add_to_read_set() X-Git-Tag: v20.0.0~1307^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=8c6cedea0af0c6aa10ac09778c9113aff85ada86;p=ceph.git 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 --- 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);