Saturday, July 24, 2010

Something I just learned about in Gnome

Just today I learned about a feature in the Gnome desktop environment that is the Ubuntu default. I absent-mindedly middle-clicked the title bar of a window, and found it sent the window to the back, behind any other windows. It's the opposite to left-clicking the title bar, which brings the window to the front, which everyone knows about.

You learn something every day.

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.