From ecb2083d39558db2664c41b5d78aa73cd51bff58 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Mon, 19 Dec 2016 13:58:42 -0700 Subject: [PATCH] options: full control of fadvise hinting Previously fio supported only 0/1 for this hint. 0 would not do any hints, but 1 (the default) would hint based on what the fio workload was - fio would tell the kernel it was a random workload, if it was random, or a sequential for a sequential workload. Now fio also supports setting what the hint type should be explicitly, by allowing a setting of 'random' or 'sequential' for full control of the hint. Signed-off-by: Jens Axboe --- HOWTO | 13 +++++++++++-- fio.1 | 22 ++++++++++++++++++++-- fio.h | 7 +++++++ ioengines.c | 16 +++++++++++++--- options.c | 20 +++++++++++++++++++- 5 files changed, 70 insertions(+), 8 deletions(-) diff --git a/HOWTO b/HOWTO index 6893c868..7274c0e9 100644 --- a/HOWTO +++ b/HOWTO @@ -476,8 +476,17 @@ fadvise_hint=bool By default, fio will use fadvise() to advise the kernel on what IO patterns it is likely to issue. Sometimes you want to test specific IO patterns without telling the kernel about it, in which case you can disable this option. - If set, fio will use POSIX_FADV_SEQUENTIAL for sequential - IO and POSIX_FADV_RANDOM for random IO. + The following options are supported: + + sequential Use FADV_SEQUENTIAL + random Use FADV_RANDOM + 1 Backwards-compatible hint for basing + the hint on the fio workload. Will use + FADV_SEQUENTIAL for a sequential + workload, and FADV_RANDOM for a random + workload. + 0 Backwards-compatible setting for not + issing a fadvise hint. fadvise_stream=int Notify the kernel what write stream ID to place these writes under. Only supported on Linux. Note, this option diff --git a/fio.1 b/fio.1 index e8a327c9..61617600 100644 --- a/fio.1 +++ b/fio.1 @@ -396,9 +396,27 @@ available on Linux. If using ZFS on Solaris this must be set to 'none' because ZFS doesn't support it. Default: 'posix'. .RE .TP -.BI fadvise_hint \fR=\fPbool +.BI fadvise_hint \fR=\fPstr Use \fBposix_fadvise\fR\|(2) to advise the kernel what I/O patterns -are likely to be issued. Default: true. +are likely to be issued. Accepted values are: +.RS +.RS +.TP +.B 0 +Backwards compatible hint for "no hint". +.TP +.B 1 +Backwards compatible hint for "advise with fio workload type". This +uses \fBFADV_RANDOM\fR for a random workload, and \fBFADV_SEQUENTIAL\fR +for a sequential workload. +.TP +.B sequential +Advise using \fBFADV_SEQUENTIAL\fR +.TP +.B random +Advise using \fBFADV_RANDOM\fR +.RE +.RE .TP .BI fadvise_stream \fR=\fPint Use \fBposix_fadvise\fR\|(2) to advise the kernel what stream ID the diff --git a/fio.h b/fio.h index 5726befc..df170742 100644 --- a/fio.h +++ b/fio.h @@ -110,6 +110,13 @@ enum { RATE_PROCESS_POISSON = 1, }; +enum { + F_ADV_NONE = 0, + F_ADV_TYPE, + F_ADV_RANDOM, + F_ADV_SEQUENTIAL, +}; + /* * Per-thread/process specific data. Only used for the network client * for now. diff --git a/ioengines.c b/ioengines.c index 1b581686..a1f8756d 100644 --- a/ioengines.c +++ b/ioengines.c @@ -448,14 +448,24 @@ int td_io_open_file(struct thread_data *td, struct fio_file *f) if (td->o.invalidate_cache && file_invalidate_cache(td, f)) goto err; - if (td->o.fadvise_hint && + if (td->o.fadvise_hint != F_ADV_NONE && (f->filetype == FIO_TYPE_BD || f->filetype == FIO_TYPE_FILE)) { int flags; - if (td_random(td)) + if (td->o.fadvise_hint == F_ADV_TYPE) { + if (td_random(td)) + flags = POSIX_FADV_RANDOM; + else + flags = POSIX_FADV_SEQUENTIAL; + } else if (td->o.fadvise_hint == F_ADV_RANDOM) flags = POSIX_FADV_RANDOM; - else + else if (td->o.fadvise_hint == F_ADV_SEQUENTIAL) flags = POSIX_FADV_SEQUENTIAL; + else { + log_err("fio: unknown fadvise type %d\n", + td->o.fadvise_hint); + flags = POSIX_FADV_NORMAL; + } if (posix_fadvise(f->fd, f->file_offset, f->io_size, flags) < 0) { td_verror(td, errno, "fadvise"); diff --git a/options.c b/options.c index 7638afc0..b81db231 100644 --- a/options.c +++ b/options.c @@ -2295,8 +2295,26 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { { .name = "fadvise_hint", .lname = "Fadvise hint", - .type = FIO_OPT_BOOL, + .type = FIO_OPT_STR, .off1 = offsetof(struct thread_options, fadvise_hint), + .posval = { + { .ival = "0", + .oval = F_ADV_NONE, + .help = "Don't issue fadvise", + }, + { .ival = "1", + .oval = F_ADV_TYPE, + .help = "Advise using fio IO pattern", + }, + { .ival = "random", + .oval = F_ADV_RANDOM, + .help = "Advise using FADV_RANDOM", + }, + { .ival = "sequential", + .oval = F_ADV_SEQUENTIAL, + .help = "Advise using FADV_SEQUENTIAL", + }, + }, .help = "Use fadvise() to advise the kernel on IO pattern", .def = "1", .category = FIO_OPT_C_FILE, -- 2.25.1