Ubuntu – Automatic TRIM vs. manual TRIM

ssdtrim

I am currently trying to find out how to trim with my new TP and was wondering about the difference of manual/online trimming.

Here is my setup:

ThinkPad T430s with SSD Samsung 830, 128GB and Xubuntu 12.10, here are some outputs to check if trim will work on my system (got these from here: http://wiki.ubuntuusers.de/SSD/TRIM)

root@eike-tp:~# sudo hdparm -I /dev/sda | grep -i TRIM
   *    Data Set Management TRIM supported (limit 8 blocks)

First, I tried the online trimming: How to enable TRIM?

my fstab with discard inserted:

UUID=d6c49c17-a4f1-466c-9f7e-896c20db3bba /  ext4  discard,noatime,errors=remount-ro  0  1
# swap was on /dev/sda5 during installation
UUID=a0322f5f-c6c1-4896-863f-668f0638d8cf none  swap  sw  0   0
tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0

I tried to test if it works (but I don't get any zeroes when I try it with /dev/sda), but found out that this method is only possible with SSD type 2 and I seem to have type 3. So I don't know if it works or not.

The Ubuntuwiki (first link) recommends manual trimming, so I set up a daily cronjob instead of discard:

#!/bin/sh
LOG=/var/log/batched_discard.log
echo "*** $(date -R) ***" >> $LOG
fstrim -v / >> $LOG

the wiki article suggests weekly or daily. Now to my questions:

How often executes the automated trim?
How often is recommended?
Online vs. manual trimming?

Thank you for your help

Best Answer

The difference between automatic and manual trim is that automatic trim (using the discard mount option) trims freed blocks on sync after any file is deleted, whereas manual trim (using fstrim) trims all the free space at once.

Testing

One way you could test whether automatic trim is working would be to create and delete a large file:

user@host:/somewhere$ dd if=/dev/urandom bs=1M count=100 of=bigfile
user@host:/somewhere$ sync
user@host:/somewhere$ rm bigfile
user@host:/somewhere$ sync

If automatic discard is working, manually trimming again won't trim many blocks, since they should have already been trimmed. Run sudo discard -v on your filesystem and see how many blocks are trimmed.

Recommendation

As for which is recommended: In my experience, automatic trim kills performance. However, this is probably hardware-dependent; it may be fine on your drive.

If you're using manual trim, as for how often, think about the rate at which you write data in your typical workload, compared to the amount of free space on your SSD. You want to trim sufficiently often, before your disk fills up with deleted data. If your SSD is mostly free space or your disk workload is light, trimming occasionally (weekly or even longer) should suffice. If your SSD is mostly full or you e.g. edit video files frequently, you'll need to trim more often.