From: Jens Axboe Date: Wed, 7 Feb 2018 18:13:05 +0000 (-0700) Subject: Let fadvise_hint also apply too mmap engine and madvise X-Git-Tag: fio-3.4~11 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=c712c97ab8714165216c5940b4a540bd42fdbd68;hp=f5ec81235eaf21bd3a97556427d4a84e48a87e54 Let fadvise_hint also apply too mmap engine and madvise Fixes: https://github.com/axboe/fio/issues/528 Signed-off-by: Jens Axboe --- diff --git a/HOWTO b/HOWTO index 78fa6ccf..307b50d4 100644 --- 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". diff --git a/engines/mmap.c b/engines/mmap.c index 77556588..28d63b7c 100644 --- a/engines/mmap.c +++ b/engines/mmap.c @@ -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 70eeeb0f..91ae4a2a 100644 --- 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 diff --git a/options.c b/options.c index 9a3431d8..68105212 100644 --- 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,