From bfff750dc4ea6649eeccc3389aa69cc0aed6dbb5 Mon Sep 17 00:00:00 2001 From: Adam Kupczyk Date: Tue, 25 Feb 2025 09:56:43 +0000 Subject: [PATCH] os/bluestore: Make write_v2 calculate affected range This reduces size for dirty_range and need_reshard range. Signed-off-by: Adam Kupczyk --- src/os/bluestore/BlueStore.cc | 4 ++++ src/os/bluestore/Writer.cc | 6 ++++-- src/os/bluestore/Writer.h | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index cd36ad6eabe24..00d07ec6ec5be 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -17656,9 +17656,13 @@ int BlueStore::_do_write_v2( BlueStore::Writer wr(this, txc, &wctx, o); uint64_t start = p2align(offset, min_alloc_size); uint64_t end = p2roundup(offset + length, min_alloc_size); + wr.left_affected_range = start; + wr.right_affected_range = end; std::tie(wr.left_shard_bound, wr.right_shard_bound) = o->extent_map.fault_range_ex(db, start, end - start); wr.do_write(offset, bl); + o->extent_map.dirty_range(wr.left_affected_range, wr.right_affected_range - wr.left_affected_range); + o->extent_map.maybe_reshard(wr.left_affected_range, wr.right_affected_range); return r; } diff --git a/src/os/bluestore/Writer.cc b/src/os/bluestore/Writer.cc index ef9d4b18971f4..41f2845e85ef0 100644 --- a/src/os/bluestore/Writer.cc +++ b/src/os/bluestore/Writer.cc @@ -558,12 +558,14 @@ inline void BlueStore::Writer::_place_extent_in_blob( // we can just expand existing Extent ex->length += map_end - map_begin; dout(20) << __func__ << " expanded extent " << ex->print(pp_mode) << dendl; + left_affected_range = std::min(left_affected_range, ex->logical_offset); } else { // disjointed, new extent needed Extent *le = new Extent( map_begin, in_blob_offset, map_end - map_begin, ex->blob); dout(20) << __func__ << " new extent " << le->print(pp_mode) << dendl; onode->extent_map.extent_map.insert(*le); + left_affected_range = std::min(left_affected_range, le->logical_offset); } } else if (ex->logical_offset >= map_end) { // we are adding to left side of target @@ -574,12 +576,14 @@ inline void BlueStore::Writer::_place_extent_in_blob( ex->blob_offset -= (map_end - map_begin); ex->length += (map_end - map_begin); dout(20) << __func__ << " expanded extent " << ex->print(pp_mode) << dendl; + right_affected_range = std::max(right_affected_range, ex->logical_end()); } else { // disjointed, new extent needed Extent *le = new Extent( map_begin, in_blob_offset, map_end - map_begin, ex->blob); dout(20) << __func__ << " new extent " << le->print(pp_mode) << dendl; onode->extent_map.extent_map.insert(*le); + right_affected_range = std::max(right_affected_range, le->logical_end()); } } } @@ -1404,8 +1408,6 @@ void BlueStore::Writer::do_write( _collect_released_allocated(); // update statfs txc->statfs_delta += statfs_delta; - onode->extent_map.dirty_range(location, data_end-location); - onode->extent_map.maybe_reshard(location, data_end); // note: compress extent is not needed; _try_reuse_allocated_* joins extents if possible // in other cases new blobs cannot be joined with existing ones dout(25) << "result: " << std::endl << onode->print(pp_mode) << dendl; diff --git a/src/os/bluestore/Writer.h b/src/os/bluestore/Writer.h index ae24066bdcc06..39f7c477b15b2 100644 --- a/src/os/bluestore/Writer.h +++ b/src/os/bluestore/Writer.h @@ -70,7 +70,8 @@ public: volatile_statfs statfs_delta; uint32_t left_shard_bound; // if sharding is in effect, uint32_t right_shard_bound; // do not cross this line - + uint32_t left_affected_range; + uint32_t right_affected_range; private: BlueStore* bstore; TransContext* txc; -- 2.39.5