Performance and Tuning

If you've chosen XFS for any of your system or storage volumes, fragmentation can be a problem which noticably affects performance. Luckily, there are a couple of relatively easy steps that can be taken.

The first is to see how bad fragmentation is. This is done using the xfs_db command. For example, on a storage volume, you'd do something like this:

     sudo xfs_db -c frag -r /dev/sdb1

On a combinded system/storage volume that is contained in the third partition on your disk, you might try something like this:

     sudo xfs_db -c frag -r /dev/sda3

Its time to defrag the system if the results of the command look like this:

     actual 209967, ideal 1022, fragmentation factor 99.51%

Numbers like 30-100% will probably impact performance.

Begin by making sure xfs_fsr is installed. It is part of the xfsdump package, which can be installed with:

     sudo apt-get install xfsdump

Of course, you can certainly run the xfs_fsr command at any time you like, by hand. However, the easiest way to ensure that fragmentation does not cause problems is to add commands to your crontab to defragment regularly, at off peak times.

If all of the XFS volumes are storage only (i.e. you run the OS from a separate non-XFS volume and only use the XFS volumes to store recordings, etc.), the following lines in crontab will work well:

     # Let's defrag all of the XFS volumes in mtab.  We'll work on 'em for a
     # couple of hours per night, which should keep them in good shape, since
     # there's not THAT much activity, on a daily basis.  Hopefully, there's
     # not too much going on when we do it.
     00 3  * * *  root  /usr/sbin/xfs_fsr -t 7200 >/dev/null 2>&1

The above command will defragment all of the XFS volumes defined in /etc/mtab for two hours each night. If the defragmentation isn't done at the end of the two hours, it will pick up where it left off the next night.

It is important that you do not run xfs_fsr on your root partition (e.g. /dev/sda3 on a system/storage volume) or on the partition that contains your boot files (e.g. /dev/sda1 on the same volume). Instead, for combined system/storage volumes we use a find command to find all of the files in the MythTV directory (i.e. the directory where recordings are stored) and defrag them one at a time.

     # Since we can't defrag all of the XFS volumes because the OS is on one
     # of them, we'll defrag only the MythTV recording files.  Since the OS
     # rarely changes, this should handle the bulk of it.  Hopefully, there's
     # not too much going on when we do it.
     00 3  * * *  root  /usr/bin/find /MythTV -type f \
                        -exec /usr/sbin/xfs_fsr \{\} \; >/dev/null 2>&1

Unfortunately, there is no way to specify a time limit on this method but, after it has been done once, it should complete in a reasonable length of time, certainly less than a couple of hours.