Skip to content

Research notes / Persistence

Why retrying a failed fsync does not prove durability

Published · Updated · Historical evidence, current documentation, explicit model

An error report and a repair are different events. After a failed writeback, a successful retry of fsync() is not, by itself, proof that the earlier data reached persistent storage.

The counterexample: clean does not mean durable

Rebello and colleagues injected single transient sector or block write faults into ext4, XFS and Btrfs on Linux 5.2.11. Their two micro-workloads exercised an overwrite and repeated appends. Failed writeback could leave pages marked clean; another sync then had nothing to write. The study also used CuttleFS to test five applications: Redis 5.0.7, LMDB 0.9.24, LevelDB 1.22, SQLite 3.30.1 and PostgreSQL 12.0. These are historical configurations, not a verdict on current releases. [1, sections 3-4]

The distinction matters during incident response: an apparently correct read can come from memory. A process restart is not necessarily a cold read from storage, because the operating-system cache can outlive that process. Testing the same value twice through the same cached path is weak evidence of persistence. [1, sections 4-5]

Why a process restart is not a cold read

The ATC 2020 study varied two factors separately: application restart and CuttleFS clean-page eviction. Single-key inserts or updates received a targeted data-write fault. This table restates that protocol, not the paper's per-application outcomes. [1, sections 4.1-4.3]

Two independent experimental controls; four observation contexts.
ApplicationClean cache pagesObservation boundary
ContinuesRetainedBoth application state and cached bytes can remain available.
RestartsRetainedRebuilding application state can still read cached bytes.
ContinuesEvictedReads may expose underlying bytes without restarting the process.
RestartsEvictedReconstruction also encounters the changed cache state.

Fault visibility depended on context. A reported application failure could precede reading the updated value later: a false failure. Do not equate an error response with a completed rollback. These were targeted tests of historical versions, not incident-frequency estimates or a complete device power-loss model. Hesela has not rerun this fault-injection study. [1, sections 4.2-4.3]

Check the FUSE daemon's synchronization contract

A different success path exists in Linux v6.12 FUSE: an ENOSYS reply to FUSE_FSYNC is accepted and disables later daemon FSYNC requests on the connection. Earlier writeback checks remain. This is not a retry-repair result. The version-pinned FUSE review traces the kernel and libfuse dispatch and explains what to verify in the backend. [36]

Four cases you can reproduce

This is a small, deterministic illustrative model, not measured filesystem behavior. Every case starts with old data on storage and new data in cache. One writeback fails. The first sync reports the error; subsequent I/O is assumed fault-free. The model varies dirty-state retention, clean-page eviction and an explicit rewrite from an independent good copy.

Model outputs: the retry succeeds in every row, but the persisted value differs.
Assumption after failureRetryCached readRead after cache loss
Clean page retained; retrysuccessnewold
Clean page evicted; retrysuccessoldold
Dirty page retained; retrysuccessnewnew
Clean page; rewrite then syncsuccessnewnew

The final two rows are sensitivity checks, not recovery recipes. A real rewrite may fail again, omit part of a transaction or overwrite the wrong state. This model has no directories, partial writes, metadata, concurrent writers or device caches. No probability or field failure rate can be inferred from four deliberately chosen cases.

Run the dependency-free JavaScript model with Node.js. It prints the machine-readable assumptions and event traces. Its four regression tests check the stale-data case, eviction, changed assumptions and determinism.

The less obvious part: an error cursor is not a repair log

Linux's generic writeback-error infrastructure can report a failure to open file descriptions for the affected file that were present when it occurred. In the sequential, non-wrapping case, a later check can return zero after reporting an error; concurrent reporting needs the separate check below. Attribution is deliberately coarse: a descriptor can receive an error even if its own writes succeeded. [3]

The underlying errseq_t mechanism combines an error value with sequence tracking. Observers keep a cursor and check what changed since their previous observation. It is not a count of all failures and does not identify every damaged byte. Advancing the cursor records that an error was observed; it does not rewrite anything. [4]

What an error cursor leaves out

In Linux v6.12, errseq_set() replaces the saved errno; its counter advances only after the state was marked seen. Repeated, unseen reports can therefore coalesce. A non-consuming errseq_check() does not set that flag. These are helper semantics, not a count of failed writes. [15] [4]

The pinned format uses 12 errno bits, one seen bit and 19 counter bits: 524,288 counter positions. A collision requires the full value, including errno and seen state, to match; raw failure count alone does not determine it. [22] [15]

Hesela model outputs. Negative numbers are internal errno values, not the userspace fsync return convention.
SequenceObservationInformation absent
Record EIO ten times, then consume-5; next check 0The ten recordings are not ten queued reports.
Record EIO, then ENOSPC before observation-28 (ENOSPC)The earlier EIO is overwritten.
Check one EIO twice without advancing-5; then -5Two observations do not establish two faults.
Keep observer A idle; B consumes every EIO for one counter cycleA: 0; B: 524,288 error reportsA's saved value aliases the final value.

In the last case both observers first consume an initial EIO. B then consumes each of 524,288 further EIO recordings; A waits. A would detect a change one step before wrap, but not after B marks the final state seen. This is an exact sequential counterexample, not a measured incident frequency or a promise that every filesystem returns zero.

Run the dependency-free model through buildObservation(); the JSON result records parameters and the script hash. It executes no kernel code or I/O and omits races. Retain observed errors in an application incident record; polling more often cannot turn this cursor into a complete audit log. See also generation counters and observation bounds.

A later error can disappear without counter wrap

Our controlled replay returns zero to observer A even though a second EIO was recorded after A's previous call returned. None of the counter bits changes. This is a different boundary from the 524,288-position wraparound example above.

Shashank Mohan Jain reported this interleaving on LKML in September 2026. It is not a Hesela discovery. The v6.12 helper advances the observer's cursor even when its attempt to mark the shared value seen fails. Our replay compiles the unmodified, hash-pinned C file with a small userspace compatibility layer. A deterministic hook substitutes one competing update at that compare-and-swap boundary. [LKML report] [pinned source]

  1. Record EIO. A begins checking and reads state 5.
  2. Before A marks it seen, the hook records ENOSPC: shared state becomes 28. A's swap fails, but A saves cursor 4101 and returns -5.
  3. After A returns, record EIO again. The still-unseen state becomes 5.
  4. B checks using its distinct cursor and marks state 4101 seen.
  5. A checks again. Its saved 4101 equals the shared 4101, so it returns 0.

Here 4096 is the seen bit; -5 and -28 are internal helper error values, not the userspace fsync() return convention. There is no shared-cursor data race. The compatibility layer orders the operations; this is not a running-kernel concurrency measurement.

Four selected schedules. Both compiler configurations (-O0 and -O2, with UBSan) produced these same final A results.
ScheduleNext A check
Competing ENOSPC; then B observes0
No competing update-5
Competing ENOSPC; no B observation-5
Competing EIO instead of ENOSPC-5

The three controls remove one condition and retain the later report. They do not establish a probability, exhaust all interleavings, test weak memory or prove a fix. The ATC 2020 paper's storage-fault and cache-recovery experiments are separate evidence, not measurements of this schedule. [1]

Download the complete replay package or inspect its exact traces and hashes and method. Run python3 run.py and python3 -m unittest -v test_replay.py inside the extracted directory. No packages or privileges are required.

Operationally, retain observed failures independently and verify the implementation actually deployed. Neither a private cursor nor this replay certifies recovery, and no current mainline, stable-backport or distribution-wide status is claimed here.

Two descriptors are not necessarily two error observers

An open file description is the kernel object behind a descriptor number. A separate open() creates a new one; dup() and descriptors inherited through fork() share the existing one. The shared object carries the file offset and status flags, but descriptor flags such as close-on-exec are separate. [11] [12]

In Linux v6.12's generic path, the writeback-error cursor is struct file.f_wb_err. The reporting helper advances that field under the file's lock. Our source-code inference: aliases of the same open file description share this observation state; a different descriptor number does not create another independent error cursor. This is a source review, not a new fault-injection result. [13]

  • Separate opens before the failure: one observer reporting an error does not advance the other's private cursor.
  • Duplicated or inherited descriptors: reporting through one alias can consume the shared pending report; the other is not guaranteed a second report of that same event.
  • Reopen after observation: a new open samples the current state. An already-seen historical error need not be reported again.
  • Reopen before observation: an error that remains unseen can still reach the new observer. Reopening does not invariably suppress old errors. [14] [15]

These cases assume the generic error-tracking path and no additional failure. They do not predict every filesystem's full fsync() return value. Record which operation first observed the error and whether descriptors were duplicated, inherited or reopened. A new descriptor, a cleared report and repaired data are three different facts.

Closing a descriptor is not a durability acknowledgement

A successful close() releases a file descriptor; it does not replace fsync(). Check close errors too: a delayed failure of an earlier write may first become visible there. Keep that error in the recovery decision, even if an earlier write returned a positive byte count. [19]

Linux-specific retry rule: do not retry close() on the saved descriptor number after an error, including EINTR. The v6.12 syscall removes the descriptor before later flush processing; its restart handling explicitly accounts for the cleared entry. An unrelated open can already have reused that number. EBADF instead means the descriptor was invalid. The source review establishes release order, not a measured rate of close failures. [21]

Portability boundary: POSIX.1-2024 requires the descriptor to remain open when EINTR is returned, where that error is permitted; EINPROGRESS means it is closed while completion continues asynchronously. POSIX also leaves it unspecified whether that retained descriptor can be used without error for anything except close() or posix_close(); open does not mean normally usable. Linux does not follow that EINTR contract. Earlier POSIX editions left the descriptor state unspecified. Select error handling for the actual platform, not a universal retry loop. [20] [19]

Closing a descriptor is also not a general cross-thread cancellation primitive: on Linux, a blocking I/O call may retain its open-file-description reference and complete after another thread closes the number. Descriptor ownership and I/O lifetime need coordination. [19]

On Linux, a successful dup2() with distinct source and target numbers atomically replaces the target; a separate close followed by dup leaves an allocation race. A valid dup2(fd, fd) instead does nothing, retaining the descriptor flags. An invalid source fails without closing the target. The replacement guarantee concerns the descriptor table, not durable bytes, and errors from the implicit target close are not reported by dup2. [12]

Reproduce descriptor lifetime without injecting a storage fault

The following are actual API observations, separate from the illustrative fsync model above. A C program uses two private temporary files in a single-threaded sequence; the Python runner starts a fresh process and directory for each of 5 repetitions. The recorded host ran Linux 6.8.0-146-generic with cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0. The compiler treated warnings as errors.

Seven ordered cases per repetition; all 35 case checks passed. Repetitions are repeatability checks, not independent statistical samples.
OperationObserved first repetitionInterpretation
Close the original descriptorDuplicate reads ABThe duplicate keeps its reference.
Open a different fileReleased fd 3 becomes replacement fd 3; reads uvSame number, different file identity.
Close the saved old number againReplacement read: -1 / EBADF; duplicate reads CDThe stale integer now closes the replacement.
Replace a target with dup2Target reads EF; source offset advances to 6Replacement shares the offset but clears target close-on-exec.
Duplicate a valid fd onto itselfReturns fd 3; offset stays 2; close-on-exec retainedA valid self-dup is a no-op.
Use -1 as the dup2 sourceReturns -1 / EBADF; target offset stays 2The invalid source leaves the target open.
Close descriptor -1Returns -1 / EBADFInvalid-descriptor error, not a failed storage flush.

The stale-number case deliberately calls close again after a successful close and reuse, not after an injected close error. Its EBADF comes from reading the now-closed replacement, not from close. All valid-descriptor close calls succeeded; the separate close(-1) case returned the expected EBADF. The dup2 case observes replacement and shared offsets; the API's atomicity guarantee comes from documentation, not a timing experiment. No signal interruption, concurrent allocation race, I/O failure, crash, fsync or power loss was tested.

The replacement case first enables FD_CLOEXEC on both distinct descriptors. After successful dup2(), the target flag is clear, while the source flag remains set. The target shares the source file offset, but does not inherit its close-on-exec flag. This flag controls descriptor closure on successful program execution, not disk persistence; no exec was performed. [12]

The two additional dup2 checks compare file identity, offset and an explicitly enabled FD_CLOEXEC flag before and after the call. A successful self-dup preserved all three, as did the invalid-source failure. These observed edge cases are not tests of silent close errors, race freedom or durable commit. [12]

Inspect the C harness, Python runner and raw observations with source SHA-256 hashes. Place both source files together and run python3 run-descriptor-lifetime.py --repeats 5 on Linux with a C compiler. The runner cleans up its temporary directory and emits environment metadata, return values, bytes, offsets and limitations as JSON. No storage device or privileged configuration is changed.

Descriptor inheritance across program replacement

Close-on-exec controls one descriptor's lifetime, not the shared open file description. fork() retains the reference. A successful execve() closes descriptors with FD_CLOEXEC set; an ordinary failure returning to the caller leaves them open. An unmarked duplicate can survive, with the same offset and access to the file. [Descriptor flags] [Fork]

Use open(..., O_CLOEXEC) when creating a descriptor that must not cross exec. A later fcntl(F_SETFD) leaves an inheritance window if another thread forks and execs between the two calls. Raw Linux dup() clears the new descriptor's flag; dup3(oldfd, newfd, O_CLOEXEC) sets it on a distinct target. Language wrappers can choose different defaults. [11] [12]

The returned-failure qualification matters: Linux documents rare execve() failures after the old program image has already been torn down. These can terminate the process instead of returning to the caller. The missing-executable test below exercises returned ENOENT, not that later failure path. [Exec failure boundary]

Separate 5 November Linux API observation; 3 fresh-process repetitions, identical outcomes.
BoundaryObserved result
Fork, before execAll three tracked descriptors remain open.
Exec of a missing executableENOENT; all three tracked descriptors remain open.
Successful exec of the probeTwo marked references close; the unmarked alias reads HESELA42.
Parent after child exitParent references remain open. Shared offset: 8 bytes.

The single-threaded C probe ran on Linux 6.8.0-146-generic, glibc 2.39, with cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0. It checks descriptor flags, surviving file identity and eight exact bytes. High-numbered, owned descriptors reduce startup descriptor-reuse ambiguity; a forced exec failure and missing-survivor controls must fail. This checks API behavior, not the multithreaded race, crash recovery or isolation against hostile code. Automatic closure does not flush user-space buffers or establish durability.

Reproduce with the C probe and test runner in one directory: python3 -B test_probe.py. The recorded checks, environment and source hashes accompany the example. The temporary files contain only generated test bytes.

A file mapping is a different reference again: see the mapped-file observations for an existing mapping that survives descriptor closure. Neither demonstration establishes persistent storage state.

A second boundary: a consistent filesystem is not a committed application

Pillai and colleagues separated persistence ordering from atomicity. Their BOB tool examined six Linux filesystems; ALICE analyzed update protocols in eleven applications and found 60 static crash vulnerabilities. ALICE explored states permitted by abstract persistence models, so that count is neither an incident rate nor 60 bugs guaranteed to appear on every filesystem. [2, sections 2-4]

SQLite makes the ordering issue concrete: its rollback-journal protocol persists recovery information before modifying the database. Its documentation also describes syncing the directory containing a super-journal. Durable file content and a durable name are distinct requirements. Those details belong to the application's commit protocol, not to an SSD health counter. [5, sections 3 and 5]

For network-server and device-cache boundaries, see NFS stable writes, COMMIT, flush and FUA.

For the separate name-persistence boundary, see why atomic rename is not a durable commit.

The user-space buffer comes before fsync

A successful stream write can precede submission to the kernel. For a descriptor-backed output stream, fflush() passes pending library output to its underlying write function. fsync(fileno(stream)) addresses the file below that buffer; calling it first cannot synchronize bytes still held by stdio. [23] [7]

Check every intended write, then the flush and file-sync results, while preventing concurrent output from changing the intended boundary. Preserve the first failure instead of replacing it with a later success. This ordering does not provide multi-file atomicity or persist a newly created directory entry. [7] [2]

fclose() flushes and closes a stream; its result also needs checking. It does not add fsync semantics. After it returns, even on failure, the FILE * must not be used again. ferror() reports a stream indicator; clearerr() clears indicators, not failed output. [24] [28]

fwrite() returns complete items, not bytes unless the item size is one. Comparing that result with a byte length can misclassify a successful write. The experiment below includes a separate unbuffered item-count control. [25]

Four API cases repeated 5 times: 20/20 checks passed. The first case is split into two rows.
OperationObserved first repetitionBoundary
Buffered fputc, then fsyncfsync: 0; file size: 0 bytesSuccessful file sync did not submit the library buffer.
fflush the same regular filefflush: 0; size: 1 byte; read: AThe byte became visible; this read is not a power-loss test.
/dev/full, then fflushfputc accepted B; fflush: ENOSPCThe stream error indicator became set; cleanup close returned 0.
Fresh /dev/full, then fclosefputc accepted B; fclose: ENOSPCClosing the stream exposed an output failure.
Unbuffered fwrite, size 4, count 3Return: 3 items; file size: 12 bytesThe return unit is an item, not a byte.

Method: a C harness ran in 5 fresh processes on Linux 6.8.0-146-generic, glibc 2.39. It configured a 4096-byte fully buffered stream before any stream I/O, used a private temporary file and checked file size before and after flushing. The post-flush read verified the byte A; the item-count control verified all twelve payload bytes. File-sync and regular-file close calls succeeded. The supplied buffers remained alive until closure. Exact deferral timing is an observation of this configuration, not a universal buffering guarantee. [26]

Limits: /dev/full rejects writes with ENOSPC. This tests controlled output rejection, not a full filesystem, delayed writeback, an errseq error or a storage-device fault. The cleanup close returned zero after the failed explicit flush in this run; that does not undo the recorded failure. No power loss, crash recovery, partial-item failure or concurrent writer was tested. Repetition is a repeatability check, not a failure-rate estimate; file size and readable bytes establish visibility, not physical persistence. [27]

Reproduce on Linux with a C compiler: place the C harness beside the Python runner and run python3 run-stdio-boundary.py --repeats 5. The raw observations record return values, source hashes, compiler, libc, kernel and filesystem type. The runner removes its private files and does not change device configuration.

A full fwrite count can coexist with a stream error

Checking only the item count misses another boundary. In our glibc 2.39 line-buffered test, fwrite() returned both requested items while ferror() became nonzero and the immediately captured errno was ENOSPC. The following fflush() returned zero without clearing that indicator. This is a measured library behavior, not proof of successful output.

The pinned glibc implementation explains the path: a newline can trigger a buffer flush inside _IO_new_file_xsputn(). When that flush fails after all input was copied, the helper can return EOF; _IO_fwrite() converts that internal result to the requested item count. The failed underlying write sets the stream error flag. This source trace explains the observed result; it is not a claim about all libc implementations. [29] [30]

Three fresh-stream cases in 5 fresh processes: 15/15 observations matched the recorded behavior. ferror is normalized to 0 or 1.
Buffering modefwrite items returned / requestedferror after fwriteNext fflush resultferror after fflush
line-buffered2 / 2101
fully-buffered2 / 20-1 (ENOSPC)1
unbuffered0 / 2101

Method and scope: Linux 6.8.0-146-generic, glibc 2.39; a new /dev/full stream for each mode, configured before I/O. Both buffered cases first accepted A without an error, then attempted B plus newline as two one-byte items. The unbuffered control omitted the seed. The supplied buffer was 4096 bytes; that is not an active buffer-size claim for unbuffered mode. We captured errno immediately after each measured call, then checked the indicator. errno alone is not a success test. All three later indicators became zero after clearerr(), which clears state without repairing output. [28]

Engineering consequence: inspect both the count and stream error status, preserve any failure, and check later flush and close results separately. A full count is not a substitute for the indicator; a later zero does not erase an earlier failure. No filesystem exhaustion, device failure, crash, concurrent writer or durability guarantee was tested. These are repeatability checks, not statistical samples of failure frequency.

This is also not a reproduction of the ATC 2020 paper: its filesystem study targets faults after synchronization begins, whereas this test uses immediate write rejection at a character device. The mechanisms belong to different layers. [1, section 3.2] [27]

Download the C probe, Python runner and raw JSON with environment and source hashes. Run python3 run-fwrite-error-indicator.py --repeats 5 with both source files together. The expected-result check describes this configuration, not a universal libc conformance rule.

The same probe, a different libc result

The full-count observation is not universal. We compiled the unchanged C probe for dynamic glibc 2.39, static glibc 2.39 and source-built static musl 1.2.5 on the same Linux host. In the seeded line-buffered case, both glibc builds returned two of two items; musl returned zero of two. All three set the stream error indicator. The static glibc control retained the original result, so static linking alone does not explain this difference in the tested configurations.

Line-buffered results from the first repetition. All three modes repeated consistently: 45 observations across three build arms and five fresh processes per arm.
Library and linkageReturned / requested itemsferror after fwriteNext fflushferror after fflush
glibc 2.39, dynamic2 / 2101
glibc 2.39, static2 / 2101
musl 1.2.5, static0 / 2101

What changed in the implementation: musl 1.2.5 sends the newline-containing prefix through its write helper and propagates a short result. On the immediate failing writev path, __stdio_write() sets F_ERR, clears pending-write pointers and returns zero. The later fflush() sees no pending output in that state and can return zero without clearing the error. This source trace explains the measured sequence; it is not proof that output was repaired. [31] [32] [33]

The other modes agreed across arms: full buffering accepted both items without an immediate error, then flush failed with ENOSPC; unbuffered output returned zero items with an error. The seed, payload, supplied buffer and call sequence were identical to the earlier probe. Five repetitions check repeatability, not incident probability. These pinned releases are comparison points, not a survey of latest versions or a libc conformance verdict.

Reading the indicators: the tables and JSON encode ferror(stream) != 0 as 0 or 1. A one means the stream error indicator is set, not that ferror() returned an error number. In every recorded mode, clearerr() subsequently cleared that indicator. This reset did not repair the failed output or change the rejecting sink. See the separate corpus records for ferror and clearerr.

Practical consequence: changing libc can move where a write failure becomes visible. Test the application's real error path on its deployed runtime, retain failures independently of later return values, and do not treat a successful later flush as a replay or repair of failed output. Neither this comparison nor its zero-returning flushes establish storage durability.

Download the comparison runner and raw observations and provenance; reuse the unchanged C probe. With the upstream musl 1.2.5 archive beside them, run python3 run-fwrite-cross-libc.py --musl-archive musl-1.2.5.tar.gz --repeats 5. The runner checks its pinned archive and probe hashes, builds in a private temporary directory, verifies linkage and records all return values. It requires Linux, Python 3.12+, GCC with static glibc development files, make and readelf; it performs no system installation or storage fault injection.

Similar names, different completion guarantees

For asynchronous request dependencies, see io_uring completion, ordering and durable acknowledgment.

Before interpreting a return value, identify the operation. These are documented Linux API boundaries, not new power-loss measurements.

Configuration is another boundary: the F2FS checkpoint audit shows why successful regular-file fsync with checkpointing disabled is not an ordinary recovery promise. That is separate from the failed-writeback cases above.

File and mapped-range synchronization: what completion does and does not cover.
OperationDocumented scopeImportant boundary
fdatasync()Modified data plus metadata needed to retrieve it, including file-size changes.May omit timestamp-only updates; does not establish directory-entry persistence. [7]
msync(MS_SYNC)Requests synchronization of a shared file-backed mapping range and waits.Does not persist MAP_PRIVATE modifications; is not an application transaction. [8] [9]
sync_file_range()Starts or waits for page-cache writeback over a file range.Does not synchronize metadata or flush volatile device write caches, even with all three wait/write flags. [10]

MS_ASYNC has been a no-op on Linux since 2.6.19: dirty pages are already tracked for writeback. It is not a durability acknowledgement. The starting address for msync() must be page-aligned; portable callers select exactly one of MS_SYNC and MS_ASYNC. Do not confuse MS_SYNC with the separate DAX-oriented MAP_SYNC mapping flag. [8] [9]

For sync_file_range(), waiting before and after writeback does not add the missing metadata and device-cache operations. Preallocation does not remove all allocation-metadata requirements, and copy-on-write overwrites need not reuse existing blocks. It is not a general substitute for fdatasync() or fsync(). [10]

These interfaces expose completion reports, not independent hardware verification. None makes a multi-file application update atomically durable; the commit protocol and error handling still matter. [7]

A range wait is not a range error report

Latency boundary: omitting the wait flags does not promise a nonblocking call. SYNC_FILE_RANGE_WRITE can block when request-queue resources are exhausted. It starts writeback for dirty pages not already under writeback; returning from submission is different from waiting for completion. Do not interpret the API's asynchronous description as a bound on caller latency or as a durability acknowledgment. [10] [17]

Range selection: the byte interval expands to the pages it touches. With a hypothetical 4096-byte page size, offset=4095, nbytes=2 selects pages 0 and 1, not two isolated bytes. This is page-selection arithmetic, not a measurement of physical device I/O. [10]

nbytes=0 means from the supplied offset to EOF, not an empty request. A wrapper intending no work for an empty interval should skip the call explicitly. Linux v6.12 represents the open-ended endpoint with LLONG_MAX, not a saved file size. [10] [17]

Engineering implication: the call does not freeze concurrent writers or establish an atomic snapshot. Coordinate writers separately to identify a synchronized version; do not infer that every later append is included. The selected pages and the error observer below have different scopes. [17]

Source-code analysis, Linux v6.12: the WAIT_BEFORE and WAIT_AFTER paths call file_fdatawait_range(). It waits over the requested range, then checks the mapping-wide writeback-error sequence against the open file description's f_wb_err cursor. That check has no byte-range argument, so the report does not identify failed bytes within the requested interval. [17] [13]

The helper also advances that cursor. A later check through the same open file description, including a duplicated descriptor, need not repeat the observed error. Preserve the earlier report; a zero return from a later check is not evidence of repair. This is the file-level cursor, unlike the separate filesystem-level cursor used by syncfs(). [13] [17] [4]

Submission boundary: if WAIT_BEFORE returns an error, the function exits before its WRITE branch. Even when all three flags were requested, that error does not establish that this call submitted new writeback. It also says nothing about concurrent or earlier submissions. This is a pinned-source reading, not running-kernel fault injection, and does not add metadata synchronization or device-cache flushing. [17] [10]

Attempted is not completed: a nonzero result from the WRITE phase also skips WAIT_AFTER. Unlike the earlier exit, submission was attempted; the error alone cannot say how much writeback started or finished. With flags=0, the normal path performs neither phase nor the error-cursor check. Zero flags is therefore not a harmless way to query pending writeback errors. These are control-flow observations in the same pinned implementation, not device experiments. [17]

Filesystem-wide synchronization is not recovery

On Linux, syncfs(fd) synchronizes the filesystem containing the descriptor's file and waits for I/O completion. The descriptor selects the scope; it does not restrict a reported error to that file. An EIO can concern another file or filesystem metadata. The C interface for sync() instead covers all filesystems and returns no error result. That absence is not evidence that every write succeeded. [16]

Mainline Linux added writeback-error reporting to syncfs() in 5.8; earlier versions reported only an invalid descriptor. In the pinned v6.12 source, the syscall checks the superblock's s_wb_err against struct file.f_sb_err. This is separate from the file-level f_wb_err cursor discussed above. Both are initialized when the file is opened. [16] [17] [14]

Source-code inference: consuming a filesystem-level report does not itself advance the separate file-level cursor. Duplicated descriptors still share their open file description, including its filesystem cursor. This describes the reviewed implementation, not a portable promise about every filesystem's return value. The cursor is neither a list of failed files nor a count of all failures. [17] [4]

Return-value precedence: in that v6.12 path, the filesystem cursor is checked and advanced even if sync_filesystem() returns an error. That error takes precedence over the saved writeback report in the syscall result. A retry need not reveal a second, queued error: this mechanism is not an error queue. [17]

A wider synchronization scope does not reconstruct data lost in an earlier failed writeback. Keep the first error in the recovery decision even if a later sync returns zero. Filesystem synchronization also does not make a concurrent, multi-file application update an atomic transaction; the application must still define its ordering and recovery protocol. [1] [2]

O_SYNC and O_DSYNC move the boundary into each write

These are open-file status flags, not alternative names for bypassing the page cache. POSIX distinguishes file-integrity completion (O_SYNC) from data-integrity completion (O_DSYNC). Linux describes their write completion as analogous to following a write with fsync() or fdatasync(), respectively. [18] [11]

Metadata needed for retrieval is not the same as all associated file metadata.
FlagCompletion coversExample distinction
O_DSYNCWritten data and retrieval-critical metadata.A length extension must be synchronized; a timestamp-only update need not be.
O_SYNCWritten data and associated file metadata.Also covers the write's modification-time update.

The table follows the Linux open(2) metadata example. Neither flag requires O_DIRECT; direct I/O and synchronized completion are different choices. Less required metadata work is not a universal performance ranking. [11]

A successful write() can report fewer bytes than requested. Check its byte count and errors: synchronized completion does not imply that one call wrote a complete application record. It also does not make a sequence of writes crash-atomic. [18] File synchronization does not alone persist a newly created name; the directory-persistence boundary remains relevant. [7]

Apple synchronization and SQLite settings

On Darwin, F_FULLFSYNC is an fcntl operation that adds a drive-cache flush request after file synchronization. Apple's archived manual warns about completion cost and drives that may ignore the request. Its historical filesystem list is not a current compatibility matrix. [Apple API]

Keep the platform limit explicit: Apple's current iOS guidance describes this operation as best-effort and says sudden power loss can still lose data. This is a documented boundary, not a Hesela device test or a claim about every macOS storage stack. [iOS persistence]

SQLite has separate controls for synchronization timing and method. The word FULL in synchronous=FULL does not by itself select F_FULLFSYNC. The default VFS distinguishes SQLITE_SYNC_FULL from SQLITE_SYNC_NORMAL on macOS; third-party VFS behavior can differ. [VFS flags]

Separate SQLite configuration questions
ControlWhat it selects
synchronousWhen the VFS receives synchronization calls.
fullfsyncF_FULLFSYNC for synchronization where supported; documented default off.
checkpoint_fullfsyncF_FULLFSYNC for checkpoints; documented default off and irrelevant when fullfsync is enabled.

A setting is not an execution trace. In SQLite 3.46.1, the Unix VFS full_fsync helper, when compiled with HAVE_FULLFSYNC, attempts ordinary fsync after a nonzero F_FULLFSYNC result. A successful fallback becomes the helper's return value. Therefore synchronization success alone does not establish that F_FULLFSYNC succeeded. This is an inference from pinned source control flow, not a macOS experiment or a claim about every SQLite build. [Pinned VFS source]

These method-selection flags do not independently define a commit protocol. Record the journal mode, synchronization settings and VFS together when evaluating durability. [fullfsync] [checkpoint scope]

Choose the injected failure, then verify it happened

A test that reports a write error asks a different question from one that acknowledges a write but discards it. The Linux dm-flakey target provides both choices during its configured down window: error_writes reports errors, while drop_writes silently drops writes. Time windows do not identify one particular failed request. [dm-flakey parameters]

Requested corruption can be skipped. In Linux v6.12, flakey_map() changes matching write-data bios through a clone. If that allocation fails, the original bio is remapped without the requested byte change. A fixed replacement outside the bio data, or equal to the existing byte, also produces no changed byte. These are pinned-source findings, not measured failure rates. [implementation]

Engineering implication: record the configured fault, evidence that it actually occurred, and the application's recovery result separately. A passing recovery test with no realized fault is a control, not evidence of tolerance. Returning an error, dropping a write and changing data must not share an undifferentiated trial count.

Rebello et al. targeted individual sector or block writes in their filesystem study and used CuttleFS for the application study. Substituting a periodic injector does not reproduce that selection protocol. Their discussion also distinguishes low-level faults from mocked syscall returns. [1, sections 3.2, 4 and 5]

Use disposable, isolated test storage. No device-mapper target or storage fault was exercised for this source review; the checks above do not certify a filesystem, device or current kernel release.

What to test in your own system

The following is Hesela's engineering synthesis, not an additional experimental result. Define the promise first: which acknowledged transactions must survive, which unacknowledged states are allowed, and what recovery source remains trustworthy?

  • Keep the first I/O error, affected files, transaction boundary and software versions in the incident record. A later zero return must not erase the earlier uncertainty.
  • Test recovery against persistent state, not only a successful in-process read. Distinguish process failure, operating-system failure and device power loss.
  • Check the complete protocol: data, recovery log, names and commit acknowledgement. A checksum can detect a mismatch without supplying the missing version.
  • Use a disposable, isolated test environment for fault injection. Never inject storage faults into the production host serving this site.

Match fault injection to the claim. Rebello et al. distinguish mocked syscall errors from faults that exercise filesystem error handling. Their discussion recommends block-level injection or a filesystem emulator such as CuttleFS for recovery tests. Our helper replay answers only the reporting question: it has no failed storage writes or recovery reads. Passing it cannot certify application recovery, and a crash-restart-only test does not exercise the same failure path. [1, section 5, observation 9]

The authors publish CuttleFS with a private page cache and selectable failure behaviors. It is a candidate for a separately pinned reproduction environment; we did not install it or reproduce the paper in this session. [6]

Evidence and limits

We inspected both full papers, their methods and result sections, plus the kernel and SQLite documentation on 10 October 2026. No new hardware measurements were collected. The fsync state-machine model demonstrates a logical counterexample under stated assumptions, not measured kernel, database or drive behavior. The separate 17 October descriptor experiment records real Linux API outcomes for one host, with no injected close failures or persistence test. The papers' tested software and fault models bound their conclusions.

Related: SSD power-loss protection. Corpus records: fsync, crash consistency, and writeback error.

Primary sources

  1. Rebello et al., Can Applications Recover from fsync Failures? USENIX ATC 2020, pp. 753-767
  2. Pillai et al., All File Systems Are Not Created Equal. OSDI 2014, pp. 433-448
  3. Linux VFS: Handling errors during writeback
  4. Linux kernel: The errseq_t datatype
  5. SQLite: Atomic Commit
  6. CuttleFS research artifact (MIT license)
  7. Linux man-pages 6.19: fsync(2), including fdatasync
  8. Linux man-pages 6.19: msync(2)
  9. Linux man-pages 6.19: mmap(2)
  10. Linux man-pages 6.19: sync_file_range(2), Warning and flag combinations
  11. Linux man-pages 6.19: open(2), open file descriptions
  12. Linux man-pages 6.19: dup(2), shared open file descriptions
  13. Linux v6.12: file_fdatawait_range and file_check_and_advance_wb_err in mm/filemap.c
  14. Linux v6.12: do_dentry_open in fs/open.c
  15. Linux v6.12: errseq_sample in lib/errseq.c
  16. Linux man-pages 6.19: sync(2), filesystem scope and error reporting
  17. Linux v6.12: syncfs and sync_file_range in fs/sync.c
  18. POSIX.1-2024: write(), synchronized I/O and partial writes
  19. Linux man-pages 6.19: close(2), errors and descriptor reuse
  20. POSIX.1-2024: close(), DESCRIPTION and RATIONALE
  21. Linux v6.12: close syscall release order
  22. Linux v6.12: MAX_ERRNO in include/linux/err.h
  23. Linux man-pages 6.19: fflush(3), user-space output buffers
  24. Linux man-pages 6.19: fclose(3), errors and stream lifetime
  25. Linux man-pages 6.19: fread(3) and fwrite(3), item counts
  26. Linux man-pages 6.19: setbuf(3), setvbuf configuration
  27. Linux man-pages 6.19: full(4), controlled ENOSPC writes
  28. Linux man-pages 6.19: ferror(3) and clearerr(3)
  29. glibc 2.39: _IO_fwrite in libio/iofwrite.c
  30. glibc 2.39: file output and newline flushing in libio/fileops.c
  31. musl 1.2.5: fwrite and line-buffered output
  32. musl 1.2.5: __stdio_write error handling
  33. musl 1.2.5: fflush and pending output
  34. Shashank Mohan Jain, LKML, 27 September 2026: lost-error interleaving and proposed patch
  35. Linux v6.12: immutable lib/errseq.c replay input
  36. Linux v6.12: fuse_fsync and connection-scoped no_fsync handling
  37. Linux man-pages: F_GETFD(2const), descriptor flags and exec outcome
  38. Linux man-pages: fork(2), inherited descriptors
  39. Linux man-pages: execve(2), failures past program-image teardown
  40. Linux v6.12: dm-flakey target parameters
  41. Linux v6.12: dm-flakey byte replacement, cloning and I/O mapping
  42. Apple archived fcntl(2): F_FULLFSYNC
  43. Apple: Reducing disk writes, explicit storage synchronization
  44. SQLite: Synchronization Type Flags
  45. SQLite: fullfsync and checkpoint_fullfsync pragmas
  46. SQLite: checkpoint_fullfsync pragma
  47. SQLite 3.46.1: full_fsync Unix VFS fallback

Research sources accessed 10 October 2026; synchronization API documentation and pinned Linux v6.12 source checked 13 October 2026; syncfs, synchronized-write flags and POSIX write semantics checked 15 October 2026; return-value precedence verified against pinned source on 16 October 2026; descriptor lifetime, close errors and the POSIX.1-2024 portability boundary checked on 17 October 2026. Error coalescing and finite observation history reviewed on 20 October 2026 against Linux v6.12. Stdio contracts, isolated API observations and the glibc 2.39 full-count error path checked on 21 October 2026. Concurrent helper replay, the credited LKML report and ATC 2020 fault-injection scope rechecked on 26 October 2026. Descriptor inheritance documentation and the separate native-C example checked on 5 November 2026. Apple synchronization and SQLite method-selection documentation checked on 13 November 2026. No DOI is asserted where none was verified in the publisher record.

Published by Hesela team · Published · Updated

Report a correction · Editorial standards · Reuse guidance

Change history

: first published.

: latest recorded update. A detailed change note is not available for this revision.

New-publication RSS · Correction RSS

Cite this page
Hesela team. Why retrying a failed fsync does not prove durability. Hesela. 2026-11-13. https://hesela.com/analyses/fsync-failure-retry-durability/