sync-file-range · shipping · also sync_file_range()

sync_file_range

sync_file_range is a Linux-specific operation that initiates or waits for page-cache writeback over a file range without synchronizing file metadata or flushing volatile device write caches.

Related Observatory article: Read on hesela.com

Combining WAIT_BEFORE, WRITE and WAIT_AFTER does not remove those omissions. Preallocated space can still require allocation metadata updates, and copy-on-write overwrites cannot assume in-place blocks. Use it to control writeback, not as a general replacement for fdatasync or fsync.

In Linux v6.12, WAIT_BEFORE and WAIT_AFTER use file_fdatawait_range. The wait covers a byte range, but the error check advances the open file description's f_wb_err cursor against the mapping-wide error sequence; it does not locate the failed bytes. Preserve that report: a later check on the same cursor need not repeat it. [3]

A WAIT_BEFORE error exits before this call reaches its WRITE step. This is source-code analysis, not running-kernel fault injection or a promise about every filesystem. [4]

The byte arguments select pages: even a partially covered page participates. A zero nbytes means from offset to EOF, not an empty request. Skip an empty application range explicitly instead of passing zero as its length. [1]

Linux v6.12 uses LLONG_MAX for that open-ended endpoint rather than saving the current file size. Engineering implication: this is not an atomic snapshot and does not freeze concurrent writers; coordinate them separately when identifying a synchronized version. [4]

If the WRITE phase itself returns an error in Linux v6.12, WAIT_AFTER is skipped. This differs from an error in WAIT_BEFORE: submission was attempted, so the result alone does not establish how much writeback started or finished. A zero flags value reaches neither phase on the normal path; it is not a writeback-error query. [4]

Relations

related
fsync, fdatasync, msync, Writeback error, errseq_t, Open file description

Advantages

  • Allows applications to control writeback over selected file ranges.

Limitations

  • Linux-specific; not a portable persistence interface.
  • WRITE alone can block under request-queue pressure despite asynchronous submission semantics. [1, 4]
  • A successful return does not establish crash-safe availability of the data.

Citations

  1. Linux man-pages 6.19: sync_file_range(2), Warning and flag combinations (accessed 2026-11-04)
  2. Linux v6.12: file_fdatawait_range and file_check_and_advance_wb_err (accessed 2026-11-04)
  3. Linux v6.12: sync_file_range wait, submit and early-return ordering (accessed 2026-11-04)

Further reading

  1. Hesela: File and mapped-range synchronization boundaries (accessed 2026-10-13)

JSON: /data/terms/sync-file-range.json

Published by Hesela team · Updated

Report a correction · Editorial standards · Reuse guidance

Cite this page
Hesela team. sync_file_range. Hesela. 2026-11-04. https://hesela.dev/terms/sync-file-range/