Flexible I/O Tester development
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: Karthick Srinivasachary <karthick@pernixdata.com>, fio@vger.kernel.org
Subject: Re: Repeat given pattern with buffer_compress_percentage
Date: Wed, 03 Dec 2014 19:49:43 -0700	[thread overview]
Message-ID: <547FCBC7.20309@kernel.dk> (raw)
In-Reply-To: <547FCA1C.1000808@kernel.dk>

[-- Attachment #1: Type: text/plain, Size: 822 bytes --]

On 12/03/2014 07:42 PM, Jens Axboe wrote:
> On 12/03/2014 11:48 AM, Karthick Srinivasachary wrote:
>> Hi Folks,
>>
>> I have question. Any feedback appreciated..!
>>
>> With buffer_compress_percentage, fio writes random data + zeros.
>>
>> Is there a way to write random data + repeat_pattern (instead of
>> zero's). Pattern can be any user given pattern.
>
> We can just make it fill with buffer_pattern instead of zeroing. Given
> that the pattern is short enough, it should not skew the compression
> rate significantly.
>
> OK, did a quick patch and ran a quick test, looks like it's still within
> half a percent.
>
> Pull the latest -git, then apply the attached patch. That should do what
> you want. Please report back.

Use this -v2 instead, it fixes a crash if you _don't_ set buffer_pattern...

-- 
Jens Axboe


[-- Attachment #2: refill-compress-pattern-v2.patch --]
[-- Type: text/x-patch, Size: 4986 bytes --]

diff --git a/io_u.c b/io_u.c
index 33c82f2c4e9e..963e8cb764b9 100644
--- a/io_u.c
+++ b/io_u.c
@@ -1859,9 +1859,9 @@ static void save_buf_state(struct thread_data *td, struct frand_state *rs)
 void fill_io_buffer(struct thread_data *td, void *buf, unsigned int min_write,
 		    unsigned int max_bs)
 {
-	if (td->o.buffer_pattern_bytes)
-		fill_buffer_pattern(td, buf, max_bs);
-	else if (!td->o.zero_buffers) {
+	struct thread_options *o = &td->o;
+
+	if (o->compress_percentage && !o->zero_buffers) {
 		unsigned int perc = td->o.compress_percentage;
 		struct frand_state *rs;
 		unsigned int left = max_bs;
@@ -1879,7 +1879,8 @@ void fill_io_buffer(struct thread_data *td, void *buf, unsigned int min_write,
 					seg = min_write;
 
 				fill_random_buf_percentage(rs, buf, perc, seg,
-								min_write);
+					min_write, o->buffer_pattern,
+						   o->buffer_pattern_bytes);
 			} else
 				fill_random_buf(rs, buf, min_write);
 
@@ -1887,7 +1888,9 @@ void fill_io_buffer(struct thread_data *td, void *buf, unsigned int min_write,
 			left -= min_write;
 			save_buf_state(td, rs);
 		} while (left);
-	} else
+	} else if (o->buffer_pattern_bytes && !o->zero_buffers)
+		fill_buffer_pattern(td, buf, max_bs);
+	else
 		memset(buf, 0, max_bs);
 }
 
diff --git a/lib/rand.c b/lib/rand.c
index a79fb9c17c32..e5332bfe7924 100644
--- a/lib/rand.c
+++ b/lib/rand.c
@@ -34,6 +34,7 @@
 */
 
 #include <string.h>
+#include <assert.h>
 #include "rand.h"
 #include "../hash.h"
 
@@ -90,15 +91,45 @@ unsigned long fill_random_buf(struct frand_state *fs, void *buf,
 	return r;
 }
 
+void fill_pattern(void *p, unsigned int len, char *pattern,
+		  unsigned int pattern_bytes)
+{
+	switch (pattern_bytes) {
+	case 0:
+		assert(0);
+		break;
+	case 1:
+		memset(p, pattern[0], len);
+		break;
+	default: {
+		unsigned int i = 0, size = 0;
+		unsigned char *b = p;
+
+		while (i < len) {
+			size = pattern_bytes;
+			if (size > (len - i))
+				size = len - i;
+			memcpy(b+i, pattern, size);
+			i += size;
+		}
+		break;
+		}
+	}
+}
+
 unsigned long fill_random_buf_percentage(struct frand_state *fs, void *buf,
 					 unsigned int percentage,
-					 unsigned int segment, unsigned int len)
+					 unsigned int segment, unsigned int len,
+					 char *pattern, unsigned int pbytes)
 {
 	unsigned long r = __rand(fs);
 	unsigned int this_len;
 
 	if (percentage == 100) {
-		memset(buf, 0, len);
+		if (pbytes)
+			fill_pattern(buf, len, pattern, pbytes);
+		else
+			memset(buf, 0, len);
 		return 0;
 	}
 
@@ -124,7 +155,10 @@ unsigned long fill_random_buf_percentage(struct frand_state *fs, void *buf,
 		if (this_len > len)
 			this_len = len;
 
-		memset(buf, 0, this_len);
+		if (pbytes)
+			fill_pattern(buf, this_len, pattern, pbytes);
+		else
+			memset(buf, 0, this_len);
 		len -= this_len;
 		buf += this_len;
 	}
diff --git a/lib/rand.h b/lib/rand.h
index 8c35ab1fa263..803bea484757 100644
--- a/lib/rand.h
+++ b/lib/rand.h
@@ -30,6 +30,7 @@ extern void init_rand(struct frand_state *);
 extern void init_rand_seed(struct frand_state *, unsigned int seed);
 extern void __fill_random_buf(void *buf, unsigned int len, unsigned long seed);
 extern unsigned long fill_random_buf(struct frand_state *, void *buf, unsigned int len);
-extern unsigned long fill_random_buf_percentage(struct frand_state *, void *buf, unsigned int percentage, unsigned int segment, unsigned int len);
+extern unsigned long fill_random_buf_percentage(struct frand_state *, void *, unsigned int, unsigned int, unsigned int, char *, unsigned int);
+extern void fill_pattern(void *p, unsigned int len, char *pattern, unsigned int pattern_bytes);
 
 #endif
diff --git a/options.c b/options.c
index 23469d8d793c..75cfe6df4b06 100644
--- a/options.c
+++ b/options.c
@@ -1048,6 +1048,7 @@ static int str_buffer_compress_cb(void *data, unsigned long long *il)
 
 	td->flags |= TD_F_COMPRESS;
 	td->o.compress_percentage = *il;
+	td->o.refill_buffers = 1;
 	return 0;
 }
 
diff --git a/verify.c b/verify.c
index c2b3c40edef8..c1791fc69743 100644
--- a/verify.c
+++ b/verify.c
@@ -29,36 +29,6 @@ static void populate_hdr(struct thread_data *td, struct io_u *io_u,
 			 struct verify_header *hdr, unsigned int header_num,
 			 unsigned int header_len);
 
-static void fill_pattern(void *p, unsigned int len, char *pattern,
-			 unsigned int pattern_bytes)
-{
-	switch (pattern_bytes) {
-	case 0:
-		assert(0);
-		break;
-	case 1:
-		dprint(FD_VERIFY, "fill verify pattern b=0 len=%u\n", len);
-		memset(p, pattern[0], len);
-		break;
-	default: {
-		unsigned int i = 0, size = 0;
-		unsigned char *b = p;
-
-		dprint(FD_VERIFY, "fill verify pattern b=%d len=%u\n",
-					pattern_bytes, len);
-
-		while (i < len) {
-			size = pattern_bytes;
-			if (size > (len - i))
-				size = len - i;
-			memcpy(b+i, pattern, size);
-			i += size;
-		}
-		break;
-		}
-	}
-}
-
 void fill_buffer_pattern(struct thread_data *td, void *p, unsigned int len)
 {
 	fill_pattern(p, len, td->o.buffer_pattern, td->o.buffer_pattern_bytes);

  reply	other threads:[~2014-12-04  2:49 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-03 18:48 Repeat given pattern with buffer_compress_percentage Karthick Srinivasachary
2014-12-03 19:45 ` Andrey Kuzmin
2014-12-03 19:49   ` Karthick Srinivasachary
2014-12-03 19:52     ` Andrey Kuzmin
2014-12-04  2:42 ` Jens Axboe
2014-12-04  2:49   ` Jens Axboe [this message]
2014-12-04  2:58     ` Jens Axboe
2014-12-04  7:53       ` Karthick Srinivasachary
2014-12-04 15:27         ` Jens Axboe
2014-12-04 22:41           ` Jens Axboe
2014-12-05  7:25             ` Karthick Srinivasachary
2014-12-05 17:02               ` Jens Axboe
2014-12-05 17:20                 ` Jens Axboe
2014-12-05 17:46                   ` Jens Axboe
2014-12-05 20:06                     ` Karthick Srinivasachary

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=547FCBC7.20309@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=fio@vger.kernel.org \
    --cc=karthick@pernixdata.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox