Merge branch 'master' of ssh://git.kernel.dk/data/git/fio
[fio.git] / memory.c
index f1cd2d770f4cbe3597ecbc5e236b355e930fc49a..76da8a86269e859889366c283281815e9ffac1dc 100644 (file)
--- a/memory.c
+++ b/memory.c
@@ -5,12 +5,12 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
-#ifndef FIO_NO_HAVE_SHM_H
-#include <sys/shm.h>
-#endif
 #include <sys/mman.h>
 
 #include "fio.h"
+#ifndef FIO_NO_HAVE_SHM_H
+#include <sys/shm.h>
+#endif
 
 void fio_unpin_memory(struct thread_data *td)
 {
@@ -119,7 +119,7 @@ static int alloc_mem_mmap(struct thread_data *td, size_t total_mem)
 {
        int flags = 0;
 
-       td->mmapfd = 1;
+       td->mmapfd = -1;
 
        if (td->o.mem_type == MEM_MMAPHUGE) {
                unsigned long mask = td->o.hugepage_size - 1;
@@ -158,9 +158,10 @@ static int alloc_mem_mmap(struct thread_data *td, size_t total_mem)
        if (td->orig_buffer == MAP_FAILED) {
                td_verror(td, errno, "mmap");
                td->orig_buffer = NULL;
-               if (td->mmapfd) {
+               if (td->mmapfd != 1) {
                        close(td->mmapfd);
-                       unlink(td->o.mmapfile);
+                       if (td->o.mmapfile)
+                               unlink(td->o.mmapfile);
                }
 
                return 1;
@@ -175,7 +176,8 @@ static void free_mem_mmap(struct thread_data *td, size_t total_mem)
                                                td->orig_buffer);
        munmap(td->orig_buffer, td->orig_buffer_size);
        if (td->o.mmapfile) {
-               close(td->mmapfd);
+               if (td->mmapfd != -1)
+                       close(td->mmapfd);
                unlink(td->o.mmapfile);
                free(td->o.mmapfile);
        }
@@ -209,7 +211,7 @@ int allocate_io_mem(struct thread_data *td)
 
        total_mem = td->orig_buffer_size;
 
-       if (td->o.odirect || td->o.mem_align ||
+       if (td->o.odirect || td->o.mem_align || td->o.oatomic ||
            (td->io_ops->flags & FIO_MEMALIGN)) {
                total_mem += page_mask;
                if (td->o.mem_align && td->o.mem_align > page_size)
@@ -240,7 +242,7 @@ void free_io_mem(struct thread_data *td)
        unsigned int total_mem;
 
        total_mem = td->orig_buffer_size;
-       if (td->o.odirect)
+       if (td->o.odirect || td->o.oatomic)
                total_mem += page_mask;
 
        if (td->o.mem_type == MEM_MALLOC)