{
  "slug": "sync-file-range",
  "term": "sync_file_range",
  "aliases": [
    "sync_file_range()"
  ],
  "definition": "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.",
  "note": "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.\n\nIn 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. [filemap-source]\n\nA 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. [sync-source]\n\nThe 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. [sync-range-api]\n\nLinux 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. [sync-source]\n\nIf 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. [sync-source]",
  "status": "shipping",
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "updated": "2026-11-04",
  "advantages": [
    "Allows applications to control writeback over selected file ranges."
  ],
  "limitations": [
    "Linux-specific; not a portable persistence interface.",
    {
      "text": "WRITE alone can block under request-queue pressure despite asynchronous submission semantics.",
      "citationIds": [
        "sync-range-api",
        "sync-source"
      ]
    },
    "A successful return does not establish crash-safe availability of the data."
  ],
  "related": [
    "fsync",
    "fdatasync",
    "msync",
    "writeback-error",
    "errseq-t",
    "open-file-description"
  ],
  "citations": [
    {
      "id": "sync-range-api",
      "title": "Linux man-pages 6.19: sync_file_range(2), Warning and flag combinations",
      "url": "https://man7.org/linux/man-pages/man2/sync_file_range.2.html",
      "accessed": "2026-11-04"
    },
    {
      "id": "hesela-fsync",
      "title": "Hesela: File and mapped-range synchronization boundaries",
      "url": "https://hesela.com/analyses/fsync-failure-retry-durability/",
      "accessed": "2026-10-13"
    },
    {
      "id": "filemap-source",
      "title": "Linux v6.12: file_fdatawait_range and file_check_and_advance_wb_err",
      "url": "https://github.com/torvalds/linux/blob/v6.12/mm/filemap.c#L602",
      "accessed": "2026-11-04"
    },
    {
      "id": "sync-source",
      "title": "Linux v6.12: sync_file_range wait, submit and early-return ordering",
      "url": "https://github.com/torvalds/linux/blob/v6.12/fs/sync.c#L279",
      "accessed": "2026-11-04"
    }
  ]
}
