SSD: how often should I do fstrim?

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.

Asked By: marmistrz


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.

Answered By: frostschutz

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
Answered By: reducing activity
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.