Tuning ext4 for performance with emphasis on SSD usage

The obligatory disclaimer: The more performance you gain, the more data integrity you loose! But if you want to tune something like a file system, I strongly assume that you know what you are doing :) These tips apply to all major Linux distributions like Fedora/Red Hat, OpenSUSE, and Ubuntu that are already using ext4 or are going to make ext4 their default file system.

As write operations on Solid State Disks (SSD) are expensive the tips below are focused on SSD usage but also apply to HDD usage as well.

My Ubuntu 9.04 Jaunty /etc/fstab after a fresh installation:
[...]
UUID=d818ddf9-ff01-e21a-a67d-3ceab43a9e2b / ext4 relatime,errors=remount-ro 0 1
UUID=0d339122-74e0-e0ea-805a-7879b1fa3172 /home ext4 relatime 0 2
[...]
My tuned Ubuntu 9.04 Jaunty /etc/fstab:
[...]
UUID=d818ddf9-ff01-e21a-a67d-3ceab43a9e2b / ext4 noatime,barrier=0,nobh,commit=100,nouser_xattr 0 1
UUID=0d339122-74e0-e0ea-805a-7879b1fa3172 /home ext4 noatime,barrier=0,data=writeback,nobh,commit=100,nouser_xattr 0 2
[...]

data=writeback

The default data mode is ordered. This mode provides only meta-data journaling which is similar to the default data mode in ReiserFS, XFS, and JFS. Enabling this option on the root partition, caused an error during boot time. So enable this option only on non-root partitions!

nobh

Implies data=writeback; Avoids buffer heads to data pages association.

barrier

The default value is barrier=1 (activated). Deactivating write barriers in the jbd code will improve the performance. If you don't have a battery-backed storage environment, you should not deactivate this mount option.

noatime

Deactivates the file access time modification which is basically a write operation that should be avoid on SSDs.

relatime

This is a faster alternative to the atime (default) option. You can set it, if you need the file access times to be set. However it is still responsible for write operations which should be avoid -- especially on SSDs.

commit

Increases the commit/write interval (default: 5s). Actually it is a sync operation between data and meta-data which is an important data-safety feature.

nouser_xattr

Disable Extended User Attributes if you don't need them. If you are using a desktop setup at home (or in a small office network), you may not need this feature.

errors=remount-ro

Many distribution add also this boot option. In fact this boot option can be omitted without any hesitation as this boot option is set by default.


If throughput is a major issue and latency not a big problem, you may also increase the min_batch_time option value which defaults to 0 microseconds.


The main source for these tips was the kernel reference documentation paper of the ext4 file system.

Note:
You also may be interested in how to tune ext3 for performance or how to use a swap file instead of a swap partition.

Update:
With these pretty aggressive performance settings my data has already survived a couple of crashes (incl. sudden power outages). So I will keep these settings :)

Update 2 (thanks to an anonymous comment!):
To enable the data=writeback on the root (mounted on /) partition boot your machine in recovery mode and execute:
tune2fs -o journal_data_writeback /dev/sdXY
Afterwards you can add the data=writeback option to your root partition in your fstab file.

Comments

  1. Anonymous25.4.09

    i guess it's:
    "ext4 noatime,barrier=0,data=writeback,nobh,commit=100,nouser_xattr 0 2"

    not:
    "noatime,barrier=0,data=writeback,nobh,commit=100,nouser_xattr ext4 0 2"

    notice the params before ext4

    anyway, thanks

    ReplyDelete
  2. Anonymous25.4.09

    Right, thanks! I have fixed this error.

    ReplyDelete
  3. hi!!! thanks for this tips, Just a question:
    the option Data=writeback is like the default data mode on systems like ReiserFS. but i'm a bit worry about this because File system ReiserFS is a bit dangerous for the SSD. I'm right?

    The fact is that I have an EeePC 901 and want to uso EXT4 but I don't want to broke my ssd disk. What do you suggest me?

    thanks for all!

    ReplyDelete
  4. Anonymous27.4.09

    I have a 128GB SSD with Ubuntu on it running with these settings on my notebook. My system survived power outages and crashes without any data loss. However I would recommend you to backup your setup before you test these settings on your system.

    ReplyDelete
  5. Anonymous28.4.09

    Thanks for this. I have Ubuntu 9.04 running on ext4 on an SSD-equipped Dell X1.

    If you want to enable data=writeback on the root partition, you have first turn this journaling model on using tune2fs.

    # tune2fs -o journal_data_writeback /dev/sdxx

    Make sure you have dropped to single-user mode and mounted the fs readonly (or better, boot from a live CD and make the change from there).

    Provided you have done this and changed fstab, your system should boot no problem.

    I have also mounted /var/log as tmpfs to stop the logs writing to the disc all the time.

    A

    ReplyDelete
  6. Anonymous2.6.09

    should I also run:
    hdparm -W1 /dev/sda
    with data=writeback as suggested here
    http://ubuntuforums.org/showpost.php?p=6418463&postcount=10
    or not?

    Thanks!

    ReplyDelete
  7. Anonymous2.6.09

    My default setting was 0 (deactivated).

    hdparm -W1 /dev/sda may additionally boost the performance. Eventually you have to set -W1 in /etc/hdparm.conf because the system may reset this setting after reboot.

    ReplyDelete
  8. Anonymous15.5.10

    is not need a grub modification?? And then give sudo update-grub like for the ext3 file system tuning???
    I think so ....and I don't know how to change the grub2 !!!

    ReplyDelete

Post a Comment

Popular posts from this blog

NetBeans 6.1: Working with Google´s Android SDK, Groovy and Grails