Since v1.4.0, Longhorn supports trimming filesystem inside Longhorn volumes. Trimming will reclaim space wasted by the removed files of the filesystem.
- The Longhorn version must be v1.4.0 or higher.
- There is a trimmable filesystem like EXT4 or XFS inside the Longhorn volume.
- The volume is attached and mounted on a mount point before trimming.
There are two ways to do trim for a Longhorn volume: with the Longhorn UI and directly via cmd.
Via Longhorn UI
Then Longhorn will try its best to figure out the mount point and execute fstrim <the mount point>
. If something is wrong or the filesystem does not exist, the UI will return an error.
Via cmd
Users need to figure out the mount point of the volume then manually execute fstrim <the mount point>
.
By design each valid snapshot of a Longhorn volume is immutable. Hence Longhorn filesystem trim feature can be applied to the volume head and the followed continuous removed or system snapshots only.
The Global Setting “Remove Snapshots During Filesystem Trim”
To help reclaim as much space as possible automatically, Longhorn introduces . This allows Longhorn filesystem trim feature to automatically mark the latest snapshot and its ancestors as removed and stops at the snapshot containing multiple children. As a result, Longhorn can reclaim space for as more snapshots as possible.
The Volume Spec Field “UnmapMarkSnapChainAsRemoved”
Of course there is a per-volume field would overwrite the global setting mentioned above.
You can directly set this field in the StoragaClasses so that the customized value can be applied to all volumes created by the StorageClasses.
Currently, Longhorn UI only supports filesystem trimming for RWO volume. It will be enhanced for RWX volume at .
Encrypted volumes
By default, TRIM commands are not enabled by the device-mapper. You can check ) for details.
If you still want to trim an encrypted Longhorn volume, you can:
- Enter into the node host the volume is attached to.
- Enable flag
discards
for the encrypted volume. The passphrase is recorded in the corresponding secert: