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")
#include "FreelistManager.h"
#include "BlueFS.h"
#include "BlueRocksEnv.h"
-#include "compressor/Compressor.h"
#define dout_subsys ceph_subsys_bluestore
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()
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;
}
goto out_stop;
_set_csum();
+ _set_compression();
+
mounted = true;
return 0;
#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"
const std::set<std::string> &changed) override;
void _set_csum();
+ void _set_compression();
+
class TransContext;
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
// 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(