From 23f394d5d70902c6f1d71ac03fa1d70e13c9c0b9 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Fri, 16 Sep 2011 22:45:27 +0200 Subject: [PATCH] Scramble on a 512b boundary 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 --- io_u.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/io_u.c b/io_u.c index af2d05f3..f4c4aa2c 100644 --- 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; + } } /* -- 2.25.1