crimson/os/seastore/transaction: count fresh blocks separately

Correct get_num_fresh_blocks() to be accurate under the effect of
delayed allocations.

Signed-off-by: Yingxin Cheng <yingxin.cheng@intel.com>
This commit is contained in:
Yingxin Cheng 2021-09-28 15:10:23 +08:00
parent 529f1a81c7
commit 2b1402b3d5
4 changed files with 28 additions and 9 deletions

View File

@ -614,10 +614,9 @@ void Cache::mark_transaction_conflicted(
efforts.retire.bytes += i->get_length();
}
efforts.fresh.extents += t.get_num_fresh_blocks();
t.for_each_fresh_block([&](auto &i) {
efforts.fresh.bytes += i->get_length();
});
auto& fresh_stats = t.get_fresh_block_stats();
efforts.fresh.extents += fresh_stats.num;
efforts.fresh.bytes += fresh_stats.bytes;
for (auto &i: t.mutated_block_list) {
if (!i->is_valid()) {
@ -641,7 +640,7 @@ void Cache::mark_transaction_conflicted(
} else {
// read transaction won't have non-read efforts
assert(t.retired_set.empty());
assert(t.get_num_fresh_blocks() == 0);
assert(t.get_fresh_block_stats().num == 0);
assert(t.mutated_block_list.empty());
assert(t.onode_tree_stats.is_clear());
assert(t.lba_tree_stats.is_clear());
@ -664,7 +663,7 @@ void Cache::on_transaction_destruct(Transaction& t)
}
// read transaction won't have non-read efforts
assert(t.retired_set.empty());
assert(t.get_num_fresh_blocks() == 0);
assert(t.get_fresh_block_stats().num == 0);
assert(t.mutated_block_list.empty());
assert(t.onode_tree_stats.is_clear());
assert(t.lba_tree_stats.is_clear());
@ -868,6 +867,11 @@ record_t Cache::prepare_record(Transaction &t)
});
}
ceph_assert(t.get_fresh_block_stats().num ==
t.inline_block_list.size() +
t.ool_block_list.size() +
t.num_delayed_invalid_extents);
return record;
}

View File

@ -365,6 +365,7 @@ public:
for (auto& extent : alloc_list) {
// extents may be invalidated
if (!extent->is_valid()) {
t.increment_delayed_invalid_extents();
continue;
}
if (should_be_inline(extent)) {

View File

@ -232,7 +232,7 @@ void BtreeLBAManager::complete_transaction(
// ...but add_pin from parent->leaf
std::vector<CachedExtentRef> to_link;
to_link.reserve(t.get_num_fresh_blocks());
to_link.reserve(t.get_fresh_block_stats().num);
t.for_each_fresh_block([&](auto &e) {
if (e->is_valid() && (is_lba_node(*e) || e->is_logical()))
to_link.push_back(e);

View File

@ -100,6 +100,8 @@ public:
offset += ref->get_length();
inline_block_list.push_back(ref);
}
++fresh_block_stats.num;
fresh_block_stats.bytes += ref->get_length();
TRACET("adding {} to write_set", *this, *ref);
write_set.insert(*ref);
}
@ -185,8 +187,12 @@ public:
std::for_each(inline_block_list.begin(), inline_block_list.end(), f);
}
auto get_num_fresh_blocks() const {
return inline_block_list.size() + ool_block_list.size();
struct io_stat_t {
uint64_t num = 0;
uint64_t bytes = 0;
};
const io_stat_t& get_fresh_block_stats() const {
return fresh_block_stats;
}
enum class src_t : uint8_t {
@ -250,6 +256,8 @@ public:
read_set.clear();
invalidate_clear_write_set();
mutated_block_list.clear();
fresh_block_stats = {};
num_delayed_invalid_extents = 0;
delayed_alloc_list.clear();
inline_block_list.clear();
ool_block_list.clear();
@ -285,6 +293,10 @@ public:
return lba_tree_stats;
}
void increment_delayed_invalid_extents() {
++num_delayed_invalid_extents;
}
private:
friend class Cache;
friend Ref make_test_transaction();
@ -322,6 +334,8 @@ private:
/**
* lists of fresh blocks, holds refcounts, subset of write_set
*/
io_stat_t fresh_block_stats;
uint64_t num_delayed_invalid_extents = 0;
/// blocks that will be committed with journal record inline
std::list<CachedExtentRef> inline_block_list;
/// blocks that will be committed with out-of-line record