Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

share|improve this question
add comment

3 Answers 3

I'm no storage engineer and I have related worries of my own, but I can make a possibly useful suggestion on scheduling. I'm pretty confident TRIM doesn't cause any worrisome wear on the SSD. It's just housekeeping that your disk will have to undergo eventually, before it can start recycling blocks. The best schedule for batch TRIMming would depend on usage; a function of writing frequency and free space, I should think. That in mind, I would unplug the cron job and fstrim -v by hand for several days.

The trick I think is to craft a schedule where batch TRIM prepares the SSD for writing before used blocks have to be recycled in order to fulfill a normal write operation, thus hurting performance. Wait 24 hours and fstrim. If it claims to have trimmed far fewer blocks than were free space, you're probably well served batch TRIMming less often than that.

share|improve this answer
add comment

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.

share|improve this answer
add comment

I prepared fstrim demon https://github.com/dobek/fstrimDemon

It seems to be more reliable to execute fstrim based on up time then cron table. Have fun.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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