4 Discarding Unused Blocks on a File System
WARNING:
This documentation is a draft and is not meant for production use. Branch: OL10-FSADMIN
Some file systems, such as XFS, Btrfs, and Ext4, provide a discard feature that discards unused blocks that are no longer in use by the mounted file system. This file system optimization can improve performance by reclaiming space more efficiently and reducing fragmentation.
The discard feature can improve garbage collection for the file system. When a file is deleted, the file system marks the corresponding blocks as free. However, the actual data remains on the disk until it's overwritten. Discarding unused blocks ensures that the garbage collector can reclaim those blocks more efficiently.
Solid-State Drives (SSDs) have limited write cycles before they start to degrade. Discarding unused blocks also helps reduce the number of writes to the SSD, extending its lifespan, and reduces wear on the disk.
In thin provisioning environments, the discard feature helps optimize storage allocation by releasing unused blocks back to the pool, reducing waste, and improving resource usage. Discarding unused blocks also helps prevent unnecessary growth of the file system and reduces the risk of running out of space.
File systems that include the discard feature also include a discard
mount option, to perform online discard operations that discard blocks as they change
from the used
to the free
state. You can also use the
fstrim
command to manually discard unused blocks on a file system
that includes the feature, or set a systemd timer unit to perform the discard operation
at frequent intervals.