Site icon New Generation Enterprise Linux

Stop your server from stalling out on big writes

Performance Tuning & Kernel Parameters (Sysctl)

Stop your server from stalling out on big writes

đź§© The Challenge

Ever had a database server or an analytics box just… freeze up for a minute or two when it’s doing a huge write operation? You kick off a big `mysqldump` or a log processing job that writes gigabytes, and suddenly `ssh` gets sluggish, keyboard input lags, and `top` shows processes stuck in `D` state. It’s maddening, and it feels like nobody tells you why.

đź’ˇ The Fix

This happens because the kernel’s letting too much “dirty” data pile up in memory before it flushes it to disk. A couple of `sysctl` parameters control how much of that buffered write data can accumulate. Tweaking them means your system starts writing back to disk sooner and more frequently, preventing those nasty, system-wide I/O stalls.

To check current values:
sysctl vm.dirty_ratio
sysctl vm.dirty_background_ratio

To set them (temporarily):
sudo sysctl -w vm.dirty_ratio=10
sudo sysctl -w vm.dirty_background_ratio=5

To make persistent (add to `/etc/sysctl.d/99-dirty-tweak.conf`):
echo "vm.dirty_ratio = 10" | sudo tee /etc/sysctl.d/99-dirty-tweak.conf
echo "vm.dirty_background_ratio = 5" | sudo tee -a /etc/sysctl.d/99-dirty-tweak.conf

Then apply with:
sudo sysctl -p /etc/sysctl.d/99-dirty-tweak.conf

⚙️ Why It Works

Linux buffers writes in RAM (the page cache) to optimize I/O. `vm.dirty_background_ratio` is when the kernel starts writing that data to disk in the background. But `vm.dirty_ratio` is the hard stop: once that percentage of memory is “dirty,” *all* new I/O stalls until enough data is written out. Lowering these values forces the kernel to flush smaller chunks more often, avoiding the huge, blocking write storms.

🚀 Pro-Tip: For consistent behavior on servers with varying RAM, especially databases, consider using `vm.dirty_bytes` and `vm.dirty_background_bytes` instead of percentages.

Linux Tips & Tricks | © ngelinux.com | 9/7/2026

0 0 votes
Article Rating
Exit mobile version