Tuning Solid State Drives in Linux

There are a few guides out there with tweaks on how to make your solid-state drive (SSD) run faster or last longer in Linux.  While researching TRIM support in SSD firmware and the Linux kernel, I wasn’t able to find all the information I needed in one place.  Here is a guide I put together based on my experiences, which will hopefully be helpful to some other people in the same situation

1. Filesystem Choice – ext4 without journaling

A lot of the older SSD+Linux guides recommend using the ext2 filesystem because it avoids the extra writes of a journaling filesystem like ext3 or ext4, which will extend the life of your drive.  With the advent of TRIM support (see below), ext2 is probably not the best choice.  Yes, TRIM commands can be run on ext2 filesystems, but with two drawbacks:

  1. Ext2 only supports offline TRIM – In other words, the filesystem must be mounted read-only.
  2. You must manually execute the TRIM commands using hdparm, or its wrapper script wiper.sh.

Ext4 filesystems, on the other hand, don’t have these restrictions, allowing the operating system to take care of all the trimming for you behind the scenes.  Since the journaling function can be disabled on ext4 filesystems, it’s probably a better choice than ext2.  Just make sure you realize that without a journal your filesystem is more susceptible to corruption and data loss if it is not cleanly unmounted (if the power goes out, for example).  But since you’re reading this you probably are willing to take that chance in order to extend the life of your drive.

So how do you disable the ext4 journal?  First, the removal of the journal cannot be done on when the filesystem is mounted.  So if you want to disable the journal on the drive containing your operating system (which is most likely the case), you’ll need to boot from another drive.  I use Arch Linux, and the Arch install disk works fine for this, as does the Ubuntu live CD.  Since the tools needed to modify filesystems are pretty much standard issue, just about any Linux distribution live CD should work.

Once you’ve booted from your alternate drive, open a terminal and get to a root prompt (or preface the following commands with sudo, if that’s the way you roll).  Assuming the ext4 partition that we want to remove the journal from is /dev/sda1, you would issue the following command:
tune2fs -O ^has_journal /dev/sda1
Then, it’s a really good idea to run a filesystem check:
e2fsck -f /dev/sda1
I’ve read some reports of filesystems not mounting if the second step is not done, so don’t skip it – since you have a solid-state drive, a fsck runs extremely fast anyways.

Now restart the computer, booting from the solid-state drive containing the ext4 partition you just de-journaled.  Open a command prompt and run:
dmesg | grep EXT4
If all went well you will see the following message from the boot process:
EXT4-fs (sda1): mounted filesystem without journal
If you ever want to add the journal back on, just run the steps above, but remove the caret (^) from the tune2fs command.



Pages: 1 2 3

44 Comments

  1. nhasian says:

    your article didnt mention how to align the drive

    [Reply]

    admin Reply:

    I know – sorry about that. When I was doing research on SSDs, aligning the drive partitions is one thing I missed.

    I hope to have a section about partition alignment posted here soon.

    [Reply]

  2. [...] The SSDs-with-Linux thread. Pasting this link for reference: Tuning Solid State Drives in Linux | cptl.org Using the following since apparently Lucid has "discard" option backported now for TRIM [...]

  3. djfake says:

    Very helpful, and will tip me into the direction of buying a SSD. What about aligning? Did you do that?

    [Reply]

  4. [...] are so new and there isn't much long term evidence of what is truly the best way to go. FWIW, I wrote up a guide of everything I did to tune my SSD, in case anyone is interested in what I [...]

  5. Thomas says:

    What about the discard mount time option ?

    I read that TRIM is deactivated by default on ext4 and that you need to pass the discard option to mount (or in fstab) ?

    [Reply]

    admin Reply:

    Yes, this is explained in the article. Maybe you missed pages 2 & 3? Look between the article and the comments section.

    [Reply]

  6. Will C. says:

    Nice article, but as said earlier no mention of alignment of partitions with SSD erase block boundaries.

    here is Ted Tso’s (kernel maintainer of ext4 fs) take on this matter:

    http://es.linuxfoundation.org/news-media/blogs/browse/2009/02/aligning-filesystems-ssd%E2%80%99s-erase-block-size

    (his original blog seems to be down right now)

    [Reply]

  7. ssd says:

    [...] slack66 thanks for replying! sorry can you teach me step command how to enable trim in fstab? http://cptl.org/wp/index.php/2010/03…ives-in-linux/ It's on page [...]

  8. tosehee says:

    Having an align article would make this a really useful blog for all Linux + SSD users.

    I know I will use it right off.

    Great work so far.

    [Reply]

  9. [...] Gex: you might find the following useful: Tuning Solid State Drives in Linux | cptl.org Reply With [...]

  10. svg says:

    re: Firefox cache. No need to tmpfs it.

    about:config…

    browser.cache.disk.enable false
    browser.cache.disk.capacity 0
    browser.cache.offline.enable false
    browser.cache.offline.enable 0
    browser.cache.memory.enable true (default)

    about:cache to verify that nothing is being written to disk (memory only).

    These are the settings I use and they are working just fine.

    [Reply]

    admin Reply:

    True. The difference is that your setup is not storing any cache. Using tempfs allows you to use cache, but it is not saved during a reboot (since it is stored in volatile memory).

    [Reply]

  11. dexgeh says:

    I just followed your guide.
    For changing the default scheduler to noop, I suggest to put the elevator parameter to the kernel at boot time (in grub), instead of editing rc.local (that can be overwrited during system update).

    http://www.wlug.org.nz/LinuxIoScheduler

    great guide anyway. thx

    [Reply]

    admin Reply:

    You’re right, it can be done in the bootloader. I like to put it in my rc.local, because I use rc.local for any bootup commands added by me. I also have my firewall script, my hdparm commands, etc in there. I like to have them all in one place.

    FYI, if you are compiling your own kernel you can also set the default scheduler in the kernel .config file.

    [Reply]

  12. DC says:

    nodiratime is another option to add to reduce unnecessary writes.

    [Reply]

    admin Reply:

    noatime means that last accessed timestamps are not written, ever.
    nodiratime means that last accessed timestamps are not written on directories, but are still written to files.

    If you specify noatime, that includes files and directories too. There is no reason to specify nodiratime if you have already specified noatime.

    http://lwn.net/Articles/245002/

    [Reply]

  13. Thomas Colliers says:

    This is great info. Thanks a lot!

    [Reply]

  14. Re: Using NOOP on an SSD.
    I would worry that the lack of write ordering in NOOP would mean *more* writes to the SSD, since only adjacent requests would be merged. The other schedulers would re-order all the outstanding writes and merge all the adjacent requests.

    [Reply]

    admin Reply:

    I’m not sure what you mean by this. NOOP is just a first-in first-out disk queue, so it doesn’t try to reorder the disk writes based on the sector of the disk that is to be written to. I don’t think any of the schedulers will increase or decrease physical writes, it’s only the ordering of the writes that is affected.

    [Reply]

    Corley Reply:

    Ian! D. Allen seems to be under the impression that gathering write operations will help decide where they are allocated to the drive.

    The destination of gathered write operations is predetermined, the gathering allows them to be re-ordered to reduce the required seek times onto a spinning disk. The actual outcome of addresses filled will be the same for any block device.

    [Reply]

    Some guy Reply:

    The addresses filled will be the same, but with another scheduler there will be fewer write operations. Gathering several writes to the same erase-block can be a big help for drive life (otherwise, the SSD controller may read the block, modify a small part, rewrite it, and repeat for each small write)

  15. Jason says:

    What about AHCI in BIOS? Will trimming work in SATA mode too?

    [Reply]

  16. rudolf says:

    question is, does this also work with encrypted partitions?

    [Reply]

  17. [...] wpis to w dużej mierze tłumaczenie tego artykułu: Tuning Solid State Drives in Linux, jednak pozwoliłem sobie dodać kilka dodatkowych informacji i wniosków do jakich doszedłem [...]

  18. MonthOLDpickle says:

    When I goto edit the fstab I use gksu edit /etc/fstab
    Looking for /dev/sda1 / ext4 defaults I don’t see that.. I see the word ext4 but non that you refer too..also I see some that says errors-forgot-ro.

    Any help?

    [Reply]

    admin Reply:

    /dev/sda1 is just an example. Your system may be partitioned differently, so you will need to know which partition(s) on your SSD you want to enable trim on.

    I would recommend reading up on the format of the fstab file. If you aren’t sure about what you’re doing, you could easily make your system unbootable.

    [Reply]

  19. [...] countless sites that describe how to enable TRIM, but I found one especially helpful. This site was cptl.org. Much of this post was based upon information on those pages but specifically directed at the XBMC [...]

  20. deniro says:

    On my intel ssd, using slackware 13.37 it seems that trim is not working when disabling journaling on the ext4 partition.

    I checked that with hdparm. Can anyone confirm that disabling journaling affects trim support?

    Because with my ssd trim worked with journaling, and without it didn’t.

    [Reply]

  21. [...] Tuning Solid State drives in Linux [...]

  22. JOhn says:

    May be useful for some people: ext4 without journal requires Kernel version 2.6.29

    [Reply]

  23. Dima says:

    Thanks for sharing this valuable information!

    [Reply]

  24. [...] discard (trim) support 和 Tuning Solid State Drives in Linux [...]

  25. [...] stopping the EXT4 file system journaling, which speeds up the system and saves writes to the disk. This blog gives the details on the first page, and the other pages cover  the stuff in the HowToGeeks [...]

  26. [...] Welcome to LQ! Look at http://cptl.org/wp/index.php/2010/03…ives-in-linux/ Plus do not forget that 'TRIM' is now supported in new [...]

  27. mykhi says:

    awesome article, really well explained.

    [Reply]

  28. [...] response Hi, Old reference that is still useful to take notice: http://cptl.org/wp/index.php/2010/03…ives-in-linux/ I like the Patriot forum & Intel Support Community. Onebuck SSD participation threads that [...]

Leave a Reply