You are not logged in.
Hey,
so I thought I had this set up correcttly but now I'm not sure anymore. The Arch Wiki is not 100% precise on that matter (or maybe I read it wrong, but I did read it twice).
So it's known that periodic TRIM via fstrim.timer is the way to go. Which is what I want. But the question is, how do you enable this correctly?
Sure, systemd unit 'fstrim.timer' needs to be enabled. But then I've read that fstrim needs to know which SSDs should actually be TRIMmed. And the way to "mark" those SSDs for trimming is to use the "discard" mount option. But when using the "discard" mount option, it would configure the partition/drive for continous TRIM as well or instead. Which is not what I want of course.
So maybe someone can clarify what steps exactly are needed to enable fstrim.timer for SSDs, and not accidentally enable continous TRIM in the process.
Also, I use LUKS encrypted btrfs partitions (no LVM or RAID) on those SSDs which adds another layer on top. Currently, I use the kernel parameter
rd.luks.name=<UUID OF LUKS CONTAINER>=cryptroot rd.luks.options=discardand in /etc/crypttab I have specified the option
discardas well. But I haven't specified
discard in my /etc/fstab so far. And I've enabled fstrim.timer. Is this correct, or do I need to change something, to just have periodic TRIM via fstrim.timer working as intended?
Thanks.
Last edited by m6x (2021-11-05 12:59:03)
int pi = 3;
Offline
lsblk -Dwill tell you if trim/discard is enabled on the drive.
here is an example from one of my machines:
lsblk -D
NAME DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
sda 0 512B 2G 0
├─sda1 0 512B 2G 0
└─sda2 0 512B 2G 0
sdb 0 0B 0B 0
├─sdb1 0 0B 0B 0
└─sdb2 0 0B 0B 0as you can see sda is the ssd and sdb is a hdd, if your ssd has all zeros then its not setup right.
you can also check to see if fstrim is working:
systemctl status fstrimor
journalctl -u fstrimOffline
Yeah, it's non-zero for the SSDs. So that works. Still doesn't explain whether I need the "discard" option or not. Well, I guess I'll first try without the "discard" option since that seems to (also) enable continuous trim. And then I'll check if fstrim works as intended. If fstrim works without the "discard" option, I guess it's set up correctly. If not, my question still stands.
int pi = 3;
Offline
discard in fstab is instant discard - whenever a file is deleted or truncated. fstrim.timer is periodic discard - you can see if it shows up in systemctl list-timers. you could use both (instant discard and run fstrim anyway just in case something was missed). or you could use neither. if you don't have much write activity, or don't care too much about write performance, there is not much point to it either. you could also run simply fstrim manually when you feel like it.
if you don't have a backup, consider disabling trim until you have one... ![]()
Offline
But then I've read that fstrim needs to know which SSDs should actually be TRIMmed. And the way to "mark" those SSDs for trimming is to use the "discard" mount option. But when using the "discard" mount option, it would configure the partition/drive for continous TRIM as well or instead.
I think this is the source of your confusion, when you mount a partition with the discard option it doesn't "mark" it for fstrim, mount(8) says that "If set, causes discard/TRIM commands to be issued to the block device when blocks are freed."
Also looking at the content of fstrim.service indicates that it doesn't need you to mark which partitions you want to TRIM:
$ systemctl cat fstrim.service
[Unit]
Description=Discard unused blocks on filesystems from /etc/fstab
Documentation=man:fstrim(8)
ConditionVirtualization=!container
[Service]
Type=oneshot
ExecStart=/usr/bin/fstrim --listed-in /etc/fstab:/proc/self/mountinfo --verbose --quiet-unsupported
PrivateDevices=no
PrivateNetwork=yes
PrivateUsers=no
ProtectKernelTunables=yes
ProtectKernelModules=yes
ProtectControlGroups=yes
MemoryDenyWriteExecute=yes
SystemCallFilter=@default @file-system @basic-io @system-serviceIt seems like fstrim simply goes through your fstab and /proc/self/mountinfo and then tells the kernel to issue TRIM on every partition it finds.
Offline
But then I've read that fstrim needs to know which SSDs should actually be TRIMmed.
https://wiki.archlinux.org/title/Solid_ … iodic_TRIM
The service executes fstrim(8) on all mounted filesystems on devices that support the discard operation.
(emphasis mine.)
--
saint_abroad
Offline
Thanks for clarifying.
Last edited by m6x (2021-11-06 10:17:53)
int pi = 3;
Offline