One of the most important questions when installing a Linux server is "What file system should I use?" Ext2/Ext3...
and ReiserFS have always been the most important players in the field of file systems. The SGI open source file system XFS is not as popular -- and that is strange, because it offers some amazing features. In this article you can read how to optimize this file system.
The best feature of XFS is its scalability. The file system is completely 64 bits, which allows for use of file systems with sizes up to 9 exabytes (that is 9 million terabytes). The XFS file system is organized in a highly-structured way, which makes it very fast . In an XFS file system, one can use three different sections.
Data, log and realtime sections
Most important of these is the data section. This is the only section that is created by default. Itcontains data blocks, and also file system metadata (the administration of the file system). The data section consists of different allocation groups, as is seen in other file systems like ext2/ext3. These block groups are created automatically when using mkfs.xfs, and their sizes are calculated based on the size of the file system. Using these block groups is good for performance, because working with several block groups allows the file system to perform actions in parallel.
One of the most important parameters when creating an XFS file system is the number of allocation groups created. The default value performs well, but for better performance, it is a good idea to increase the number of block allocation groups. This is what you should do if the file system is very write intensive, and if sufficient memory is available. If the server in question doesn't have much available memory, using too many block groups is very bad for performance.
Also, when using a large amount of block groups, you should make sure that there is enough available disk space in the file system at all times. When the file system is almost full, the file system will allocate lots of CPU cycles to handle all the simultaneous requests from the different block allocation groups. Fortunately, you can always use the xfs_growfs command to grow an XFS file system if necessary.
Apart from the data section, there can be a log section and a realtime section. The log section is used as a file system journal; changes in file system metadata are stored in it until the file system has time to commit these changes to the data section. When the file system crashes, upon mount, the file system can read incomplete transactions from this log section and recover the file system rapidly. In the default setting, the log section is included in the data section. For better performance, you can choose to put it outside of the data section, which allows you to put it on another medium as well.
A unique property of the XFS file system is the realtime section. This section is used by files that have to be written to a disk as quickly as possible – in real time. To mark a file as a real time file, the xfsctl function is used. This function is not available as a command line utility. It has to be implemented by developers who need it in the tools they are writing to handle data on the XFS file system. If a file is real time, that means that it will never be stored in memory buffers before writing it to disk, but that it will be written without further delay. This is an excellent way to prevent file system corruption.
To set these properties for the XFS file system, you need to specify them when creating the file system. Creating an XFS file system with default settings is not too hard; the following command for instance is used to format /dev/sda1 as an XFS file system:
This command would format the file system as XFS with an internal log section, and without any realtime section. If, however, you would like to put the log section on a different device, which leads to a better performance, use the following:
Mkfs.xfs –l logdev=/dev/sdb1,size=10000b /dev/sda1
With this command, a 10000 blocks log section is created on /dev/sdb1.
Specifying the number of allocation groups
An important setting when creating the XFS file system is the one that specifies the number of allocation groups that need to be created. Depending on the file system size you are using, the number of allocation groups is set automatically; use the xfs_info command to find out the number of allocation groups set on your file system. Listing 1 below shows the agcount (number of allocation groups) parameter,which is set to 16, and the agsize (size per allocation group), set to 1638400 blocks. Click here to view Listing 1: Showing XFS file system information with xfs_info
To increase performance for this file system, you can change the number of allocation groups to 32, for example. You would do this using the agcount=32 option when creating the file system. The complete command to do this for a file system that you want to create on /dev/sda1, is:
mkfs.xfs –f –d agcount=32
No need to calculate the size of the allocation groups. That will be calculated automatically. In the above command you can see that the option –f is used. This option is required in certain cases; mkfs.xfs will not write to the device if it suspects that there already is a file system on that device. So in case you want to recreate an XFS file system, make sure that the option –f is used.
In this article, you've learned about some important features that you can use during file system creation to tune an XFS file system for optimal performance. Apart from these options, there are a few other management commands that may come in useful. These will be covered in a later article.
About the author:Sander van Vugt is an author and independent technical trainer, specializing in Linux since 1994. Vugt is also a technical consultant for high-availability (HA) clustering and performance optimization, as well as an expert on SUSE Linux Enterprise Desktop 10 (SLED 10) administration.