Chapter 16. Discarding unused blocks
You can perform or schedule discard operations on block devices that support them.
16.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.
16.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.
16.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
16.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
16.5. Enabling online block discard using RHEL System Roles
This section describes how to enable online block discard using the
An Ansible playbook including the
For information on how to apply such a playbook, see Applying a role.
16.5.1. Example Ansible playbook to enable online block discard
This section provides an example Ansible playbook. This playbook applies the
storage role to mount an XFS file system with online block discard enabled.
Example 16.1. A playbook that enables online block discard on /mnt/data/
--- - hosts: all vars: storage_volumes: - name: barefs type: disk disks: - sdb fs_type: xfs mount_point: /mnt/data mount_options: discard roles: - rhel-system-roles.storage
- This playbook also performs all the operations of the persistent mount example described in Section 2.4, “Example Ansible playbook to persistently mount a file system”.
For details about the parameters used in the
storagesystem role, see the
16.5.2. Additional resources
For more information about the
storagerole, see Section 2.1, “Introduction to the storage role”.
16.6. 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