From a0540ae936ec5c5a67a135244383a81a8d625922 Mon Sep 17 00:00:00 2001 From: Yingxin Cheng Date: Thu, 9 Dec 2021 11:09:27 +0800 Subject: [PATCH] crimson/os/seastore/cache: misc cleanup Signed-off-by: Yingxin Cheng --- src/crimson/os/seastore/cache.cc | 80 ++++++++++++++------------- src/crimson/os/seastore/cache.h | 2 +- src/crimson/os/seastore/transaction.h | 11 ++++ 3 files changed, 55 insertions(+), 38 deletions(-) diff --git a/src/crimson/os/seastore/cache.cc b/src/crimson/os/seastore/cache.cc index 9ab7c9e6f1985..e145b231c40c7 100644 --- a/src/crimson/os/seastore/cache.cc +++ b/src/crimson/os/seastore/cache.cc @@ -814,9 +814,9 @@ void Cache::mark_transaction_conflicted( } else { // read transaction won't have non-read efforts assert(t.retired_set.empty()); - assert(t.get_fresh_block_stats().num == 0); + assert(t.get_fresh_block_stats().is_clear()); assert(t.mutated_block_list.empty()); - assert(t.get_ool_write_stats().num_records == 0); + assert(t.get_ool_write_stats().is_clear()); assert(t.onode_tree_stats.is_clear()); assert(t.lba_tree_stats.is_clear()); } @@ -917,27 +917,8 @@ record_t Cache::prepare_record(Transaction &t) assert(!t.is_weak()); assert(t.get_src() != Transaction::src_t::READ); - if (t.get_src() == Transaction::src_t::CLEANER_TRIM || - t.get_src() == Transaction::src_t::CLEANER_RECLAIM) { - // CLEANER transaction won't contain any onode tree operations - assert(t.onode_tree_stats.is_clear()); - } else { - if (t.onode_tree_stats.depth) { - stats.onode_tree_depth = t.onode_tree_stats.depth; - } - get_by_src(stats.committed_onode_tree_efforts, t.get_src() - ).increment(t.onode_tree_stats); - } - - if (t.lba_tree_stats.depth) { - stats.lba_tree_depth = t.lba_tree_stats.depth; - } - get_by_src(stats.committed_lba_tree_efforts, t.get_src() - ).increment(t.lba_tree_stats); - auto& efforts = get_by_src(stats.committed_efforts_by_src, t.get_src()); - ++(efforts.num_trans); // Should be valid due to interruptible future for (auto &i: t.read_set) { @@ -1079,26 +1060,51 @@ record_t Cache::prepare_record(Transaction &t) auto& ool_stats = t.get_ool_write_stats(); ceph_assert(ool_stats.extents.num == t.ool_block_list.size()); - efforts.num_ool_records += ool_stats.num_records; - efforts.ool_record_overhead_bytes += ool_stats.header_bytes; - - auto& record_header_fullness = get_by_src( - stats.record_header_fullness_by_src, t.get_src()); - record_header_fullness.ool_stats.filled_bytes += ool_stats.header_raw_bytes; - record_header_fullness.ool_stats.total_bytes += ool_stats.header_bytes; - - // TODO: move to Journal to get accurate result - auto record_size = record_group_size_t( - record.size, reader.get_block_size()); - auto inline_overhead = - record_size.get_encoded_length() - record.get_raw_data_size(); - efforts.inline_record_overhead_bytes += inline_overhead; - record_header_fullness.inline_stats.filled_bytes += record_size.get_raw_mdlength(); - record_header_fullness.inline_stats.total_bytes += record_size.get_mdlength(); // FIXME: prevent submitting empty records if (record.is_empty()) { ERRORT("record is empty!", t); + assert(t.onode_tree_stats.is_clear()); + assert(t.lba_tree_stats.is_clear()); + assert(ool_stats.is_clear()); + ++(efforts.num_trans); + } else { + if (t.get_src() == Transaction::src_t::CLEANER_TRIM || + t.get_src() == Transaction::src_t::CLEANER_RECLAIM) { + // CLEANER transaction won't contain any onode tree operations + assert(t.onode_tree_stats.is_clear()); + } else { + if (t.onode_tree_stats.depth) { + stats.onode_tree_depth = t.onode_tree_stats.depth; + } + get_by_src(stats.committed_onode_tree_efforts, t.get_src() + ).increment(t.onode_tree_stats); + } + + if (t.lba_tree_stats.depth) { + stats.lba_tree_depth = t.lba_tree_stats.depth; + } + get_by_src(stats.committed_lba_tree_efforts, t.get_src() + ).increment(t.lba_tree_stats); + + ++(efforts.num_trans); + + efforts.num_ool_records += ool_stats.num_records; + efforts.ool_record_overhead_bytes += ool_stats.header_bytes; + + auto& record_header_fullness = get_by_src( + stats.record_header_fullness_by_src, t.get_src()); + record_header_fullness.ool_stats.filled_bytes += ool_stats.header_raw_bytes; + record_header_fullness.ool_stats.total_bytes += ool_stats.header_bytes; + + // TODO: move to Journal to get accurate result + auto record_size = record_group_size_t( + record.size, reader.get_block_size()); + auto inline_overhead = + record_size.get_encoded_length() - record.get_raw_data_size(); + efforts.inline_record_overhead_bytes += inline_overhead; + record_header_fullness.inline_stats.filled_bytes += record_size.get_raw_mdlength(); + record_header_fullness.inline_stats.total_bytes += record_size.get_mdlength(); } return record; diff --git a/src/crimson/os/seastore/cache.h b/src/crimson/os/seastore/cache.h index a1a442fa25d53..9f508057ea627 100644 --- a/src/crimson/os/seastore/cache.h +++ b/src/crimson/os/seastore/cache.h @@ -742,7 +742,7 @@ private: counter_by_extent_t mutate_by_ext; counter_by_extent_t delta_bytes_by_ext; counter_by_extent_t retire_by_ext; - counter_by_extent_t fresh_invalid_by_ext; + counter_by_extent_t fresh_invalid_by_ext; // inline but is already invalid (retired) counter_by_extent_t fresh_inline_by_ext; counter_by_extent_t fresh_ool_by_ext; uint64_t num_trans = 0; // the number of inline records diff --git a/src/crimson/os/seastore/transaction.h b/src/crimson/os/seastore/transaction.h index 11927d34c8573..c41880550cf0d 100644 --- a/src/crimson/os/seastore/transaction.h +++ b/src/crimson/os/seastore/transaction.h @@ -190,6 +190,10 @@ public: struct io_stat_t { uint64_t num = 0; uint64_t bytes = 0; + + bool is_clear() const { + return (num == 0 && bytes == 0); + } }; const io_stat_t& get_fresh_block_stats() const { return fresh_block_stats; @@ -317,6 +321,13 @@ public: uint64_t header_raw_bytes = 0; uint64_t header_bytes = 0; uint64_t num_records = 0; + + bool is_clear() const { + return (extents.is_clear() && + header_raw_bytes == 0 && + header_bytes == 0 && + num_records == 0); + } }; ool_write_stats_t& get_ool_write_stats() { return ool_write_stats; -- 2.39.5