Let fadvise_hint also apply too mmap engine and madvise
authorJens Axboe <axboe@kernel.dk>
Wed, 7 Feb 2018 18:13:05 +0000 (11:13 -0700)
committerJens Axboe <axboe@kernel.dk>
Wed, 7 Feb 2018 18:13:05 +0000 (11:13 -0700)
Fixes: https://github.com/axboe/fio/issues/528
Signed-off-by: Jens Axboe <axboe@kernel.dk>
HOWTO
engines/mmap.c
fio.1
options.c

diff --git a/HOWTO b/HOWTO
index 78fa6ccf4a61e623a44c0e1137f46cc416382ee8..307b50d47c85762f07d82e2e8e332cf5c77f1fb6 100644 (file)
--- a/HOWTO
+++ b/HOWTO
@@ -1093,8 +1093,9 @@ I/O type
 
 .. option:: fadvise_hint=str
 
-       Use :manpage:`posix_fadvise(2)` to advise the kernel on what I/O patterns
-       are likely to be issued.  Accepted values are:
+       Use :manpage:`posix_fadvise(2)` or :manpage:`posix_fadvise(2)` to
+       advise the kernel on what I/O patterns are likely to be issued.
+       Accepted values are:
 
                **0**
                        Backwards-compatible hint for "no hint".
index 77556588e1a21218ead2006d5d73ee1bd41087c5..28d63b7c30642e5700e6218cd901e3874e4d76c6 100644 (file)
@@ -27,6 +27,39 @@ struct fio_mmap_data {
        off_t mmap_off;
 };
 
+static bool fio_madvise_file(struct thread_data *td, struct fio_file *f,
+                            size_t length)
+
+{
+       struct fio_mmap_data *fmd = FILE_ENG_DATA(f);
+
+       if (!td->o.fadvise_hint)
+               return true;
+
+       if (!td_random(td)) {
+               if (posix_madvise(fmd->mmap_ptr, length, POSIX_MADV_SEQUENTIAL) < 0) {
+                       td_verror(td, errno, "madvise");
+                       return false;
+               }
+       } else {
+               if (posix_madvise(fmd->mmap_ptr, length, POSIX_MADV_RANDOM) < 0) {
+                       td_verror(td, errno, "madvise");
+                       return false;
+               }
+       }
+       if (posix_madvise(fmd->mmap_ptr, length, POSIX_MADV_DONTNEED) < 0) {
+               td_verror(td, errno, "madvise");
+               return false;
+       }
+
+#ifdef FIO_MADV_FREE
+       if (f->filetype == FIO_TYPE_BLOCK)
+               (void) posix_madvise(fmd->mmap_ptr, fmd->mmap_sz, FIO_MADV_FREE);
+#endif
+
+       return true;
+}
+
 static int fio_mmap_file(struct thread_data *td, struct fio_file *f,
                         size_t length, off_t off)
 {
@@ -50,26 +83,8 @@ static int fio_mmap_file(struct thread_data *td, struct fio_file *f,
                goto err;
        }
 
-       if (!td_random(td)) {
-               if (posix_madvise(fmd->mmap_ptr, length, POSIX_MADV_SEQUENTIAL) < 0) {
-                       td_verror(td, errno, "madvise");
-                       goto err;
-               }
-       } else {
-               if (posix_madvise(fmd->mmap_ptr, length, POSIX_MADV_RANDOM) < 0) {
-                       td_verror(td, errno, "madvise");
-                       goto err;
-               }
-       }
-       if (posix_madvise(fmd->mmap_ptr, length, POSIX_MADV_DONTNEED) < 0) {
-               td_verror(td, errno, "madvise");
+       if (!fio_madvise_file(td, f, length))
                goto err;
-       }
-
-#ifdef FIO_MADV_FREE
-       if (f->filetype == FIO_TYPE_BLOCK)
-               (void) posix_madvise(fmd->mmap_ptr, fmd->mmap_sz, FIO_MADV_FREE);
-#endif
 
 err:
        if (td->error && fmd->mmap_ptr)
diff --git a/fio.1 b/fio.1
index 70eeeb0f6c8ca35634e98ed648b833df8299bb98..91ae4a2ae4761a972498af7e9312164d843030f6 100644 (file)
--- a/fio.1
+++ b/fio.1
@@ -870,8 +870,8 @@ pre\-allocation methods are available, \fBnone\fR if not.
 .RE
 .TP
 .BI fadvise_hint \fR=\fPstr
-Use \fBposix_fadvise\fR\|(2) to advise the kernel what I/O patterns
-are likely to be issued. Accepted values are:
+Use \fBposix_fadvise\fR\|(2) or \fBposix_madvise\fR\|(2) to advise the kernel
+what I/O patterns are likely to be issued. Accepted values are:
 .RS
 .RS
 .TP
index 9a3431d8723147b31e783bcc60d423a589e2ae56..681052127be67b2db7fbaa6d1bf927f7fdbb0342 100644 (file)
--- a/options.c
+++ b/options.c
@@ -2443,7 +2443,7 @@ struct fio_option fio_options[FIO_MAX_OPTS] = {
                .posval = {
                          { .ival = "0",
                            .oval = F_ADV_NONE,
-                           .help = "Don't issue fadvise",
+                           .help = "Don't issue fadvise/madvise",
                          },
                          { .ival = "1",
                            .oval = F_ADV_TYPE,