[PATCH] Add hugepage-size option
[fio.git] / init.c
diff --git a/init.c b/init.c
index 346c465a3d9d9a7bb6d5a0311bd6575b8b9a7fd8..4ca5ee6f8f9e41df678ad56a0569187775eed47f 100644 (file)
--- a/init.c
+++ b/init.c
@@ -29,7 +29,7 @@
 #define DEF_IO_ENGINE_NAME     "sync"
 #define DEF_SEQUENTIAL         (1)
 #define DEF_RAND_REPEAT                (1)
-#define DEF_OVERWRITE          (1)
+#define DEF_OVERWRITE          (0)
 #define DEF_INVALIDATE         (1)
 #define DEF_SYNCIO             (0)
 #define DEF_RANDSEED           (0xb1899bedUL)
 #define DEF_RWMIX_READ         (50)
 #define DEF_NICE               (0)
 #define DEF_NR_FILES           (1)
-#define DEF_UNLINK             (0)
+#define DEF_UNLINK             (1)
 #define DEF_WRITE_BW_LOG       (0)
 #define DEF_WRITE_LAT_LOG      (0)
 #define DEF_NO_RAND_MAP                (0)
+#define DEF_HUGEPAGE_SIZE      FIO_HUGE_PAGE
 
 #define td_var_offset(var)     ((size_t) &((struct thread_data *)0)->var)
 
@@ -358,6 +359,11 @@ static struct fio_option options[] = {
                .type   = FIO_OPT_STR_SET,
                .off1   = td_var_offset(bs_unaligned),
        },
+       {
+               .name   = "hugepage-size",
+               .type   = FIO_OPT_STR_VAL,
+               .off1   = td_var_offset(hugepage_size),
+       },
        {
                .name = NULL,
        },
@@ -508,6 +514,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 +576,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 +584,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,15 +839,46 @@ 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;
+       } else if (!strncmp(mem, "shmhuge", 7)) {
+#ifdef FIO_HAVE_HUGETLB
+               td->mem_type = MEM_SHMHUGE;
+               return 0;
+#else
+               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\n");
+       log_err("fio: mem type: malloc, shm, shmhuge, mmap, mmaphuge\n");
        return 1;
 }
 
@@ -1021,6 +1064,7 @@ static int fill_def_thread(void)
        def_thread.write_bw_log = write_bw_log;
        def_thread.write_lat_log = write_lat_log;
        def_thread.norandommap = DEF_NO_RAND_MAP;
+       def_thread.hugepage_size = DEF_HUGEPAGE_SIZE;
 #ifdef FIO_HAVE_DISK_UTIL
        def_thread.do_disk_util = 1;
 #endif