]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: Moved selection of compressor to choose_write_options
authorAdam Kupczyk <akupczyk@ibm.com>
Thu, 13 Jun 2024 20:07:22 +0000 (20:07 +0000)
committerAdam Kupczyk <akupczyk@ibm.com>
Wed, 9 Apr 2025 13:59:07 +0000 (13:59 +0000)
This is borrowed from https://github.com/ceph/ceph/pull/57631;
selective cherry-picked from commit:
    os/bluestore: implement data reformatting on reads
Signed-off-by: Garry Drankovich <garry.drankovich@clyso.com>
Signed-off-by: Adam Kupczyk <akupczyk@ibm.com>
src/os/bluestore/BlueStore.cc
src/os/bluestore/BlueStore.h

index 279e008d128cb6573ac44c65f11702d02f86932a..a34c6f08992b8eac8b8bcf655ec0f05a3d2381e3 100644 (file)
@@ -16879,17 +16879,6 @@ int BlueStore::_do_alloc_write(
     return 0;
   }
 
-  CompressorRef c;
-  double crr = 0;
-  if (wctx->compress) {
-    c = coll->compression_algorithm.has_value() ?
-      compressors[*(coll->compression_algorithm)]:
-      compressors[def_compressor_alg];
-    crr = coll->compression_req_ratio.has_value() ?
-      *(coll->compression_req_ratio) :
-      cct->_conf->bluestore_compression_required_ratio;
-  }
-
   // checksum
   int64_t csum = wctx->csum_type;
 
@@ -16909,7 +16898,7 @@ int BlueStore::_do_alloc_write(
 
   auto max_bsize = std::max(wctx->target_blob_size, min_alloc_size);
   for (auto& wi : wctx->writes) {
-    if (c && wi.blob_length > min_alloc_size) {
+    if (wctx->compressor && wi.blob_length > min_alloc_size) {
       auto start = mono_clock::now();
 
       // compress
@@ -16919,8 +16908,8 @@ int BlueStore::_do_alloc_write(
       // FIXME: memory alignment here is bad
       bufferlist t;
       std::optional<int32_t> compressor_message;
-      int r = c->compress(wi.bl, t, compressor_message);
-      uint64_t want_len_raw = wi.blob_length * crr;
+      int r = wctx->compressor->compress(wi.bl, t, compressor_message);
+      uint64_t want_len_raw = wi.blob_length * wctx->crr;
       uint64_t want_len = p2roundup(want_len_raw, min_alloc_size);
       bool rejected = false;
       uint64_t compressed_len = t.length();
@@ -16929,7 +16918,7 @@ int BlueStore::_do_alloc_write(
       uint64_t result_len = p2roundup(compressed_len, min_alloc_size);
       if (r == 0 && result_len <= want_len && result_len < wi.blob_length) {
        bluestore_compression_header_t chdr;
-       chdr.type = c->get_type();
+       chdr.type = wctx->compressor->get_type();
        chdr.length = t.length();
        chdr.compressor_message = compressor_message;
        encode(chdr, wi.compressed_bl);
@@ -16946,7 +16935,7 @@ int BlueStore::_do_alloc_write(
          logger->inc(l_bluestore_write_pad_bytes, result_len - compressed_len);
          dout(20) << __func__ << std::hex << "  compressed 0x" << wi.blob_length
                   << " -> 0x" << compressed_len << " => 0x" << result_len
-                  << " with " << c->get_type()
+                  << " with " << wctx->compressor->get_type()
                   << std::dec << dendl;
          txc->statfs_delta.compressed() += compressed_len;
          txc->statfs_delta.compressed_original() += wi.blob_length;
@@ -16959,7 +16948,7 @@ int BlueStore::_do_alloc_write(
        }
       } else if (r != 0) {
        dout(5) << __func__ << std::hex << "  0x" << wi.blob_length
-                << " bytes compressed using " << c->get_type_name()
+                << " bytes compressed using " << wctx->compressor->get_type_name()
                 << std::dec
                 << " failed with errcode = " << r
                 << ", leaving uncompressed"
@@ -16974,7 +16963,7 @@ int BlueStore::_do_alloc_write(
       if (rejected) {
        dout(20) << __func__ << std::hex << "  0x" << wi.blob_length
                 << " compressed to 0x" << compressed_len << " -> 0x" << result_len
-                << " with " << c->get_type()
+                << " with " << wctx->compressor->get_type()
                 << ", which is more than required 0x" << want_len_raw
                 << " -> 0x" << want_len
                 << ", leaving uncompressed"
@@ -17366,6 +17355,14 @@ void BlueStore::_choose_write_options(
       wctx->target_blob_size < min_alloc_size * 2) {
     wctx->target_blob_size = min_alloc_size * 2;
   }
+  if (wctx->compress) {
+    wctx->compressor = c->compression_algorithm.has_value() ?
+      compressors[*(c->compression_algorithm)]:
+      compressors[def_compressor_alg];
+    wctx->crr = c->compression_req_ratio.has_value() ?
+      *(c->compression_req_ratio) :
+      cct->_conf->bluestore_compression_required_ratio;
+  }
 
   dout(20) << __func__ << " prefer csum_order " << wctx->csum_order
            << " target_blob_size 0x" << std::hex << wctx->target_blob_size
index bd53c9a1324825da6960d5a3838f3552fa4c2e9a..9bc60bf77426f9d042117c0694caa90bb09bac9d 100644 (file)
@@ -3663,6 +3663,8 @@ private:
   struct WriteContext {
     bool buffered = false;          ///< buffered write
     bool compress = false;          ///< compressed write
+    CompressorRef compressor;       ///< effective compression engine
+    double crr = 0.0;               ///< compression required ratio
     uint8_t csum_type = 0;          ///< checksum type for new blobs
     unsigned csum_order = 0;        ///< target checksum chunk order
     uint64_t target_blob_size = 0;  ///< target (max) blob size