A couple of minor ext3 performance tweaks

Posted by Steve on Mon 30 Apr 2007 at 06:42

The ext3 filesystem is probably the most common filesystem used upon GNU/Linux machines. It isn't necessarily the fastest, the best, or the most modern filesystem but it does perform adequately for the majority of users.

There are some people who wish to use the "fastest" filesystem around, regardless of any potential drawbacks ext3 probably isn't for them, but for the rest of us there are a couple of small tweaks you make to improve its performance.

In general there are two types of tweaks you can perform to your filesystem to improve performance:

The ext3 filesystem is the successor to the ext2 filesystem, the version number changed primarily because of the addition of journalling.

What does this mean? Well if you go back a few years you'll discover that there are two ways to create an ext3 filesystem:

The process of adding the journal support to an existing ext2 filesystem is very simple (and safe!):

root@mine:~# tune2fs -j /dev/sda1

What a lot of people don't realise is that you can also use the tun2fs program to adjust other parameters of the filesystem - and this is what do.

The most useful tweak you can perform is the way that directory indexes are scanned when looking for files. This is controlled by the option "dir_index". By default this wouldn't be enabled but you can add it by running:

mine:~# tune2fs -O dir_index /dev/sda1

Once you've done this you'll be able to see the updated filesystem flags which are in use:

mine:~# tune2fs -l /dev/sda1 | grep features
Filesystem features:      has_journal resize_inode dir_index filetype needs_recovery sparse_super large_file

Once you've done this you should find that listing the contents of directories with large numbers of files becomes faster, and that finding files in directories is also better.

The final thing that we'll mention with regard to ext3 filesystem improvements is the mount option noatime.

When you mount a filesystem at bootup the options which are used are read from /etc/fstab. (I'm ignoring the case where you mount things manually!)

An entry in the fstab file usually looks something like this:

/dev/sda1       /               ext3    defaults,errors=remount-ro 0       1

Here there are fields which specify what is mounted, and where it will be mounted. The fourth column contains the options which should be passed to the mount command. In this case we mount the filesystem with the two flags "defaults" (ie. nothing special) and "errors=remount-ro", which instructs the system to remount the filesystem read-only in the case of errors.

One speedup can be gained by adding noatime. This instructs the system not to update the access-time of any files which are accessed. There can be drawbacks here which are worth noting, for example if you're using find to find files which have recently been accessed, etc, this will fail. But otherwise the benefit is that reading files will not require the access time to be updated, not a huge speed-gain, but certainly noticeable for many systems.


This article can be found online at the Debian Administration website at the following bookmarkable URL:

This article is copyright 2007 Steve - please ask for permission to republish or translate.