Disk vs Memory Tuning
Match workload.
Overview
Disk and memory tuning matches kernel and database settings to the actual IO and memory profile of the workload. Blanket sysctl changes copied from blog posts produce surprises; profile-driven changes produce performance.
- Match workload. IO-heavy and memory-heavy workloads need different tuning. One sysctl set does not fit both.
- vm.swappiness. Trades swap usage for page-cache aggressiveness. Database hosts want it near zero; mixed workloads want a higher value.
- vm.dirty_ratio. Controls when dirty pages flush to disk. Lower values smooth IO bursts; higher values amortise writes.
- Database buffer pool plus OS page cache. Postgres
shared_buffersand MySQLinnodb_buffer_pool_sizeshare RAM with the OS page cache. The split matters.
The approach
Three habits keep the tuning honest: profile first, size the database buffer pool deliberately, and monitor page-cache utilisation as a standing signal.
- Profile first.
iostatandvmstatreveal what the workload actually does. Tuning without a profile is guessing. - Database buffer pool sizing. 25 to 40 percent of RAM for Postgres
shared_buffers; let the OS page cache handle the rest. - vm.swappiness=1 for DB hosts. Avoid swap on database servers. Swap thrashing under load is worse than OOM.
- Monitor page cache and document changes.
/proc/meminfoCached field tells you whether tuning is working; per-host tuning rationale lives in source.
Why this compounds
Each tuned host produces ongoing performance benefit. Patterns transfer across the fleet; new hosts ship with the right settings rather than the distribution defaults.
- Better performance. Matched tuning produces faster IO and lower latency. p99 query time benefits especially.
- Better resource utilisation. Right buffer pool uses RAM effectively. Smaller instance types become viable.
- Better stability. Avoiding swap thrashing prevents the cliff where the host slows to a crawl under load.
- Year-one investment, year-two habit. The first tuning takes profiling effort. Subsequent hosts inherit the pattern.