Skip to content

Instantly share code, notes, and snippets.

@diffficult
Created August 2, 2020 09:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diffficult/b4428833e64f5863a3e1256e6c9cbfee to your computer and use it in GitHub Desktop.
Save diffficult/b4428833e64f5863a3e1256e6c9cbfee to your computer and use it in GitHub Desktop.
Proper TRIM setup on your system

TRIM on your Linux System

⚠️ WARNING ⚠️

DO NOT ENABLE BOTH PERIODIC TRIM AND CONTINOUS TRIM AT THE SAME TIME

ALSO DEBIAN, REDHAT AND OTHERS HIGHLY RECOMMEND TO DITCH CONTINUOS TRIM TO KEEP YOUR SSD HEALTHY AND THERE'S NO GOOD REASON TO HAVE IT RUNNING ON YOUR SYSTEM.


🖥️ TRIM

Most SSDs support the ATA_TRIM command for sustained long-term performance and wear-leveling.

As of Linux kernel version 3.8 onwards, support for TRIM was continually added for the different filesystems.

File System Continous TRIM Periodic TRIM
Btrfs Yes Yes
Ext3 No ???
Ext4 Yes Yes
F2FS Yes Yes
JFS Yes Yes
NILFS2 Yes Yes
NTFS-3G No Yes
VFAT Yes Yes
XFS Yes Yes

Just in case verify TRIM support with the following command

$ lsblk --discard

Preparing your system to enable Periodic TRIM

In order to do so, you need to also check that you are not currently using Continuos TRIM. To do so, check your fstab file.

For Example

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
#
UUID=YOURUUIDFROMYOURDRIVEHERE swap swap defaults 0 0
UUID=YOURUUIDFROMYOURDRIVEHERE / ext4 defaults,noatime,discard 0 1
UUID=YOURUUIDFROMYOURDRIVEHERE /boot ext4 defaults,noatime,discard 0 0
/dev/mapper/home /home ext4 defaults 0 0

Notice the discard flag after each affected partition/drive. That means you are currently using Continuos TRIM. to disable it, just delete the discardflag and save your fstabfile.

Enabling Periodic TRIM

To turn Periodic TRIM on, just enable the fstrim.timer service which in turn will run the fstrim.service once a week.

Just run the follow command:

$ systemctl enable fstrim.timer

To check if it is enabled, run:

$ systemctl status fstrim.timer | grep enabled

And later on to check it is properly running, check the logs to review the last time TRIM run:

$ journalctl -u fstrim

For more information related to TRIM you should check the wiki.


Source:

  • The Arch wiki

  • some reddit post on the archlinux subreddit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment