Esta página está atualmente no estágio de tradução.
Desculpe pelo inconveniente.

Getting to know the XFS file system

basic structure, specific features and disadvantages of xfs file system

The modern Linux kernel supports a wide variety of file system types, and each of them adopts its own approach to placing and retrieving data from a digital medium. This fact, of course, opens up many opportunities. But, at the same time, it puts additional responsibility on users, who need to acquire at least basic understanding of their peculiarities. Besides ext4, the default choice for most distributions, XFS remains amongst the top options and requires more detailed consideration. So, what kind of file system it is, and how does it differ from the rest of formats?

Introduction to XFS

XFS is one of the most robust file systems deployed in Linux. It was initially designed by Silicon Graphics Inc. and released in 1994 on their UNIX-based IRIX platform. Later, the file system was handed over to the open-source community, who in 2001 incorporated it into the kernel. Since then, it has paved its way into all major Linux distributions. The ones based on Red Hat even choose this format by default during installation, for instance, CentOS, RHEL and Rocky Linux.

Created with high-capacity devices in mind, XFS is best known for its high performance when dealing with massive amounts of data. This file system is typically found on servers, storage arrays, and less frequently – on consumer PCs. Its popularity has also increased with the widespread usage of NAS boxes, a big share of which are supplied with XFS from the manufacturer, including such brands as Buffalo LinkStation and TeraStation, NetGear, LaCie, Iomega and others.

Despite its advanced age, the file system is still under active development. It underwent a number of modifications, and now we have the third generation of XFS that has been in extensive use for the past few years:

1st XFS generation – simple SGI XFS for the UNIX-based IRIX OS;

2nd XFS generation – older Linux XFS of an extended format, currently applied mostly in NAS units;

3rd XFS generation – Linux XFS (gen 3),  the most recent version used in modern Linux-based systems, where the on-disk metadata format was changed for its easier identification and verification.

XFS allows creating a volume of 18 exabytes in size and handle individual files as large as 9 exabytes. The number of files is limited only by the amount of space at its disposal. The file system can grow as long as there are unallocated blocks and can even span multiple physical devices.

As a journaling file system, XFS keeps record of modifications before they are committed to its internal structures, which ensures its overall consistency in case of a crash or power loss.

Basic structure of the file system

XFS has an extent-oriented organization. Instead of allocating its space in individual blocks, it combines them into contiguous units of variable lengths referred to as extents. A single file may consist of multiple extents when a contiguous range on the storage is not available for it. Yet, XFS seeks to keep their number as small as possible and attempts to merge extents as the file grows. The information about a file (file’s metadata) is stored in its inode. Such inodes are allocated in chunks, 64 per each.

The file system itself can be divided into up to three separate parts:

  • Data section

The data section contains the metadata of the file system and the data of user files. The storage space in it is further subdivided into equal allocation groups. The minimum size of an allocation group is 16 MB, and the maximum one is about 1 TB. Each allocation group autonomously controls the space usage within its boundaries. Therefore, concurrent processes can perform allocation throughout the file system in parallel and do not interfere with each other.

Free extents in the allocation group are managed using a pair of B+ trees. Their entries contain information about the starting block address of a free-space region and its length in blocks. The first B+ tree is indexed by the address value, whereas the second one – by the length value.

The locations of inodes within the allocation group are also indexed using a B+ tree. Its records contain the offset for each 64-inode-chunk and a flag for each inode within a chunk indicating whether it is in use.

A similar approach is used to keep track of extents assigned to files. The descriptor of each extent, besides its address and length in blocks, contains the logical offset from the start of the file and a flag that characterizes an extent as preallocated but not yet written to. Extent descriptors are usually stored as a linear array embedded into the file’s inode. Yet, if the number of extents is too large, they are indexed using another B+ tree, whose root is located in the file’s inode.

XFS implements delayed allocation to improve write performance and reduce file system fragmentation. A virtual extent is first built in the memory and the appropriate amount of space is reserved for it in the file system. However, the exact location of the data remains unknown until XFS makes the decision to actually write it. Thus, some short-lived temporary files might never get allocated to real blocks on the storage.

  • Log (journal) section

This area stores the modifications to the file system metadata. The entry in the log for each structural item consists of header information that describes it and a copy of the new image of this item as it should appear on the disk. The entry is kept in the log until those changes are actually committed to the data section. In case of a crash, the log can be read out to complete the interrupted operations and restore the file system consistency. This section can be located withing the data section itself or even externally on a separate device for enhanced speed/reliability, depending on the configuration.

  • Real-time section

This optional section stores only the data of real-time files – ones with special I/O speed requirements. It usually placed on a separate high-performance storage device. The section is divided into a number of extents of a fixed size. The allocation in it is performed in a more simple manner. It is managed with the help of a linear bitmap, and the free space is indexed using a two-dimensional array.

Advantages and drawbacks of XFS

Thanks to its design, XFS excels in organizing large files, directories and volumes as well as vast numbers of files. Also, it offers many features that make it optimal for big computing systems and other environments that require a reliable high-performance file system. Among them one can single out:

  • Reduced file fragmentation and scattering

XFS makes every effort to store files as contiguously as possible. The concept of extents enables it to efficiently allocate free ranges of adjacent blocks, whereas B+ trees make it easy to search for free extents. If there are "holes" in a file, XFS will just skip them, without wasting storage space on empty blocks. The use of delayed allocation gives it the understanding of the eventual size of the file. Knowing how many blocks are to be allocated, XFS often manages to fit the entire file into a single extent, provided that there is contiguous space to hold it, or at least allocate it in much larger extents, which wouldn’t be achievable otherwise. Moreover, the buffering of short-lived files lowers the impact of such files on fragmentation and reduces the number of metadata updates.

  • Suitability for multi-component storage systems

XFS is capable of spanning multiple storage devices and has its own volume manager. For striped disk arrays (for example, RAID 5), one can define the size of each stripe unit and the number of units per stripe at the moment of file system creation. XFS will use this information to place data in accordance with the storage specifics and thus reach better performance.

The XLV volume manager used by XFS serves as an additional layer of abstraction between the file system and the underlying physical storage devices. It provides XFS with the support of disk striping for higher I/O performance, mirroring for higher reliability, and concatenation for creating very big logical volumes. Also, XLV enables online reconfiguration of a volume when it is mounted and active. For instance, one can expand the size of a volume or defragment it nearly without downtime.

  • Speedy parallel I/O operations

XFS is optimized for parallel access. As has already been mentioned, it splits the storage space into independent allocation groups. Each allocation group behaves almost like a separate file system – controls the space usage of its own and writes its own metadata. Therefore, such allocation groups can be concurrently addressed by the kernel, and multiple parallel operations do not affect performance.

  • High recovery chances

XFS employs metadata journaling, which facilitates its recovery after system crashes or power outages. The user data, in the event of its loss, has high chances to be recovered as well, though with external data recovery tools, like UFS Explorer or Recovery Explorer. When a file gets deleted, the file system partially wipes the information about its inode and updates the B+tree of free extents. The information about the name of this file is disconnected from the respective directory entry. Yet, with the help of heuristics, the software is able to find the name, size and the position of this file rounded to the block. The probability that it will be restored is close to 100%, and with its real name – to 80%. In case of accidental formatting of the file system, the information about the used extents will be destroyed, and the allocation groups will be updated. However, the information about user files will remain on the storage, using which the software has an up 100% chance to get them back.

However, this robust file system has several weak points. First of all, XFS doesn't use checksums. Therefore, it cannot guarantee that the data stored within it will always remain intact. Some files may get silently corrupted, and the damaged bits may be discovered too late, leading to serious data loss. In addition, XFS doesn't log any changes to the user data, like it does with its internal structures. Hence, an unexpected shutdown of the OS may cause the loss of information from the recently created or modified files. On the other had, there is no option to disable journaling altogether, which may affect the lifespan of solid-state drives. Eventually, this file system cannot boast wide compatibility. This fact may be a problem in case of an external device or a dual-boot system, since such operating systems as Windows and macOS do not have native support for XFS.

On the whole, though having some minor flaws, XFS is a quite dependable and versatile file system. Thus, in can be an excellent format choice, especially for capacious storage solutions.

Last update: July 20, 2022

Compartilhe: