fio: atomic write support
v2 cover fio: atomic write support
This series re-introduces atomic write support.
Some time ago support was added for O_ATOMIC in fio, but O_ATOMIC support never made it into the linux kernel, so fio support was dropped. However some plumbing was left behind; specifically, we can still pass command line arg --atomic=1, which sets thread option oatomic, but that is just ignored.
Linux v6.11-rc added initial atomic write support through RWF_ATOMIC flag. See latest man pages for details of RWF_ATOMIC:
https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/
This series uses the "atomic" command line option to set RWF_ATOMIC on a per IO.
Support is added for libaio, pvsync2, and io_uring ioengines.
Since RWF_ATOMIC is only relevant to those ioengines mentioned, trying to set --atomic=1 for other ioengines now errors.
The verify feature can be useful to prove atomic writes. However, atomic writes only ensure a proper CRC, but not sequence number. So a new option to ignore sequence numbers is added.
Compile tested only for Linux (ok?)
Differences to RFC:
- Drop patch to ignore verify sequence number
- Add support for new option verify_sequence_number
- Add atomic writes fio file example
- Update documentation for atomic option
Alan Adamson (1):
pvsync2: Support RWF_ATOMIC
John Garry (8):
os-linux: Define RWF_ATOMIC
os: Reintroduce atomic write support
libaio: Support RWF_ATOMIC
io_uring: Support RWF_ATOMIC
tools/fiograph: Update for atomic support
doc: Document atomic command
fio: Support verify_write_sequence
examples: Add example for atomic write verify
HOWTO.rst | 25 +++++++++++++++++++++++++ engines/io_uring.c | 5 ++++- engines/libaio.c | 7 ++++++- engines/sync.c | 9 ++++++--- examples/atomic-verify.fio | 36 ++++++++++++++++++++++++++++++++++++ fio.1 | 21 +++++++++++++++++++++ init.c | 14 ++++++++++++++ ioengines.h | 2 ++ options.c | 13 +++++++++++++ os/os-linux.h | 5 +++++ thread_options.h | 1 + tools/fiograph/fiograph.conf | 6 +++--- verify.c | 7 ++++--- 13 files changed, 140 insertions(+), 11 deletions(-) create mode 100644 examples/atomic-verify.fio
Signature · 1 line
2.31.1
PATCH v2 1/9 os-linux: Define RWF_ATOMIC
Add a definition of RWF_ATOMIC when not available from uapi headers.
RWF_ATOMIC is going to be part of Linux v6.11
--- os/os-linux.h | 4 ++++ 1 file changed, 4 insertions(+)
os/os-linux.h +4 -0
@@ -328,6 +328,10 @@ static inline int fio_set_sched_idle(void)#define RWF_NOWAIT 0x00000008#endif +#ifndef RWF_ATOMIC +#define RWF_ATOMIC 0x00000040 +#endif +#ifndef RWF_WRITE_LIFE_SHIFT #define RWF_WRITE_LIFE_SHIFT 4#define RWF_WRITE_LIFE_SHORT (1 << RWF_WRITE_LIFE_SHIFT)
Signature · 1 line
2.31.1
PATCH v2 2/9 os: Reintroduce atomic write support
In reply to John GarryPreviously O_ATOMIC support was added in commit d01612f3ae25 ("Add support for O_ATOMIC"). But support was removed in commit a25ba6c64fe1 ("Get rid of O_ATOMIC"), as support was never added in the Linux kernel.
Linux kernel 6.11 will add support for RWF_ATOMIC, which can be supported for various ioengines. See latest man pages for details.
The plumbing was left in place for thread option oatomic, so that will be reused.
Add a flag to say whether an engine supports atomic writes, and reject when oatomic is set for an engine which does not support atomic writes.
This is a change in behaviour, as since commit a25ba6c64fe1 ("Get rid of O_ATOMIC"), this oatomic has been ignored. However, it is better to tell the user that their ioengine of choice does not support atomic writes.
Today RWF_ATOMIC is only supported for direct-IO. In future it may be supported for buffered IO. As such, do not auto-set odirect=1 when oatomic==1.
--- init.c | 11 +++++++++++ ioengines.h | 2 ++ options.c | 2 ++ os/os-linux.h | 1 + 4 files changed, 16 insertions(+)
init.c +11 -0
@@ -855,6 +855,17 @@ static int fixup_options(struct thread_data *td) o->max_bs[DDIR_WRITE]); } +if (td->o.oatomic) { +if (!td_ioengine_flagged (td,FIO_ATOMICWRITES )) { +log_err ("fio: engine does not support atomic writes\n" ); + td->o.oatomic =0 ; + ret |=1 ; + } + +if (!td_write (td)) + td->o.oatomic =0 ; + } +if (o->pre_read) {if (o->invalidate_cache) o->invalidate_cache =0 ;
ioengines.h +2 -0
@@ -96,6 +96,7 @@ enum { __FIO_RO_NEEDS_RW_OPEN,/* open files in rw mode even if we have a read job; only affects ioengines using generic_open_file */ __FIO_MULTI_RANGE_TRIM,/* ioengine supports trim with more than one range */ + __FIO_ATOMICWRITES,/* ioengine supports atomic writes */ __FIO_IOENGINE_F_LAST, /* not a real bit; used to count number of bits */ };
@@ -120,6 +121,7 @@ enum fio_ioengine_flags {FIO_SKIPPABLE_IOMEM_ALLOC =1 << __FIO_SKIPPABLE_IOMEM_ALLOC,FIO_RO_NEEDS_RW_OPEN =1 << __FIO_RO_NEEDS_RW_OPEN,FIO_MULTI_RANGE_TRIM =1 << __FIO_MULTI_RANGE_TRIM, + FIO_ATOMICWRITES = 1 << __FIO_ATOMICWRITES, };/*
options.c +2 -0
@@ -2926,6 +2926,7 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .category = FIO_OPT_C_IO, .group = FIO_OPT_G_IO_TYPE, }, +#ifdef FIO_HAVE_RWF_ATOMIC { .name = "atomic", .lname = "Atomic I/O",
@@ -2936,6 +2937,7 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .category = FIO_OPT_C_IO, .group = FIO_OPT_G_IO_TYPE, }, +#endif { .name = "buffered", .lname = "Buffered I/O",
os/os-linux.h +1 -0
@@ -62,6 +62,7 @@#define FIO_HAVE_BYTEORDER_FUNCS #define FIO_HAVE_PWRITEV2 #define FIO_HAVE_SHM_ATTACH_REMOVED +#define FIO_HAVE_RWF_ATOMIC #ifdef MAP_HUGETLB #define FIO_HAVE_MMAP_HUGE
Signature · 1 line
2.31.1
PATCH v2 3/9 pvsync2: Support RWF_ATOMIC
In reply to John GarryFrom: Alan Adamson <[email protected]>
Set RWF_ATOMIC for writes and atomic==1.
jpg: Set FIO_ATOMICWRITES for pvsync2
--- engines/sync.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
engines/sync.c +6 -3
@@ -175,9 +175,11 @@ static enum fio_q_status fio_pvsyncio2_queue(struct thread_data *td,if (io_u->ddir ==DDIR_READ ) ret =preadv2 (f->fd, iov,1 , io_u->offset, flags); -else if (io_u->ddir ==DDIR_WRITE ) +else if (io_u->ddir ==DDIR_WRITE ) { +if (td->o.oatomic) + flags |=RWF_ATOMIC ; ret =pwritev2 (f->fd, iov,1 , io_u->offset, flags); -else if (io_u->ddir ==DDIR_TRIM ) { + }else if (io_u->ddir ==DDIR_TRIM ) {do_io_u_trim (td, io_u);return FIO_Q_COMPLETED ; }else
@@ -476,7 +478,8 @@ static struct ioengine_ops ioengine_pvrw2 = { .open_file = generic_open_file, .close_file = generic_close_file, .get_file_size = generic_get_file_size, - .flags = FIO_SYNCIO, + .flags = FIO_SYNCIO | + FIO_ATOMICWRITES, .options = options, .option_struct_size = sizeof(struct psyncv2_options), };
Signature · 1 line
2.31.1
PATCH v2 4/9 libaio: Support RWF_ATOMIC
In reply to John GarrySet RWF_ATOMIC for writes and oatomic==1.
Guard setting RWF_ATOMIC by FIO_HAVE_RWF_ATOMIC, as only linux supports RWF_ATOMIC.
--- engines/libaio.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
engines/libaio.c +6 -1
@@ -110,6 +110,10 @@ static int fio_libaio_prep(struct thread_data *td, struct io_u *io_u)io_prep_pwrite (iocb, f->fd, io_u->xfer_buf, io_u->xfer_buflen, io_u->offset);if (o->nowait) iocb->aio_rw_flags |=RWF_NOWAIT ; +#ifdef FIO_HAVE_RWF_ATOMIC +if (td->o.oatomic) + iocb->aio_rw_flags |=RWF_ATOMIC ; +#endif }else if (ddir_sync (io_u->ddir))io_prep_fsync (iocb, f->fd);
@@ -440,7 +444,8 @@ FIO_STATIC struct ioengine_ops ioengine = { .name = "libaio", .version = FIO_IOOPS_VERSION, .flags =FIO_ASYNCIO_SYNC_TRIM | - FIO_ASYNCIO_SETS_ISSUE_TIME, +FIO_ASYNCIO_SETS_ISSUE_TIME | + FIO_ATOMICWRITES, .init = fio_libaio_init, .post_init = fio_libaio_post_init, .prep = fio_libaio_prep,
Signature · 1 line
2.31.1
PATCH v2 5/9 io_uring: Support RWF_ATOMIC
In reply to John GarrySet RWF_ATOMIC for writes and oatomic==1.
--- engines/io_uring.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
engines/io_uring.c +4 -1
@@ -392,6 +392,8 @@ static int fio_ioring_prep(struct thread_data *td, struct io_u *io_u) sqe->rw_flags =0 ;if (o->nowait) sqe->rw_flags |=RWF_NOWAIT ; +if (td->o.oatomic && io_u->ddir ==DDIR_WRITE ) + sqe->rw_flags |=RWF_ATOMIC ;/* * Since io_uring can have a submission context (sqthread_poll)
@@ -1582,7 +1584,8 @@ static struct ioengine_ops ioengine_uring = { .name = "io_uring", .version = FIO_IOOPS_VERSION, .flags =FIO_ASYNCIO_SYNC_TRIM |FIO_NO_OFFLOAD | - FIO_ASYNCIO_SETS_ISSUE_TIME, +FIO_ASYNCIO_SETS_ISSUE_TIME | + FIO_ATOMICWRITES, .init = fio_ioring_init, .post_init = fio_ioring_post_init, .io_u_init = fio_ioring_io_u_init,
Signature · 1 line
2.31.1
PATCH v2 6/9 tools/fiograph: Update for atomic support
In reply to John GarryAdd atomic support for the specific engines which support this option.
This just means that "atomic" will show up as a special iongeine config option (if fio 'atomic' option is specified).
--- tools/fiograph/fiograph.conf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/fiograph/fiograph.conf +3 -3
@@ -51,13 +51,13 @@ specific_options=https http_host http_user http_pass http_s3_key http_s3_ke specific_options=ime_psync ime_psyncv [ioengine_io_uring] -specific_options=hipri cmdprio_percentage cmdprio_class cmdprio cmdprio_bssplit fixedbufs registerfiles sqthread_poll sqthread_poll_cpu nonvectored nowait force_async +specific_options=hipri cmdprio_percentage cmdprio_class cmdprio cmdprio_bssplit fixedbufs registerfiles sqthread_poll sqthread_poll_cpu nonvectored nowait force_async atomic [ioengine_io_uring_cmd] specific_options=hipri cmdprio_percentage cmdprio_class cmdprio cmdprio_bssplit fixedbufs registerfiles sqthread_poll sqthread_poll_cpu nonvectored nowait force_async cmd_type md_per_io_size pi_act pi_chk apptag apptag_mask [ioengine_libaio] -specific_options=userspace_reap cmdprio_percentage cmdprio_class cmdprio cmdprio_bssplit nowait +specific_options=userspace_reap cmdprio_percentage cmdprio_class cmdprio cmdprio_bssplit nowait atomic [ioengine_libblkio] specific_options=libblkio_driver libblkio_path libblkio_pre_connect_props libblkio_num_entries libblkio_queue_size libblkio_pre_start_props hipri libblkio_vectored libblkio_write_zeroes_on_trim libblkio_wait_mode libblkio_force_enable_completion_eventfd
@@ -99,7 +99,7 @@ specific_options=hostname bindname port verb specific_options=hipri readfua writefua sg_write_mode stream_id [ioengine_pvsync2] -specific_options=hipri hipri_percentage nowait sync psync vsync pvsync +specific_options=hipri hipri_percentage nowait sync psync vsync pvsync atomic [ioengine_xnvme] specific_options=hipri sqthread_poll xnvme_be xnvme_async xnvme_sync xnvme_admin xnvme_dev_nsid xnvme_iovec
Signature · 1 line
2.31.1
PATCH v2 7/9 doc: Document atomic command
In reply to John GarryNow that the atomic command is formally supported, document it.
--- HOWTO.rst | 14 ++++++++++++++ fio.1 | 13 +++++++++++++ 2 files changed, 27 insertions(+)
HOWTO.rst +14 -0
@@ -2501,6 +2501,20 @@ with the caveat that when used on the command line, they must come after the For direct I/O, requests will only succeed if cache invalidation isn't required, file blocks are fully allocated and the disk request could be issued immediately. +.. option:: atomic=bool : [pvsync2] [libaio] [io_uring] + + This option means that writes are issued with torn-write protection, meaning + that for a power fail or kernel crash, all or none of the data from the write + will be stored, but never a mix of old and new data. Torn-write protection is + also known as atomic writes. + + This option sets the RWF_ATOMIC flag (supported from the 6.11 Linux kernel) on + a per-IO basis. + + Writes with RWF_ATOMIC set will be rejected by the kernel when the file does + not support torn-write protection. To learn a file's torn-write limits, issue + statx with STATX_WRITE_ATOMIC. + .. option:: fdp=bool : [io_uring_cmd] [xnvme] Enable Flexible Data Placement mode for write commands.
fio.1 +13 -0
@@ -2266,6 +2266,19 @@ cached data. Currently the RWF_NOWAIT flag does not supported for cached write. For direct I/O, requests will only succeed if cache invalidation isn't required, file blocks are fully allocated and the disk request could be issued immediately. .TP +.BI (pvsync2,libaio,io_uring)atomic \fR=\fPbool +This option means that writes are issued with torn-write protection, meaning +that for a power fail or kernel crash, all or none of the data from the write +will be stored, but never a mix of old and new data. Torn-write protection is +also known as atomic writes. + +This option sets the RWF_ATOMIC flag (supported from the 6.11 Linux kernel) on +a per-IO basis. + +Writes with RWF_ATOMIC set will be rejected by the kernel when the file does +not support torn-write protection. To learn a file's torn-write limits, issue +statx with STATX_WRITE_ATOMIC. +.TP .BI (io_uring_cmd,xnvme)fdp \fR=\fPbool Enable Flexible Data Placement mode for write commands. .TP
Signature · 1 line
2.31.1
PATCH v2 8/9 fio: Support verify_write_sequence
In reply to John GarryAdd an option to disable verifying the write sequence number. By default, it is enabled. However disable for verify_only mode.
--- HOWTO.rst | 11 +++++++++++ fio.1 | 8 ++++++++ init.c | 3 +++ options.c | 11 +++++++++++ thread_options.h | 1 + verify.c | 7 ++++--- 6 files changed, 38 insertions(+), 3 deletions(-)
HOWTO.rst +11 -0
@@ -4002,6 +4002,17 @@ Verification instead resets the file after the write phase and then replays I/Os for the verification phase. +.. option:: verify_write_sequence=bool + + Verify the header write sequence number. In a scenario with multiple jobs, + verification of the write sequence number may fail. Disabling this option + will mean that write sequence number checking is skipped. Doing that can be + useful for testing atomic writes, as it means that checksum verification can + still be attempted. For when :option:`atomic` is enabled, checksum + verification is expected to succeed (while write sequence checking can still + fail). + Defaults to true. + .. option:: trim_percentage=int Number of verify blocks to discard/trim.
fio.1 +8 -0
@@ -3726,6 +3726,14 @@ Enable experimental verification. Standard verify records I/O metadata for later use during the verification phase. Experimental verify instead resets the file after the write phase and then replays I/Os for the verification phase. .TP +.BI verify_write_sequence \fR=\fPbool +Verify the header write sequence number. In a scenario with multiple jobs, +verification of the write sequence number may fail. Disabling this option +will mean that write sequence number checking is skipped. Doing that can be +useful for testing atomic writes, as it means that checksum verification can +still be attempted. For when \fBatomic\fR is enabled, checksum verification +is expected to succeed (while write sequence checking can still fail). +.TP .BI trim_percentage \fR=\fPint Number of verify blocks to discard/trim. .TP
init.c +3 -0
@@ -853,6 +853,9 @@ static int fixup_options(struct thread_data *td) (o->max_bs[DDIR_WRITE] % o->verify_interval)) o->verify_interval = gcd(o->min_bs[DDIR_WRITE], o->max_bs[DDIR_WRITE ]); + +if (td->o.verify_only) + o->verify_write_sequence =0 ; }if (td->o.oatomic) {
options.c +11 -0
@@ -3397,6 +3397,17 @@ struct fio_option fio_options[FIO_MAX_OPTS] = { .category = FIO_OPT_C_IO, .group = FIO_OPT_G_VERIFY, }, + { + .name = "verify_write_sequence", + .lname = "Verify write sequence number", + .off1 = offsetof(struct thread_options, verify_write_sequence), + .type = FIO_OPT_BOOL, + .def = "1", + .help = "Verify header write sequence number", + .parent = "verify", + .category = FIO_OPT_C_IO, + .group = FIO_OPT_G_VERIFY, + }, #ifdef FIO_HAVE_TRIM { .name = "trim_percentage",
thread_options.h +1 -0
@@ -156,6 +156,7 @@ struct thread_options {unsigned int experimental_verify;unsigned int verify_state;unsigned int verify_state_save; +unsigned int verify_write_sequence;unsigned int use_thread;unsigned int unlink;unsigned int unlink_each_loop;
verify.c +4 -3
@@ -848,12 +848,13 @@ static int verify_header(struct io_u *io_u, struct thread_data *td,/* * For read-only workloads, the program cannot be certain of the * last numberio written to a block. Checking of numberio will be -* done only for workloads that write data. For verify_only, -* numberio check is skipped. +* done only for workloads that write data. For verify_only or +* any mode de-selecting verify_write_sequence, numberio check is +* skipped. */ if (td_write (td) && (td_min_bs (td) ==td_max_bs (td)) && !td->o.time_based) -if (!td->o.verify_only) +if (td->o.verify_write_sequence)if (hdr->numberio != io_u->numberio) { log_err("verify: bad header numberio %"PRIu16 ", wanted %"PRIu16,
Signature · 1 line
2.31.1
PATCH v2 9/9 examples: Add example for atomic write verify
In reply to John GarryAdd an example for verifying atomic writes.
Until now, atomic writes are only supported on Linux for block devices, so only give instructions on for that.
Currently support is being worked on for XFS and EXT4, and instructions can be updated in due course.
--- examples/atomic-verify.fio | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 examples/atomic-verify.fio
examples/atomic-verify.fio new file +36 -0
@@ -0,0 +1,36 @@ +# Data verification with atomic writes +# +# Some background on atomic writes: +# +# The main selling point of atomic writes is that it is guaranteed writes +# to storage will not be torn for a power failure or kernel crash. + +# Another aspect of atomic writes is that they handle racing writes and +# reads, such that a read racing with a write will see all the data from +# the write or none. Well, SCSI and NVMe guarantee this if using +# RWF_ATOMIC, but it is not formally stated as a feature of RWF_ATOMIC. +# +# Fio verify mode can be used to prove that atomic writes can make "safe" +# racing reads and writes. This done by having many jobs in a xsum verify +# mode. In this way, xsums should be correct, although a job may be +# reading a data block written by another job; however +# verify_write_sequence must be disabled, as it cannot be helped that data +# blocks will be out of sequence between with many jobs. +# +# Atomic write limits: +# For a block device, the max block size for atomic=1 is in +# /sys/block/sdXXX/queue/atomic_write_unit_max_bytes +# or this value can also be read with a statx syscall on the bdev file. + +[write-and-verify] +rw=randwrite +bs=4k +direct=1 +ioengine=libaio +iodepth=16 +verify=crc64 +atomic=1 +verify_write_sequence=0 +numjobs=10 +# Use /dev/XXX or filename +filename=/dev/XXX
Signature · 1 line
2.31.1
Jens Axboe
AppliedQuoted 9 lines · John Garry
This series re-introduces atomic write support.
Some time ago support was added for
O_ATOMICin fio, butO_ATOMICsupport never made it into the linux kernel, so fio support was dropped. However some plumbing was left behind; specifically, we can still pass command line arg --atomic=1, which sets thread option oatomic, but that is just ignored.[...]
Applied, thanks!
[1/9] os-linux: Define RWF_ATOMIC
commit: 5ba34480dc222db47d7813009eb95a7543790dd3
[2/9] os: Reintroduce atomic write support
commit: 40f1fc11d4fc6dbbd3c0eb5852e24126dad5fd4e
[3/9] pvsync2: Support RWF_ATOMIC
commit: 80226c53d994e8a9206ed7acf4a4dc75a8691792
[4/9] libaio: Support RWF_ATOMIC
commit: a79319fe6efd138ae346aff28b528682fbed0a7c
[5/9] io_uring: Support RWF_ATOMIC
commit: b1552b6e655dba1b1d4957c04a19361654ab38ad
[6/9] tools/fiograph: Update for atomic support
commit: 274a69eab08837e4e32185f2944e3b98dd5258c0
[7/9] doc: Document atomic command
commit: cd3de3d7700294f28d52cc781d1ce3982c12ba7e
[8/9] fio: Support verify_write_sequence
commit: 2dd80ee4598bcd69d1413fd2f1205cbffb56d787
[9/9] examples: Add example for atomic write verify
commit: f23208c8860de515f025af6ac34d6a227f277e67Best regards,
Signature · 1 line
Jens Axboe