Skip to content

Commit 5cbd352

Browse files
authored
Merge pull request ceph#62838 from cyx1231st/wip-seastore-simplify-cache-access-metrics
crimson/os/seastore: simplify cache access metrics Reviewed-by: Xuehan Xu <[email protected]>
2 parents 84a42f7 + a622de2 commit 5cbd352

File tree

7 files changed

+69
-159
lines changed

7 files changed

+69
-159
lines changed

src/crimson/os/seastore/backref/btree_backref_manager.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,10 @@ const get_phy_tree_root_node_ret get_phy_tree_root_node<
3636
return {true,
3737
c.cache.get_extent_viewable_by_trans(c.trans, backref_root)};
3838
} else {
39-
c.cache.account_absent_access(c.trans.get_src());
4039
return {false,
4140
Cache::get_extent_iertr::make_ready_future<CachedExtentRef>()};
4241
}
4342
} else {
44-
c.cache.account_absent_access(c.trans.get_src());
4543
return {false,
4644
Cache::get_extent_iertr::make_ready_future<CachedExtentRef>()};
4745
}

src/crimson/os/seastore/btree/fixed_kv_btree.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,7 +1503,6 @@ class FixedKVBtree {
15031503
return on_found(child->template cast<internal_node_t>());
15041504
});
15051505
}
1506-
c.cache.account_absent_access(c.trans.get_src());
15071506

15081507
auto child_pos = v.get_child_pos();
15091508
auto next_iter = node_iter + 1;
@@ -1575,7 +1574,6 @@ class FixedKVBtree {
15751574
return on_found(child->template cast<leaf_node_t>());
15761575
});
15771576
}
1578-
c.cache.account_absent_access(c.trans.get_src());
15791577

15801578
auto child_pos = v.get_child_pos();
15811579
auto next_iter = node_iter + 1;
@@ -2135,7 +2133,6 @@ class FixedKVBtree {
21352133
return do_merge(child->template cast<NodeType>());
21362134
});
21372135
}
2138-
c.cache.account_absent_access(c.trans.get_src());
21392136

21402137
auto child_pos = v.get_child_pos();
21412138
return get_node<NodeType>(

src/crimson/os/seastore/cache.cc

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ void Cache::register_metrics()
208208
sm::make_counter(
209209
"cache_hit",
210210
[this] {
211-
return stats.access.s.get_cache_hit();
211+
return stats.access.get_cache_hit();
212212
},
213213
sm::description("total number of cache hits")
214214
),
@@ -2417,22 +2417,20 @@ cache_stats_t Cache::get_stats(
24172417
oss << "\ncache total"
24182418
<< cache_size_stats_t{extents_index.get_bytes(), extents_index.size()};
24192419

2420-
counter_by_src_t<counter_by_extent_t<extent_access_stats_t> >
2420+
counter_by_src_t<counter_by_extent_t<cache_access_stats_t> >
24212421
_access_by_src_ext = stats.access_by_src_ext;
24222422
counter_by_src_t<cache_access_stats_t> access_by_src;
24232423
for (uint8_t _src=0; _src<TRANSACTION_TYPE_MAX; ++_src) {
24242424
auto src = static_cast<transaction_type_t>(_src);
24252425
cache_access_stats_t& trans_access = get_by_src(access_by_src, src);
2426-
trans_access.cache_absent = get_by_src(stats.cache_absent_by_src, src);
2427-
trans_access.cache_absent -= get_by_src(last_cache_absent_by_src, src);
24282426
auto& access_by_ext = get_by_src(_access_by_src_ext, src);
24292427
const auto& last_access_by_ext = get_by_src(last_access_by_src_ext, src);
24302428
for (uint8_t _ext=0; _ext<EXTENT_TYPES_MAX; ++_ext) {
24312429
auto ext = static_cast<extent_types_t>(_ext);
2432-
extent_access_stats_t& extent_access = get_by_ext(access_by_ext, ext);
2430+
cache_access_stats_t& extent_access = get_by_ext(access_by_ext, ext);
24332431
const auto& last_extent_access = get_by_ext(last_access_by_ext, ext);
24342432
extent_access.minus(last_extent_access);
2435-
trans_access.s.add(extent_access);
2433+
trans_access.add(extent_access);
24362434
}
24372435
}
24382436
oss << "\naccess: total"
@@ -2443,9 +2441,9 @@ cache_stats_t Cache::get_stats(
24432441
if (trans_access.is_empty()) {
24442442
continue;
24452443
}
2446-
extent_access_stats_t data_access;
2447-
extent_access_stats_t mdat_access;
2448-
extent_access_stats_t phys_access;
2444+
cache_access_stats_t data_access;
2445+
cache_access_stats_t mdat_access;
2446+
cache_access_stats_t phys_access;
24492447
const auto& access_by_ext = get_by_src(_access_by_src_ext, src);
24502448
for (uint8_t _ext=0; _ext<EXTENT_TYPES_MAX; ++_ext) {
24512449
auto ext = static_cast<extent_types_t>(_ext);
@@ -2461,11 +2459,11 @@ cache_stats_t Cache::get_stats(
24612459
oss << "\n " << src << ": "
24622460
<< cache_access_stats_printer_t{seconds, trans_access}
24632461
<< "\n data"
2464-
<< extent_access_stats_printer_t{seconds, data_access}
2462+
<< cache_access_stats_printer_t{seconds, data_access}
24652463
<< "\n mdat"
2466-
<< extent_access_stats_printer_t{seconds, mdat_access}
2464+
<< cache_access_stats_printer_t{seconds, mdat_access}
24672465
<< "\n phys"
2468-
<< extent_access_stats_printer_t{seconds, phys_access};
2466+
<< cache_access_stats_printer_t{seconds, phys_access};
24692467
}
24702468

24712469
INFO("{}", oss.str());

src/crimson/os/seastore/cache.h

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,6 @@ class Cache : public ExtentTransViewRetriever {
186186
return t.root;
187187
}
188188

189-
void account_absent_access(Transaction::src_t src) {
190-
++(get_by_src(stats.cache_absent_by_src, src));
191-
++stats.access.cache_absent;
192-
}
193-
194189
/**
195190
* get_extent_if_cached
196191
*
@@ -208,7 +203,7 @@ class Cache : public ExtentTransViewRetriever {
208203
const auto t_src = t.get_src();
209204
CachedExtentRef ret;
210205
auto result = t.get_extent(paddr, &ret);
211-
extent_access_stats_t& access_stats = get_by_ext(
206+
cache_access_stats_t& access_stats = get_by_ext(
212207
get_by_src(stats.access_by_src_ext, t_src),
213208
type);
214209
if (result == Transaction::get_extent_ret::RETIRED) {
@@ -217,27 +212,28 @@ class Cache : public ExtentTransViewRetriever {
217212
t, type, paddr, len);
218213
return get_extent_if_cached_iertr::make_ready_future<CachedExtentRef>();
219214
} else if (result == Transaction::get_extent_ret::PRESENT) {
215+
if (ret->get_length() != len) {
216+
SUBDEBUGT(seastore_cache,
217+
"{} {}~0x{:x} is present on t with inconsistent length 0x{:x} -- {}",
218+
t, type, paddr, len, ret->get_length(), *ret);
219+
return get_extent_if_cached_iertr::make_ready_future<CachedExtentRef>();
220+
}
221+
222+
ceph_assert(ret->get_type() == type);
223+
220224
if (ret->is_stable()) {
221225
if (ret->is_dirty()) {
222226
++access_stats.trans_dirty;
223-
++stats.access.s.trans_dirty;
227+
++stats.access.trans_dirty;
224228
} else {
225229
++access_stats.trans_lru;
226-
++stats.access.s.trans_lru;
230+
++stats.access.trans_lru;
227231
}
228232
} else {
229233
++access_stats.trans_pending;
230-
++stats.access.s.trans_pending;
231-
}
232-
233-
if (ret->get_length() != len) {
234-
SUBDEBUGT(seastore_cache,
235-
"{} {}~0x{:x} is present on t with inconsistent length 0x{:x} -- {}",
236-
t, type, paddr, len, ret->get_length(), *ret);
237-
return get_extent_if_cached_iertr::make_ready_future<CachedExtentRef>();
234+
++stats.access.trans_pending;
238235
}
239236

240-
ceph_assert(ret->get_type() == type);
241237
if (!ret->is_fully_loaded()) {
242238
SUBDEBUGT(seastore_cache,
243239
"{} {}~0x{:x} is present on t without fully loaded -- {}",
@@ -261,7 +257,6 @@ class Cache : public ExtentTransViewRetriever {
261257
SUBDEBUGT(seastore_cache,
262258
"{} {}~0x{:x} is absent in cache",
263259
t, type, paddr, len);
264-
account_absent_access(t_src);
265260
return get_extent_if_cached_iertr::make_ready_future<CachedExtentRef>();
266261
}
267262

@@ -270,18 +265,9 @@ class Cache : public ExtentTransViewRetriever {
270265
SUBDEBUGT(seastore_cache,
271266
"{} {}~0x{:x} ~0x{:x} is absent(placeholder) in cache",
272267
t, type, paddr, len, ret->get_length());
273-
account_absent_access(t_src);
274268
return get_extent_if_cached_iertr::make_ready_future<CachedExtentRef>();
275269
}
276270

277-
if (ret->is_dirty()) {
278-
++access_stats.cache_dirty;
279-
++stats.access.s.cache_dirty;
280-
} else {
281-
++access_stats.cache_lru;
282-
++stats.access.s.cache_lru;
283-
}
284-
285271
if (ret->get_length() != len) {
286272
SUBDEBUGT(seastore_cache,
287273
"{} {}~0x{:x} is present in cache with inconsistent length 0x{:x} -- {}",
@@ -290,6 +276,15 @@ class Cache : public ExtentTransViewRetriever {
290276
}
291277

292278
ceph_assert(ret->get_type() == type);
279+
280+
if (ret->is_dirty()) {
281+
++access_stats.cache_dirty;
282+
++stats.access.cache_dirty;
283+
} else {
284+
++access_stats.cache_lru;
285+
++stats.access.cache_lru;
286+
}
287+
293288
t.add_to_read_set(ret);
294289
touch_extent(*ret, &t_src, t.get_cache_hint());
295290
if (!ret->is_fully_loaded()) {
@@ -402,11 +397,11 @@ class Cache : public ExtentTransViewRetriever {
402397
// FIXME: assert(ext.is_stable_clean());
403398
assert(ext.is_stable());
404399
assert(T::TYPE == ext.get_type());
405-
extent_access_stats_t& access_stats = get_by_ext(
400+
cache_access_stats_t& access_stats = get_by_ext(
406401
get_by_src(stats.access_by_src_ext, t_src),
407402
T::TYPE);
408403
++access_stats.load_absent;
409-
++stats.access.s.load_absent;
404+
++stats.access.load_absent;
410405

411406
t.add_to_read_set(CachedExtentRef(&ext));
412407
touch_extent(ext, &t_src, t.get_cache_hint());
@@ -475,7 +470,7 @@ class Cache : public ExtentTransViewRetriever {
475470

476471
const auto t_src = t.get_src();
477472
auto ext_type = extent->get_type();
478-
extent_access_stats_t& access_stats = get_by_ext(
473+
cache_access_stats_t& access_stats = get_by_ext(
479474
get_by_src(stats.access_by_src_ext, t_src),
480475
ext_type);
481476

@@ -487,7 +482,7 @@ class Cache : public ExtentTransViewRetriever {
487482
assert(p_extent->is_pending_in_trans(t.get_trans_id()));
488483
assert(!p_extent->is_stable_writting());
489484
++access_stats.trans_pending;
490-
++stats.access.s.trans_pending;
485+
++stats.access.trans_pending;
491486
if (p_extent->is_mutable()) {
492487
assert(p_extent->is_fully_loaded());
493488
assert(!p_extent->is_pending_io());
@@ -502,27 +497,27 @@ class Cache : public ExtentTransViewRetriever {
502497
if (t.maybe_add_to_read_set(p_extent)) {
503498
if (p_extent->is_dirty()) {
504499
++access_stats.cache_dirty;
505-
++stats.access.s.cache_dirty;
500+
++stats.access.cache_dirty;
506501
} else {
507502
++access_stats.cache_lru;
508-
++stats.access.s.cache_lru;
503+
++stats.access.cache_lru;
509504
}
510505
touch_extent(*p_extent, &t_src, t.get_cache_hint());
511506
} else {
512507
if (p_extent->is_dirty()) {
513508
++access_stats.trans_dirty;
514-
++stats.access.s.trans_dirty;
509+
++stats.access.trans_dirty;
515510
} else {
516511
++access_stats.trans_lru;
517-
++stats.access.s.trans_lru;
512+
++stats.access.trans_lru;
518513
}
519514
}
520515
}
521516
} else {
522517
assert(!extent->is_stable_writting());
523518
assert(extent->is_pending_in_trans(t.get_trans_id()));
524519
++access_stats.trans_pending;
525-
++stats.access.s.trans_pending;
520+
++stats.access.trans_pending;
526521
if (extent->is_mutable()) {
527522
assert(extent->is_fully_loaded());
528523
assert(!extent->is_pending_io());
@@ -564,11 +559,11 @@ class Cache : public ExtentTransViewRetriever {
564559
t, extent->get_type(), extent->get_paddr(), extent->get_length(),
565560
partial_off, partial_len, *extent);
566561
const auto t_src = t.get_src();
567-
extent_access_stats_t& access_stats = get_by_ext(
562+
cache_access_stats_t& access_stats = get_by_ext(
568563
get_by_src(stats.access_by_src_ext, t_src),
569564
extent->get_type());
570565
++access_stats.load_present;
571-
++stats.access.s.load_present;
566+
++stats.access.load_present;
572567
return trans_intr::make_interruptible(
573568
do_read_extent_maybe_partial(
574569
std::move(extent), partial_off, partial_len, &t_src));
@@ -878,11 +873,11 @@ class Cache : public ExtentTransViewRetriever {
878873
auto f = [&t, this, t_src](CachedExtent &ext) {
879874
// FIXME: assert(ext.is_stable_clean());
880875
assert(ext.is_stable());
881-
extent_access_stats_t& access_stats = get_by_ext(
876+
cache_access_stats_t& access_stats = get_by_ext(
882877
get_by_src(stats.access_by_src_ext, t_src),
883878
ext.get_type());
884879
++access_stats.load_absent;
885-
++stats.access.s.load_absent;
880+
++stats.access.load_absent;
886881

887882
t.add_to_read_set(CachedExtentRef(&ext));
888883
touch_extent(ext, &t_src, t.get_cache_hint());
@@ -1763,7 +1758,7 @@ class Cache : public ExtentTransViewRetriever {
17631758

17641759
cache_access_stats_t access;
17651760
counter_by_src_t<uint64_t> cache_absent_by_src;
1766-
counter_by_src_t<counter_by_extent_t<extent_access_stats_t> >
1761+
counter_by_src_t<counter_by_extent_t<cache_access_stats_t> >
17671762
access_by_src_ext;
17681763

17691764
uint64_t onode_tree_depth = 0;
@@ -1800,7 +1795,7 @@ class Cache : public ExtentTransViewRetriever {
18001795
mutable rewrite_stats_t last_reclaim_rewrites;
18011796
mutable cache_access_stats_t last_access;
18021797
mutable counter_by_src_t<uint64_t> last_cache_absent_by_src;
1803-
mutable counter_by_src_t<counter_by_extent_t<extent_access_stats_t> >
1798+
mutable counter_by_src_t<counter_by_extent_t<cache_access_stats_t> >
18041799
last_access_by_src_ext;
18051800

18061801
void account_conflict(Transaction::src_t src1, Transaction::src_t src2) {

src/crimson/os/seastore/lba_manager/btree/btree_lba_manager.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,10 @@ const get_phy_tree_root_node_ret get_phy_tree_root_node<
6060
return {true,
6161
c.cache.get_extent_viewable_by_trans(c.trans, lba_root)};
6262
} else {
63-
c.cache.account_absent_access(c.trans.get_src());
6463
return {false,
6564
Cache::get_extent_iertr::make_ready_future<CachedExtentRef>()};
6665
}
6766
} else {
68-
c.cache.account_absent_access(c.trans.get_src());
6967
return {false,
7068
Cache::get_extent_iertr::make_ready_future<CachedExtentRef>()};
7169
}
@@ -103,7 +101,6 @@ BtreeLBAMapping::get_logical_extent(Transaction &t)
103101
: get_key();
104102
auto v = p.template get_child<LogicalChildNode>(ctx.trans, ctx.cache, pos, k);
105103
if (!v.has_child()) {
106-
ctx.cache.account_absent_access(ctx.trans.get_src());
107104
this->child_pos = v.get_child_pos();
108105
}
109106
return v;

0 commit comments

Comments
 (0)