March 19, 2013

How to boost EXT4

Recently I tried some tweaks to boost the ext4 file system on my small download station (Pentium 3) and the most effective were:

  1. deadline scheduler
  2. noatime mount option
  3. set the journal data as writeback
Let's explain better:




1. Deadline scheduler

You can find a very good explanation of what a scheduler is  on the Wikipedia pages (for the lazies here!) so I'll only write about how to set on a debian/ubuntu machine.

as root (you can use the command sudo) on a terminal shell

# nano /etc/default/grub

you will see a lot of text but you must reach the line with the following text:

GRUB_CMDLINE_LINUX_DEFAULT="quiet"

and change it as follow:

GRUB_CMDLINE_LINUX_DEFAULT="elevator=deadline quiet"

press ctrl+o and ctrl+x (the first to save the file and the second command to exit nano)

now update the grub config file with the command

# update-grub

You now just need to reboot the computer


2. noatime mount option

Linux has a special mount option for file systems called noatime. If this option is set for a file system in /etc/fstab, then reading accesses will no longer cause the atime information (last access time - don't mix this up with the last modified time - if a file is changed, the modification date will still be set) that is associated with a file to be updated (in reverse this means that if noatime is not set, each read access will also result in a write operation). Therefore, using noatime can lead to significant performance gains.

To se the noatime option you have to edit your fstab file
(as root on a terminal shell)

# nano /etc/fstab 

find the line regarding your desired partition (in the example you'll see my root partition)

UUID=2a3a53ea-2873-4c35-8b40-9bae383ae868  /  ext4  noatime  0  1


and change defaults with noatime

press ctrl+o and ctrl+x (the first to save the file and the second command to exit nano)

Now you just need to reboot the computer


3. Set the journal data as writeback

Set the mode to journal_data_writeback basically means that data may be written to the disk before the journal. The data consistency guarantees are the same as the ext3 file system. The downside is that if your system crashes before the journal gets written then you may loose new data -- the old data may magically reappear. This is still better than ext2 because file system integrity is maintained, so the file system is at least consistent even after an unclean shutdown. In other words, you may loose data, but you won't have corrupt data

To do this you have to execute the following command as root on the terminal shell:

# tune2fs -o journal_data_writeback /dev/sdXY
Where /dev/sdXY is replaced by the partition that you want to boost

now dit fstab

# nano /mnt/fstab

Find the line that references sdXY. It will look something like:

UUID=be2f0ac2-4683-4550-bcd1-704a1a840b3e / ext4 relatime,errors=remount-ro 0 1

The first entry is the UUID (although on your system this could just be /dev/sdXY). The second entry is the path (/ for me). Third is the fstype (ext3/4). Fourth are the options. Fifth is for dump and sixth is pass. See man fstab(5) for more info.

Change the options to:

noatime,data=writeback,barrier=0,nobh,errors=remount-ro

(you can leave all of yours in place, if they weren’t the same as mine.

press ctrl+o and ctrl+x (the first to save the file and the second command to exit nano)

Now you just need to reboot the computer





IMPORTANT: If you experience any trouble you can revert all the changes without problems.


Cheers!