Language and Page Formatting Options
Chapter 8. Discarding unused blocks
You can perform or schedule discard operations on block devices that support them.
8.1. Block discard operations
Block discard operations discard blocks that are no longer in use by a mounted file system. They are useful on:
- Solid-state drives (SSDs)
- Thinly-provisioned storage
The block device underlying the file system must support physical discard operations.
Physical discard operations are supported if the value in the
/sys/block/device/queue/discard_max_bytes file is not zero.
8.2. Types of block discard operations
You can run discard operations using different methods:
- Batch discard
- Are run explicitly by the user. They discard all unused blocks in the selected file systems.
- Online discard
- Are specified at mount time. They run in real time without user intervention. Online discard operations discard only the blocks that are transitioning from used to free.
- Periodic discard
Are batch operations that are run regularly by a
All types are supported by the XFS and ext4 file systems and by VDO.
Red Hat recommends that you use batch or periodic discard.
Use online discard only if:
- the system’s workload is such that batch discard is not feasible, or
- online discard operations are necessary to maintain performance.
8.3. Performing batch block discard
This procedure performs a batch block discard operation to discard unused blocks on a mounted file system.
- The file system is mounted.
- The block device underlying the file system supports physical discard operations.
To perform discard only on a selected file system, use:
# fstrim mount-point
To perform discard on all mounted file systems, use:
# fstrim --all
If you execute the
fstrim command on:
- a device that does not support discard operations, or
- a logical device (LVM or MD) composed of multiple devices, where any one of the device does not support discard operations,
the following message displays:
# fstrim /mnt/non_discard fstrim: /mnt/non_discard: the discard operation is not supported
8.4. Enabling online block discard
This procedure enables online block discard operations that automatically discard unused blocks on all supported file systems.
Enable online discard at mount time:
When mounting a file system manually, add the
-o discardmount option:
# mount -o discard device mount-point
When mounting a file system persistently, add the
discardoption to the mount entry in the
8.5. Enabling periodic block discard
This procedure enables a
systemd timer that regularly discards unused blocks on all supported file systems.
Enable and start the
# systemctl enable --now fstrim.timer