mmap engine: fix for large files on 32-bit archs
[fio.git] / engines / mmap.c
index a5e0c6fc25646329336bd91f35759bcec6f3d709..bd9a9428661abe38048233c0c56c5be256ee7311 100644 (file)
 #include <sys/mman.h>
 
 #include "../fio.h"
+#include "../verify.h"
 
 /*
- * Limits us to 2GB of mapped files in total
+ * Limits us to 1GB of mapped files in total
  */
-#define MMAP_TOTAL_SZ  (2 * 1024 * 1024 * 1024UL)
+#define MMAP_TOTAL_SZ  (1 * 1024 * 1024 * 1024UL)
 
 static unsigned long mmap_map_size;
 static unsigned long mmap_map_mask;
@@ -46,9 +47,6 @@ static int fio_mmap_file(struct thread_data *td, struct fio_file *f,
                goto err;
        }
 
-       if (file_invalidate_cache(td, f))
-               goto err;
-
        if (!td_random(td)) {
                if (madvise(f->mmap_ptr, length, MADV_SEQUENTIAL) < 0) {
                        td_verror(td, errno, "madvise");
@@ -92,9 +90,7 @@ static int fio_mmapio_prep(struct thread_data *td, struct io_u *io_u)
        if (f->mmap_sz  > f->io_size)
                f->mmap_sz = f->io_size;
 
-       f->mmap_off = io_u->offset & ~mmap_map_mask;
-       if (io_u->offset + io_u->buflen >= f->mmap_off + f->mmap_sz)
-               f->mmap_off -= io_u->buflen;
+       f->mmap_off = io_u->offset;
 
        ret = fio_mmap_file(td, f, f->mmap_sz, f->mmap_off);
 done:
@@ -115,7 +111,7 @@ static int fio_mmapio_queue(struct thread_data *td, struct io_u *io_u)
                memcpy(io_u->xfer_buf, io_u->mmap_data, io_u->xfer_buflen);
        else if (io_u->ddir == DDIR_WRITE)
                memcpy(io_u->mmap_data, io_u->xfer_buf, io_u->xfer_buflen);
-       else if (io_u->ddir == DDIR_SYNC) {
+       else if (ddir_sync(io_u->ddir)) {
                if (msync(f->mmap_ptr, f->mmap_sz, MS_SYNC)) {
                        io_u->error = errno;
                        td_verror(td, io_u->error, "msync");
@@ -125,7 +121,7 @@ static int fio_mmapio_queue(struct thread_data *td, struct io_u *io_u)
        /*
         * not really direct, but should drop the pages from the cache
         */
-       if (td->o.odirect && io_u->ddir != DDIR_SYNC) {
+       if (td->o.odirect && !ddir_sync(io_u->ddir)) {
                if (msync(io_u->mmap_data, io_u->xfer_buflen, MS_SYNC) < 0) {
                        io_u->error = errno;
                        td_verror(td, io_u->error, "msync");