From: Jens Axboe Date: Thu, 28 Jan 2010 10:31:31 +0000 (+0100) Subject: Add specific knob for controlling fallocate() usage X-Git-Tag: fio-1.37~5 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=7bc8c2cf02fbd538ca388618ff2f4618787a86e0;hp=-c;ds=sidebyside Add specific knob for controlling fallocate() usage Signed-off-by: Jens Axboe --- 7bc8c2cf02fbd538ca388618ff2f4618787a86e0 diff --git a/HOWTO b/HOWTO index 45a96bb1..91a1ec35 100644 --- a/HOWTO +++ b/HOWTO @@ -324,6 +324,11 @@ kb_base=int The base unit for a kilobyte. The defacto base is 2^10, 1024. randrepeat=bool For random IO workloads, seed the generator in a predictable way so that results are repeatable across repetitions. +fallocate=bool By default, fio will use fallocate() to advise the system + of the size of the file we are going to write. This can be + turned off with fallocate=0. May not be available on all + supported platforms. + fadvise_hint=bool By default, fio will use fadvise() to advise the kernel on what IO patterns it is likely to issue. Sometimes you want to test specific IO patterns without telling the diff --git a/filesetup.c b/filesetup.c index 70589aa5..cbef672e 100644 --- a/filesetup.c +++ b/filesetup.c @@ -64,6 +64,19 @@ static int extend_file(struct thread_data *td, struct fio_file *f) return 1; } +#ifdef FIO_HAVE_FALLOCATE + if (td->o.fallocate && !td->o.fill_device) { + dprint(FD_FILE, "fallocate file %s size %llu\n", f->file_name, + f->real_file_size); + + r = posix_fallocate(f->fd, 0, f->real_file_size); + if (r < 0) { + log_err("fio: posix_fallocate fails: %s\n", + strerror(-r)); + } + } +#endif + if (!new_layout) goto done; @@ -78,16 +91,6 @@ static int extend_file(struct thread_data *td, struct fio_file *f) td_verror(td, errno, "ftruncate"); goto err; } - -#ifdef FIO_HAVE_FALLOCATE - dprint(FD_FILE, "fallocate file %s, size %llu\n", f->file_name, - f->real_file_size); - r = posix_fallocate(f->fd, 0, f->real_file_size); - if (r < 0) { - log_err("fio: posix_fallocate fails: %s\n", - strerror(-r)); - } -#endif } b = malloc(td->o.max_bs[DDIR_WRITE]); diff --git a/fio.1 b/fio.1 index dfca43ef..60f787a1 100644 --- a/fio.1 +++ b/fio.1 @@ -182,6 +182,11 @@ reasons. Allow values are 1024 or 1000, with 1024 being the default. Seed the random number generator in a predictable way so results are repeatable across runs. Default: true. .TP +.BI fallocate \fR=\fPbool +By default, fio will use fallocate() to advise the system of the size of the +file we are going to write. This can be turned off with fallocate=0. May not +be available on all supported platforms. +.TP .BI fadvise_hint \fR=\fPbool Disable use of \fIposix_fadvise\fR\|(2) to advise the kernel what I/O patterns are likely to be issued. Default: true. diff --git a/fio.h b/fio.h index 119dc09e..bdc17081 100644 --- a/fio.h +++ b/fio.h @@ -227,6 +227,7 @@ struct thread_options { unsigned int file_service_type; unsigned int group_reporting; unsigned int fadvise_hint; + unsigned int fallocate; unsigned int zero_buffers; unsigned int refill_buffers; unsigned int time_based; diff --git a/options.c b/options.c index 1543eb95..1c07982d 100644 --- a/options.c +++ b/options.c @@ -1081,6 +1081,15 @@ static struct fio_option options[] = { }, .parent = "nrfiles", }, +#ifdef FIO_HAVE_FALLOCATE + { + .name = "fallocate", + .type = FIO_OPT_BOOL, + .off1 = td_var_offset(fallocate), + .help = "Use fallocate() when laying out files", + .def = "1", + }, +#endif { .name = "fadvise_hint", .type = FIO_OPT_BOOL,