Course contentsShow
← Linux
Lesson 1798 of 1,81915. Kernel Concepts for Systems AdministratorsFree lesson

Dirty page writeback behavior

You will balance I/O performance and data safety by tuning kernel writeback intervals.

In this lesson, you will learn how to balance I/O performance and data safety by tuning the Linux kernel’s dirty page writeback intervals.

The Writeback Balancing Act

When you write data to a file, the kernel does not immediately push that data to physical storage. Instead, it marks memory pages as "dirty" and stores them in the page cache. This improves performance significantly, as RAM is orders of magnitude faster than disk I/O. However, this creates a trade-off: if the system crashes before these pages are flushed to the underlying storage, that data is lost.

The kernel manages this through background writeback threads (the flusher threads) that wake up periodically to write dirty pages to disk, ensuring that the system does not accumulate an unmanageable amount of pending I/O.

Tuning the Behavior

You can influence this behavior by modifying variables under /proc/sys/vm/. These settings allow you to dictate how "dirty" the memory is allowed to get before the kernel takes action:

  • dirty_background_ratio: The percentage of total system memory that can be filled with dirty pages before background writeback starts. Setting this lower triggers I/O sooner, smoothing out throughput but potentially increasing disk pressure.
  • dirty_ratio: The maximum percentage of total system memory that can hold dirty pages before the process performing the write is forced to wait and perform the writeback itself (synchronous I/O).
  • dirty_writeback_centisecs: The interval (in hundredths of a second) at which the kernel wakes up the background threads to inspect and write back dirty pages.

For example, to be more aggressive about data safety on a write-heavy database server, you might tighten the background threshold:

# Start background writeback at 5% of memory instead of the default 10%
sysctl -w vm.dirty_background_ratio=5

By lowering these thresholds, you minimize the "blast radius" of a power failure by forcing data to disk more frequently. Conversely, increasing them can drastically improve performance on systems with fast storage by allowing the kernel to batch writes more efficiently and optimize I/O scheduling.

Key Takeaway: Tuning dirty page writeback allows you to trade off raw I/O throughput for data durability by controlling when and how much memory the kernel allows to remain "in-flight" before committing it to permanent storage.