Linux·8 min read·

Linux Page Cache and Dirty Ratio Tuning for High-Speed I/O

Prevent I/O stalls and writeback spikes by fine-tuning vm.dirty_ratio, vm.dirty_background_ratio, and flush intervals on SSD storage.

NB

Netbay Cloud Team

Netbay Engineering

On this page

The Linux page cache acts as an invisible acceleration layer between user applications and physical block storage. When a process issues an asynchronous write, the kernel quickly copies the buffer into system RAM, marks the corresponding memory pages as dirty, and returns success immediately. A fleet of kernel flusher threads (kworker) later writes these dirty pages out to storage.

However, default Linux sysctl parameters were conceived when servers had small amounts of RAM and slow spinning disks. Default settings allow dirty pages to accumulate up to 20% of system memory before forcing synchronous writeback. On a server with 64GB of RAM, this permits over 12GB of unwritten dirty buffers to accumulate. When the flushers finally engage, the storage controller faces a massive queue spike that freezes active applications for seconds at a time.

Expand
High-Speed SSD I/O
SSD Storage and Cache Writeback Architecture
Linux Page Cache Dirty Page Writeback Thresholds App write() Call Buffers marked Dirty in RAM dirty_background_bytes Background Flusher Wakes Up dirty_bytes Ceiling Apps Block Synchronously High-Speed SSD Storage Array Smooth, continuous stream of I/O operations without burst stalls Switching from percentage ratios to absolute byte thresholds prevents multi-gigabyte memory write stalls.

Inspecting Active Dirty Memory

Before modifying kernel tunables, inspect the current volume of unwritten dirty memory:

bash
# Inspect current system-wide page cache status
cat /proc/meminfo | grep -E "Dirty|Writeback|Cached"

# Sample output:
# Cached:         18420120 kB
# Dirty:             42180 kB
# Writeback:             0 kB

If Dirty fluctuates dramatically from a few megabytes to dozens of gigabytes during database imports or batch processing, your server is experiencing writeback batching.

Modern Byte-Based Writeback Configuration

On high-speed SSD storage nodes, setting dirty limits using absolute byte quantities rather than percentages provides deterministic control regardless of total RAM size.

ini
# /etc/sysctl.d/99-pagecache-tuning.conf
# Wake up background flushers once dirty memory reaches 128MB
vm.dirty_background_bytes = 134217728

# Force processes to throttle synchronously if dirty memory reaches 512MB
vm.dirty_bytes = 536870912

# Check for dirty pages every 1.5 seconds (150 centiseconds)
vm.dirty_writeback_centisecs = 150

# Expire pages once they have been dirty for 5 seconds (500 centiseconds)
vm.dirty_expire_centisecs = 500

Apply these changes immediately:

bash
# Reload sysctl parameters
sudo sysctl --system

By forcing background flushers to trigger at 128MB, the kernel maintains a steady, continuous stream of small write operations. This prevents the storage controller queue from getting overwhelmed and ensures user transactions never block on synchronous page write throttles.

Storage Architecture Exploration

Review this detailed exploration of how filesystems handle caching and physical persistence:

Filesystems and Page Cache Architecture
YouTube

Benchmarking Writeback Stability

Validate your new configuration by running an intense random write workload with fio:

bash
# Run 4K buffered random write test to verify steady throughput
fio --name=dirty-cache-test --filename=/tmp/fio-dirty.test --size=4G --rw=randwrite --bs=4k --direct=0 --numjobs=4 --time_based --runtime=30 --group_reporting

Notice that with byte-based dirty tuning, I/O latency percentiles remain flat without periodic sawtooth dips.

Experience sustained I/O throughput on High-Speed SSD VPS nodes at netbayhosts.in.

Keep reading

Follow along on a real VPS

Deploy Linux in under 60 seconds

These guides are written against Ubuntu, Debian, and RHEL-family images — the same ones on NetBay.

Deploy an instance