Scramble on a 512b boundary
authorJens Axboe <axboe@kernel.dk>
Fri, 16 Sep 2011 20:45:27 +0000 (22:45 +0200)
committerJens Axboe <axboe@kernel.dk>
Fri, 16 Sep 2011 20:47:15 +0000 (22:47 +0200)
Instead of just scrambling the full block at the beginning at the
end, make it a bit more clever by:

- Doing it at 512b intervals to ensure full 512b de-dupe attemts, and
- Do it at a "random" offset into that block.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_u.c

diff --git a/io_u.c b/io_u.c
index af2d05f360eaed2f4d6c169f6ee5eb5f62da18f8..f4c4aa2ca432532d894d61c9559940c7b1ee43b4 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -1122,15 +1122,35 @@ static int check_get_verify(struct thread_data *td, struct io_u *io_u)
 
 /*
  * Fill offset and start time into the buffer content, to prevent too
- * easy compressible data for simple de-dupe attempts.
+ * easy compressible data for simple de-dupe attempts. Do this for every
+ * 512b block in the range, since that should be the smallest block size
+ * we can expect from a device.
  */
 static void small_content_scramble(struct io_u *io_u)
 {
-       void *end;
+       unsigned int i, nr_blocks = io_u->buflen / 512;
+       unsigned int offset;
+       void *p, *end;
 
-       *((unsigned long long *) io_u->xfer_buf) = io_u->offset;
-       end = io_u->xfer_buf + io_u->xfer_buflen - sizeof(io_u->start_time);
-       memcpy(end, &io_u->start_time, sizeof(io_u->start_time));
+       if (!nr_blocks)
+               return;
+
+       p = io_u->xfer_buf;
+       for (i = 0; i < nr_blocks; i++) {
+               /*
+                * Fill the byte offset into a "random" start offset of
+                * the buffer, given by the product of the usec time
+                * and the actual offset.
+                */
+               offset = (io_u->start_time.tv_usec * io_u->offset) & 511;
+               if (offset >= 512 - sizeof(unsigned long long))
+                       offset -= sizeof(unsigned long long);
+               *((unsigned long long *) p + offset) = io_u->offset;
+
+               end = p + 512 - sizeof(io_u->start_time);
+               memcpy(end, &io_u->start_time, sizeof(io_u->start_time));
+               p += 512;
+       }
 }
 
 /*