Skip to content

Commit aa86e49

Browse files
committed
crimson/os/seastore/cache: cleanup add_extent()
Move add_to_dirty() and touch_extent() out of add_extent(), this removes duplicated calls to touch_extent() from the on_cache callback. Signed-off-by: Yingxin Cheng <[email protected]>
1 parent 0d92425 commit aa86e49

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

src/crimson/os/seastore/cache.cc

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ Cache::retire_extent_ret Cache::retire_extent_addr(
9797
TRANS_ID_NULL);
9898
DEBUGT("retire {}~{} as placeholder, add extent -- {}",
9999
t, addr, length, *ext);
100-
const auto t_src = t.get_src();
101-
add_extent(ext, &t_src);
100+
add_extent(ext);
102101
}
103102
t.add_to_read_set(ext);
104103
t.add_to_retired_set(ext);
@@ -126,8 +125,7 @@ void Cache::retire_absent_extent_addr(
126125
TRANS_ID_NULL);
127126
DEBUGT("retire {}~{} as placeholder, add extent -- {}",
128127
t, addr, length, *ext);
129-
const auto t_src = t.get_src();
130-
add_extent(ext, &t_src);
128+
add_extent(ext);
131129
t.add_to_read_set(ext);
132130
t.add_to_retired_set(ext);
133131
}
@@ -727,19 +725,12 @@ void Cache::register_metrics()
727725
);
728726
}
729727

730-
void Cache::add_extent(
731-
CachedExtentRef ref,
732-
const Transaction::src_t* p_src=nullptr)
728+
void Cache::add_extent(CachedExtentRef ref)
733729
{
734730
assert(ref->is_valid());
735731
assert(ref->user_hint == PLACEMENT_HINT_NULL);
736732
assert(ref->rewrite_generation == NULL_GENERATION);
737733
extents.insert(*ref);
738-
if (ref->is_dirty()) {
739-
add_to_dirty(ref);
740-
} else {
741-
touch_extent(*ref, p_src);
742-
}
743734
}
744735

745736
void Cache::mark_dirty(CachedExtentRef ref)
@@ -1573,9 +1564,11 @@ void Cache::complete_commit(
15731564
i->prior_instance.reset();
15741565
DEBUGT("add extent as fresh, inline={} -- {}",
15751566
t, is_inline, *i);
1576-
const auto t_src = t.get_src();
15771567
i->invalidate_hints();
1578-
add_extent(i, &t_src);
1568+
add_extent(i);
1569+
assert(!i->is_dirty());
1570+
const auto t_src = t.get_src();
1571+
touch_extent(*i, &t_src);
15791572
epm.commit_space_used(i->get_paddr(), i->get_length());
15801573
if (is_backref_mapped_extent_node(i)) {
15811574
DEBUGT("backref_list new {} len {}",
@@ -1691,8 +1684,13 @@ void Cache::complete_commit(
16911684
i->get_length(),
16921685
i->get_type(),
16931686
start_seq));
1694-
const auto t_src = t.get_src();
1695-
add_extent(i, &t_src);
1687+
add_extent(i);
1688+
if (i->is_dirty()) {
1689+
add_to_dirty(i);
1690+
} else {
1691+
const auto t_src = t.get_src();
1692+
touch_extent(*i, &t_src);
1693+
}
16961694
}
16971695
}
16981696
if (!backref_list.empty()) {
@@ -1868,6 +1866,7 @@ Cache::replay_delta(
18681866
journal_seq, record_base, delta, *root);
18691867
root->set_modify_time(modify_time);
18701868
add_extent(root);
1869+
add_to_dirty(root);
18711870
return replay_delta_ertr::make_ready_future<std::pair<bool, CachedExtentRef>>(
18721871
std::make_pair(true, root));
18731872
} else {
@@ -1895,7 +1894,9 @@ Cache::replay_delta(
18951894
delta.length,
18961895
nullptr,
18971896
[](CachedExtent &) {},
1898-
[](CachedExtent &) {}) :
1897+
[this](CachedExtent &ext) {
1898+
touch_extent(ext);
1899+
}) :
18991900
_get_extent_if_cached(
19001901
delta.paddr)
19011902
).handle_error(

src/crimson/os/seastore/cache.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,8 @@ class Cache {
585585
SUBDEBUG(seastore_cache,
586586
"{} {}~{} is absent, add extent and reading ... -- {}",
587587
T::TYPE, offset, length, *ret);
588-
const auto p_src = p_src_ext ? &p_src_ext->first : nullptr;
589-
add_extent(ret, p_src);
588+
add_extent(ret);
589+
// touch_extent() should be included in on_cache
590590
on_cache(*ret);
591591
extent_init_func(*ret);
592592
return read_extent<T>(
@@ -1642,7 +1642,10 @@ class Cache {
16421642
const journal_seq_t &);
16431643

16441644
/// Add extent to extents handling dirty and refcounting
1645-
void add_extent(CachedExtentRef ref, const Transaction::src_t* t_src);
1645+
///
1646+
/// Note, it must follows with add_to_dirty() or touch_extent().
1647+
/// The only exception is RetiredExtentPlaceholder.
1648+
void add_extent(CachedExtentRef ref);
16461649

16471650
/// Mark exising extent ref dirty -- mainly for replay
16481651
void mark_dirty(CachedExtentRef ref);

0 commit comments

Comments
 (0)