Skip to content

Commit

Permalink
os/bluestore: add compression required ratio to enable/disable compre…
Browse files Browse the repository at this point in the history
…ssion

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>
  • Loading branch information
xiexingguo committed Jul 1, 2016
1 parent 85bb43e commit 819e854
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/common/config_opts.h
Expand Up @@ -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)
Expand Down
15 changes: 10 additions & 5 deletions src/os/bluestore/BlueStore.cc
Expand Up @@ -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) {
// 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
Expand All @@ -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) {
Expand Down

0 comments on commit 819e854

Please sign in to comment.