options: full control of fadvise hinting
authorJens Axboe <axboe@fb.com>
Mon, 19 Dec 2016 20:58:42 +0000 (13:58 -0700)
committerJens Axboe <axboe@fb.com>
Mon, 19 Dec 2016 20:58:42 +0000 (13:58 -0700)
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 <axboe@fb.com>
HOWTO
fio.1
fio.h
ioengines.c
options.c

diff --git a/HOWTO b/HOWTO
index 6893c86878b2d9420bf263eb5e04056440cd322d..7274c0e940af1c3850e33c5a84092702dff56c13 100644 (file)
--- 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 e8a327c93769e9751112325d8abfa6b13b353662..6161760043bb77d0b092a11e8afdb40687619cc7 100644 (file)
--- 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 5726befcb9abc1f4423246862a73cdc5affd89d7..df17074211a33e6beb08032b87de4335a9d7673a 100644 (file)
--- 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.
index 1b58168608046390146765b7f546c9b9d964736e..a1f8756d086ca5d06c5e1de063ec702f8294a228 100644 (file)
@@ -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");
index 7638afc0f8ed94b87f26ea835c2e59bce44936db..b81db23115009e065b49eb717dd16cf52bc5b8a3 100644 (file)
--- 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,