Thursday, July 1, 2010

Should you use the XFS file system?

One of the good things, and also one of the confusing things about Linux, is the amount of choice you have. Even down to what sort of file system you want to use for storing your data. By default, the Ubuntu installer will use ext4, a good, general purpose file system that will suit most people's needs just fine.

There are other options though, depending on your usage patterns. If you have a lot of large files stored, such as lots of video or movies, maybe even if you record TV with MythTV like I do, a good alternative is XFS. Its design means it is particularly good at handling large files, such as High Definition TV recording, giving good performance in reading and writing them.

You can specify a partition to be in XFS format at the time of installation, or later on by using GParted. Once it is created, there are some further tweaks you can do to make its performance better, and also to maintain its performance over time.

1. Add the following options to the fstab entry for the partition (located in /etc/fstab):

UUID=xxxx /var/lib/mythtv xfs defaults,noatime,allocsize=512m,logbufs=8 0 2

noatime refers to stopping the file system logging each time the file is accessed. Normally it is not needed, and this option reduces the number of writes done to disk, speeding things up.

allocsize=512m lets XFS set aside 512 megabytes of space at a time when it writes. This reduces the chance of the file being split up into many small chunks, or fragmenting. Especially good for recording TV.

logbufs=8 refers to the log buffers held in RAM. Values can be from 2 to 8 buffers, which are 32K in size. Since most PCs have RAM to spare these days, there is no problem maxing this out.

Sometimes a bit of periodic maintenance is needed with XFS, and this can make people used to NTFS on Windows feel a little more at home. You sometime have to defragment the file system, and there is a utility that can do it. It isn't installed by default - you have to install the xfsdump package to get the folllowing commands.

To check the fragmentation level of a drive, for example located at /dev/sda6:

sudo xfs_db -c frag -r /dev/sda6

The result will look something like so:

actual 51270, ideal 174, fragmentation factor 99.66%

That is an actual result I got from the first time I installed these utilities, previously having no knowledge of XFS maintenance. Pretty nasty. Basically, the 174 files on the partition were spread over 51270 separate pieces. To defragment, run the following command:

sudo xfs_fsr -v /dev/sda6

Let it run for a while. the -v option lets it show the progress. After it finishes, try checking the fragmentation level again:

sudo xfs_db -c frag -r /dev/sda6

actual 176, ideal 174, fragmentation factor 1.14%

Much better! I have the xfs_fsr command scheduled to run daily with a cron job, at a time when it is unlikely to be recording, to keep things in good shape.

More in depth information on XFS can be found at the MythTV wiki. Some more detailed performance optimisation info can be found here and here.

4 comments:

  1. Thanks Steve. I've been looking for the reasons that I should change from Ext4 to XFS, and yours is the first argument that shows how I would personally benefit. Good job!

    ReplyDelete
  2. I have been trying to read XFS data from a Buffalo linkstation (not raid) drive and have been having very bad success. Ubuntu did boot off CD that i created, and it did read the XFS filesystem. However, when I tried to copy some folders, inevitably, there would be an error and the copy failed. I had to reboot Ubuntu to read the XFS again. I have had only at 50% success rate in copying the data.

    Any suggestions? I don't believe the disk is damaged. In searching the web, I have found some references to modifying the XFS install, but have not been able to find them again.

    ReplyDelete
  3. Hello Heidi, thanks for the comment. I haven't really come across it myself, but it might be worth running the xfs_check or xfs_repair commands on that partition. More info is at http://www.mythtv.org/wiki/XFS_Filesystem#Keeping_XFS_Healthy_.28Disk_Checking.29 - hopefully that will help you.

    ReplyDelete
  4. Thanks for this. Needed to hear this to make the switch from ext4. :)

    ReplyDelete