]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
os/bluestore: add compression required ratio to enable/disable compression
authorxie xingguo <xie.xingguo@zte.com.cn>
Fri, 1 Jul 2016 03:19:13 +0000 (11:19 +0800)
committerxie xingguo <xie.xingguo@zte.com.cn>
Sat, 2 Jul 2016 01:57:10 +0000 (09:57 +0800)
Require the net gain of compression at least to be at a specified ratio,
otherwise we don't compress.

Ask for compressing at least 12.5% off, by default.

This is for the sake of performance because if the compression turns out
to be meaningless(saving little space), we can simply shut it down, as we
know the compression/decompression can be rather CPU-consuming.

Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
src/common/config_opts.h
src/os/bluestore/BlueStore.cc

index 221e8507d4d537bd1f070fb1afeafc005ae4a33a..10d91b4c0107be1ad042ac71733e94de69b13789 100644 (file)
@@ -965,6 +965,12 @@ OPTION(bluestore_compression, OPT_STR, "none")  // force|aggressive|passive|none
 OPTION(bluestore_compression_algorithm, OPT_STR, "snappy")
 OPTION(bluestore_compression_min_blob_size, OPT_U32, 256*1024)
 OPTION(bluestore_compression_max_blob_size, OPT_U32, 4*1024*1024)
+/*
+ * Require the net gain of compression at least to be at this ratio,
+ * otherwise we don't compress.
+ * And ask for compressing at least 12.5%(1/8) off, by default.
+ */
+OPTION(bluestore_compression_required_ratio, OPT_DOUBLE, .875)
 OPTION(bluestore_cache_type, OPT_STR, "2q")   // lru, 2q
 OPTION(bluestore_onode_cache_size, OPT_U32, 16*1024)
 OPTION(bluestore_buffer_cache_size, OPT_U32, 512*1024*1024)
index 3ec1533bfb746ae3f17a07d75dfd0d8ceb6e1be5..f080eb9c5ba8e3759f57fab45aa4b46cde1c554a 100644 (file)
@@ -5943,8 +5943,12 @@ int BlueStore::_do_alloc_write(
       compressed_bl.claim_append(t);
       uint64_t rawlen = compressed_bl.length();
       uint64_t newlen = ROUND_UP_TO(rawlen, min_alloc_size);
-      if (newlen < final_length) {
-       // pad out to min_alloc_size
+      uint64_t dstlen = final_length *
+        g_conf->bluestore_compression_required_ratio;
+      dstlen = ROUND_UP_TO(dstlen, min_alloc_size);
+      if (newlen <= dstlen && newlen < final_length) {
+        // Cool. We compressed at least as much as we were hoping to.
+        // pad out to min_alloc_size
        compressed_bl.append_zero(newlen - rawlen);
        logger->inc(l_bluestore_write_pad_bytes, newlen - rawlen);
        dout(20) << __func__ << hex << "  compressed 0x" << wi.blob_length
@@ -5962,9 +5966,10 @@ int BlueStore::_do_alloc_write(
        compressed = true;
       } else {
        dout(20) << __func__ << hex << "  compressed 0x" << l->length()
-                << " -> 0x" << rawlen << " with " << chdr.type
-                << ", leaving uncompressed"
-                << dec << dendl;
+                 << " -> 0x" << rawlen << " with " << chdr.type
+                 << ", which is more than required 0x" << dstlen
+                 << ", leaving uncompressed"
+                 << dec << dendl;
       }
     }
     if (!compressed) {