STATX_WRITE_ATOMIC
STATX_WRITE_ATOMIC is a Linux statx request for a file's reported atomic-write size limits and maximum vector count.
Requesting STATX_WRITE_ATOMIC asks statx for stx_atomic_write_unit_min, stx_atomic_write_unit_max, stx_atomic_write_segments_max and stx_atomic_write_unit_max_opt. The returned mask must be checked before the fields are read, because a requested capability is not necessarily supported. The minimum and maximum are sizes in bytes for direct I/O with torn-write protection, each a power of 2. Block devices support the query since Linux 6.11, while support on regular files varies by filesystem. [1]
The limits govern a later pwritev2 call with RWF_ATOMIC. Its total length must be a power of 2 within the reported range and its offset naturally aligned to that length, so a 32 KiB write at offset 32 KiB is permitted but one at 48 KiB is not, and the vector count must not exceed stx_atomic_write_segments_max. [4] A nonzero stx_atomic_write_unit_max_opt is an optimized size limit, not the validity ceiling, and zero means stx_atomic_write_unit_max is the optimized limit. [1] Direct-I/O buffer alignment is a separate query.
Relations
- related
- RWF_ATOMIC, Torn write, Direct I/O, Direct-I/O alignment
Advantages
- Reading the limits first lets an application size and align atomic writes before issuing them instead of discovering EINVAL afterwards. [4]
Limitations
- A filesystem without a software fallback reports usable limits only when the device supports hardware atomic writes, so drive-level limits do not establish the capability of a file. [5]
- Torn-write protection applies only to the data range written by the call. [4]
- Writes larger than a nonzero optimized limit may be slower. [1]
Citations
- Linux man-pages 6.19, statx(2): atomic-write fields and returned masks
- Linux man-pages 6.19, readv(2): pwritev2 and RWF_ATOMIC length, alignment and vector rules
- Linux kernel documentation, ext4 data structures and algorithms, section 2.10: Atomic Block Writes
Further reading
- Linux man-pages, open(2): O_DIRECT, O_DSYNC and O_SYNC
- Linux atomic writes: untorn does not mean durable
Sources & caveats
- statx is the Linux man-pages 6.19 statx(2) page, re-read for the requested fields, the returned mask, the units and the kernel versions.
- readv is the Linux man-pages 6.19 readv(2) page, read for the RWF_ATOMIC length, alignment and vector-count rules and the EINVAL cases.
- ext4aw is the Linux kernel documentation on ext4 atomic block writes, read for the dependence on hardware atomic-write support.
- The pwrite entry links here because the reported limits decide which positioned atomic writes are valid.