From: Sage Weil Date: Mon, 23 May 2016 19:03:18 +0000 (-0400) Subject: os/bluestore: track new compression config options X-Git-Tag: v11.0.0~359^2~28 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=53b73328dd30de903897f362926d2b7f991706db;p=ceph.git 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 --- diff --git a/src/common/config_opts.h b/src/common/config_opts.h index 6d4fa06167df..866074189ca2 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -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") diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index a429ee419189..b957dd979001 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -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; diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 583373625c38..eaa6678d2b97 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -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 &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 lex_new; ///< new lextents vector lex_old; ///< must deref blobs vector blob_new; ///< new blobs vector bl_new; ///< new data, for above blobs - - WriteContext() : fadvise_flags(0), buffered(false) {} }; void _do_write_small(