Hardware & Performance·5 min read·

TRIM and Discard for Virtualized SSD Storage

How fstrim and the discard mount option keep a virtualized SSD from wearing out or reporting phantom usage, with the guest-side commands to verify.

NB

Netbay Developer Relations

Netbay Engineering

On this page

Solid-state storage does not recycle space the way spinning disks do. Deleting a file on a magnetic disk frees the sector on the spot; on a flash device the block still holds its data until the storage firmware explicitly trims it, because flash must erase in large chunks before anything can be rewritten. When that handshake is missing, and inside a VM it is easy for it to be missing, two things happen: deleted space still counts against the usable ceiling, and writes slow down as the device runs out of already-erased blocks. TRIM is the standard mechanism that closes the loop.

The handshake you need

TRIM needs three participants talking to each other: the filesystem tells the block layer which blocks are free, the block layer forwards a discard request to the virtual disk, and the storage beneath, Netbay's enterprise High-Speed SSD pool, actually reclaims the erased space. Break any leg of the chain and the disk keeps working, but with slower writes and a shrinking apparent capacity that df cannot explain.

  • Online discard (the discard mount option) sends allocation hints in real time as blocks are freed.
  • Batch TRIM (fstrim) scans the filesystem once and issues a single large sweep, typically weekly.
who reclaims a deleted block filesystem marks block free discard hint sent online or batch underlying SSD pool erases and reuses the block fstrim -av sweeps all mounts freed size reported per volume no trim = writes slow down as the pool gets busy verify support with lsblk DISC-GRAN / DISC-MAX

Check whether the guest is discarding at all

The fastest way to waste an afternoon is tuning something that was never broken. Check support, then check behavior:

bash
findmnt -no fstype,discard,options /srv/data
lsblk -d -o NAME,DISC-GRAN,DISC-MAX,ROTA

Non-zero DISC-GRAN and DISC-MAX mean the virtual disk accepts discard requests, and ROTA 0 means it is being presented as solid state. If the numbers are present but the filesystem options never mention discard, the filesystem is simply not asking the block layer to trim anything, and you have found your missing leg.

Set it up: batch and online

bash
# sweep everything now, and see what was reclaimed
fstrim -av
# make the weekly batch trim permanent (timer is preset on most distros)
systemctl enable --now fstrim.timer
# or attach discards to a specific mount
echo '/dev/vg0/data /srv/data ext4 defaults,discard 0 2' >> /etc/fstab
mount -o remount,discard /srv/data

For most workloads prefer the weekly fstrim timer over the discard mount option: it batches the work into one quiet pass instead of adding a hint to every single delete, which many small writes do not need. Keep both if the workload is delete-heavy, think caches and build artifacts, and the virtual disk handles inline discards without latency spikes; measure before you assume.

Keep an eye on the published numbers

Right after a big delete, df inside the VM can still show the old usage until the sweep runs, which is not an error. fstrim -av reports the freed amount per volume in human units precisely because of this. And if you monitor allocated size anywhere above the guest, a clean, periodic fstrim line in the logs is the evidence that the loop is healthy and the pool stays as fast as the day you started.

Takeaway

TRIM is free performance and honest capacity reporting: enable the fstrim timer where discards are supported and you will never argue with a phantom full disk again. Practice on a Netbay High-Speed SSD instance, where the two lsblk commands above confirm discard support in seconds — 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