#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)
static int str_mem_cb(void *, const char *);
static int str_verify_cb(void *, const char *);
static int str_lockmem_cb(void *, unsigned long *);
+#ifdef FIO_HAVE_IOPRIO
static int str_prio_cb(void *, unsigned int *);
static int str_prioclass_cb(void *, unsigned int *);
+#endif
static int str_exitall_cb(void);
static int str_cpumask_cb(void *, unsigned int *);
},
{
.name = "bs",
- .type = FIO_OPT_STR_VAL,
- .off1 = td_var_offset(bs),
+ .type = FIO_OPT_STR_VAL_INT,
+ .off1 = td_var_offset(bs[DDIR_READ]),
+ .off2 = td_var_offset(bs[DDIR_WRITE]),
},
{
.name = "offset",
{
.name = "bsrange",
.type = FIO_OPT_RANGE,
- .off1 = td_var_offset(min_bs),
- .off2 = td_var_offset(max_bs),
+ .off1 = td_var_offset(min_bs[DDIR_READ]),
+ .off2 = td_var_offset(max_bs[DDIR_READ]),
+ .off3 = td_var_offset(min_bs[DDIR_WRITE]),
+ .off4 = td_var_offset(max_bs[DDIR_WRITE]),
},
{
.name = "nrfiles",
.type = FIO_OPT_STR_SET,
.off1 = td_var_offset(write_lat_log),
},
+ {
+ .name = "norandommap",
+ .type = FIO_OPT_STR_SET,
+ .off1 = td_var_offset(norandommap),
+ },
+ {
+ .name = "bs_unaligned",
+ .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,
},
static int def_timeout = DEF_TIMEOUT;
-static char fio_version_string[] = "fio 1.7";
+static char fio_version_string[] = "fio 1.10";
static char **ini_file;
static int max_jobs = MAX_JOBS;
struct thread_data def_thread;
struct thread_data *threads = NULL;
-int rate_quit = 0;
int exitall_on_terminate = 0;
int terse_output = 0;
unsigned long long mlock_size = 0;
static void put_job(struct thread_data *td)
{
+ if (td == &def_thread)
+ return;
+
memset(&threads[td->thread_number - 1], 0, sizeof(*td));
thread_number--;
}
*/
static void fixup_options(struct thread_data *td)
{
- if (!td->min_bs)
- td->min_bs = td->bs;
- if (!td->max_bs)
- td->max_bs = td->bs;
-
if (!td->rwmixread && td->rwmixwrite)
td->rwmixread = 100 - td->rwmixwrite;
free(td->write_iolog_file);
td->write_iolog_file = NULL;
}
+
+ if (td->io_ops->flags & FIO_SYNCIO)
+ td->iodepth = 1;
+ else {
+ if (!td->iodepth)
+ td->iodepth = td->nr_files;
+ }
+
+ /*
+ * only really works for sequential io for now, and with 1 file
+ */
+ if (td->zone_size && !td->sequential && td->nr_files == 1)
+ td->zone_size = 0;
+
+ /*
+ * Reads can do overwrites, we always need to pre-create the file
+ */
+ if (td_read(td) || td_rw(td))
+ td->overwrite = 1;
+
+ if (!td->min_bs[DDIR_READ])
+ td->min_bs[DDIR_READ]= td->bs[DDIR_READ];
+ if (!td->max_bs[DDIR_READ])
+ td->max_bs[DDIR_READ] = td->bs[DDIR_READ];
+ if (!td->min_bs[DDIR_WRITE])
+ td->min_bs[DDIR_WRITE]= td->bs[DDIR_WRITE];
+ if (!td->max_bs[DDIR_WRITE])
+ td->max_bs[DDIR_WRITE] = td->bs[DDIR_WRITE];
+
+ td->rw_min_bs = min(td->min_bs[DDIR_READ], td->min_bs[DDIR_WRITE]);
+
+ if (td_read(td) && !td_rw(td))
+ td->verify = 0;
+
+ if (td->norandommap && td->verify != VERIFY_NONE) {
+ log_err("fio: norandommap given, verify disabled\n");
+ td->verify = VERIFY_NONE;
+ }
+ 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;
+}
+
+/*
+ * This function leaks the buffer
+ */
+static char *to_kmg(unsigned int val)
+{
+ char *buf = malloc(32);
+ char post[] = { 0, 'K', 'M', 'G', 'P', 0 };
+ char *p = post;
+
+ do {
+ if (val & 1023)
+ break;
+
+ val >>= 10;
+ p++;
+ } while (*p);
+
+ snprintf(buf, 31, "%u%c", val, *p);
+ return buf;
}
/*
*/
static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
{
- char *ddir_str[] = { "read", "write", "randread", "randwrite",
- "rw", NULL, "randrw" };
+ const char *ddir_str[] = { "read", "write", "randread", "randwrite",
+ "rw", NULL, "randrw" };
struct stat sb;
int numjobs, ddir, i;
struct fio_file *f;
-#ifndef FIO_HAVE_LIBAIO
- if (td->io_engine == FIO_LIBAIO) {
- log_err("Linux libaio not available\n");
- return 1;
- }
-#endif
-#ifndef FIO_HAVE_POSIXAIO
- if (td->io_engine == FIO_POSIXAIO) {
- log_err("posix aio not available\n");
- return 1;
- }
-#endif
-
- fixup_options(td);
-
/*
* the def_thread is just for options, it's not a real job
*/
}
}
- if (td->io_ops->flags & FIO_SYNCIO)
- td->iodepth = 1;
- else {
- if (!td->iodepth)
- td->iodepth = td->nr_files;
- }
-
- /*
- * only really works for sequential io for now, and with 1 file
- */
- if (td->zone_size && !td->sequential && td->nr_files == 1)
- td->zone_size = 0;
-
- /*
- * Reads can do overwrites, we always need to pre-create the file
- */
- if (td_read(td) || td_rw(td))
- td->overwrite = 1;
+ if (td->odirect)
+ td->io_ops->flags |= FIO_RAWIO;
td->filetype = FIO_TYPE_FILE;
if (!stat(jobname, &sb)) {
td->filetype = FIO_TYPE_CHAR;
}
- if (td->odirect)
- td->io_ops->flags |= FIO_RAWIO;
+ fixup_options(td);
if (td->filename)
td->nr_uniq_files = 1;
if (td->filetype == FIO_TYPE_FILE || td->filename) {
char tmp[PATH_MAX];
int len = 0;
- int i;
if (td->directory && td->directory[0] != '\0')
sprintf(tmp, "%s/", td->directory);
td->slat_stat[0].min_val = td->slat_stat[1].min_val = ULONG_MAX;
td->bw_stat[0].min_val = td->bw_stat[1].min_val = ULONG_MAX;
- if (td->min_bs == -1U)
- td->min_bs = td->bs;
- if (td->max_bs == -1U)
- td->max_bs = td->bs;
- if (td_read(td) && !td_rw(td))
- td->verify = 0;
-
if (td->stonewall && td->thread_number > 1)
groupid++;
if (!job_add_num) {
if (td->io_ops->flags & FIO_CPUIO)
fprintf(f_out, "%s: ioengine=cpu, cpuload=%u, cpucycle=%u\n", td->name, td->cpuload, td->cpucycle);
- else
- fprintf(f_out, "%s: (g=%d): rw=%s, odir=%d, bs=%d-%d, rate=%d, ioengine=%s, iodepth=%d\n", td->name, td->groupid, ddir_str[ddir], td->odirect, td->min_bs, td->max_bs, td->rate, td->io_ops->name, td->iodepth);
+ else {
+ char *c1, *c2, *c3, *c4;
+
+ c1 = to_kmg(td->min_bs[DDIR_READ]);
+ c2 = to_kmg(td->max_bs[DDIR_READ]);
+ c3 = to_kmg(td->min_bs[DDIR_WRITE]);
+ c4 = to_kmg(td->max_bs[DDIR_WRITE]);
+
+ fprintf(f_out, "%s: (g=%d): rw=%s, odir=%u, bs=%s-%s/%s-%s, rate=%u, ioengine=%s, iodepth=%u\n", td->name, td->groupid, ddir_str[ddir], td->odirect, c1, c2, c3, c4, td->rate, td->io_ops->name, td->iodepth);
+
+ free(c1);
+ free(c2);
+ free(c3);
+ free(c4);
+ }
} else if (job_add_num == 1)
fprintf(f_out, "...\n");
}
if (td->rand_repeatable)
seeds[3] = DEF_RANDSEED;
- for_each_file(td, f, i) {
- blocks = (f->file_size + td->min_bs - 1) / td->min_bs;
- num_maps = blocks / BLOCKS_PER_MAP;
- f->file_map = malloc(num_maps * sizeof(long));
- f->num_maps = num_maps;
- memset(f->file_map, 0, num_maps * sizeof(long));
+ if (!td->norandommap) {
+ for_each_file(td, f, i) {
+ blocks = (f->file_size + td->rw_min_bs - 1) / td->rw_min_bs;
+ num_maps = (blocks + BLOCKS_PER_MAP-1)/ BLOCKS_PER_MAP;
+ f->file_map = malloc(num_maps * sizeof(long));
+ f->num_maps = num_maps;
+ memset(f->file_map, 0, num_maps * sizeof(long));
+ }
}
os_random_seed(seeds[3], &td->random_state);
td->sequential = 0;
return 0;
} else if (!strncmp(mem, "rw", 2)) {
- td->ddir = 0;
+ td->ddir = DDIR_READ;
td->iomix = 1;
td->sequential = 1;
return 0;
} else if (!strncmp(mem, "randrw", 6)) {
- td->ddir = 0;
+ td->ddir = DDIR_READ;
td->iomix = 1;
td->sequential = 0;
return 0;
return 1;
}
+/*
+ * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
+ */
+static char *get_mmap_file(const char *str)
+{
+ char *p = strstr(str, ":");
+
+ if (!p)
+ return NULL;
+
+ p++;
+ strip_blank_front(&p);
+ strip_blank_end(p);
+ return strdup(p);
+}
+
static int str_mem_cb(void *data, const char *mem)
{
struct thread_data *td = data;
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
+ /*
+ * mmaphuge must be appended with the actual file
+ */
+ td->mmapfile = get_mmap_file(mem);
+ if (!td->mmapfile) {
+ log_err("fio: mmaphuge:/path/to/file\n");
+ return 1;
+ }
+
+ td->mem_type = MEM_MMAPHUGE;
return 0;
+#else
+ log_err("fio: mmaphuge not available\n");
+ return 1;
+#endif
} else if (!strncmp(mem, "mmap", 4)) {
+ /*
+ * Check if the user wants file backed memory. It's ok
+ * if there's no file given, we'll just use anon mamp then.
+ */
+ td->mmapfile = get_mmap_file(mem);
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;
}
if (td->io_ops)
return 0;
- log_err("fio: ioengine: { linuxaio, aio, libaio }, posixaio, sync, mmap, sgio, splice, cpu\n");
+ log_err("fio: ioengine= libaio, posixaio, sync, mmap, sgio, splice, cpu, null\n");
+ log_err("fio: or specify path to dynamic ioengine module\n");
return 1;
}
return 0;
}
+#ifdef FIO_HAVE_IOPRIO
static int str_prioclass_cb(void *data, unsigned int *val)
{
struct thread_data *td = data;
td->ioprio |= *val;
return 0;
}
+#endif
static int str_exitall_cb(void)
{
/*
* This is our [ini] type file parser.
*/
-int parse_jobs_ini(char *file, int stonewall_flag)
+static int parse_jobs_ini(char *file, int stonewall_flag)
{
unsigned int global;
struct thread_data *td;
- char *string, *name, *tmpbuf;
+ char *string, *name;
fpos_t off;
FILE *f;
char *p;
string = malloc(4096);
name = malloc(256);
- tmpbuf = malloc(4096);
+ memset(name, 0, 256);
stonewall = stonewall_flag;
- while ((p = fgets(string, 4096, f)) != NULL) {
- if (ret)
+ do {
+ p = fgets(string, 4095, f);
+ if (!p)
break;
if (is_empty_or_comment(p))
continue;
- if (sscanf(p, "[%s]", name) != 1)
+ if (sscanf(p, "[%255s]", name) != 1)
continue;
global = !strncmp(name, "global", 6);
while ((p = fgets(string, 4096, f)) != NULL) {
if (is_empty_or_comment(p))
continue;
- if (strstr(p, "["))
- break;
strip_blank_front(&p);
+
+ if (p[0] == '[')
+ break;
+
strip_blank_end(p);
fgetpos(f, &off);
* dump all the bad ones. Makes trial/error fixups
* easier on the user.
*/
- ret = parse_option(p, options, td);
+ ret |= parse_option(p, options, td);
}
if (!ret) {
fsetpos(f, &off);
ret = add_job(td, name, 0);
+ } else {
+ log_err("fio: job %s dropped\n", name);
+ put_job(td);
}
- if (ret)
- break;
- }
+ } while (!ret);
free(string);
free(name);
- free(tmpbuf);
fclose(f);
return ret;
}
*/
def_thread.ddir = DDIR_READ;
def_thread.iomix = 0;
- def_thread.bs = DEF_BS;
- def_thread.min_bs = -1;
- def_thread.max_bs = -1;
+ def_thread.bs[DDIR_READ] = DEF_BS;
+ def_thread.bs[DDIR_WRITE] = DEF_BS;
+ def_thread.min_bs[DDIR_READ] = def_thread.min_bs[DDIR_WRITE] = 0;
+ def_thread.max_bs[DDIR_READ] = def_thread.max_bs[DDIR_WRITE] = 0;
def_thread.odirect = DEF_ODIRECT;
def_thread.ratecycle = DEF_RATE_CYCLE;
def_thread.sequential = DEF_SEQUENTIAL;
def_thread.unlink = DEF_UNLINK;
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
static int parse_cmd_line(int argc, char *argv[])
{
struct thread_data *td = NULL;
- int c, ini_idx = 0, lidx;
+ int c, ini_idx = 0, lidx, ret;
while ((c = getopt_long(argc, argv, "", long_options, &lidx)) != -1) {
switch (c) {
const char *opt = long_options[lidx].name;
char *val = optarg;
+ if (!strncmp(opt, "name", 4) && td) {
+ ret = add_job(td, td->name ?: "fio", 0);
+ if (ret) {
+ put_job(td);
+ return 0;
+ }
+ td = NULL;
+ }
if (!td) {
- td = get_new_job(0, &def_thread);
+ int global = !strncmp(val, "global", 6);
+
+ td = get_new_job(global, &def_thread);
if (!td)
return 0;
}
- if (parse_cmd_option(opt, val, options, td))
- printf("foo\n");
+
+ ret = parse_cmd_option(opt, val, options, td);
+ if (ret) {
+ log_err("fio: job dropped\n");
+ put_job(td);
+ td = NULL;
+ }
break;
}
default:
- printf("optarg <<%s>>\n", argv[optind]);
break;
}
}
if (td) {
- const char *name = td->name;
- int ret;
-
- if (!name)
- name = "fio";
-
- ret = add_job(td, name, 0);
+ ret = add_job(td, td->name ?: "fio", 0);
if (ret)
put_job(td);
}
if (!thread_number) {
log_err("No jobs defined(s)\n");
- usage();
return 1;
}