13

I noticed that manual seldom invocations of fstrim -av take a lot of time (over 10 minutes) and report a lot of free space to the SSD:

# /usr/bin/time -p fstrim -av
/boot/efi: 503,2 MiB (527671296 Bytes) auf /dev/sda1 getrimmt
/: 377 GiB (404832960512 Bytes) auf /dev/sda2 getrimmt
real 691.65
user 0.00
sys 4.90

This makes me think that for whatever reason, the free blocks are not reported by the operating system automatically despite of the discard flags in /etc/fstab. So, I wish to go sure and get fstrim -a executed regularly; I'm ok with each computer start, each day, each week, or once a month. What's the best way to arrange this schedule automatically; in other words, into which script file do I add this call?

1 Answers1

18

Your system by default is setup to do this using systemd. Check the status of the timer:

systemctl status fstrim.timer

By default, it is set to run fstrim -A once every week, as you can see in the output of:

systemctl cat fstrim.service

There is no use to do this more than once a week, expect for extreme usage with lots of file deletes, moves, etc., where more frequent trimming may be needed.

This actually answers also your question: you can have any job setup to run automatically using systemd. You still can use the "old" approach using crontab, which still is available by default on Ubuntu.

If you know what you do, you can edit the service.

vanadium
  • 97,564