X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=engines%2Fmmap.c;h=ea7179da2325ece1b0fd7772271d74fff4e90a3e;hb=9f75af77ea4b13cd44e5246426dbdbceff22f27c;hp=99e1d6a4b35861ccb8be485cf4831d36c72ce40a;hpb=420b104a3f6ba4328b6b167808f71bb7849102ec;p=fio.git diff --git a/engines/mmap.c b/engines/mmap.c index 99e1d6a4..ea7179da 100644 --- a/engines/mmap.c +++ b/engines/mmap.c @@ -27,15 +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; + } + } + + return true; +} + static int fio_mmap_file(struct thread_data *td, struct fio_file *f, size_t length, off_t off) { struct fio_mmap_data *fmd = FILE_ENG_DATA(f); int flags = 0; - if (td_rw(td)) + if (td_rw(td) && !td->o.verify_only) flags = PROT_READ | PROT_WRITE; - else if (td_write(td)) { + else if (td_write(td) && !td->o.verify_only) { flags = PROT_WRITE; if (td->o.verify != VERIFY_NONE) @@ -50,24 +74,16 @@ 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 (!fio_madvise_file(td, f, length)) + goto err; + if (posix_madvise(fmd->mmap_ptr, length, POSIX_MADV_DONTNEED) < 0) { td_verror(td, errno, "madvise"); goto err; } #ifdef FIO_MADV_FREE - if (f->filetype == FIO_TYPE_BD) + if (f->filetype == FIO_TYPE_BLOCK) (void) posix_madvise(fmd->mmap_ptr, fmd->mmap_sz, FIO_MADV_FREE); #endif @@ -137,7 +153,7 @@ static int fio_mmapio_prep(struct thread_data *td, struct io_u *io_u) * It fits within existing mapping, use it */ if (io_u->offset >= fmd->mmap_off && - io_u->offset + io_u->buflen < fmd->mmap_off + fmd->mmap_sz) + io_u->offset + io_u->buflen <= fmd->mmap_off + fmd->mmap_sz) goto done; /*