Systems study
Offline — showing the cached copy.
Home / Operating Systems / 5. Page cache and writeback

5. Page cache and writeback

One-liner. The kernel uses free RAM as a cache, and writes back lazily unless you force it.

Memorize

  • Reads populate the page cache; repeated reads hit memory, not disk.
  • Writes go to the cache and are marked dirty; writeback flushes them later (dirty_ratio, dirty_background_ratio).
  • fsync/fdatasync force durability; sync flushes everything (rarely what you want).
  • O_DIRECT bypasses the cache (databases), trading simplicity for control.
  • Read-ahead prefetches sequential data; random I/O gets little benefit.
  • Cached memory is reclaimable: "free" RAM being low is normal; look at available.
  • io_uring submits many async I/Os with far fewer syscalls than epoll + read.
WRITE PATH write() page cache(dirty) writeback thread block layer device ack cache clean
Write path

Trap. Assuming a successful write() survives a power loss — it doesn't until fsync or writeback completes. Do this. fsync the file and the directory entry when creating files that must survive.

Check

Why can write() return successfully and still lose data on power loss?