Add specific knob for controlling fallocate() usage
authorJens Axboe <jens.axboe@oracle.com>
Thu, 28 Jan 2010 10:31:31 +0000 (11:31 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Thu, 28 Jan 2010 10:31:31 +0000 (11:31 +0100)
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
HOWTO
filesetup.c
fio.1
fio.h
options.c

diff --git a/HOWTO b/HOWTO
index 45a96bb1618182c0251fb8a77a4bdfd1ab6e460b..91a1ec353cf3180168ea7352b8a506c94b04ed99 100644 (file)
--- 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.
 
 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
 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
index 70589aa513eaa95d6108664df88d43270d8ba475..cbef672e673e6d3c1d0d363466b677702e1953f1 100644 (file)
@@ -64,6 +64,19 @@ static int extend_file(struct thread_data *td, struct fio_file *f)
                return 1;
        }
 
                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;
 
        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;
                }
                        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]);
        }
 
        b = malloc(td->o.max_bs[DDIR_WRITE]);
diff --git a/fio.1 b/fio.1
index dfca43efd9ca0707c563a5395aa31e8bde39399f..60f787a140940f9ad5888c84fd96cf8e60f456ff 100644 (file)
--- 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
 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.
 .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 119dc09e74b47728c85095a5445dbbcaecbd944f..bdc1708123e89f73f704fecdd34301f76f1ca37e 100644 (file)
--- 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 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;
        unsigned int zero_buffers;
        unsigned int refill_buffers;
        unsigned int time_based;
index 1543eb95c160aa1afd2fae34c402dd3cab0092de..1c07982d41cf23497862289d814b294a6e1edcb8 100644 (file)
--- a/options.c
+++ b/options.c
@@ -1081,6 +1081,15 @@ static struct fio_option options[] = {
                },
                .parent = "nrfiles",
        },
                },
                .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,
        {
                .name   = "fadvise_hint",
                .type   = FIO_OPT_BOOL,