Skip to content
WebsiteHosting.com

concept Linux & administration

Linux page cache versus durable writeback

Linux can accept a buffered write before it reaches durable storage. At power loss, the difference between bytes accepted and bytes covered by a successful sync is an uncertainty, not a count of bytes lost.

Latest recorded source check · P0166

What it means

A successful buffered write tells you how much data Linux accepted, not how much will survive a power loss. The application can get a successful return while the changes are still in memory, in the page cache. Writeback moves those changes toward storage. A successful synchronization such as fsync gives the application evidence of persistence for the data it covers, assuming the storage device honors its flush and completion guarantees.

Try it

Simulation: Leave Bytes accepted by page cache at 100 KiB, Power-loss event at yes, and Required scenario evidence at provided. Change Bytes with completed durable sync from 40 to 100 KiB. The power loss is the same in both cases; what changes is how much data has evidence of persistence before the loss.

Linux page cache versus durable writeback

Separate cached writes, dirty pages and durable storage completion

Simulation
Modeled outcome: Risk

Crash before durable completion leaves remaining bytes unproved.

Linux page cache versus durable writeback: synthetic scenario inputs
Replaces all inputs with the documented starting example and the indicated change. Reset restores the starting example.
Accepted writes versus established durability

Crash boundary

  1. Crash stipulatedyes
  2. ConclusionRisk, loss count unknown
Accepted100 modeled units
Durable under premise40 modeled units
Unproved60 modeled units

The unproved portion is not a count of lost bytes. Crash is a stipulated event, and there is no actual filesystem or device observation.

Evaluated inputs

Required scenario evidence
provided
Bytes with completed durable sync
40 KiB
Bytes accepted by page cache
100 KiB
Power-loss event
yes

Stipulated durable completion under reliable device assumptions; no file metadata, ordering, partial recovery or actual disk operations.

About this model

The controls set only a local, bounded scenario. The computed branch is not a verdict about a live system. Inputs listed as not evaluated did not participate in this branch after validation.

Reset restores the original inputs. It does not change the open or closed state of help or FAQ answers.

At the point of power lossAcceptedDurableDurability unproved
Sync completed for only part of the data100 KiB40 KiB60 KiB
Sync completed for all the data100 KiB100 KiB0 KiB

In the first row, 60 KiB is the difference between what the application wrote and what it can count as durable. It is not a measurement of data lost, or even of data still in the cache. The amounts are scenario inputs, not byte counts reported by fsync.

Reset restores 100 KiB accepted, 40 KiB durable, power loss set to yes, and evidence provided. From there, change just the power-loss event to no. The same 60 KiB remains unproved, but no crash has occurred. If you instead mark the required evidence as missing, the result is unknown; the selected amounts no longer justify a conclusion. The simulation does not inspect a disk.

Where a power loss falls

Consider one buffered change. The application sees a return from write; the kernel manages the modified page and its writeback. The important question is what had finished when power failed.

  • After acceptance, while the page is dirty: Linux has accepted the change in memory. A dirty page is a modified page that needs writeback. Neither the write return nor the dirty page establishes that storage holds the change.
  • During writeback, or after a write has been sent to the device: The kernel is no longer merely holding the change for later. But sending data toward storage is not the same as confirming that it reached persistent media. Without evidence of durable completion, you cannot say whether this change survived.
  • After a successful `fsync` covering the change: Under the stated filesystem and device guarantees, the covered file data counts as durable. A power loss before fsync reports success does not give the application that same evidence. It does not prove loss, either.

Compare the same accepted count of 100 with completed durability evidence of 100 instead of 40. The unproved count becomes zero under the stated premise. With 40 completed and no stipulated crash, the remaining 60 are still unproved: absence of a crash is not a persistence observation. No inferred loss count or writeback stage should be added to either result.

In practice

When an application reports “file saved,” find out which operation that message acknowledges. Was it a buffered write, a file close, or a successful synchronization covering the intended changes? Check the amount the write accepted and the results of the relevant operations, including errors. A successful close is not a substitute for a successful sync. On Linux, do not blindly retry close after an error: the descriptor number may already have been reused, so a retry could close a different file. Investigate the error instead.

Also match the evidence to what needs to survive. Persisting a file's contents and persisting a newly created name in its containing directory are different requirements. The simulation counts file data only; it does not model directory entries, write ordering, or what a filesystem will recover. For a real persistence claim, identify the changes covered by the successful sync and check the storage guarantees it relies on. If all you have is a write acknowledgment, report the data as accepted, not as proven durable.

Frequently asked questions

Editorial questions based on the listed sources and explicitly labeled local examples.

Does close guarantee durability?

No. Closing a descriptor is not a guarantee of persistence. A successful close does not substitute for the applicable synchronization evidence, including separate metadata needs. Do not blindly retry a failed close on Linux.

What does fsync attempt?

Synchronize file data and necessary metadata according to its contract.

Can directory metadata need separate sync?

Yes. For changes to directory entries, synchronizing the file alone may not persist the directory metadata. Verify the applicable filesystem and operation contract.

Does page cache mean only reads?

No. Buffered writes can leave modified pages in the cache awaiting writeback. A cached or dirty page is not evidence that the underlying device has persisted the data. Use the applicable synchronization contract when durability matters.

Sources & model boundaries

Primary references used for this explanation. The interactive example is an educational model, not a live check.

  1. fsync(2)

    DESCRIPTION. Successful file fsync flushes data and associated metadata but does not necessarily persist the containing directory entry.

    Checked .

  2. write(2)

    NOTES. Successful write does not prove storage durability; short writes and delayed errors are possible.

    Checked .

  3. Linux VFS

    Writeback operations. Buffered writes may leave dirty pages awaiting writeback. Cache presence or dirty state alone does not establish persistence on the underlying device.

    Checked .

  4. close(2)

    NOTES, Dealing with error returns. Successful close does not guarantee persistence. On Linux, retrying close after an error can close a reused descriptor; investigate the reported error without blindly retrying.

    Checked .

Report an issue. Include the article URL and ID, not passwords or access keys.