35

There are different sources and different practices are suggested. I found the following proposals how often one should run fstrim.

  • run weekly by cron
  • run daily by cron
  • run at each boot

What is the optimal option and why? Ubuntu 14.04 uses the first option by default.

2 Answers 2

39

TRIM does at least three things:

  1. minimize write amplification
  2. prevent long-term performance degradation
  3. irrecoverably delete your data

Now it depends where your priorities are.

For 1), you should not be using fstrim at all, but make use of the discard option of your filesystem. Only if everything is trimmed instantly will the SSD stop copying no longer needed bits of data around. In practice though, it has been shown that preventing write amplification is not that important since SSD are fine with lots of writes.

For 2), using fstrim weekly or even monthly is completely fine. There is no need to use instant discard, or to trim daily - that would be a short-term measure, but this is about keeping the SSD happy in the long-term. But it also depends on your usage: if your filesystem is always full and sees lots of writes, you might need to trim more regularly than if you tend to have lots of free space and not that much writes in your filesystems.

For 3), you should not be using any kind of trim at all. Basically if you expect to be human, making errors, having accidents - like you just deleted your photo collection, whoops - recovery tools like photorec won't work after TRIM because with TRIM everything is gone forever.

From a pure data recovery point of view, SSD is a huge headache. There's too much trim happening in Linux, even without asking you (mkfs implies trim, lvremove/lvresize/... might if issue_discards, some partitioners might be having ideas, ...). Suddenly previously reversible actions become irreversible, all for the sake of getting a few more points in some filesystem benchmark...

If you decide on fstrim you should know where the cron job is located so you can disable it when you have an accident, that way you get a compromise between 2) and 3). In general with SSD you should make sure you have good backups, they are even more important than with HDD since you have lesser chance of recovery on SSD.

8
  • Isn't the performance degradation strictly bound with the write amplification? I read that discard is suboptimal performance-wise: blog.neutrino.es/2013/… and patrick-nagel.net/blog/archives/337
    – marmistrz
    Jul 24, 2015 at 8:04
  • 1
    It's related, of course, but strictly bound? TRIM helps performance even in cases that do not involve write amplification. If you overwrite a full erase block worth of data there is no write amplification (you have to write the whole thing either way). But if there are no free blocks the SSD has to erase one first and erasing is considerably slower than writing an already erased block. Jul 24, 2015 at 8:19
  • And how many writes are fine? I'd rather use the drive for a long time. (5 years would be great) How big is the write amplification when trimming weekly?
    – marmistrz
    Jul 24, 2015 at 8:20
  • 1
    Google ssd endurance test, there are several. Most SSD can handle more writes than you will ever need (outside of heavy duty database server or something). Of course it may still fail for various reasons, there is no reliable storage, you have to make backups in any case. Jul 24, 2015 at 8:29
  • 1
    @PeterT. discard=async is essentially still the same as instant discard (delayed by seconds/minutes, not days/weeks/months). It's an implementation detail of btrfs, other filesystems like XFS may be using async discard anyway, without providing a separate mount option. So there is no difference other than performance impact of the discard operation itself. fstrim also has a few performance related options, you can limit it to a specific region or set a minimum size, that way fstrim finishes faster (at the cost of not trimming everything). Apr 2, 2022 at 8:47
7

man fstrim in Ubuntu 16.04 has

Running fstrim frequently, or even using mount -o discard, might  nega‐
tively affect the lifetime of poor-quality SSD devices.  For most desk‐
top and server systems the sufficient  trimming  frequency  is  once  a
week.
2
  • 1
    +1 continuous trim is bad, source for it easy searchable, so, depending on ssd usage and hardware quality you should choose daily or weekly. If using anacron it will execute it correctly not depending of reboots and power off, so each boot option should be used in combination with daily or weekly or turned off.
    – LeonidMew
    Jan 24, 2019 at 11:27
  • 1
    FYI, the paragraph was added to the manpage on April 10, 2014 following this mailinglist discussion regarding adding daily fstrim as systemd timer service (also changed to weekly). Jan 25, 2019 at 0:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .