TRIM is an maintenance and optimisation operation for SSD drives that "that enables an operating system to inform a NAND flash solid-state drive (SSD) which data blocks it can erase because they are no longer in use. The use of TRIM can improve the performance of writing data to SSDs and contribute to longer SSD life." [techtarget.com].
On Arch-based distributions the util-linux package has a systemd service and timer which, when enabled, it uses fstrim to run TRIM operations on your primary drive weekly.
Things are a little more complicated if you drive is LUKS encrypted. The Arch wiki has a great writeup on enabling (or allowing) periodic TRIM on a LUKS partition. Note TRIM isn't allowed by default as it does have potential implications with regards to security etc. (which you can read about here).
We'll cover the following here:
Enabling fstrim.timer on Arch-based distros (like Arch, Manjaro, etc.)
Execute the following to enable and start the
fstrim.timer which will execute TRIM weekly:
Allowing TRIM operations on a LUKS partition
As mentioned previously, by default LUKS does not allow TRIM operations to passthrough to the encrypted drive. If you want to execute periodic TRIM on a LUKS partition, first enable the
fstrim.timer as above.
I assume here that you have a working root partition that is LUKS encrypted, and you're using a
systemd based distro. We'll need to modify our grub config and append two parameters:
- we need to append
cryptdeviceargument on the
GRUB_CMDLINE_LINUX_DEFAULTline of grub;
- add the kernel parameter
Open /etc/default/grub in your favourite text editor (here we use vim):
And modify the
GRUB_CMDLINE_LINUX_DEFAULT line as above. It should end up looking similar to:
Note your line might have extra arguments like
security=apparmor etc. This is okay, just add the
rd.luks.options=discard in the appropriate place.
Save your changes and update grub:
Now reboot and check that TRIM is allowed on your LUKS partitions.
Check fstrim is allowed on LUKS paritions
Check with lsblk
An easy way to check that TRIM operations are enabled for your LUKS partition is to use lsblk:
It should print out something like this:
Non-zero entries (like above) in the
DISC-MAX columns means TRIM is enabled/allowed.