Fixes #833. Provides the ability to initially "layout" the file
by ftruncating it to the desired size before performing IO. This
is mainly useful on Windows, which serializes all writes that
extend the size of a file. Using this option with a suitable
iodepth allows fio to emulate the behavior of Windows Explorer
file copy, which always truncates to the expected size before
issuing writes for performance reasons.
Pre-allocate via :manpage:`fallocate(2)` with
FALLOC_FL_KEEP_SIZE set.
Pre-allocate via :manpage:`fallocate(2)` with
FALLOC_FL_KEEP_SIZE set.
+ **truncate**
+ Extend file to final size via :manpage:`ftruncate(2)`
+ instead of allocating.
+
**0**
Backward-compatible alias for **none**.
**0**
Backward-compatible alias for **none**.
May not be available on all supported platforms. **keep** is only available
on Linux. If using ZFS on Solaris this cannot be set to **posix**
because ZFS doesn't support pre-allocation. Default: **native** if any
May not be available on all supported platforms. **keep** is only available
on Linux. If using ZFS on Solaris this cannot be set to **posix**
because ZFS doesn't support pre-allocation. Default: **native** if any
- pre-allocation methods are available, **none** if not.
+ pre-allocation methods except **truncate** are available, **none** if not.
+
+ Note that using **truncate** on Windows will interact surprisingly
+ with non-sequential write patterns. When writing to a file that has
+ been extended by setting the end-of-file information, Windows will
+ backfill the unwritten portion of the file up to that offset with
+ zeroes before issuing the new write. This means that a single small
+ write to the end of an extended file will stall until the entire
+ file has been filled with zeroes.
.. option:: fadvise_hint=str
.. option:: fadvise_hint=str
FIO_FALLOCATE_POSIX = 2,
FIO_FALLOCATE_KEEP_SIZE = 3,
FIO_FALLOCATE_NATIVE = 4,
FIO_FALLOCATE_POSIX = 2,
FIO_FALLOCATE_KEEP_SIZE = 3,
FIO_FALLOCATE_NATIVE = 4,
+ FIO_FALLOCATE_TRUNCATE = 5,
break;
}
#endif /* CONFIG_LINUX_FALLOCATE */
break;
}
#endif /* CONFIG_LINUX_FALLOCATE */
+ case FIO_FALLOCATE_TRUNCATE: {
+ int r;
+
+ dprint(FD_FILE, "ftruncate file %s size %llu\n",
+ f->file_name,
+ (unsigned long long) f->real_file_size);
+ r = ftruncate(f->fd, f->real_file_size);
+ if (r != 0)
+ td_verror(td, errno, "ftruncate");
+
+ break;
+ }
default:
log_err("fio: unknown fallocate mode: %d\n", td->o.fallocate_mode);
assert(0);
default:
log_err("fio: unknown fallocate mode: %d\n", td->o.fallocate_mode);
assert(0);
Pre-allocate via \fBfallocate\fR\|(2) with
FALLOC_FL_KEEP_SIZE set.
.TP
Pre-allocate via \fBfallocate\fR\|(2) with
FALLOC_FL_KEEP_SIZE set.
.TP
+.B truncate
+Extend file to final size using \fBftruncate\fR|(2)
+instead of allocating.
+.TP
.B 0
Backward-compatible alias for \fBnone\fR.
.TP
.B 0
Backward-compatible alias for \fBnone\fR.
.TP
May not be available on all supported platforms. \fBkeep\fR is only available
on Linux. If using ZFS on Solaris this cannot be set to \fBposix\fR
because ZFS doesn't support pre-allocation. Default: \fBnative\fR if any
May not be available on all supported platforms. \fBkeep\fR is only available
on Linux. If using ZFS on Solaris this cannot be set to \fBposix\fR
because ZFS doesn't support pre-allocation. Default: \fBnative\fR if any
-pre-allocation methods are available, \fBnone\fR if not.
+pre-allocation methods except \fBtruncate\fR are available, \fBnone\fR if not.
+.P
+Note that using \fBtruncate\fR on Windows will interact surprisingly
+with non-sequential write patterns. When writing to a file that has
+been extended by setting the end-of-file information, Windows will
+backfill the unwritten portion of the file up to that offset with
+zeroes before issuing the new write. This means that a single small
+write to the end of an extended file will stall until the entire
+file has been filled with zeroes.
.RE
.TP
.BI fadvise_hint \fR=\fPstr
.RE
.TP
.BI fadvise_hint \fR=\fPstr
o->unit_base = N2S_BYTEPERSEC;
}
o->unit_base = N2S_BYTEPERSEC;
}
-#ifndef FIO_HAVE_ANY_FALLOCATE
- /* Platform doesn't support any fallocate so force it to none */
- o->fallocate_mode = FIO_FALLOCATE_NONE;
-#endif
-
#ifndef CONFIG_FDATASYNC
if (o->fdatasync_blocks) {
log_info("fio: this platform does not support fdatasync()"
#ifndef CONFIG_FDATASYNC
if (o->fdatasync_blocks) {
log_info("fio: this platform does not support fdatasync()"
.parent = "nrfiles",
.hide = 1,
},
.parent = "nrfiles",
.hide = 1,
},
-#ifdef FIO_HAVE_ANY_FALLOCATE
{
.name = "fallocate",
.lname = "Fallocate",
.type = FIO_OPT_STR,
.off1 = offsetof(struct thread_options, fallocate_mode),
.help = "Whether pre-allocation is performed when laying out files",
{
.name = "fallocate",
.lname = "Fallocate",
.type = FIO_OPT_STR,
.off1 = offsetof(struct thread_options, fallocate_mode),
.help = "Whether pre-allocation is performed when laying out files",
+#ifdef FIO_HAVE_DEFAULT_FALLOCATE
+#else
+ .def = "none",
+#endif
.category = FIO_OPT_C_FILE,
.group = FIO_OPT_G_INVALID,
.posval = {
.category = FIO_OPT_C_FILE,
.group = FIO_OPT_G_INVALID,
.posval = {
.help = "Use fallocate(..., FALLOC_FL_KEEP_SIZE, ...)",
},
#endif
.help = "Use fallocate(..., FALLOC_FL_KEEP_SIZE, ...)",
},
#endif
+ { .ival = "truncate",
+ .oval = FIO_FALLOCATE_TRUNCATE,
+ .help = "Truncate file to final size instead of allocating"
+ },
/* Compatibility with former boolean values */
{ .ival = "0",
.oval = FIO_FALLOCATE_NONE,
/* Compatibility with former boolean values */
{ .ival = "0",
.oval = FIO_FALLOCATE_NONE,
-#else /* FIO_HAVE_ANY_FALLOCATE */
- {
- .name = "fallocate",
- .lname = "Fallocate",
- .type = FIO_OPT_UNSUPPORTED,
- .help = "Your platform does not support fallocate",
- },
-#endif /* FIO_HAVE_ANY_FALLOCATE */
{
.name = "fadvise_hint",
.lname = "Fadvise hint",
{
.name = "fadvise_hint",
.lname = "Fadvise hint",
#endif
#if defined(CONFIG_POSIX_FALLOCATE) || defined(FIO_HAVE_NATIVE_FALLOCATE)
#endif
#if defined(CONFIG_POSIX_FALLOCATE) || defined(FIO_HAVE_NATIVE_FALLOCATE)
-# define FIO_HAVE_ANY_FALLOCATE
+# define FIO_HAVE_DEFAULT_FALLOCATE
#endif
#ifndef FIO_HAVE_CPU_HAS
#endif
#ifndef FIO_HAVE_CPU_HAS