From 1907dbc6c0c9e1b663156e64c64c172aaf04ae8a Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Mon, 12 Mar 2007 11:44:28 +0100 Subject: [PATCH] Add nr parameter to file_service_type Right now we switch for every IO, add a postfix that allows to switch for every 'x' number of ios. Signed-off-by: Jens Axboe --- HOWTO | 5 +++++ fio.h | 7 +++++++ init.c | 18 ++++++++++++++++-- io_u.c | 14 ++++++++++++-- 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/HOWTO b/HOWTO index 1374d05e..f9e3fc70 100644 --- a/HOWTO +++ b/HOWTO @@ -265,6 +265,11 @@ file_service_type=str Defines how fio decides which file from a job to roundrobin Round robin over open files. This is the default. + The string can have a number appended, indicating how + often to switch to a new file. So if option random:4 is + given, fio will switch to a new random file after 4 ios + have been issued. + ioengine=str Defines how the job issues io to the file. The following types are defined: diff --git a/fio.h b/fio.h index a60be104..9d190b14 100644 --- a/fio.h +++ b/fio.h @@ -473,6 +473,13 @@ struct thread_data { */ struct timeval timeout_end; struct itimerval timer; + + /* + * for fileservice, how often to switch to a new file + */ + unsigned int file_service_nr; + unsigned int file_service_left; + struct fio_file *file_service_file; }; /* diff --git a/init.c b/init.c index 2129882f..eee23359 100644 --- a/init.c +++ b/init.c @@ -30,6 +30,7 @@ static int str_prioclass_cb(void *, unsigned int *); #endif static int str_exitall_cb(void); static int str_cpumask_cb(void *, unsigned int *); +static int str_fst_cb(void *, const char *); #define __stringify_1(x) #x #define __stringify(x) __stringify_1(x) @@ -190,6 +191,7 @@ static struct fio_option options[] = { { .name = "file_service_type", .type = FIO_OPT_STR, + .cb = str_fst_cb, .off1 = td_var_offset(file_service_type), .help = "How to select which file to service next", .def = "roundrobin", @@ -1048,7 +1050,7 @@ static int is_empty_or_comment(char *line) /* * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that. */ -static char *get_mmap_file(const char *str) +static char *get_opt_postfix(const char *str) { char *p = strstr(str, ":"); @@ -1066,7 +1068,7 @@ static int str_mem_cb(void *data, const char *mem) struct thread_data *td = data; if (td->mem_type == MEM_MMAPHUGE || td->mem_type == MEM_MMAP) { - td->mmapfile = get_mmap_file(mem); + td->mmapfile = get_opt_postfix(mem); if (td->mem_type == MEM_MMAPHUGE && !td->mmapfile) { log_err("fio: mmaphuge:/path/to/file\n"); return 1; @@ -1114,6 +1116,18 @@ static int str_cpumask_cb(void *data, unsigned int *val) return 0; } +static int str_fst_cb(void *data, const char *str) +{ + struct thread_data *td = data; + char *nr = get_opt_postfix(str); + + td->file_service_nr = 1; + if (nr) + td->file_service_nr = atoi(nr); + + return 0; +} + /* * This is our [ini] type file parser. */ diff --git a/io_u.c b/io_u.c index e283e727..c9a344f2 100644 --- a/io_u.c +++ b/io_u.c @@ -368,13 +368,23 @@ static struct fio_file *get_next_file_rr(struct thread_data *td) static struct fio_file *get_next_file(struct thread_data *td) { + struct fio_file *f; + if (!td->nr_open_files) return NULL; + f = td->file_service_file; + if (f && f->open && td->file_service_left--) + return f; + if (td->file_service_type == FIO_FSERVICE_RR) - return get_next_file_rr(td); + f = get_next_file_rr(td); else - return get_next_file_rand(td); + f = get_next_file_rand(td); + + td->file_service_file = f; + td->file_service_left = td->file_service_nr - 1; + return f; } struct io_u *__get_io_u(struct thread_data *td) -- 2.25.1