Skip to content

Solid State Drive

Usage

TRIM

What Is TRIM

The TRIM command informs the SSD which blocks are to be considered not in use (e.g. deleted files) and to perform garbage collection in the background. This will improve the endurance and performance of the drive.

Most solid state drives (SSDs) now support TRIM command.

The Linux kernel added TRIM support in v3.8. Ensure the desired file system/RAID being used supports TRIM.

Warning

Data loss may occur if drive does not support TRIM.

Verify TRIM Support

Choose one of the following methods to verify for TRIM support.

  • List block devices (lsblk).

    $ lsblk --discard
    
    NAME   DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
    sda           0        0B       0B         0
    ├─sda1        0        0B       0B         0
    ├─sda2        0        0B       0B         0
    ├─sda3        0        0B       0B         0
    └─sda4        0        0B       0B         0
    sdb           0      512B       2G         0
    ├─sdb1        0      512B       2G         0
    └─sdb2        0      512B       2G         0
    sdc           0      512B       2G         0
    sdd           0        0B       0B         0
    sr0           0        0B       0B         0
    

    Note

    Ensure the values of DISC-GRAN (discard granularity) and DISC-MAX (discard max bytes) columns have a non-zero value (TRIM support).

  • Get device parameters (hdparam).

    # hdparm -I /dev/sda | grep TRIM
    
    *    Data Set Management TRIM supported (limit 8 block)
    

    Note

    The output may vary depending on the different types of TRIM support. See Wikipedia:TRIM#ATA for more information.

Automate Periodic TRIM

Arch Linux

  1. Install Arch Linux package to get "fstrim.service" and "fstrim.timer".
    # pacman -Sy util-linux
    
  2. Enable fstrim timer.

    # systemctl enable fstrim.timer
    

    Note

    By default TRIM is run weekly.

    Note

    Refer to "journalctl" to see the units activity and status.