IT lexicon › Programming › fsync

fsync

Programming På svenska → Updated: 2026-07-29

The system call that forces writes out of the kernel's page cache onto durable storage. Without it your "saved" file merely sits in RAM and vanishes when the power goes.

An ordinary write() returns as soon as the data is in the page cache — fast, but no promise. fsync(fd) waits until the disk confirms, which costs milliseconds and is the very reason databases have commit latency. fdatasync() skips metadata and is cheaper. Two classic traps: syncing the file isn't enough if the directory entry is new, in which case the directory must be synced too; and disks with write caches can lie about data reaching the platter when barriers are missing. In 2018 the PostgreSQL developers also discovered "fsyncgate" — Linux discarded the error flag after a failed writeback, so the next fsync returned success despite lost data.

← Back to the lexicon