Storage advice often compresses three different ideas into one word: TRIM, discard, and fstrim. They are related, but they operate at different points in the Linux storage stack. Understanding that distinction matters even more when the filesystem sits inside LUKS encryption.
What discard is trying to accomplish
When a filesystem deletes a file, the blocks become available for reuse, but the storage device may not know that immediately. A discard request tells a lower layer that a range is no longer needed. SSDs commonly call this TRIM; SCSI devices may call it UNMAP. The purpose is not to erase the contents securely, but to let the device or a thin-provisioned backend manage unused space more intelligently.
fstrim performs this operation from a mounted filesystem. For a cautious one-off test, run sudo fstrim -v /. The -v output tells you how much potential discard the filesystem submitted, not necessarily how much physical flash was reclaimed. The kernel and lower storage layers can adjust, coalesce, or reject those ranges.
Online discard versus periodic fstrim
Mounting a filesystem with discard enables online discard: deletion activity can generate requests immediately. That keeps the device informed, but it can add work and latency to ordinary filesystem operations. Periodic fstrim batches the work instead, which is why a weekly timer is often a sensible default for desktops and servers.
Do not assume that running fstrim once proves the complete path works. A request may travel through the filesystem, dm-crypt, LVM, RAID, a hypervisor, a virtual disk, and finally the physical device. Any layer can limit or suppress discard. lsblk -D is useful for inspecting the discard capabilities advertised by the block stack, while journalctl -u fstrim.service can show what a systemd run actually did.
Why LUKS does not pass it through by default
A common encrypted layout looks like this: filesystem → /dev/mapper/cryptroot → LUKS/dm-crypt → SSD. By default, dm-crypt ignores discard requests. That default is intentional. Discard patterns can reveal information about the encrypted device, such as which regions are unused and clues about filesystem layout or activity, even though the file contents remain encrypted.
If the trade-off is acceptable, discard can be enabled when opening the mapping with --allow-discards, or persistently with the corresponding discard option in /etc/crypttab. The exact initramfs steps vary by distribution. Some LUKS configurations, including combinations involving dm-integrity, have additional limitations, so this is not a setting to copy blindly into every machine.
The gotchas people usually discover late
- Discard is not secure deletion. It is a storage hint, not a guaranteed erasure mechanism.
blkdiscardis different. It operates on block devices and can destroy data. It is not a replacement forfstrimon a live filesystem.- Swap is not a normal filesystem. It has separate discard controls through
swapon. - Snapshots and thin pools complicate the picture. Guest-level trimming may not reduce host allocation unless every layer is configured to honor it.
- USB bridges and virtual storage are frequent weak links. They may report limited or no discard support even when the underlying SSD supports it.
- There is a privacy trade-off. Passing discard through LUKS can improve space reclamation while exposing allocation patterns below the encryption layer.
A reasonable default
For many Linux systems, the conservative starting point is periodic fstrim, verified with lsblk -D and a verbose test on the intended mountpoint. Enable LUKS discard only after deciding that the performance or thin-provisioning benefit outweighs the information it can reveal. The filesystem, encryption layer, and storage device each have a say; a successful command at the top is not proof that the bottom layer acted.
Further reading: the fstrim manual page, the Linux dm-crypt documentation, and cryptsetup’s LUKS open documentation.
