When you delete a file, the filesystem marks its blocks as free, but the SSD (or the virtual disk’s storage) doesn’t know that by default. TRIM (also called discard or unmap) tells the storage which blocks are no longer used. On SSDs, this keeps write performance consistent. On thin-provisioned virtual disks, it can return space to the underlying storage.

Does your disk support it?

lsblk --discard
NAME   DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
vda           0      512B       2G         0

Non-zero DISC-GRAN and DISC-MAX mean discard is supported. Zeros mean the device (or the virtual disk configuration) doesn’t pass TRIM through. Then there’s nothing to configure, and fstrim reports that the operation isn’t supported.

Most distributions ship a weekly timer:

systemctl status fstrim.timer
sudo systemctl enable --now fstrim.timer
systemctl list-timers fstrim.timer

It runs fstrim on all mounted filesystems that support it, once a week. That’s low overhead, and works well for servers.

Run it manually:

sudo fstrim -av
# /: 3.2 GiB (3435973836 bytes) trimmed on /dev/vda1

Option 2: continuous discard (mount option)

UUID=…  /data  ext4  defaults,discard  0 2

Every delete immediately sends TRIM commands. It can add latency to delete-heavy workloads on some devices, so periodic fstrim is generally preferred. Some filesystems (Btrfs on recent kernels) use an efficient asynchronous discard mode by default. See fstab guide and mount options.

On a VPS

  • Whether TRIM reaches the host’s storage depends on the hypervisor and the disk configuration. Check lsblk --discard.
  • If supported, enabling fstrim.timer is harmless and helpful. If not, skip it. There’s no benefit to forcing discard options.
  • TRIM doesn’t free space in your filesystem (that’s already free after deleting files). It informs the underlying storage. Your df -h numbers don’t change.

LVM, LUKS and swap

  • LVM: TRIM passes through to physical volumes. issue_discards = 1 in /etc/lvm/lvm.conf only affects removing or shrinking logical volumes. Not needed for fstrim. See LVM guide.
  • LUKS encryption: discards are blocked by default (to avoid leaking information about used blocks). Enable with the discard option in /etc/crypttab, if you accept that trade-off.
  • Swap: swapon --discard (or discard in the fstab swap entry) trims swap areas.

Troubleshooting

Message Meaning
the discard operation is not supported Device or virtual disk doesn’t support TRIM
Very long first fstrim run Normal: the first run trims all free space
fstrim.timer not present Install util-linux, or add a weekly cron job running fstrim -av

Should you bother?

On a dedicated server with SSDs, yes: enable fstrim.timer and forget about it. It keeps the drives’ write performance consistent as they fill up. On a VPS, check lsblk --discard once. If discard is supported, enabling the timer costs nothing. If it isn’t, there’s nothing to gain, and nothing to configure. In neither case is TRIM a substitute for keeping enough free space on the filesystem.

Quick reference

Task Command
Check support lsblk --discard
Enable weekly TRIM systemctl enable --now fstrim.timer
Trim now sudo fstrim -av
Continuous (not usually needed) discard mount option
LUKS discard in /etc/crypttab

Related: ext4 vs XFS and Linux disk performance.

  • Linux
  • Storage
  • SSD