This site is now 100% read-only, and retired.

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:

  • Change the options used by the filesystem itself.
  • Change the way you mount your filesystem.

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:

  • Run mkfs.ext3 to create a new filesystem "from scratch".
  • Create an ext2 filesystem and then add journalling to it - essentially converting it to ext3.

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.

 

 


Re: A couple of minor ext3 performance tweaks
Posted by TRS-80 (203.59.xx.xx) on Mon 30 Apr 2007 at 08:56
If you're using etch, you can add resize_inode to the feature list, which will allow online resizing of the filesystem to 1024 its initial size. To combine this with dir_index, you'd go mkfs.ext3 -O dir_index,resize_inode /dev/hda3

[ Parent ]

Re: A couple of minor ext3 performance tweaks
Posted by Anonymous (62.45.xx.xx) on Mon 30 Apr 2007 at 11:39
If you're using etch you should already have both options configured in /etc/mke2fs.conf.

[ Parent ]

Re: A couple of minor ext3 performance tweaks
Posted by Anonymous (193.225.xx.xx) on Mon 30 Apr 2007 at 09:08
Hi!

Another tweaks:

1) The mount option data=journal|ordered|writeback.

Man mount says:

data=journal / data=ordered / data=writeback

Specifies the journalling mode for file data. Metadata is always journaled. To use modes other than ordered on the root file system, pass the mode to the kernel as boot parameter, e.g. rootflags=data=journal.

journal
All data is committed into the journal prior to being written into the main file system.

ordered
This is the default mode. All data is forced directly out to the main file system prior to its meta data being committed to the journal.

writeback
Data ordering is not preserved - data may be written into the main file system after its metadata has been committed to the journal. This is rumoured to be the highest-throughput option. It guarantees internal file system integrity, however it can allow old data to appear in files after a crash and journal recovery.


2) You can have an external journal on a faster disk or on some nvram.

Bence Romsics

[ Parent ]

Re: A couple of minor ext3 performance tweaks
Posted by Anonymous (134.130.xx.xx) on Mon 30 Apr 2007 at 09:33
AFAIK, the dir_index tweak won't immediately improve performance if applied to a non-empty filesystem, because tune2fs doesn't create the idexes, it only enables them.
You can use fsck -fD on the (unmounted!) FS to create them manually (add -C0 to get a neat progress bar).

[ Parent ]

Re: A couple of minor ext3 performance tweaks
Posted by Anonymous (213.164.xx.xx) on Mon 30 Apr 2007 at 13:34
or run ls on the big dir on an online filesystem..

[ Parent ]

Re: A couple of minor ext3 performance tweaks
Posted by Anonymous (88.198.xx.xx) on Wed 19 Sep 2007 at 14:02
or run ls on the big dir on an online filesystem..

No, but copying it and moving the copy back to the original position will create the b-tree index.

[ Parent ]

Re: A couple of minor ext3 performance tweaks
Posted by Anonymous (62.219.xx.xx) on Tue 1 May 2007 at 11:53
2 more tweaks:

add nodiratime and reservation to your /etc/fstab
reservation is supported starting from 2.6.13

also you don't need reboot system on each update in fstab

just perform something like: mount -o remount /
and then check with 'mount' if settings been applied

use it on your own risk;)

[ Parent ]

Re: A couple of minor ext3 performance tweaks
Posted by Hercynium (64.69.xx.xx) on Tue 1 May 2007 at 14:28
I didn't see 'reservation' as an option for ext* filesystems in the mount man page... what does it do?

[ Parent ]

Re: A couple of minor ext3 performance tweaks
Posted by Anonymous (62.219.xx.xx) on Tue 1 May 2007 at 15:41
When using Ext3 with multiple threads appending
to files in the same directory, consider turning
preallocation on:
# mount -o reservation

[ Parent ]

Re: A couple of minor ext3 performance tweaks
Posted by ajt (85.211.xx.xx) on Tue 1 May 2007 at 20:36
[ View Weblogs ]
Nice points, I can see a nice article on filesystem tweaking in the making...

Be aware that if you add features to an ext3 file system you may not be able to read the file system with an older kernel/distro as I found: http://www.debian-administration.org/tip/58

--
"It's Not Magic, It's Work"
Adam

[ Parent ]

Re: A couple of minor ext3 performance tweaks
Posted by Anonymous (190.2.xx.xx) on Wed 2 May 2007 at 04:28
echo 10 > /proc/sys/vm/dirty_ratio
echo 5 > /proc/sys/vm/dirty_background_ratio
http://lkml.org/lkml/2007/4/27/289

[ Parent ]

Re: A couple of minor ext3 performance tweaks
Posted by Anonymous (81.164.xx.xx) on Sun 16 Mar 2008 at 09:42
Hi. I get a "Permission denied" when I try to do this with sudo..

[ Parent ]

Re: A couple of minor ext3 performance tweaks
Posted by Anonymous (2001:0xx:0xx:0xxx:0xxx:0xxx:xx) on Sat 29 Mar 2008 at 15:16
When you run "sudo echo text > file", that is first parsed by your non-privileged shell. It sees ">file", and - before exec()ing sudo - tries to open "file" for writing. Surely it fails. Try "sudo -s", or "sudo bash" and type that command in root shell. Or create a script that contains redirection inside itself, and run the script with sudo. Or try to guess escaping rules of sudo. Should be like

sudo bash -c 'echo text > file'

[ Parent ]

Re: A couple of minor ext3 performance tweaks
Posted by Anonymous (89.245.xx.xx) on Fri 6 Jun 2008 at 00:35
This should work:
echo text | sudo tee file

"tee" redirects the output to the file, and it runs as superuser.

[ Parent ]

ext3cow question
Posted by Anonymous (85.216.xx.xx) on Sun 6 May 2007 at 00:05
hello all,

I know this is a different topic but I ask it anyway...

Did anybody try ext3cow? Any practical experience?


cb

[ Parent ]

Re: A couple of minor ext3 performance tweaks
Posted by molsonrocks (75.131.xx.xx) on Sun 12 Aug 2007 at 21:35
Question for anyone that might know the answer.

I have a mail server that is using ext3 software raid1, and I want to enable dir_index.

Any one know if I should enable the index on the single drives that make up the raid1 mirror (/dev/sda,/dev/sdb), the software raid partition (/dev/md*), or both?

Thanks in advance

[ Parent ]

Re: A couple of minor ext3 performance tweaks
Posted by Steve (62.30.xx.xx) on Sun 12 Aug 2007 at 21:43
[ View Weblogs ]

You need to do it on the raid volume - after all that is what you'd have run mkfs upon..

Steve

[ Parent ]

Re: A couple of minor ext3 performance tweaks
Posted by Anonymous (217.235.xx.xx) on Thu 7 Aug 2008 at 15:58
Adding noatime option will break popularity-contest[1]. It uses noatime to check if installed package is used.

[1] http://packages.debian.org/unstable/misc/popularity-contest

[ Parent ]