FITRIM/discard
Purpose
FITRIM is a mounted filesystem feature to discard (or "trim") blocks which are not in use by the filesystem. This is useful for solid-state drives (SSDs) and thinly-provisioned storage.
Requirements
- The block device underneath the filesystem must support the FITRIM operation.
- The kernel must include TRIM support and XFS must include FITRIM support (this has been true for Linux since v2.6.38, Jan 18 2011)
- Realtime discard mode requires a more recent v3.0 kernel
This can be verified by viewing /sys/block/<dev>/queue/discard_max_bytes -- If the value is zero then your device doesn't support discard operations.
Modes of Operation
- Realtime discard -- As files are removed, the filesystem issues discard requests automatically
- Batch Mode -- A user procedure that trims all or portions of the filesystem
Realtime discard
This mode issues discard requests automatically as files are removed from the filesystem. No other command or process is required.
Realtime discard is selected by adding the filesystem option discard
while mounting.
This can be done by the following examples:
- placing
discard
in your /etc/fstab for the filesystem:/dev/sda1 /mountpoint xfs defaults,discard 0 1
- mount options:
mount -o discard /dev/sda1 /mountpoint
Batch Mode
This mode requires user intervention. This intervention is in the form of the command fstrim
. It has been included in util-linux-ng since about Nov 26, 2010.
Usage example:
fstrim /mountpoint
References
- FITRIM description - Lukas Czerner <lczerner at redhat.com> http://patchwork.xfs.org/patch/1490/
- Block requirements - Dave Chinner <david at fromorbit.com> http://oss.sgi.com/pipermail/xfs/2011-October/053379.html
- util-linux-ng addition - Karel Zak <kzak@xxxxxxxxxx> http://www.spinics.net/lists/util-linux-ng/msg03646.html