From 0f706479f2a93638772dd8156ab60a569921f2fc Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Fri, 1 Jul 2016 11:19:13 +0800 Subject: [PATCH] os/bluestore: add compression required ratio to enable/disable compression 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 --- src/common/config_opts.h | 6 ++++++ src/os/bluestore/BlueStore.cc | 15 ++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/common/config_opts.h b/src/common/config_opts.h index 221e8507d4d..10d91b4c010 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -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) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 3ec1533bfb7..f080eb9c5ba 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -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) {