From 8f933caebc879fa06bb8d2d25802dd6f27da8071 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Sat, 4 Jul 2009 20:29:04 +0200 Subject: [PATCH] mmap engine: remove code duplication Signed-off-by: Jens Axboe --- engines/mmap.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/engines/mmap.c b/engines/mmap.c index 71abfb9a..53fd358c 100644 --- a/engines/mmap.c +++ b/engines/mmap.c @@ -75,12 +75,6 @@ static int fio_mmapio_prep_limited(struct thread_data *td, struct io_u *io_u) return EIO; } - if (f->mmap_ptr) { - if (munmap(f->mmap_ptr, f->mmap_sz) < 0) - return errno; - f->mmap_ptr = NULL; - } - f->mmap_sz = mmap_map_size; if (f->mmap_sz > f->io_size) f->mmap_sz = f->io_size; @@ -101,12 +95,6 @@ static int fio_mmapio_prep_full(struct thread_data *td, struct io_u *io_u) if (fio_file_partial_mmap(f)) return EINVAL; - if (f->mmap_ptr) { - if (munmap(f->mmap_ptr, f->mmap_sz) < 0) - return errno; - f->mmap_ptr = NULL; - } - f->mmap_sz = f->io_size; f->mmap_off = 0; @@ -122,10 +110,22 @@ static int fio_mmapio_prep(struct thread_data *td, struct io_u *io_u) struct fio_file *f = io_u->file; int ret; + /* + * It fits within existing mapping, use it + */ if (io_u->offset >= f->mmap_off && io_u->offset + io_u->buflen < f->mmap_off + f->mmap_sz) goto done; + /* + * unmap any existing mapping + */ + if (f->mmap_ptr) { + if (munmap(f->mmap_ptr, f->mmap_sz) < 0) + return errno; + f->mmap_ptr = NULL; + } + if (fio_mmapio_prep_full(td, io_u)) { td_clear_error(td); ret = fio_mmapio_prep_limited(td, io_u); -- 2.25.1