RWF_ATOMIC
RWF_ATOMIC is a Linux pwritev2 flag requesting torn-write protection for the data range of a supported direct-I/O write.
Request geometry must obey the reported size and vector limits, with power-of-two total length and natural offset alignment. Synchronized I/O semantics are separate from this protection, and O_DIRECT alone does not supply O_SYNC guarantees. [1] [2]
The flag dates from Linux 6.11. The length must lie between stx_atomic_write_unit_min and stx_atomic_write_unit_max, so a 32 KiB write at offset 32 KiB is valid but the same write at offset 48 KiB is not. The vector count is capped by stx_atomic_write_segments_max, and buffered writes are not supported. [1]
statx reports these limits through STATX_WRITE_ATOMIC, available for block devices since Linux 6.11 and for files on ext4 and XFS since Linux 6.13. A nonzero stx_atomic_write_unit_max_opt marks the largest size that avoids slower writes. [4]
Relations
- related
- Torn write, STATX_WRITE_ATOMIC, Direct I/O, fsync, AdvFS syncv
Advantages
- After a power or hardware failure the written range holds either all old or all new data, never a mix. [1]
Limitations
- Filesystem support varies, so limits have to be queried for each file before use. [4]
- Only pwritev2 honours the flag, so ordinary write calls cannot request the protection. [1]
Citations
- Linux man-pages, readv(2): pwritev2 and RWF_ATOMIC
- Linux man-pages, open(2): O_DIRECT, O_DSYNC and O_SYNC
- Linux man-pages, statx(2): STATX_WRITE_ATOMIC and atomic write limits
Further reading
Sources & caveats
- pwritev2 is the Linux man-pages readv(2) page, reread on the access date in the RWF_ATOMIC entry.
- open is the Linux man-pages open(2) page, cited for O_DIRECT and synchronized I/O and not reread.
- statx is the Linux man-pages statx(2) page, read in the STATX_WRITE_ATOMIC mask and the stx_atomic_write_* fields.
- 6.11, 32 KiB and 48 KiB come from pwritev2. 6.11 and 6.13 come from statx.