I know that weekly TRIM is enabled by default from 14.10 onwards. Source: How to enable TRIM?
But running sudo nano /etc/cron.weekly/fstrim
returns an empty file. Also tail -n1 /etc/cron.weekly/fstrim
says that this file does not exist.
Running lsblk -D
returns non zero values for DISC-GRAN
and DISC-MAX
so TRIM is supported on my SSD. Is weekly TRIM actually enabled for my SSD or not?
I am using a Kingston SSD
From 18.04
fstrim
(discard unused blocks) is enabled to run weekly by default for all mounted filesystems on devices that support the discard operation.fstrim
is managed bysystemctl
, notcron
, and is defined by asystemd
service unit (fstrim.service
) and timer unit (fstrim.timer
)View configuration of
fstrim.service
:Note:
ExecStart=/sbin/fstrim
-av
Where:
-a
, Trim all mounted filesystems on devices that support the discard operation.-v
, Verbose execution. Output the number of bytes passed from the filesystem down the block stack to the device for potential discard.View configuration of
fstrim.timer
:View status of
fstrim.timer
:Start/Stop/Restart
fstrim.timer
:(does not change startup status)
Enable/Disable
fstrim.timer
:(add to/remove from startup, does not change current active status)
View journal entries for
fstrim.service
:View journal entries for
fstrim.timer
:Edit: Please read the comments, this answer mixes up two mechanisms!
Old answer
there is an important point which needs to be added to the answer of @Broadsworde to make it complete.
While on my laptop all the timers and services were enabled, the fstrim log entry was missing (only:
starting… stopping… reboot… starting…
etc.).Missing step
You might need to mark the file systems as discardable. If a file system is not marked as discardable, the trim will skip it[1].
To mark a filesystem as discardable, you have two options:
1. Option:
tune2fs
sudo tune2fs -o discard /dev/mapper/ubuntu--vg-root
This will set the discard option as default for my ext4 device. If you don't use encryption, try
/dev/sda
instead.2. Option:
/etc/fstab
Make sure to prepend or append the option
discard
to your existing mount options. For example like this:/dev/mapper/ubuntu--vg-root / ext4 discard,relatime,errors=remount-ro 0 1
Only after this the timer service will really do something.
Footnotes
TRIM
operation. But on linux, this is a file system flag. Still, the device the file system is running on needs to support theTRIM
operation. To see if your device supports it, use:sudo hdparm -I /dev/sda | grep -i TRIM
.