]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
compressor/zlib: switch to raw deflate 11122/head
authorPiotr Dałek <git@predictor.org.pl>
Sat, 17 Sep 2016 22:10:40 +0000 (00:10 +0200)
committerPiotr Dałek <git@predictor.org.pl>
Sat, 17 Sep 2016 22:10:40 +0000 (00:10 +0200)
By using raw deflate instead of default zlib deflate, we're
saving 6 bytes on each compression stream and some CPU time
by not calculating Adler32 during both compression and
decompression (which is waste of time as Bluestore has its
own checksumming code that is *also* executed).

Signed-off-by: Piotr Dałek <git@predictor.org.pl>
src/compressor/zlib/ZlibCompressor.cc

index 137c682c99b012ab47e1480b11989620019525b1..b7c33a20adcb837b1d6c550fd347bee047e6cfd8 100644 (file)
@@ -38,20 +38,30 @@ _prefix(std::ostream* _dout)
 
 #define MAX_LEN (CEPH_PAGE_SIZE)
 
+// default window size for Zlib 1.2.8, negated for raw deflate
+#define ZLIB_DEFAULT_WIN_SIZE -15
+
+// compression level we use. probably should be configurable...
+#define ZLIB_COMPRESSION_LEVEL 5
+
+// desired memory usage level. increasing to 9 doesn't speed things up
+// significantly (helps only on >=16K blocks) and sometimes degrades
+// compression ratio.
+#define ZLIB_MEMORY_LEVEL 8
+
 int ZlibCompressor::zlib_compress(const bufferlist &in, bufferlist &out)
 {
   int ret;
   unsigned have;
   z_stream strm;
   unsigned char* c_in;
-  int level = 5;
   int begin = 1;
 
   /* allocate deflate state */
   strm.zalloc = Z_NULL;
   strm.zfree = Z_NULL;
   strm.opaque = Z_NULL;
-  ret = deflateInit(&strm, level);
+  ret = deflateInit2(&strm, ZLIB_COMPRESSION_LEVEL, Z_DEFLATED, ZLIB_DEFAULT_WIN_SIZE, ZLIB_MEMORY_LEVEL, Z_DEFAULT_STRATEGY);
   if (ret != Z_OK) {
     dout(1) << "Compression init error: init return "
          << ret << " instead of Z_OK" << dendl;
@@ -74,6 +84,7 @@ int ZlibCompressor::zlib_compress(const bufferlist &in, bufferlist &out)
       strm.next_out = (unsigned char*)ptr.c_str() + begin;
       strm.avail_out = MAX_LEN - begin;
       if (begin) {
+        // put a compressor variation mark in front of compressed stream
         ptr.c_str()[0] = 0;
         begin = 0;
       }
@@ -129,6 +140,7 @@ int ZlibCompressor::isal_compress(const bufferlist &in, bufferlist &out)
       strm.next_out = (unsigned char*)ptr.c_str() + begin;
       strm.avail_out = MAX_LEN - begin;
       if (begin) {
+        // put a compressor variation mark in front of compressed stream
         ptr.c_str()[0] = 1;
         begin = 0;
       }
@@ -177,10 +189,12 @@ int ZlibCompressor::decompress(bufferlist::iterator &p, size_t compressed_size,
   strm.opaque = Z_NULL;
   strm.avail_in = 0;
   strm.next_in = Z_NULL;
+
+  // choose the variation of compressor
   if (*p == 1)
     ret = inflateInit2(&strm, -HIST_SIZE);
   else
-    ret = inflateInit(&strm);
+    ret = inflateInit2(&strm, ZLIB_DEFAULT_WIN_SIZE);
   if (ret != Z_OK) {
     dout(1) << "Decompression init error: init return "
          << ret << " instead of Z_OK" << dendl;