X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=engines%2Fmmap.c;h=856547befda3dea5e42ece3a123ed35c70663f66;hp=51606e12ff316c3ff537ec328103b17e4c3b1ba0;hb=d3b07186b1d4;hpb=f7c305464667b118b62aff9b846d1a939fbc1547 diff --git a/engines/mmap.c b/engines/mmap.c index 51606e12..856547be 100644 --- a/engines/mmap.c +++ b/engines/mmap.c @@ -7,7 +7,6 @@ */ #include #include -#include #include #include @@ -27,6 +26,30 @@ 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) { @@ -50,17 +73,9 @@ 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; @@ -137,7 +152,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; /* @@ -162,7 +177,8 @@ done: return 0; } -static int fio_mmapio_queue(struct thread_data *td, struct io_u *io_u) +static enum fio_q_status +fio_mmapio_queue(struct thread_data *td, struct io_u *io_u) { struct fio_file *f = io_u->file; struct fio_mmap_data *fmd = FILE_ENG_DATA(f);