Weekly or daily TRIM for ssd?

it will enable the timer and the first run will trigger the trim service after the first week and scheduled weekly:

[22:31:54] joekamprad :: UNGEHEUER64  ➜  ~ » systemctl status fstrim.timer     
● fstrim.timer - Discard unused blocks once a week
     Loaded: loaded (/usr/lib/systemd/system/fstrim.timer; enabled; vendor preset: disabled)
     Active: active (waiting) since Mon 2021-11-01 20:31:29 CET; 2h 0min ago
    Trigger: Mon 2021-11-08 01:28:03 CET; 6 days left
   Triggers: ● fstrim.service
       Docs: man:fstrim

Nov 01 20:31:29 UNGEHEUER64 systemd[1]: Started Discard unused blocks once a week.
[22:32:05] joekamprad :: UNGEHEUER64  ➜  ~ » systemctl status fstrim.service
○ fstrim.service - Discard unused blocks on filesystems from /etc/fstab
     Loaded: loaded (/usr/lib/systemd/system/fstrim.service; static)
     Active: inactive (dead)
TriggeredBy: ● fstrim.timer
       Docs: man:fstrim(8)
1 Like

The way that timers work is when the timer is triggered, it executes the service of the same name. So the service should only run when the timer tells it to.

For testing purposes, you can run the service manually as @anon49550872 suggests above.

1 Like

UNGEHEUER64? :rofl:

You will have to additionally edit a couple of files.

  1. sudo nano /etc/default/grub
    add :allow-discards to the ‘cryptdevice=…’ entry

  2. sudo nano /etc/crypttab
    add discard to the options of your cryptdevice
    e . g. ... luks,discard

  3. periodically run fstrim or mount the filesystem with the discard option in /etc/fstab
    e. g. add discard to (btrfs) mount options (= continuous trim)

  • rebuild some stuff and reboot
    sudo grub-mkconfig -o /boot/grub/grub.cfg
    sudo mkinitcpio -p linux

  • verify whether the device actually was opened with discards by inspecting the dmsetup table output
    sudo dmsetup table
    should contain: allow_discards

2 Likes

Thx for all the answers folks!

I decided that I will not use TRIM for now. I’m going to disable the timer/service. If I ever feel like the performance of the drive is going down I will activate it later.

@2000: Thx for the guide :+1: But do you have any idea why it seems to work without those steps for @Erreffel1 ?

The Limiting the disk write actions of Firefox is actually something to consider.

If you have enough RAM and a decent Internet-connection put the network cache into RAM. Firefox writes into this cache constantly. If you watch videos FF is dumping all stream chunks into it just to delete them a few seconds later. Essentially the whole streams makes it through the disk cache without imho any benefit.

Session storage with hundreds of open tabs is an issue too, not because the SSD wears out but constant I/O spikes which may lead to micro-stuttering on less powerful systems. You don’t have to disable it, just increase it to a reasonable value, e.g. every three minutes instead of every 15 seconds.

PS: Personally I don’t trim or set-up weekly trimming if I feel fancy.

I always set Firefox / Librewolf like that:

user_pref("browser.cache.disk.enable", false);
user_pref("browser.sessionstore.interval", 1800000);

Defaults are insane for most modern systems, scratching disk like crazy :upside_down_face:

3 Likes

According to this info

Solid state drive users should be aware that, by default, TRIM commands are not enabled by the device-mapper, i.e. block-devices are mounted without the discard option unless you override the default.

So if @Erreffel1 didn’t set up the cryptdevice to explicitly allow discards (:allow-discards) or manually set up the luks2 device to persistently unlock with allow-discards as a default flag, I think that trimming isn’t actually working on his system. Simply activating fstrim in the underlying filesystem isn’t enough.

1 Like

Those are the good settings, yes… :+1:

1 Like