During the installation process, we encrypted the entire SSD and then we set the LVM inside the encrypted disk. Then we set the LVM to hold the different partitions /, /home, and etc.
We now have a SSD that looks like the following image.
To trim the SSD properly we’ll need to enable it on all three layers - LUKS, LVM, and filesystem.
Install the util-linux package and enable the fstrim.timer service. This service will activate the fstrim.service when necessary.
sudo pacman -S util-linux sudo systemctl enable fstrim.timer # optional step, if you want to run fstrim.service sudo systemctl start fstrim.service
The second step is to configure the LVM layer. Edit the /etc/lvm/lvm.conf by changing the issue_discards from 0 to 1.
The last step is to configure the root filesystem by adding the right kernel parameter to the bootloader configuration.
Edit the /boot/loader/entries/<your-entry>.conf file and append :allow-discards at the end of the cryptdevice option and append rd.luks.options=discard at the end of the options line.
Your conf file should look like the following:
title Arch Linux Encrypted via UUID linux /vmlinuz-linux initrd /initramfs-linux.img options cryptdevice=UUID=<DEV_UUID>:vgroup00:allow-discards root=UUID=<UUID> quite rw rd.luks.options=discard
Note: DEV_UUID is the UUID of the device containing the LUKS partition. LVM_VOL_UUID is the UUID of the LVM root volume. You can get those UUIDs using the command blkid.
For more information, please refer to the Arch Linux wiki