From 4f48d9cc637e55e3ff5feedf9ec070149ef7f8e3 Mon Sep 17 00:00:00 2001 From: Igor Fedotov Date: Tue, 8 Nov 2022 18:16:21 +0300 Subject: [PATCH] os/bluestore: introduce method to estimate BlueFS transaction size Signed-off-by: Igor Fedotov (cherry picked from commit 05478fc46bc6437e8e57642a5ffdedde851f08f3) --- src/os/bluestore/BlueFS.cc | 28 +++++++++++++++++----------- src/os/bluestore/BlueFS.h | 4 +++- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/os/bluestore/BlueFS.cc b/src/os/bluestore/BlueFS.cc index a6885acd76f99..42b74c5e63776 100644 --- a/src/os/bluestore/BlueFS.cc +++ b/src/os/bluestore/BlueFS.cc @@ -2157,6 +2157,17 @@ void BlueFS::invalidate_cache(FileRef f, uint64_t offset, uint64_t length) } } + +uint64_t BlueFS::_estimate_transaction_size(bluefs_transaction_t* t) +{ + uint64_t max_alloc_size = std::max(alloc_size[BDEV_WAL], + std::max(alloc_size[BDEV_DB], + alloc_size[BDEV_SLOW])); + + // conservative estimate for final encoded size + return round_up_to(t->op_bl.length() + super.block_size * 2, max_alloc_size); +} + uint64_t BlueFS::_estimate_log_size_N() { std::lock_guard nl(nodes.lock); @@ -2466,13 +2477,7 @@ void BlueFS::_compact_log_async_LD_LNF_D() //also locks FW for new_writer // log can be used to write to, ops in log will be continuation of captured state log.lock.unlock(); - uint64_t max_alloc_size = std::max(alloc_size[BDEV_WAL], - std::max(alloc_size[BDEV_DB], - alloc_size[BDEV_SLOW])); - - // conservative estimate for final encoded size - new_log_jump_to = round_up_to(t.op_bl.length() + super.block_size * 2, - max_alloc_size); + new_log_jump_to = _estimate_transaction_size(&t); //newly constructed log head will jump to what we had before t.op_jump(seq_now, new_log_jump_to); @@ -2554,13 +2559,14 @@ void BlueFS::_compact_log_async_LD_LNF_D() //also locks FW for new_writer ceph_assert(old_is_comp); } -void BlueFS::_pad_bl(bufferlist& bl) +void BlueFS::_pad_bl(bufferlist& bl, uint64_t pad_size) { - uint64_t partial = bl.length() % super.block_size; + pad_size = std::max(pad_size, uint64_t(super.block_size)); + uint64_t partial = bl.length() % pad_size; if (partial) { dout(10) << __func__ << " padding with 0x" << std::hex - << super.block_size - partial << " zeros" << std::dec << dendl; - bl.append_zero(super.block_size - partial); + << pad_size - partial << " zeros" << std::dec << dendl; + bl.append_zero(pad_size - partial); } } diff --git a/src/os/bluestore/BlueFS.h b/src/os/bluestore/BlueFS.h index e9718f0f5f9d7..57eeb1c6ae601 100644 --- a/src/os/bluestore/BlueFS.h +++ b/src/os/bluestore/BlueFS.h @@ -384,7 +384,8 @@ private: void _init_alloc(); void _stop_alloc(); - void _pad_bl(ceph::buffer::list& bl); ///< pad ceph::buffer::list to block size w/ zeros + ///< pad ceph::buffer::list to max(block size, pad_size) w/ zeros + void _pad_bl(ceph::buffer::list& bl, uint64_t pad_size = 0); uint64_t _get_used(unsigned id) const; uint64_t _get_total(unsigned id) const; @@ -427,6 +428,7 @@ private: int64_t available_runway); int _flush_and_sync_log_LD(uint64_t want_seq = 0); + uint64_t _estimate_transaction_size(bluefs_transaction_t* t); uint64_t _estimate_log_size_N(); bool _should_start_compact_log_L_N(); -- 2.39.5