File systems are used to control how data is written to disk, to control access to this data, and to store information and metadata about files. File systems are continually being reviewed to provide more functionality and are becoming more efficient each time.
- What is the XFS file system?
- XFS file system structure
- Architecture features
- Create and resize XFS
- Advantages of XFS
- Comparison of XFS performance with other file systems
- Disadvantages of the XFS file system
- Accessing XFS partitions from Windows
- Installing XFS on SSD drive
What is the XFS file system?
XFS is a highly scalable, high-performance journaling file system with all the benefits of modern file systems, such as metadata logging for fast recovery. Still, it supports grouping of I/O streams, which significantly improves read and write performance. But it only works for large files. You can also increase the file system size or perform defragmentation even if it is mounted.
XFS is considered an extended file system. It is a high-performance file system with 64-bit logs. Support for XFS was included in the Linux kernel around 2002. XFS supports a maximum file system size of 8 exabytes for the 64-bit file system.
But XFS has some limitations. For example, the partition of this file system cannot be reduced, and there is low performance when working with large numbers of files. RHEL 7.0 uses XFS as the default file system.
XFS file system structure
The entire XFS file system is divided into so-called Allocation Groups, the analogue of Block Groups in Ext2FS.
The size/quantity and other description of Allocation Groups is in the superblock, and the superblock is at the beginning of each of the Selection Groups (i.e. it’s the same as in Ext2FS), so let’s go straight to the description of its structure.
At least the first 0x800 bytes (2048 bytes, 2 Kb) of each Allocation Group have the same format. And the zero (you have to read everything from zero) Allocation Group (and with it the zero superblock) is located right at the beginning of the device. Here is an important difference from the absolute number of other File Systems: when the XFS file system was designed for the IRIX platform, the developers did not even think about any bootloaders at the beginning of the disk, so there is no sense try to install the loader on an XFS partition.
The Allocation Group is divided into four other structures:
- Information on free blocks
- Information on dedicated and free information nodes
- Blocks dedicated for B-tree extension
The Superblock is at the beginning of the Allocation Group. You can find the definition of struct xfs_sb structure describing it in the file /usr/include/xfs/xfs_sb.h
You can quote this file as you would normally do in such cases, but it is not convenient to describe the structure in this case because type names like xfs_drfsbno_t say nothing about their size.
Therefore, it is better to record structures in a format that was more convenient for you.
We will use 5 fields to describe the structure:
- Offset from the beginning of the structure (in hexadecimal number system)
- Field size in bits
- Name of the element in the structure
- Some typical value (which is taken after formatting some test image)
Information about free blocks
The information on the Free blocks of the Allocation Group is located in it at an offset of 0x0200.
The definition of the xfs_agf structure is located in the /usr/include/xfs/xfs_ag.h file.
It was decided to store the list of free blocks not in a bitmap, but in B-tree with elements “Initial block of free blocks fragment”/”Fragment size”, and not in one B-tree, but in two duplicate: one element is sorted by a number of the initial block of fragment, and the second – by size of these free space fragments.
It allows you to quickly find a group of free blocks of the most suitable size.
Information on free and allocated information nodes
Similar to free blocks, free and dedicated information nodes of the Allocation Groups are described in the xfs_agi structure (see also /usr/include/xfs/xfs_ag.h for definition) at an offset of 0x400.
The information nodes are allocated in groups with 64 pieces. Information about occupancy/freighting of information nodes of this group is stored in the same bitmap (64-bit number).
But since every next group of info nodes is not necessarily located behind the previous one, this information still has to be stored in the B-tree.
This scheme allows you to remove the limitation on the number of information nodes typical of many other file systems. On XFS the message “Not enough space” is unambiguous, it cannot mean “table of information nodes is overflowed” when creating a file.
XFS uses B+ trees everywhere. They are used to index inodes packs, lists of free extents, directory elements and records of file cards.
B+ XFS trees have a quite traditional structure: in internal nodes, only the keys and pointers to the descendants are stored, and the leaves contain the keys and data.
Since there are several tree types in XFS, the general code handles only the standard block headers (xfs_btree.h).
After the header, there are data arrays. For internal nodes, these are:
- Two lists – keys and pointers to descendants growing in the middle. For leaves is an array of records, sorted in ascending order.
- Key Format and records, respectively, are determined by the tree type.
As mentioned above, XFS consists of data sections (contains metadata and can contain logs), a log, and a real-time section.
The data section is divided into equal groups of blocks (allocation groups), the number of which determines the level of parallelism in the allocation of space; each group contains a superblock, free space management of the group, table inode (created on demand).
The block size in Linux is 4 KB. Space allocation is done by extents (up to 8 GB).
XFS was not previously suitable for storing a large number of small files (such as a mail server) as it is slow to handle metadata, but it is gradually improving. For example:
- files opened during a sudden computer shutdown will be filled with zeros (fixed);
- instant file system creation and expansion at zero overhead (ext4 has 1.5%, i.e. 269GB for 16TB) and approximately the same as ext4 overhead for file storage (0.07% less for a set of 10TB out of 10 million files
- 64-bit inode numbers for a file system with the size 2T and more, not all 32-bit programs will survive it (fixed);
64-bit file system
Allocation of space by extents (Extent – pointer to the beginning and number of consecutive blocks). In extents space is allocated for storing files and free blocks B-tree indexes are actively used for storing various file system data: for the list of blocks with inode-series, the list of extents with file contents, file directories, lists of free blocks extents (free blocks are indexed both by block size and location). However, using b-tree indexes is not a dogma – a small file or directory can be placed directly inside the inode.
When a file is written, it is allocated space in memory, while the disk only allocates space when the file is written to disk. In this way, it optimally allocates disk space for the file, which reduces fragmentation.
Change of size “on the fly” (expand only).
Placing in several linear areas (4 by default) so-called “allocation groups” (increases performance by aligning the activity of requests to different disks on RAID-arrays like “stripe”, as well as in asynchronous access to the file system on a regular disk).
Defragmentation on the fly is done with these tools:
- Real-time I/O API (for hard or soft real-time applications such as streaming video).
- Interface (DMAPI) to support hierarchical media management (HSM).
- Backup and recovery tools (xfsdump and xfsrestore).
- “Index blocks” inode are allocated dynamically (when needed), and unused inode can be freed up (freeing up storage space).
- Small “overheads” – the size of service data structures. On the newly created XFS file system, about 0.54% is spent on service needs. It is achieved by a small number of headers for groups (allocation groups) and the dynamic allocation of inode.
Create and resize in XFS
Suppose that you already have a ready-made partition to create a file system. If not, you can create it using the Gparted or fdisk utility. Suppose the partition on which you want to create the XFS file system is /dev/sda11, you can do this with the standard mkfs utility. The command is:
$ sudo mkfs.xfs /dev/sda11
If a file system already exists on the specified partition, you should use option -f to overwrite it:
$ sudo mkfs.xts -f /dev/sda11
During creation, the utility will display current information about the file system and metadata table.
Now we need to mount the partition we just created. You can create a separate folder to mount or mount the partition in /mnt. For example, we could create the /mnt/db folder. Then you can mount the partition, just like all other file systems, with the mount command:
$ sudo mkdir /mnt/da11
$ sudo mount /dev/sda11 /mnt/db
$ sudo mount | grep sda11
Now you can write files to this section. Most file system options are installed using mount. Let’s look at the basic mounting options specific to XFS:
- inode64 – if you have a device larger than 2Tb, you need to use this mount option to improve the file system;
- nobarrier – XFS has a data-write barrier so that important data is not lost during an unexpected reboot. If you are sure that your hardware is fully reliable, then the barrier should be disabled to improve performance;
- logdev – allows you to log the file system to an external file;
- sunit – sets the size of one data block for RAID arrays. The default size is 512 bytes;
- norecovery – by default, every time the file system is mounted, it is checked and corrected if it was not mounted correctly. This option disables this procedure;
- quota – enables support for disk quotas for users.
You can use any of these options to configure your file system
Once mounted, you can view information about the file system metadata:
$ sudo xfs_info /dev/sda11
If you want this partition to mount automatically, you must configure xfs fstab to mount. All you have to do is add a line:
$ sudo vi /etc/fstab/dev/sda11 /mnt/db xfs defaults 0 0
You can resize the XFS file system on the fly, right when it is mounted. First, we see the current partition size:
$ df –h
Next, the XFS size is increased in two steps. There is one thing about expanding the size online, you need to increase the size of the partition in the partition table, and the only way to do that without unmounting is in LVM. In other configurations, you will still have to unmount. First, resize the partition using Gparted, for example, and then you have to increase the size of the file system. You can do that even if the file system is mounted. Run the command:
$ xfs_growfs /mnt/db
To make sure that everything works, we check the file system size again using the command:
$ df –h
Before expanding the file system size, you should remember that you can never compress the file system.
Advantages of XFS
XFS is an excellent file system that shows outstanding performance when working with large files. In addition to fast operation with large files and on-the-go resizing, it is also worth noting the presence of a built-in defragmenter and metadata journaling for fast recovery.
To reorganize the location of files (defragmentation) the command xfs_fsr is used. It can be used either for the whole partition or a separate file. To perform defragmentation, you need to have enough free space on the partition to copy any file. At the end of the operation, each file will take up one extent.
To defragment the entire partition, a command is used:
xfs_fsr -v /dev/
Defragmentation of an individual file is performed by a command:
-v option displays additional information.
Checking the fragmentation degree in XFS
You can get information about the fragmentation of the partition with a command:
xfs_db -r -c frag /dev/
The -r option is required to check the partition that is currently mounted and in use. Option –c frag is needed directly to display information about the fragmentation of the partition.
The result looks like this:
Like most modern file systems, XFS supports metadata journaling for fast recovery in the case of an emergency reboot. Like ReiserFS, XFS uses logical journaling. Otherwise, the journaling is not done by file blocks (as in ext3), but in an efficient disk format with only the metadata being changed. For XFS, logical logging is especially recommended. On high-end hardware (which is usually for XFS) the journaling is the most controversial resource. Using space-efficient logical journaling minimizes non-productive resource consumption. Besides, XFS allows the journal to be stored on another block device (partition, “cheap” disk). This feature saves expensive resources and “works” to an even greater extent to increase XFS speed.
As with ReiserFS, XFS only journals metadata and does not do so for the data itself. It means that in XFS (as in ReiserFS), it is possible to lose the data that has been changed before a disaster reboot. However, the XFS log has two properties that reduce the chances of data loss compared to ReiserFS.
XFS has the guarantee that any “unrecorded” blocks are filled with zeros. Since blocks with zero bytes in the system files are ignored, a security loophole is removed.
The problem of data loss in XFS is minimized by the fact that the operation of resetting metadata modifications waiting to be processed on disk in XFS is more frequent than in ReiserFS, for example (especially with high intensity I/O operations). As a consequence, there will be fewer XFS losses after a crash than under the same conditions in ReiserFS. Note that the more frequent metadata writing itself does not eliminate the problem, but only provokes the more frequent disc and data resets.
Comparison of XFS performance with other file systems.
Until recently, the choice of a file system for Linux was small. Those who wanted high performance preferred ReiserFS, and those who cared about data integrity preferred ext3. With the advent of XFS support for Linux, the choice was not so straightforward. The big question that arose was, is ReiserFS, the performance leader under all conditions?
Recently our experts have compared XFS, ReiserFS, and ext3 in performance. But, first of all, it should be noted that the results show only the general dynamics of dependence of file system performance on a single-processor system load.
Testing showed that XFS is a very fast file system. XFS is a constant leader in tests with large file manipulation. This result is entirely predictable as it was designed for this purpose. Relatively slow file deletion operations were also noticed. At this point, it lost both ReiserFS and ext3.
In other tests, XFS performance was close to that of ReiserFS and always better than ext3. A nice feature of XFS is that it does not generate excessive disk activity. XFS tries to cache as much data as possible, and the “reason” for resetting to disk is to fill the memory, not the time interval. When data is written to the drive, it does not have a significant impact on other IO operations. In contrast, in ext3 (mode “data=ordered”) periodic data resets to disk cause problems with interactivity and, at high IO operations, even disk thrashing.
Disadvantages of the XFS file system
Unfortunately, XFS has disadvantages as well. Among the most significant are the following:
- It is impossible to reduce the size of an existing file system. If the partition on the disk is filled with XFS, it cannot be resized to a smaller size (it is important to consider when partitioning the disk).
- Recovering deleted files in XFS is a very complicated process, so there are currently only a few software products for this purpose, for example, “RS Partition Recovery”
- Possible data loss during recording in case of power failure, because a large number of data buffers are stored in memory, while metadata is journalled (on disk) operatively. This is also true for other file systems with metadata journaling.
- Relatively slow directory creation and removal (a disadvantage that can be greatly reduced by properly configuring the file system).
Accessing XFS partitions from Windows
Unfortunately, OS Windows does not have a built-in utility to open file systems other than NTFS or FAT. Therefore, for example to open a flash drive, you will have to use either third-party software or install Linux on a virtual machine. The second option is less convenient so that we will consider the Linux File Systems for Windows application from Paragon Software. With this program, you can view, edit, copy, and delete the files on your XFS partition. The app exists in two versions: paid and free. The free version gives the user 10 days to test the program.
You can also use the XFS Explorer application. There are also free and paid versions. In the free version, you can view files up to 3 MB in size. If you need to work with a large files, you will have to purchase the paid version.
Installing XFS on SSD drive
XFS can work with large data better than any other file system, and does so reliably. That is why XFS can be a great candidate for installation on SSDs. As modern computing becomes more advanced, data files become more and more demanding. It makes sense to consider installing this file system on an SSD drive.
XFS, like Ext4, is a journaled file system. But unlike Extended 4, it is impossible to disable journaling so it can put a heavy load on the disk. However, XFS supports standard SSD functions and even defragmentation.
Benefits of using XFS on SSD
- XFS is well known for its ability to easily manage large amounts of data. By using XFS on your SSD, you can ensure that your files are secure
- The performance advantages of XFS on SSDs mean that you can transfer and access files and data much faster than other file systems.
- XFS has an SSD defragmentation feature that is very useful and will help keep your drive running for a long time.
Disadvantages of using XFS on the SSD
- XFS is a journaling file system, and this feature cannot be disabled. Impossibility to disable logging is something to be afraid of if you are concerned about SSD read/write restrictions.
- Besides, there is increased wear on the SSD when using the XFS file system. So you have to make a decision here – faster working with large files, or longer life of the SSD.