Add specific knob for controlling fallocate() usage

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diff --git a/HOWTO b/HOWTO
index 45a96bb..91a1ec3 100644
--- a/HOWTO
+++ b/HOWTO
@@ -324,6 +324,11 @@
 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 70589aa..cbef672 100644
--- a/filesetup.c
+++ b/filesetup.c
@@ -64,6 +64,19 @@
 		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 @@
 			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 dfca43e..60f787a 100644
--- a/fio.1
+++ b/fio.1
@@ -182,6 +182,11 @@
 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 119dc09..bdc1708 100644
--- a/fio.h
+++ b/fio.h
@@ -227,6 +227,7 @@
 	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 1543eb9..1c07982 100644
--- a/options.c
+++ b/options.c
@@ -1081,6 +1081,15 @@
 		},
 		.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,