Compression fixes
authorJens Axboe <axboe@kernel.dk>
Fri, 2 Mar 2012 21:23:36 +0000 (22:23 +0100)
committerJens Axboe <axboe@kernel.dk>
Fri, 2 Mar 2012 21:23:36 +0000 (22:23 +0100)
- memset() remainder of buffer instead of copying random segment.
  Provides more reliable compression (yes yes, you told me so).

- Allow 100 as well, just means full memset. Make that just set
  zero_buffers=1 instead, since we only need to do it once
  instead of for every write.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
init.c
lib/rand.c

diff --git a/init.c b/init.c
index 710e86730b7d82aa085eff13433dcc536df1f7f0..6c74ea6b75ddc403d0abc4b59d84de0b8c22a960 100644 (file)
--- a/init.c
+++ b/init.c
@@ -568,6 +568,15 @@ static int fixup_options(struct thread_data *td)
        }
 #endif
 
+       /*
+        * For fully compressible data, just zero them at init time.
+        * It's faster than repeatedly filling it.
+        */
+       if (td->o.compress_percentage == 100) {
+               td->o.zero_buffers = 1;
+               td->o.compress_percentage = 0;
+       }
+
        return ret;
 }
 
index 66d04729a49eaa073f822d77a93b66ae426f659d..995035fea742ad211f757bc12427c2160629b4c1 100644 (file)
@@ -34,7 +34,6 @@
 */
 
 #include <string.h>
-#include <assert.h>
 #include "rand.h"
 #include "../hash.h"
 
@@ -95,10 +94,16 @@ unsigned long fill_random_buf_percentage(struct frand_state *fs, void *buf,
                                         unsigned int percentage,
                                         unsigned int segment, unsigned int len)
 {
-       unsigned int this_len, rep_len;
        unsigned long r = __rand(fs);
+       unsigned int this_len;
 
-       assert(segment <= len);
+       if (percentage == 100) {
+               memset(buf, 0, len);
+               return 0;
+       }
+
+       if (segment > len)
+               segment = len;
 
        if (sizeof(int) != sizeof(long *))
                r *= (unsigned long) __rand(fs);
@@ -116,16 +121,10 @@ unsigned long fill_random_buf_percentage(struct frand_state *fs, void *buf,
                len -= this_len;
                buf += this_len;
 
-               /*
-                * Now duplicate random chunk in rest of buf
-                */
-               rep_len = segment - this_len;
-               if (rep_len > len)
-                       rep_len = len;
+               if (this_len > len)
+                       this_len = len;
 
-               memcpy(buf, buf + rep_len, rep_len);
-               buf += rep_len;
-               len -= rep_len;
+               memset(buf, 0, this_len);
        }
 
        return r;