Databases & Storage
SSD Write Amplification: What It Is and How to Reduce It on a VPS
By NileVPS Team · Published · 5 min read
اقرأ المقال بالعربيWhen your application writes 1 GB of data to an SSD, the drive itself may end up writing noticeably more than 1 GB to its flash chips. That gap is called write amplification. It affects how long flash storage lasts, how consistent its latency is under heavy load, and, on a shared virtual server, how much I/O your workload actually costs the underlying hardware. You cannot see the flash controller from inside a VPS, but you can control a lot of what reaches it. This article explains the mechanism in plain terms and gives practical steps to keep unnecessary writes down.
Why SSDs write more than you asked
Flash memory has two awkward properties that hard disks do not:
- You cannot overwrite in place. A flash page (often a few KB to tens of KB) must be erased before it can be written again.
- Erasing happens in large blocks. An erase block holds many pages, commonly measured in megabytes.
So when you change a small piece of a file, the SSD controller writes the new version to a fresh page and marks the old one as stale. Over time, erase blocks fill with a mix of valid and stale pages. To reclaim space, the controller runs garbage collection: it copies the still-valid pages into a new block, then erases the old block. Those copies are writes you never asked for.
The ratio between what the flash actually writes and what the host sent is the write amplification factor (WAF):
WAF = bytes written to flash / bytes written by the hostA WAF of 1.0 is ideal. Real values depend on the drive, how full it is, how random the writes are, and whether the drive knows which data is deleted.
What makes write amplification worse
| Factor | Effect |
|---|---|
| Small random writes | Scatter changes across many blocks, so garbage collection copies more valid data |
| A nearly full drive | Less free space to work with, so blocks are reclaimed while still holding lots of valid data |
| No TRIM / discard | The drive keeps "deleted" data as valid and keeps copying it around |
| Misaligned partitions | One logical write can touch two physical pages |
| Chatty logging and temp files | Constant small writes for data nobody reads |
| Filesystem and database journaling | Data is written once to a journal or log and again to its final place |
The last point is not a bug: journaling is what keeps your data consistent after a crash. The goal is not to remove safety features, it is to stop writes that add no value.
Practical steps on a Linux VPS
1. Make sure TRIM reaches the storage
TRIM (called discard in Linux) tells the storage layer which blocks no longer hold useful data. Check whether your virtual disk advertises discard support:
lsblk --discardNon-zero values in the DISC-GRAN and DISC-MAX columns mean discard is supported. On most modern distributions, periodic TRIM is handled by a systemd timer:
systemctl status fstrim.timer
sudo systemctl enable --now fstrim.timerYou can also run it manually and see how much was trimmed:
sudo fstrim -avPeriodic fstrim is generally preferred over the discard mount option, which issues a trim on every delete and can add latency on some setups.
2. Stop updating access times on every read
By default, many filesystems record when a file was last read. relatime (the default on most distributions) already limits this. For servers that never need access times, you can use noatime in /etc/fstab:
UUID=xxxx-xxxx / ext4 defaults,noatime 0 1Test with sudo mount -o remount / and confirm with findmnt /.
3. Tame logging
Logs are often the largest source of pointless writes. A few ideas:
- Set limits for the systemd journal in
/etc/systemd/journald.conf, for exampleSystemMaxUse=500M, thensudo systemctl restart systemd-journald. - Lower application log levels in production (
infoorwarninstead ofdebug). - Make sure
logrotatecompresses and removes old files instead of letting them grow forever. - Avoid writing the same message both to a file and to the journal.
4. Keep temporary data in memory where it fits
Short-lived files that never need to survive a reboot can live in RAM with tmpfs. Many distributions already mount /tmp this way. Check with:
findmnt /tmpOnly do this if you have enough memory; a full tmpfs will push the system toward swap, which brings its own writes.
5. Watch swap usage
Constant swapping turns memory pressure into disk writes. Check with free -h and vmstat 5. If the si and so columns are busy, the real fix is more RAM or less memory usage, not a swap tweak. Lowering vm.swappiness can help on database servers, but test before and after.
6. Tune databases sensibly
Databases are write-heavy by design, but defaults are often conservative:
- In PostgreSQL, a larger
max_wal_sizemeans fewer forced checkpoints, which reduces repeated writes of the same pages. - In MySQL/MariaDB with InnoDB, a properly sized
innodb_buffer_pool_sizekeeps hot pages in memory and batches writes. - Batch inserts in your application instead of committing row by row where your consistency needs allow it.
Never disable fsync or crash safety to save writes on a production database.
7. Leave free space
Keep your filesystem comfortably below full. Free space gives both the filesystem and the storage underneath room to avoid expensive reshuffling. Check with df -h.
Measuring your own writes
You cannot read the physical drive's wear counters from inside a VPS, but you can see what your system sends to the disk:
sudo apt install sysstat iotop # Debian/Ubuntu
iostat -dx 5
sudo iotop -oaiotop -oa accumulates writes per process, which quickly shows whether a logger, a cache, or a database is responsible. Measure before and after each change. If you want to understand the related metrics, see our guide on IOPS, throughput and latency.
On NileVPS plans, disks are SSD-based, and the habits above apply directly. If you need more headroom for a write-heavy database, compare disk sizes on the pricing page.
FAQ
Can I see the write amplification factor of my VPS disk?
Not directly. The physical drive's internal counters are only visible to the host. Inside the VPS you can measure what you write with iostat and iotop and reduce it, which lowers the load that reaches the flash.
Is the discard mount option better than fstrim?
For most servers, a weekly fstrim.timer is the safer default. Continuous discard trims on every delete and can add latency on busy systems, while batched trimming achieves the same result with less overhead.
Does write amplification slow down my server?
It can. When garbage collection is busy, write latency can rise and become less predictable, which databases notice most. Fewer unnecessary writes and enough free space help keep latency stable.