Add mmapshared option to use mmaped files with the MAP_SHARED flag.
authorLogan Gunthorpe <logang@deltatee.com>
Tue, 27 Oct 2015 16:20:53 +0000 (10:20 -0600)
committerLogan Gunthorpe <logang@deltatee.com>
Tue, 27 Oct 2015 16:20:53 +0000 (10:20 -0600)
This is primarily useful for benchmarking DAX files. If they are mmaped
with the MAP_PRIVATE flag they will still have copy on write semantics
and the test will not actually run against the memory that backs the
DAX file. This memory option allows tests to be constructed that use the
MAP_SHARED flag which allows running directly with the memory backed
by a DAX file.

memory.c
options.c
thread_options.h

index 23a0d94b73e3d353b61044fe85149dfda4e59f55..50602239a41c85ede74e124c5e52ef7848ce0ee0 100644 (file)
--- a/memory.c
+++ b/memory.c
@@ -146,12 +146,14 @@ static int alloc_mem_mmap(struct thread_data *td, size_t total_mem)
                        return 1;
                }
                if (td->o.mem_type != MEM_MMAPHUGE &&
+                   td->o.mem_type != MEM_MMAPSHARED &&
                    ftruncate(td->mmapfd, total_mem) < 0) {
                        td_verror(td, errno, "truncate mmap file");
                        td->orig_buffer = NULL;
                        return 1;
                }
-               if (td->o.mem_type == MEM_MMAPHUGE)
+               if (td->o.mem_type == MEM_MMAPHUGE ||
+                   td->o.mem_type == MEM_MMAPSHARED)
                        flags |= MAP_SHARED;
                else
                        flags |= MAP_PRIVATE;
@@ -231,7 +233,8 @@ int allocate_io_mem(struct thread_data *td)
                ret = alloc_mem_malloc(td, total_mem);
        else if (td->o.mem_type == MEM_SHM || td->o.mem_type == MEM_SHMHUGE)
                ret = alloc_mem_shm(td, total_mem);
-       else if (td->o.mem_type == MEM_MMAP || td->o.mem_type == MEM_MMAPHUGE)
+       else if (td->o.mem_type == MEM_MMAP || td->o.mem_type == MEM_MMAPHUGE ||
+                td->o.mem_type == MEM_MMAPSHARED)
                ret = alloc_mem_mmap(td, total_mem);
        else {
                log_err("fio: bad mem type: %d\n", td->o.mem_type);
@@ -256,7 +259,8 @@ void free_io_mem(struct thread_data *td)
                free_mem_malloc(td);
        else if (td->o.mem_type == MEM_SHM || td->o.mem_type == MEM_SHMHUGE)
                free_mem_shm(td);
-       else if (td->o.mem_type == MEM_MMAP || td->o.mem_type == MEM_MMAPHUGE)
+       else if (td->o.mem_type == MEM_MMAP || td->o.mem_type == MEM_MMAPHUGE ||
+                td->o.mem_type == MEM_MMAPSHARED)
                free_mem_mmap(td, total_mem);
        else
                log_err("Bad memory type %u\n", td->o.mem_type);
index 0169ca2974329bda89c1444246ddfebade1ac462..55844130fae135793cb7619063c9f668993bf9e3 100644 (file)
--- a/options.c
+++ b/options.c
@@ -351,7 +351,8 @@ static int str_mem_cb(void *data, const char *mem)
 {
        struct thread_data *td = data;
 
-       if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP)
+       if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP ||
+           td->o.mem_type == MEM_MMAPSHARED)
                td->o.mmapfile = get_opt_postfix(mem);
 
        return 0;
@@ -2228,6 +2229,10 @@ struct fio_option fio_options[FIO_MAX_OPTS] = {
                            .oval = MEM_MMAP,
                            .help = "Use mmap(2) (file or anon) for IO buffers",
                          },
+                         { .ival = "mmapshared",
+                           .oval = MEM_MMAPSHARED,
+                           .help = "Like mmap, but use the shared flag",
+                         },
 #ifdef FIO_HAVE_HUGETLB
                          { .ival = "mmaphuge",
                            .oval = MEM_MMAPHUGE,
index 5ef560ef157d02e58f7c42f74f5a0780a9feefc0..ed960eeb2861de263d3ac036d3e55483ab008396 100644 (file)
@@ -19,6 +19,7 @@ enum fio_memtype {
        MEM_SHMHUGE,    /* use shared memory segments with huge pages */
        MEM_MMAP,       /* use anonynomous mmap */
        MEM_MMAPHUGE,   /* memory mapped huge file */
+       MEM_MMAPSHARED, /* use mmap with shared flag */
 };
 
 #define ERROR_STR_MAX  128