X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=engines%2Fmmap.c;h=308b4665444cd619b73e6f5c3aeefbed78e56002;hb=2e7888ef96495d4e89c50914e0bc4dbff316be90;hp=51606e12ff316c3ff537ec328103b17e4c3b1ba0;hpb=f7c305464667b118b62aff9b846d1a939fbc1547;p=fio.git diff --git a/engines/mmap.c b/engines/mmap.c index 51606e12..308b4665 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);