fstrim
fstrim is a command line tool used for trimming unused blocks on filesystems that support the discard or trim operations.
When files are deleted on solid-state drives (SSDs) or flash-based storage devices, the filesystem keeps track of these deleted blocks as free space. However, these blocks are not actually erased immediately at the file deletion. This results in data remnants occupying space on the drive, decreasing performance over time.
To address this, fstrim is used to send discard or trim commands to the storage device, notifying it about the unused blocks that can be reclaimed. By doing so, fstrim ensures the filesystem and the storage device are in sync, reducing wear on the drive and improving performance.
The fstrim utility is typically used periodically or as scheduled by the operating system. It is common to run fstrim in the background using cron jobs or systemd timers.
It is important to note that fstrim requires a filesystem and a storage device that support the discard or trim functionality. Popular filesystems like ext4, XFS, and Btrfs, along with modern SSDs, generally support this feature.
Running fstrim too frequently may not yield any significant benefits and could potentially impact the drive's lifetime. It is crucial to strike a balance between running fstrim frequently enough to maintain performance and minimizing unnecessary wear on the drive.
One can verify if their filesystem supports the discard operation by checking the /etc/fstab file or using the tune2fs command on ext4 filesystems.
Using fstrim command with the --verbose option allows you to see the progress and details of the trimming process.
Overall, fstrim is an essential utility for maintaining the performance and longevity of solid-state drives and flash-based storage devices by discarding or trimming unused blocks.
List of commands for fstrim:
-
fstrim:tldr:0503f fstrim: Display statistics after trimming.$ sudo fstrim --verbose ${-}try on your machineexplain this command
-
fstrim:tldr:9bff1 fstrim: Trim unused blocks on all mounted partitions that support it.$ sudo fstrim --alltry on your machineexplain this command
-
fstrim:tldr:9caad fstrim: Trim unused blocks on a specified partition.$ sudo fstrim ${-}try on your machineexplain this command