Research notes / Write guarantees
Linux atomic writes: untorn does not mean durable
Updated / Source review and worked examples
An untorn update and a durable update answer different questions: can recovery see mixed versions, and must the new version already be persistent?
On this page14 sections
Three questions, not one guarantee
Linux RWF_ATOMIC requests protection against power loss or hardware failure leaving mixed old and new contents in the affected range. Its scope is one supported pwritev2() operation, not an arbitrary application transaction. [1]
O_DIRECT concerns the data-transfer path; it does not supply the synchronization guarantees of O_SYNC. On successful synchronized-I/O completion, O_DSYNC covers data and metadata needed to retrieve it; O_SYNC also covers other associated file metadata. Select the completion contract separately. [3]
Names add another boundary. Synchronizing file contents does not necessarily persist a changed directory entry; that requires a separate directory synchronization on Linux. A protected data range is not a durable filename replacement. [5] See the directory durability analysis.
For a database page, write down the promised recovery state before selecting flags. "No mixture" can still allow the complete previous page; "committed" must match the application's persistence and recovery protocol.
Check that the synchronization mode actually changed
On Linux, fcntl(fd, F_SETFL, flags) cannot enable or disable O_SYNC or O_DSYNC: these changes are ignored even when the call succeeds. Choose the mode with open() and inspect it with F_GETFL. [12] In Linux v6.12, setfl() preserves synchronization bits outside SETFL_MASK. [13]
For per-write synchronization on an existing descriptor, pwritev2() accepts RWF_SYNC or RWF_DSYNC, corresponding to O_SYNC or O_DSYNC for the written range. This does not change the descriptor's mode. Check returned bytes and errors; neither flag alone supplies torn-write protection or a multi-file transaction. [1] This is documented API behavior, not an additional result of the flag probe below.
A six-case native probe on Linux 6.8.0-146-generic, x86_64, observed the following. Each case opens an empty regular file with the selected initial flag, attempts a change and reads the flags back. O_APPEND supplies a mutable-flag control. No file data was written and no crash was induced.
| Attempt | Return | Flag before / after |
|---|---|---|
Set O_SYNC | 0 | Off / Off |
Clear O_SYNC | 0 | On / On |
Set O_DSYNC | 0 | Off / Off |
Clear O_DSYNC | 0 | On / On |
Set O_APPEND | 0 | Off / On |
Clear O_APPEND | 0 | On / Off |
Inspect the raw flags and environment, Python probe and regression tests. The probe checks the complete flag mask, not just any overlapping bit. These observations check configuration behavior, not whether data would survive power loss.
Per-write flags add requirements; they do not downgrade the open mode
RWF_DSYNC and RWF_SYNC, documented since Linux 4.7, request data-integrity and file-integrity completion for the range written by pwritev2(). Data-integrity completion still includes metadata needed to retrieve the bytes, such as an extended file length; file-integrity completion also includes other associated metadata. Neither is a request for torn-write protection. [1] [3]
The existing open mode remains relevant. Linux v6.12 initializes the I/O operation from the file's flags, then adds the per-call synchronization bits. Thus RWF_DSYNC on an O_SYNC file does not downgrade it to data-only completion; passing zero per-call flags does not disable an existing synchronous mode. RWF_SYNC can add file-integrity completion to an otherwise ordinary write. These are source-traced flag combinations, not measured persistence outcomes. [16]
A range-scoped completion contract is not a promise that only those bytes reach the device. The generic helper passes the completed byte interval and metadata mode to vfs_fsync_range(), which delegates to the filesystem. Do not infer a narrower physical flush or a latency reduction from the API range alone. [16] [17]
A historical example makes the cost boundary concrete. In section 4.6 of their OSDI '14 paper, Pillai and colleagues wrote to file A, then appended one byte to B and synchronized B. On their ext3-ordered setup, B waited behind A's earlier data. Their separate-partition comparison was a proxy for a proposed design, not a deployed ext3-fast filesystem. The result illustrates cross-file persistence dependencies; it does not predict modern RWF_DSYNC latency. When benchmarking a smaller synchronization range, record competing dirty data and filesystem mode as well as request size. This last point is our engineering inference. [18, section 4.6, p. 445]
Check both errors and the actual transfer count. In this generic path, a synchronization error replaces the byte-count return after writing; an error is therefore not proof that the file stayed unchanged. A short positive result does not complete the rest of the requested application record. Keep directory persistence and recovery of earlier failed writes as separate responsibilities. [16] [1] [5]
Ask the file, not the product label
Request STATX_WRITE_ATOMIC and inspect the returned stx_mask. For attributes, use stx_attributes_mask before interpreting STATX_ATTR_WRITE_ATOMIC. A requested bit is not proof of support. The reported minimum/maximum units are byte sizes; stx_atomic_write_segments_max limits the vector count. [2]
Direct-I/O memory and offset alignment are separate constraints, queryable through STATX_DIOALIGN where supported. Do not infer them from an advertised sector size alone. [3]
For the documented interface, use direct I/O, a power-of-two total length within the reported bounds, an offset divisible by that length, and no more than the reported number of vectors. [1]
A supported maximum is not an optimized maximum. stx_atomic_write_unit_max_opt, when nonzero, identifies an optimized upper size; zero means to use the supported maximum. A larger supported request is not invalid merely because it exceeds the optimized size, but may be slower. [2]
A block-aligned offset can still be wrong
These are synthetic examples, not measurements: assume a 4 KiB minimum, 64 KiB supported maximum, 16 KiB optimized maximum and one vector. The arithmetic uses bytes; 1 KiB is 1,024 bytes. "Fits" means only that these three geometry checks pass. It does not verify capability, buffer alignment, direct-I/O flags or durability.
| Length (KiB) | Offset (KiB) | Vectors | Geometry only | Within optimized size |
|---|---|---|---|---|
| 4 | 0 | 1 | Fits | Yes |
| 16 | 16 | 1 | Fits | Yes |
| 16 | 4 | 1 | offset is not a multiple of length | Not applicable |
| 12 | 12 | 1 | length is not a power of two | Not applicable |
| 128 | 0 | 1 | length outside reported limits | Not applicable |
| 16 | 0 | 2 | too many vectors | Not applicable |
| 32 | 32 | 1 | Fits | No; still supported |
| 64 | 64 | 1 | Fits | No; still supported |
The third row is the useful trap: 4 KiB alignment is insufficient for this 16 KiB request. Splitting a larger update into independently protected writes would also change the recovery contract: it would not establish one all-or-nothing update across those operations.
The filesystem is part of the contract
Ext4 documents hardware-backed atomic writes for extent-based regular files using direct I/O. Single-filesystem-block support and multi-block support are different configurations; the latter uses bigalloc and is bounded by cluster and device limits. Ext4 does not document a software or copy-on-write fallback for this feature. [4]
Mixed mapped and unwritten regions require extra preparation: the documented implementation arranges a contiguous backing extent and consistent allocation metadata before issuing the protected data write. This explains why a drive's capability alone cannot describe a filesystem operation. It is not a latency benchmark. [4]
NVMe: decode the unit before trusting the boundary
AWUN describes normal-operation atomicity relative to other reads and writes. AWUPF addresses a write interrupted by power loss or another error. Neither is a claim that an arbitrary database transaction is indivisible. The Write Atomicity Normal feature can disable the former without disabling power-fail atomicity. [14, sections 2.1.4 and 4.1.3.4]
Controller unit fields encode a logical-block count minus one. Namespace overrides require NSFEAT bit 1 support: nonzero NAWUN or NAWUPF supplies a namespace value, while zero inherits the corresponding controller field. Do not decode that namespace zero as a one-block override. Convert blocks using the namespace's selected LBA format, not a presumed sector size. Formatting may change namespace parameters. [15] [14, section 2.1.4.1]
| NSFEAT bit 1 | Raw AWUPF | Raw NAWUPF | LBA data bytes | Unit in blocks | Unit data bytes |
|---|---|---|---|---|---|
| 1 | 7 | 0 | 512 | 8 | 4096 |
| 1 | 7 | 0 | 4096 | 8 | 32768 |
| 0 | 0 | 7 (ignored) | 4096 | 1 | 4096 |
| 1 | 0 | 7 | 4096 | 8 | 32768 |
These examples decode size only: select a supported, nonzero namespace field or fall back to the controller field, add one, then multiply by LBA data bytes. The conversion excludes separate metadata. Boundary and mode constraints still apply; the result is neither a Linux file capability nor a durable-commit size. [15]
Atomic boundaries add address constraints. NABSN and NABSPF describe normal and power-fail boundaries; NABO specifies the first boundary's LBA offset. Zero boundary size means no corresponding boundary, unlike the namespace unit's zero fallback. In Single Atomicity Mode, crossing a boundary can remove the larger namespace guarantee. Crucially, the controller AWUN/AWUPF baseline must remain supported across those boundaries. [14, section 2.1.4.4] [15]
Multiple Atomicity Mode protects each resulting LBA subrange separately; a command spanning them is not one all-or-nothing transaction. Atomicity also does not settle persistence: section 2.1.4.3.2 describes when acknowledged data still in volatile cache may be lost. Write FUA requires its data and metadata to reach nonvolatile media before completion but does not order other commands. [14, sections 2.1.4.3.2, 2.1.4.5 and 3.3.6]
Engineering synthesis: preserve the controller and namespace Identify responses, formatted LBA size and atomicity mode together. Then query the actual Linux file's capabilities and choose its synchronization contract separately. This section reviews NVM Command Set 1.3; it does not validate a device, exercise a power cut or extend the synthetic Linux geometry model above into an NVMe conformance test.
TxFlash: commit evidence survives beyond the write
TxFlash moves an isolated, durable write-set transaction into a research SSD interface. Its cyclic commit stores links between page versions. Reclamation can break a committed cycle, so recovery must distinguish reclaimed versions from incomplete transactions. This is a protocol requirement, not evidence of a TxFlash defect. [19, sections 2-3]
The contrast is about the operation being protected. The earlier TFFS design supports reads, writes and file operations inside explicit transactions on reprogrammable NOR flash. It uses logical pointers, versioned trees and a transaction log. Its memory-saving choice to avoid write buffering and its non-POSIX API belong to that embedded-system design. [20, sections 1, 3-4]
| Interface | Protected operation | Important boundary |
|---|---|---|
| Linux RWF_ATOMIC | One supported write range | Synchronization is separate. [1] |
| TxFlash WriteAtomic | A declared set of page writes | Application reads are outside the transaction. [19] |
| TFFS | Explicit filesystem transaction | NOR assumptions and API differ from Linux. [20] |
Engineering implication: do not substitute one interface merely because both descriptions say "atomic." Match the write set, read dependencies, acknowledgement and recovery rules. These historical designs are source comparisons, not newly reproduced experiments or a claim of current hardware support.
A different contract: AdvFS at FAST '15
Verma and colleagues described an O_ATOMIC interface in AdvFS, using hidden writable clones and copy-on-write to preserve a synchronized file version. Their syncv mechanism grouped multiple files by journaling clone-deletion metadata. This is a filesystem recovery protocol, not another name for Linux RWF_ATOMIC. [6, sections 3 and 3.1]
The paper explicitly excludes overlapping or concurrent modifications through multiple file descriptors from its guarantee. Its implementation and failure-injection results are historical evidence, not a test of today's Linux atomic-write interface or proof of current AdvFS availability. We did not reproduce those experiments. [6]
Our synthesis: identify the protected range, commit boundary and concurrency rules separately. Individually untorn pages do not make a multi-page update failure-atomic. Compare WAL and page recovery and the crash-test oracle before replacing an existing recovery mechanism.
How many files fit in one atomic commit?
The FAST '15 AdvFS syncv design avoids journaling application data, but still journals clone-deletion metadata. Its worst-case file count depends on that metadata budget, not just free data space. [6, section 3.1, p. 207]
(128 × 1024 × 1024 / 4) / (128 × 1024) = 256 files: a 128 MiB journal, one-quarter transaction budget, and 128 KiB per clone deletion. The paper labels these MB/KB but uses binary factors. This reproduces its arithmetic, not a measured universal ceiling.
More files via delayed deletion were a proposed improvement, not an evaluated result. The correctness tests also assumed synchronous persistence and atomic 512-byte sectors. [6, sections 3.1 and 4.1]
Inspect the inputs and calculation. A storage-engine review should distinguish data volume, metadata capacity, request geometry and concurrency rules.
A fourth question: what about bytes outside the write?
SQLite calls this powersafe overwrite (PSOW): an interrupted file write must not change bytes outside the requested range. It imposes no old-or-new rule inside that range. A torn update can therefore coexist with PSOW; neither property establishes durable commit. [7]
SQLite exposes distinct VFS flags for this distinction. SQLITE_IOCAP_ATOMICnnn describes aligned writes of a specified size; SQLITE_IOCAP_SAFE_APPEND concerns appended data reaching storage before the enlarged file size; SQLITE_IOCAP_SEQUENTIAL concerns write ordering. None is merely a synonym for SQLITE_IOCAP_POWERSAFE_OVERWRITE. [8]
The constructed file below begins as ab1234yz. One overwrite requests WXYZ at byte offset 2, replacing offsets 2 through 5. All characters are one ASCII byte. The two checks describe each supplied recovery state, not a guarantee inferred from testing a device.
| Recovered file | Old or new? | Outside intact? |
|---|---|---|
ab1234yz | Yes | Yes |
abWXYZyz | Yes | Yes |
abWX34yz | No | Yes |
qbWXYZyz | Yes | No |
qbWX34yz | No | No |
The first row passes both checks without preserving the new value. The third fails the in-range check but preserves its neighbors. The fourth has a complete new target range while damaging a neighbor. These are logical counterexamples to conflating the questions, not claims that Linux permits such collateral damage.
Reproduce the table with the byte-state evaluator and Node tests; the machine-readable examples include a source-code hash. Run node --test powersafe-overwrite.test.mjs with both source files in the same directory. The model excludes appends, truncation, concurrency, metadata, media errors and acknowledgement timing.
A SQLite setting is an assumption, not a power-cut test
The historical PSOW discussion explains why protecting an entire sector can add journal work when only a smaller database page changes. Default SQLite configurations still do not assume atomic database-page writes merely because PSOW is enabled. Recovery and synchronization remain separate responsibilities. [7]
A URI such as file:example.db?psow=0 asks the standard Unix or Windows VFS not to assume PSOW. URI handling must be enabled for the connection; a custom VFS may ignore this parameter. This does not change controller firmware, demonstrate hardware behavior or compensate for a broken persistence stack. [9]
The SQLITE_FCNTL_POWERSAFE_OVERWRITE file-control operation can query or change the reported setting. Treat that answer as configured behavior, not a measured property of the disk. Before changing an application, record its SQLite build, selected VFS, journal mode and synchronization configuration. [10]
Zheng and colleagues' FAST 2013 study used raw-device workloads and hardware power cuts. Section 5.3 reports shorn writes on three tested SSDs; Table 5 says flying writes were not observed. These categories must not be silently relabelled as SQLite PSOW failures: a partial update inside a requested range does not establish corruption outside it. The paper is historical device evidence, not a SQLite conformance test or a current fleet failure rate. [11]
Our engineering inference: a crash-test oracle should examine both the target and known-unchanged surrounding data, then independently assess the commit protocol. A passing finite test cannot establish a universal storage guarantee. No power interruption or SQLite workload was run for these examples.
A review checklist before changing a storage engine
- Record the actual kernel, filesystem, mount configuration and storage stack. Query the intended file and preserve the returned capability masks and limits.
- Validate request and buffer constraints, then check the operation's actual return value. Do not silently substitute an ordinary write when protection is required.
- Choose and check the required synchronization boundary before acknowledging a durable application commit.
- Define a recovery oracle for an isolated test environment, including failures before acknowledgement and dependencies between records. Geometry tests cannot replace crash testing.
This checklist is Hesela's engineering synthesis, not a certified implementation. No hardware interruption or performance measurement was performed; the flag probe above does not exercise file-data persistence. The model deliberately excludes device behavior, mapping changes, overlapping writers, metadata transactions and persistence. Support must be established on the deployed stack.
Corpus: torn write, RWF_ATOMIC, STATX_WRITE_ATOMIC. Related: failed synchronization and RAID write-hole protection.
Primary sources
- Linux man-pages, readv(2): pwritev2 and RWF_ATOMIC.
- Linux man-pages, statx(2): atomic-write fields and returned masks.
- Linux man-pages, open(2): O_DIRECT, O_DSYNC and O_SYNC.
- Linux kernel documentation: ext4 Atomic Block Writes, requirements and implementation.
- Linux man-pages, fsync(2): file synchronization and directory entries.
- Verma et al. (2015), Failure-Atomic Updates of Application Data in a Linux File System. FAST 15, pp. 203-211; sections 3-4.
- SQLite: Powersafe Overwrite, scope, assumptions and torn pages.
- SQLite C interface: Device Characteristics.
- SQLite: URI filenames, enabling URI handling and psow overrides.
- SQLite C interface: SQLITE_FCNTL_POWERSAFE_OVERWRITE.
- Zheng, Tucek, Qin and Lillibridge (2013). Understanding the Robustness of SSDs under Power Fault. FAST 13, pp. 271-284; section 4.2, Table 5 and section 5.3.
- Linux man-pages 6.19: F_GETFL and F_SETFL, unchanged synchronization flags.
- Linux v6.12: fs/fcntl.c, SETFL_MASK and setfl().
- NVM Express NVM Command Set 1.3 (2026): sections 2.1.4, 3.3.6 and 4.1.3.4; Figures 123 and 126. Copyright 2008-2026 NVM Express, Inc. All rights reserved.
- Microsoft: NVME_IDENTIFY_NAMESPACE_DATA, namespace atomic unit and boundary encodings
- Linux v6.12: init_sync_kiocb, iocb_flags, kiocb_set_rw_flags and generic_write_sync
- Linux v6.12: vfs_fsync_range delegates range and metadata requirements to the filesystem
- Pillai et al., OSDI 2014: All File Systems Are Not Created Equal, section 4.6 (p. 445)
- Prabhakaran, Rodeheffer and Zhou (2008), Transactional Flash. OSDI 08, sections 2-5.
- Gal and Toledo (2005), A Transactional Flash File System for Microcontrollers. USENIX ATC, sections 1, 3 and 4.
Linux API review: 12 October 2026. PSOW extension: 14 October 2026. AdvFS journal-budget review: 20 October 2026. Synchronous-flag review and probe: 5 November 2026. Documentation describes an interface, not proof of support on every Linux installation.