Fully parallellize io_u verification
[fio.git] / memory.c
index d336c2bcb8cea017b6d9db980e3c39a95d70c717..079c0760f0993d22baee775c43561e11d90c7bb1 100644 (file)
--- a/memory.c
+++ b/memory.c
@@ -81,12 +81,33 @@ int allocate_io_mem(struct thread_data *td)
                        td->orig_buffer = NULL;
                        return 1;
                }
-       } else if (td->mem_type == MEM_MMAP) {
-               td->orig_buffer = mmap(NULL, td->orig_buffer_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | OS_MAP_ANON, 0, 0);
+       } else if (td->mem_type == MEM_MMAP || td->mem_type == MEM_MMAPHUGE) {
+               int flags = MAP_PRIVATE;
+
+               td->mmapfd = 0;
+
+               if (td->mmapfile) {
+                       td->mmapfd = open(td->mmapfile, O_RDWR|O_CREAT, 0644);
+
+                       if (td->mmapfd < 0) {
+                               td_verror(td, errno);
+                               perror("open mmap file");
+                               td->orig_buffer = NULL;
+                               return 1;
+                       }
+               } else
+                       flags |= OS_MAP_ANON;
+
+               td->orig_buffer = mmap(NULL, td->orig_buffer_size, PROT_READ | PROT_WRITE, flags, td->mmapfd, 0);
                if (td->orig_buffer == MAP_FAILED) {
                        td_verror(td, errno);
                        perror("mmap");
                        td->orig_buffer = NULL;
+                       if (td->mmapfd) {
+                               close(td->mmapfd);
+                               unlink(td->mmapfile);
+                       }
+                               
                        return 1;
                }
        }
@@ -103,9 +124,14 @@ void free_io_mem(struct thread_data *td)
 
                shmdt(td->orig_buffer);
                shmctl(td->shm_id, IPC_RMID, &sbuf);
-       } else if (td->mem_type == MEM_MMAP)
+       } else if (td->mem_type == MEM_MMAP || td->mem_type == MEM_MMAPHUGE) {
                munmap(td->orig_buffer, td->orig_buffer_size);
-       else
+               if (td->mmapfile) {
+                       close(td->mmapfd);
+                       unlink(td->mmapfile);
+                       free(td->mmapfile);
+               }
+       } else
                log_err("Bad memory type %u\n", td->mem_type);
 
        td->orig_buffer = NULL;