os/bluestore: track new compression config options

Class-wide Compressor, compression mode, and options.  For now these are
global, although later we'll do them per-Collection so they can be pool-
specific.

Signed-off-by: Sage Weil <sage@redhat.com>
This commit is contained in:
Sage Weil 2016-05-23 15:03:18 -04:00
parent a7c9c84eac
commit 53b73328dd
3 changed files with 88 additions and 7 deletions

View File

@ -956,6 +956,10 @@ OPTION(bluestore_max_csum_block, OPT_U32, 64*1024)
OPTION(bluestore_min_alloc_size, OPT_U32, 0)
OPTION(bluestore_min_alloc_size_hdd, OPT_U32, 64*1024)
OPTION(bluestore_min_alloc_size_ssd, OPT_U32, 4*1024)
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)
OPTION(bluestore_onode_map_size, OPT_U32, 1024) // onodes per collection
OPTION(bluestore_cache_tails, OPT_BOOL, true) // cache tail blocks in Onode
OPTION(bluestore_kvbackend, OPT_STR, "rocksdb")

View File

@ -29,7 +29,6 @@
#include "FreelistManager.h"
#include "BlueFS.h"
#include "BlueRocksEnv.h"
#include "compressor/Compressor.h"
#define dout_subsys ceph_subsys_bluestore
@ -802,6 +801,58 @@ void BlueStore::handle_conf_change(const struct md_config_t *conf,
changed.count("bluestore_csum")) {
_set_csum();
}
if (changed.count("bluestore_compression") ||
changed.count("bluestore_compression_algorithm") ||
changed.count("bluestore_compression_min_blob_size") ||
changed.count("bluestore_compression_max_blob_size")) {
_set_compression();
}
}
void BlueStore::_set_compression()
{
comp_min_blob_size = g_conf->bluestore_compression_min_blob_size;
comp_max_blob_size = g_conf->bluestore_compression_max_blob_size;
const char *alg = 0;
if (g_conf->bluestore_compression_algorithm == "snappy") {
alg = "snappy";
} else if (g_conf->bluestore_compression_algorithm == "zlib") {
alg = "zlib";
} else if (g_conf->bluestore_compression_algorithm.length()) {
derr << __func__ << " unrecognized compression algorithm '"
<< g_conf->bluestore_compression_algorithm << "'" << dendl;
}
if (alg) {
compressor = Compressor::create(cct, alg);
if (!compressor) {
derr << __func__ << " unable to initialize " << alg << " compressor"
<< dendl;
}
} else {
compressor = nullptr;
}
CompressionMode m = COMP_NONE;
if (compressor) {
if (g_conf->bluestore_compression == "force") {
m = COMP_FORCE;
} else if (g_conf->bluestore_compression == "aggressive") {
m = COMP_AGGRESSIVE;
} else if (g_conf->bluestore_compression == "passive") {
m = COMP_PASSIVE;
} else if (g_conf->bluestore_compression == "none") {
m = COMP_NONE;
} else {
derr << __func__ << " unrecognized value '"
<< g_conf->bluestore_compression
<< "' for bluestore_compression, reverting to 'none'" << dendl;
m = COMP_NONE;
}
}
comp_mode = m;
dout(10) << __func__ << " mode " << get_comp_mode_name(comp_mode)
<< " alg " << (compressor ? compressor->get_type() : "(none)")
<< dendl;
}
void BlueStore::_set_csum()
@ -1953,7 +2004,8 @@ int BlueStore::mount()
string type;
int r = read_meta("type", &type);
if (r < 0) {
derr << __func__ << " failed to load os-type: " << cpp_strerror(r) << dendl;
derr << __func__ << " failed to load os-type: " << cpp_strerror(r)
<< dendl;
return r;
}
@ -2027,6 +2079,8 @@ int BlueStore::mount()
goto out_stop;
_set_csum();
_set_compression();
mounted = true;
return 0;

View File

@ -31,6 +31,7 @@
#include "include/unordered_map.h"
#include "include/memory.h"
#include "common/Finisher.h"
#include "compressor/Compressor.h"
#include "os/ObjectStore.h"
#include "bluestore_types.h"
@ -69,6 +70,8 @@ public:
const std::set<std::string> &changed) override;
void _set_csum();
void _set_compression();
class TransContext;
@ -888,6 +891,27 @@ private:
uint64_t min_alloc_size; ///< minimum allocation unit (power of 2)
// compression options
enum CompressionMode {
COMP_NONE, ///< compress never
COMP_PASSIVE, ///< compress if hinted COMPRESSIBLE
COMP_AGGRESSIVE, ///< compress unless hinted INCOMPRESSIBLE
COMP_FORCE ///< compress always
};
const char *get_comp_mode_name(int m) {
switch (m) {
case COMP_NONE: return "none";
case COMP_PASSIVE: return "passive";
case COMP_AGGRESSIVE: return "aggressive";
case COMP_FORCE: return "force";
default: return "???";
}
}
CompressionMode comp_mode = COMP_NONE; ///< compression mode
CompressorRef compressor;
uint64_t comp_min_blob_size = 0;
uint64_t comp_max_blob_size = 0;
// --------------------------------------------------------
// private methods
@ -1205,15 +1229,14 @@ private:
// write ops
struct WriteContext {
unsigned fadvise_flags; ///< write flags
bool buffered; ///< buffered write
unsigned fadvise_flags = 0; ///< write flags
bool buffered = false; ///< buffered write
bool compress = false; ///< compressed write
uint64_t comp_blob_size = 0; ///< target compressed blob size
//map<uint64_t,bluestore_lextent_t> lex_new; ///< new lextents
vector<bluestore_lextent_t> lex_old; ///< must deref blobs
vector<bluestore_blob_t*> blob_new; ///< new blobs
vector<bufferlist> bl_new; ///< new data, for above blobs
WriteContext() : fadvise_flags(0), buffered(false) {}
};
void _do_write_small(