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)
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
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) {