26

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.

30

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.

  • 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 '15 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. – frostschutz Jul 24 '15 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 '15 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. – frostschutz Jul 24 '15 at 8:29
  • "using fstrim weekly or even monthly is completely fine" can you consider adding source? I encountered claim that it should be done daily (and both claims have no sources whatsoever) – Mateusz Konieczny Jan 24 at 11:15
4

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.
  • 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 at 11:27
  • 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). – frostschutz Jan 25 at 0:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.