LinuxCommandLibrary

fstrim-all

Trim all mounted file systems on SSDs

SYNOPSIS

The functionality of fstrim-all is commonly achieved by invoking the fstrim command with the --all option:
fstrim --all [OPTIONS]

Alternatively, it is often managed by systemd services:
systemctl start fstrim.service
systemctl enable --now fstrim.timer

PARAMETERS

--all
    Performs the TRIM operation on all mounted filesystems that support it and are not explicitly excluded (e.g., via noauto-trim in /etc/fstab). This is the core of 'fstrim-all' functionality.

--fstab
    Restricts the processing of all filesystems to those defined in /etc/fstab. This option is commonly used in systemd units to ensure only relevant filesystems are trimmed.

--verbose, -v
    Prints detailed information about the progress and results of the TRIM operation for each filesystem.

--quiet, -q
    Suppresses output, showing nothing unless an error occurs. Useful for cron jobs or systemd services where verbose output is not desired.

--json
    Outputs information in JSON format, facilitating programmatic parsing and integration with other tools.

--dry-run, -n
    Performs a simulated TRIM operation without actually discarding any blocks. It shows what would be done, useful for testing configurations.

DESCRIPTION

fstrim-all conceptually represents the process of performing the TRIM operation on all mounted filesystems that support it. This is crucial for Solid State Drives (SSDs) and other flash-based storage devices. The TRIM command (also known as a 'discard' operation) allows the operating system to inform the SSD which data blocks are no longer considered 'in use' by the filesystem. When blocks are deleted by the user, the operating system simply marks them as free, but the SSD controller doesn't know this until explicitly told via TRIM.

By periodically performing TRIM, the SSD can internally erase these unused blocks, keeping its internal block management (garbage collection) efficient. This prevents 'write amplification' (where the SSD has to read, modify, and rewrite larger blocks than necessary) and helps maintain consistent performance over time, extending the drive's lifespan. Without TRIM, SSDs can experience significant performance degradation as they run out of pre-erased blocks.

While not a direct standalone command on most modern Linux systems, fstrim-all functionality is typically implemented via a systemd timer (fstrim.timer) that triggers a service (fstrim.service), which in turn executes the fstrim --all --fstab command weekly or as configured. This automates the process across all suitable filesystems, ensuring optimal SSD health without manual intervention.

CAVEATS

  • Requires SSD/Flash Storage: TRIM is only relevant for Solid State Drives (SSDs) and other flash-based storage devices. It has no effect on traditional Hard Disk Drives (HDDs).
  • Filesystem Support: The filesystem must support the TRIM operation (e.g., ext4, XFS, Btrfs, F2FS). Older filesystems or certain configurations may not be compatible.
  • Performance Impact: While beneficial in the long run, the TRIM operation itself can temporarily consume system resources and might cause a brief pause or performance dip, especially on very busy or fragmented filesystems, or if performed too frequently.
  • Root Privileges: Executing fstrim (and thus fstrim-all functionality) requires root privileges.
  • Not Always Needed with 'discard' Mount Option: If a filesystem is mounted with the discard option (e.g., /dev/sda1 /mnt/data ext4 defaults,discard 0 0), TRIM commands are sent to the drive immediately upon block deallocation. While this can provide real-time optimization, it might introduce minor latency for individual deletion operations. Periodic fstrim is still often recommended even with discard enabled, as it can catch blocks freed before discard was enabled or aggregate trims more efficiently.

HISTORY

The TRIM command was standardized as part of the ATA-8 ACS-2 specification to address the unique characteristics of flash-based storage. Linux kernel support for TRIM operations was introduced around version 2.6.33. Subsequently, the fstrim utility was developed and integrated into the util-linux package, providing a command-line interface for manual or scheduled TRIM operations.

In modern Linux distributions, the functionality associated with 'fstrim-all' evolved from traditional cron jobs (e.g., a script in /etc/cron.weekly/fstrim) to more robust and flexible systemd units. The introduction of fstrim.timer and fstrim.service in systemd allowed for standardized, event-driven scheduling of the TRIM operation across all relevant filesystems, making automated, periodic TRIM a common and recommended practice for systems utilizing SSDs.

SEE ALSO

fstrim(8), systemd.service(5), systemd.timer(5), mount(8)

Copied to clipboard