]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: Make write_v2 not need to use compress_extents
authorAdam Kupczyk <akupczyk@ibm.com>
Thu, 6 Mar 2025 19:40:29 +0000 (19:40 +0000)
committerAdam Kupczyk <akupczyk@ibm.com>
Thu, 13 Mar 2025 06:49:03 +0000 (06:49 +0000)
Remove need to call compress_extents.
The only place that could produce compressable extents are
_try_reuse_allocated_[l/r] functions.

Create _place_extent_in_blob() function that adds mapping to blob.
If possible, it expands the extent; if not, creates the new one.
The function is used whenever we need new mapping to an existing Blob.

Signed-off-by: Adam Kupczyk <akupczyk@ibm.com>
Signed-off-by: Adam Kupczyk <akupczyk@ibm.com>
src/os/bluestore/Writer.cc
src/os/bluestore/Writer.h

index a41cab3cb87297c77ab46551f126c2c01e27988b..ef9d4b18971f481a89bab575ec4b16fdcc2c35a3 100644 (file)
@@ -282,7 +282,6 @@ inline BlueStore::extent_map_t::iterator BlueStore::Writer::_find_mutable_blob_r
       if (it->blob_end() <= mapmust_end) continue;
     }
     return it;
-    break;
   };
   return map.end();
 }
@@ -547,6 +546,44 @@ BlueStore::BlobRef BlueStore::Writer::_blob_create_full(
   return blob;
 }
 
+inline void BlueStore::Writer::_place_extent_in_blob(
+  Extent* ex,
+  uint32_t map_begin,
+  uint32_t map_end,
+  uint32_t in_blob_offset)
+{
+  if (ex->logical_end() <= map_begin) {
+    // we are adding to right side of the target
+    if (ex->logical_end() == map_begin) {
+      // we can just expand existing Extent
+      ex->length += map_end - map_begin;
+      dout(20) << __func__ << " expanded extent " << ex->print(pp_mode) << dendl;
+    } 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);
+    }
+  } else if (ex->logical_offset >= map_end) {
+    // we are adding to left side of target
+    if (ex->logical_offset == map_end) {
+      // we can just expand existing Extent
+      //ceph_assert(ref_end == want_subau_end);
+      ex->logical_offset -= (map_end - map_begin);
+      ex->blob_offset -= (map_end - map_begin);
+      ex->length += (map_end - map_begin);
+      dout(20) << __func__ << " expanded extent " << ex->print(pp_mode) << dendl;
+    } 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);
+    }
+  }
+}
+
 /**
  * Note from developer
  * This module tries to keep naming convention:
@@ -782,11 +819,7 @@ void BlueStore::Writer::_try_reuse_allocated_l(
     uint32_t ref_end = std::min(ref_end_offset, want_subau_end);
     //fixme/improve - need something without stupid extras - that is without coll
     b->get_ref(onode->c, in_blob_offset, ref_end - want_subau_begin);
-    Extent *le = new Extent(
-      want_subau_begin, in_blob_offset, ref_end - want_subau_begin, it->blob);
-    dout(20) << __func__ << " new extent " << le->print(pp_mode) << dendl;
-    emap.extent_map.insert(*le);
-
+    _place_extent_in_blob(&*it, want_subau_begin, ref_end, in_blob_offset);
     logical_offset += data_size;
     break;
   }
@@ -856,11 +889,7 @@ void BlueStore::Writer::_try_reuse_allocated_r(
     uint32_t ref_end = std::min(ref_end_offset, want_subau_end);
     //fixme/improve - need something without stupid extras - that is without coll
     b->get_ref(onode->c, in_blob_offset, ref_end - want_subau_begin);
-    Extent *le = new Extent(
-      want_subau_begin, in_blob_offset, ref_end - want_subau_begin, it->blob);
-    dout(20) << __func__ << " new extent " << le->print(pp_mode) << dendl;
-    emap.extent_map.insert(*le);
-
+    _place_extent_in_blob(&*it, want_subau_begin, ref_end, in_blob_offset);
     end_offset -= data_size;
     break;
   }
@@ -1025,14 +1054,11 @@ void BlueStore::Writer::_do_put_blobs(
       uint32_t ref_end = std::min(ref_end_offset, data_end_offset);
       //fixme/improve - need something without stupid extras - that is without coll
       left_b->blob->get_ref(coll, in_blob_offset, ref_end - logical_offset);
-      Extent *le = new Extent(
-        logical_offset, in_blob_offset, ref_end - logical_offset, left_b->blob);
-      dout(20) << __func__ << " new extent " << le->print(pp_mode) << dendl;
-      emap.insert(*le);
+      _place_extent_in_blob(&*left_b, logical_offset, ref_end, in_blob_offset);
+      bstore->logger->inc(l_bluestore_write_small);
+      bstore->logger->inc(l_bluestore_write_small_bytes, ref_end - logical_offset);
       logical_offset = ref_end;
       ++bd_it;
-      bstore->logger->inc(l_bluestore_write_small);
-      bstore->logger->inc(l_bluestore_write_small_bytes, le->length);
     } else {
       // it is still possible to use first bd and put it into
       // blob after punch_hole
@@ -1064,13 +1090,10 @@ void BlueStore::Writer::_do_put_blobs(
         uint32_t ref_end = std::min(ref_end_offset, data_begin_offset + back_it->disk_data.length());
         //fixme - need something without stupid extras
         right_b->blob->get_ref(coll, in_blob_offset, ref_end - data_begin_offset);
-        Extent *le = new Extent(
-          data_begin_offset, in_blob_offset, ref_end - data_begin_offset, right_b->blob);
-        dout(20) << __func__ << " new extent " << le->print(pp_mode) << dendl;
-        emap.insert(*le);
+        _place_extent_in_blob(&*right_b, data_begin_offset, ref_end, in_blob_offset);
         bd.erase(back_it); //TODO - or other way of limiting end
         bstore->logger->inc(l_bluestore_write_small);
-        bstore->logger->inc(l_bluestore_write_small_bytes, le->length);
+        bstore->logger->inc(l_bluestore_write_small_bytes, ref_end - data_begin_offset);
       }
     }
   }
@@ -1381,9 +1404,10 @@ void BlueStore::Writer::do_write(
   _collect_released_allocated();
   // update statfs
   txc->statfs_delta += statfs_delta;
-  onode->extent_map.compress_extent_map(location, data_end - location);
   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;
 }
 
index f12d25c2f1bfab52ae3c27ebad0510647c5a31a7..ae24066bdcc0628c3d7ccdb4519d253e2cc92e8f 100644 (file)
@@ -143,8 +143,13 @@ private:
   void _align_to_disk_block(
     uint32_t& location,
     uint32_t& ref_end,
-    blob_vec& blobs
-  );
+    blob_vec& blobs);
+
+  void _place_extent_in_blob(
+    Extent* target,
+    uint32_t map_begin,
+    uint32_t map_end,
+    uint32_t in_blob_offset);
 
   inline void _blob_put_data_subau(
     Blob* blob,