You are not logged in.

#1 2021-11-05 12:54:26

m6x
Member
From: Germany
Registered: 2020-04-01
Posts: 19

Clarification on continuous TRIM / periodic TRIM for SSDs

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=discard

and in /etc/crypttab I have specified the option

discard

as 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

#2 2021-11-05 14:11:25

jonno2002
Member
Registered: 2016-11-21
Posts: 868

Re: Clarification on continuous TRIM / periodic TRIM for SSDs

lsblk -D

will 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         0

as 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 fstrim

or

journalctl -u fstrim

Offline

#3 2021-11-05 15:43:32

m6x
Member
From: Germany
Registered: 2020-04-01
Posts: 19

Re: Clarification on continuous TRIM / periodic TRIM for SSDs

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

#4 2021-11-05 15:56:25

frostschutz
Member
Registered: 2013-11-15
Posts: 1,647

Re: Clarification on continuous TRIM / periodic TRIM for SSDs

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... wink

Offline

#5 2021-11-06 08:22:58

Ketsui
Member
Registered: 2018-04-16
Posts: 11

Re: Clarification on continuous TRIM / periodic TRIM for SSDs

m6x wrote:

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-service

It 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

#6 2021-11-06 08:55:19

sabroad
Member
Registered: 2015-05-24
Posts: 242

Re: Clarification on continuous TRIM / periodic TRIM for SSDs

m6x wrote:

But then I've read that fstrim needs to know which SSDs should actually be TRIMmed.

https://wiki.archlinux.org/title/Solid_ … iodic_TRIM

wiki wrote:

The service executes fstrim(8) on all mounted filesystems on devices that support the discard operation.

(emphasis mine.)


--
saint_abroad

Offline

#7 2021-11-06 09:44:09

m6x
Member
From: Germany
Registered: 2020-04-01
Posts: 19

Re: Clarification on continuous TRIM / periodic TRIM for SSDs

Thanks for clarifying.

Last edited by m6x (2021-11-06 10:17:53)


int pi = 3;

Offline

Board footer

Powered by FluxBB