• Indonesian
  • English
  • Tune Linux Dirty Ratio Page Cache: Complete Guide 2026

    Kecepatan:
    ⏱ 11 min read

    How to Tune Linux Dirty Ratio Page Cache Safely: A Step-by-Step Guide for Production Servers

    So here’s the deal. It was a lazy Tuesday afternoon, I had a fresh cup of coffee, and life was genuinely good. Then a ticket landed in my lap. Database server, periodic stalls, MySQL slow queries out of nowhere. Load looked fine on paper, RAM was half empty, and the app team was already pointing fingers at everything that wasn’t the actual culprit. That’s when I started poking around the dirty page cache. Spoiler: the fix was a lot more chill than the panic suggested.

    Let me be real with you — I’ve watched this exact story play out more times than I can count. And honestly? I get why people get it wrong. Dirty page cache tuning sounds like it should be some deep kernel wizardry, but once you see how the pieces fit together, it’s honestly pretty straightforward. Grab a drink, get comfortable, and let’s walk through it together. No rushed decisions, no magic numbers.

    Difficulty: Intermediate
    Last Updated: August 2026
    Tested On: CentOS 7/8, Rocky Linux 9, Ubuntu 20.04/22.04, Debian 11/12

    What Is a Dirty Page, Anyway?

    Alright, so let’s set the scene. Every time an application writes data, Linux doesn’t push it straight to the disk. Instead, it keeps the fresh data in the page cache and marks those pages as dirty — meaning they’ve been modified but haven’t been flushed to storage yet. The kernel handles the cleanup through a process called writeback, and it decides when to flush based on a handful of sysctl knobs. On paper, this is a smart design. Writes feel fast because the kernel says got it before the data even touches metal. It’s like a restaurant writing orders on a notepad and only walking to the kitchen every so often.

    Think of it like a checkout counter at the grocery store. If the cashier only scans everything once in a while, the line stays short and everyone’s happy — until the moment they finally start scanning, and suddenly there’s a mountain of groceries flying through in one go. That mountain is your write burst. If it’s small, nobody notices. If it’s huge, the whole store — read: your disk — grinds to a halt.

    The trouble starts when those knobs don’t match the workload. The classic case I keep running into: a database server with plenty of RAM, dirty pages stacking up into the tens of gigabytes, and then the kernel decides it’s time and flushes everything at once. Boom. Your disk goes from sipping coffee to chugging espresso in a split second. Write latency spikes, queries start queuing up, and everyone assumes the database is the problem. Half the time, it’s the writeback policy that’s the real troublemaker.

    Why do people get this tuning wrong so often? Because the numbers are sneaky. You look at 64GB of RAM and think, sure, let’s crank dirty_ratio to 50 — more cache means faster, right? It sounds logical. It’s backwards in practice. The higher the ratio, the more dirty data piles up, and when the flush finally happens, the burst is bigger. On an entry-level SSD or an old spinning disk, that burst can pin your IO wait to 100% and make the box feel frozen. And there’s the crash angle too — anything still sitting dirty in the cache is gone the moment power cuts. Nobody wants to explain that one to a client on a Monday morning.

    tune linux dirty ratio page cache sysctl check

    What the Default Values Actually Mean

    Parameter Default What It Does
    vm.dirty_background_ratio 10 The RAM percentage at which the kernel starts flushing dirty pages slowly in the background.
    vm.dirty_ratio 20 The hard ceiling. Once hit, writers get blocked until the kernel flushes enough.
    vm.dirty_expire_centisecs 3000 How old data in the cache can get before it’s forced to disk (3000 centisecs = 30 seconds).
    vm.dirty_writeback_centisecs 500 How often the kernel wakes up to flush (500 centisecs = 5 seconds).

    Here’s the thing — the defaults aren’t bad. They’re just tuned for a generic machine, not for your specific workload. And a generic setting on a busy production box is exactly where the pain usually starts. So no, you don’t need to memorize kernel internals. You just need to know which knob controls what.

    Step 1: Look at Your Current State

    Before changing anything, let’s see where you stand right now. I always check three things: how much dirty data is piled up, the current sysctl values, and how the disk is behaving. Here’s how.

    cat /proc/meminfo | grep -i dirty

    Which gives you something like this:

    Dirty: 1485824 kB

    That’s roughly 1.4GB of data waiting to hit the disk. Not a problem by itself, but if this number stays high on a database box, it’s worth a closer look. Next, check the current settings:

    sysctl vm.dirty_ratio vm.dirty_background_ratio vm.dirty_expire_centisecs vm.dirty_writeback_centisecs
    vm.dirty_background_ratio = 10
    vm.dirty_ratio = 20
    vm.dirty_expire_centisecs = 3000
    vm.dirty_writeback_centisecs = 500

    That’s the stock kernel default on most distros. Not wrong, just generic. Now we figure out if it fits your machine.

    Step 2: Know Your Workload

    There’s no magic number that works for every server. I always ask the same question first: what is this box actually doing? A database server is write-heavy, so you want dirty pages to stay short. A file server or backup target can be more relaxed. A static web server barely cares at all.

    Storage matters too. A good NVMe drive can swallow a big flush without blinking. A SATA SSD or an old HDD can’t. If you don’t know what’s under the hood, this will tell you:

    lsblk -d -o NAME,ROTA,MODEL,SIZE

    The ROTA column is the giveaway — 1 means spinning disk, 0 means SSD. That single number decides a lot of your tuning strategy, and it’s shocking how often people skip this step entirely.

    Step 3: Pick Values That Make Sense

    Here’s what I actually use out in the field. Not extreme numbers — just values that keep writeback calm and disks unbothered:

    Workload dirty_background_ratio dirty_ratio Notes
    Database (MySQL/PostgreSQL) on HDD 5 10 Keep flushes small and frequent.
    Database on NVMe SSD 10 20 Modern SSDs can handle bigger bursts.
    File server / backup on HDD 5 15 Balance between throughput and latency.
    Small VPS (1-2GB RAM) 1-5% or use dirty_bytes 5-10% Ratios lie on small RAM — use bytes instead.

    For a database server on a spinning disk that’s actively misbehaving, I usually set it like this. Drop this into /etc/sysctl.d/99-dirty-tuning.conf:

    vm.dirty_background_ratio = 5
    vm.dirty_ratio = 10
    vm.dirty_expire_centisecs = 3000
    vm.dirty_writeback_centisecs = 500

    Then apply it right away, no reboot needed:

    sysctl -p /etc/sysctl.d/99-dirty-tuning.conf

    If you’re still testing and want it temporary, sysctl -w does the job — but remember, it won’t survive a reboot. Write it to the file once you’re confident.

    Heads up: Don’t change these values during peak hours without monitoring. If a setting makes IO worse, revert to the previous value and reassess. And always write down the defaults before you touch anything — rollback is a lot easier when you know exactly what you changed.

    Step 4: Verify Everything Landed

    After applying, double-check that the kernel actually picked up the new values:

    sysctl vm.dirty_background_ratio vm.dirty_ratio
    vm.dirty_background_ratio = 5
    vm.dirty_ratio = 10

    Then watch the disk under real load. If IO wait used to spike to 100% regularly, it should be calmer now:

    vmstat 2 30

    Keep an eye on the wa column (wait) and the bo column (blocks out). If bo stops spiking in giant bursts, your writeback is spreading out nicely. On a database box, also check the queries that were queueing before — the difference should be noticeable. And if nothing changes at all, don’t force it. The problem might not be writeback in the first place.

    dirty_bytes vs Ratios: The Small RAM Edition

    Ratios are percentages of total RAM, and that’s where they can lie to you. On a server with lots of RAM, 5% might be 3GB. On a 1GB VPS, 10% is barely 100MB — nearly meaningless, and the kernel ends up waking up constantly. For cases like that, absolute byte values work better:

    vm.dirty_background_bytes = 104857600
    vm.dirty_bytes = 209715200

    That means background flushing kicks off at 100MB and the hard cap is 200MB. Perfect for small VPS boxes or light write workloads. One catch: you can’t mix ratios and bytes. Setting one disables the other. Pick a lane and stick with it.

    Quick Troubleshooting Reference

    Symptom Likely Cause Fix
    IO wait spikes to 100% every few minutes Dirty ratio too high, flushes pile up into one big burst Lower dirty_ratio and dirty_background_ratio
    MySQL locks up during peak hours Writeback blocking writers, queries waiting on IO Lower dirty_background_ratio so flushes are more frequent but smaller
    Disk always busy despite low traffic dirty_background_ratio too low, kernel wakes up too often Raise the background ratio slightly or switch to dirty_bytes
    Data gone after a crash, no error logged Dirty cap too high, lots of data never flushed Lower dirty_ratio and schedule periodic syncs
    No performance change at all The bottleneck isn’t writeback Check CPU, memory leaks, or traffic overload; this tuning isn’t a cure-all

    dirty ratio page cache sysctl configuration file linux

    A Few Warnings Before You Touch Production

    • Write down your defaults first. Run sysctl -a | grep dirty before and after, every single time.
    • Make changes during a maintenance window, then watch for at least a week. Don’t set it and forget it.
    • For database servers, don’t stop at dirty tuning. Pair it with something like tuning the MySQL InnoDB buffer pool so both layers play nice together.
    • If the box is still slow after this, don’t force it. Run a proper high load troubleshooting flow instead of guessing.
    • Dirty ratio tuning is just one piece of the disk performance puzzle. I/O scheduler and filesystem mount options matter just as much.
    • Start monitoring disk IO before you tune, so you have a baseline to compare against. You can’t tell if a change helped if you never measured the before.

    Wrapping Up

    So here’s the takeaway. Tuning the dirty ratio page cache isn’t about chasing big numbers to look smart in front of your team. It’s about keeping writeback smooth, your disk unshocked, and your data from piling up into a dangerous cliff. Check your current state, know your workload, pick sane values, verify, and keep an eye on it. Slow and steady wins this particular race.

    Q: What happens if I set dirty_ratio too low on a server with small RAM?

    On a 1-2GB VPS, a low ratio like 5% means the writeback threshold is tiny, so the kernel wakes up constantly and the disk chokes on a flood of tiny writes. That’s exactly the scenario where dirty_bytes works better than a percentage.

    Q: Is dirty_ratio 50 dangerous on a machine with lots of RAM?

    It can be. With 64GB of RAM, 50% means up to 32GB of dirty data can pile up before flushing. When that flush finally happens, it’s a massive burst that can saturate the disk and cause serious latency spikes — plus a much bigger data loss window if the power dies.

    Q: Do I need to reboot after changing vm.dirty_ratio?

    No. Running sysctl -p or sysctl -w applies the change immediately to the running kernel. Rebooting is only needed if you forgot to write the setting to a persistent file like /etc/sysctl.d/99-dirty-tuning.conf.

    Q: Can I use dirty_bytes together with dirty_background_ratio?

    Not really. The kernel treats the bytes-based and ratio-based controls as mutually exclusive. Setting vm.dirty_bytes disables vm.dirty_ratio, and vice versa. Choose one system and stick with it consistently.

    Author: Syslog Solutions — NOC & Server Management Team. We handle 500+ servers daily, from shared hosting to enterprise dedicated infrastructure.

    Alright, that’s the whole walkthrough. Bookmark this one for the next time your database starts stalling out of nowhere — you’ll thank yourself later. And if you’ve got a weird writeback story of your own, I’d genuinely love to hear it. Drop it in the comments sometime, it’s always nice trading war stories with fellow sysadmins. Coffee’s on me, metaphorically.