From 5973cafb37fbf24c3ca2cdf86a3d03f1b00d6d2b Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Wed, 21 May 2008 19:52:35 +0200 Subject: [PATCH] Add option for refilling IO buffers on each submit If the device looks at whether the data changed, then this can make a difference. Signed-off-by: Jens Axboe --- HOWTO | 5 +++++ fio.c | 20 ++------------------ fio.h | 2 ++ io_u.c | 21 +++++++++++++++++++++ options.c | 6 ++++++ 5 files changed, 36 insertions(+), 18 deletions(-) diff --git a/HOWTO b/HOWTO index 32e7322c..36e42aaf 100644 --- a/HOWTO +++ b/HOWTO @@ -336,6 +336,11 @@ bs_unaligned If this option is given, any byte size value within bsrange zero_buffers If this option is given, fio will init the IO buffers to all zeroes. The default is to fill them with random data. +refill_buffers If this option is given, fio will refill the IO buffers + on every submit. The default is to only fill it at init + time and reuse that data. Only makes sense if zero_buffers + isn't specified, naturally. + nrfiles=int Number of files to use for this job. Defaults to 1. openfiles=int Number of files to keep open at the same time. Defaults to diff --git a/fio.c b/fio.c index b79aa93e..c79fad87 100644 --- a/fio.c +++ b/fio.c @@ -642,22 +642,6 @@ static void cleanup_io_u(struct thread_data *td) free_io_mem(td); } -/* - * "randomly" fill the buffer contents - */ -static void fill_io_buf(struct thread_data *td, struct io_u *io_u, int max_bs) -{ - long *ptr = io_u->buf; - - if (!td->o.zero_buffers) { - while ((void *) ptr - io_u->buf < max_bs) { - *ptr = rand() * GOLDEN_RATIO_PRIME; - ptr++; - } - } else - memset(ptr, 0, max_bs); -} - static int init_io_u(struct thread_data *td) { struct io_u *io_u; @@ -700,8 +684,8 @@ static int init_io_u(struct thread_data *td) if (!(td->io_ops->flags & FIO_NOIO)) { io_u->buf = p + max_bs * i; - if (td_write(td)) - fill_io_buf(td, io_u, max_bs); + if (td_write(td) && !td->o.refill_buffers) + io_u_fill_buffer(td, io_u, max_bs); } io_u->index = i; diff --git a/fio.h b/fio.h index 47b6d488..25d05bdc 100644 --- a/fio.h +++ b/fio.h @@ -478,6 +478,7 @@ struct thread_options { unsigned int group_reporting; unsigned int fadvise_hint; unsigned int zero_buffers; + unsigned int refill_buffers; unsigned int time_based; char *read_iolog_file; @@ -907,6 +908,7 @@ extern void io_u_log_error(struct thread_data *, struct io_u *); extern void io_u_init_timeout(void); extern void io_u_set_timeout(struct thread_data *); extern void io_u_mark_depth(struct thread_data *, unsigned int); +extern void io_u_fill_buffer(struct thread_data *td, struct io_u *, unsigned int); /* * io engine entry points diff --git a/io_u.c b/io_u.c index 92cdd717..06fb3cef 100644 --- a/io_u.c +++ b/io_u.c @@ -6,6 +6,7 @@ #include #include "fio.h" +#include "hash.h" /* * Change this define to play with the timeout handling @@ -780,6 +781,9 @@ struct io_u *get_io_u(struct thread_data *td) io_u->endpos = io_u->offset + io_u->buflen; io_u->xfer_buf = io_u->buf; io_u->xfer_buflen = io_u->buflen; + + if (td->o.refill_buffers && io_u->ddir == DDIR_WRITE) + io_u_fill_buffer(td, io_u, io_u->xfer_buflen); out: if (!td_io_prep(td, io_u)) { fio_gettime(&io_u->start_time, NULL); @@ -943,6 +947,23 @@ void io_u_queued(struct thread_data *td, struct io_u *io_u) add_slat_sample(td, io_u->ddir, slat_time); } +/* + * "randomly" fill the buffer contents + */ +void io_u_fill_buffer(struct thread_data *td, struct io_u *io_u, + unsigned int max_bs) +{ + long *ptr = io_u->buf; + + if (!td->o.zero_buffers) { + while ((void *) ptr - io_u->buf < max_bs) { + *ptr = rand() * GOLDEN_RATIO_PRIME; + ptr++; + } + } else + memset(ptr, 0, max_bs); +} + #ifdef FIO_USE_TIMEOUT void io_u_set_timeout(struct thread_data *td) { diff --git a/options.c b/options.c index 8a6a4338..ba57e446 100644 --- a/options.c +++ b/options.c @@ -1215,6 +1215,12 @@ static struct fio_option options[] = { .off1 = td_var_offset(zero_buffers), .help = "Init IO buffers to all zeroes", }, + { + .name = "refill_buffers", + .type = FIO_OPT_STR_SET, + .off1 = td_var_offset(refill_buffers), + .help = "Refill IO buffers on every IO submit", + }, #ifdef FIO_HAVE_DISK_UTIL { .name = "disk_util", -- 2.25.1