[PATCH] Support for mmap of hugetlb files as memory backing
[fio.git] / init.c
diff --git a/init.c b/init.c
index bfe698106b3bf02fe529990c19aa204267ef273b..edaec144f3aaaa5895339df4f2a703bdff7d9c48 100644 (file)
--- a/init.c
+++ b/init.c
@@ -508,6 +508,12 @@ static void fixup_options(struct thread_data *td)
        }
        if (td->bs_unaligned && (td->odirect || td->io_ops->flags & FIO_RAWIO))
                log_err("fio: bs_unaligned may not work with raw io\n");
+
+       /*
+        * O_DIRECT and char doesn't mix, clear that flag if necessary.
+        */
+       if (td->filetype == FIO_TYPE_CHAR && td->odirect)
+               td->odirect = 0;
 }
 
 /*
@@ -564,8 +570,6 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
        if (td->odirect)
                td->io_ops->flags |= FIO_RAWIO;
 
-       fixup_options(td);
-
        td->filetype = FIO_TYPE_FILE;
        if (!stat(jobname, &sb)) {
                if (S_ISBLK(sb.st_mode))
@@ -574,6 +578,8 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
                        td->filetype = FIO_TYPE_CHAR;
        }
 
+       fixup_options(td);
+
        if (td->filename)
                td->nr_uniq_files = 1;
        else
@@ -827,9 +833,29 @@ static int str_mem_cb(void *data, const char *mem)
        if (!strncmp(mem, "malloc", 6)) {
                td->mem_type = MEM_MALLOC;
                return 0;
-       } else if (!strncmp(mem, "shm", 3)) {
-               td->mem_type = MEM_SHM;
+       } else if (!strncmp(mem, "mmaphuge", 8)) {
+#ifdef FIO_HAVE_HUGETLB
+               char *hugefile;
+
+               /*
+                * mmaphuge must be appended with the actual file
+                */
+               hugefile = strstr(mem, ":");
+               if (!hugefile) {
+                       log_err("fio: mmaphuge:/path/to/file\n");
+                       return 1;
+               }
+
+               hugefile++;
+               strip_blank_front(&hugefile);
+               strip_blank_end(hugefile);
+               td->hugefile = strdup(hugefile);
+               td->mem_type = MEM_MMAPHUGE;
                return 0;
+#else
+               log_err("fio: mmaphuge not available\n");
+               return 1;
+#endif
        } else if (!strncmp(mem, "mmap", 4)) {
                td->mem_type = MEM_MMAP;
                return 0;
@@ -841,9 +867,12 @@ static int str_mem_cb(void *data, const char *mem)
                log_err("fio: shmhuge not available\n");
                return 1;
 #endif
+       } else if (!strncmp(mem, "shm", 3)) {
+               td->mem_type = MEM_SHM;
+               return 0;
        }
 
-       log_err("fio: mem type: malloc, shm, mmap, shmhuge\n");
+       log_err("fio: mem type: malloc, shm, shmhuge, mmap, mmaphuge\n");
        return 1;
 }