The XFS File System Explained for Beginners

Illustration for article titled The XFS File System Explained for Beginnersem/em

The choice of a file system has always caused a heated debate among Linux devotees, who are ready to beat their breasts trying to convince their opponents that they are totally wrong. And it is more than understandable since, unlike Windows or macOS, whose users much more rarely need to give a thought to that matter during their day-to-day computing adventures, this operating system has no lack of various file system options. Although ext is employed by default on most Linux distributions, XFS is hardly bringing up the rear and enjoys great popularity in the Linux world. But what is this file system all about and how does it differ from its counterparts?

Advertisement

XFS is, in fact, one of the oldest and most mature file systems available for Linux. Being developed by Silicon Graphics and introduced in 1994 with their IRIX operating system, it migrated to the Linux kernel in 2001 with a mission to successfully deal with whopping amounts of data. The format has been optional for quite a long time and was finally chosen as the default for Red Hat Enterprise Linux 7 in 2014. Currently, it is supported by most Linux distributions while RHEL, Oracle Linux 7, CentOS 7 and some others deploy it as the default file system.

XFS is a 64-bit journaling file system. The contents of each file in XFS are stored in data blocks on the disk. To efficiently record all allocated and free space, XFS groups these blocks into contiguous sequences called extents which can be addressed by the file system as single units. The minimal size of an extent is one block, and it can grow as the size of the file increases. All the information about a file (its metadata) is stored in a special data structure called an inode. The file system itself is comprised of three major components:

The data section is used to store all file system metadata as well as user data (except real-time files). This section is divided into a certain number of equal-sized allocation groups (you can predetermine their number or the size – the minimal one is 16 MB, while the maximum is up to a terabyte). Each allocation group can be viewed as a separate file system which independently controls space usage of its own. Multiple allocation groups allow XFS to simultaneously handle numerous operations avoiding degraded performance. To track free space each allocation group employs a pair of special structures called B+ trees whose nodes contain information about the starting block of each free region and its size in blocks. The same approach is used to track data blocks and inodes belonging to each file.

Advertisement

The log section contains all journaling information which is written when any changes are made to the file system metadata and kept there until they are actually committed: in case of a sudden crash or blackout, this makes it possible to complete all operations that were in progress at that moment and thus keep the consistency of the file system.

The real-time section stores the data of real-time files – files that need to be written or updated immediately, without any delays.

Advertisement
Illustration for article titled The XFS File System Explained for Beginnersem/em

Such a design makes XFS particularly good at handling large files and storages. The maximum file size currently supported is 9 exabytes, while a single volume can be up to 18 exabytes. The total number of files is not limited at all. Among other strong points of this file system are:

Journaling. The use of journaling for metadata operations guarantees the consistency of XFS even after a crash or power loss.

Advertisement

Delayed allocation. Data in XFS is not instantly written to the hard disk, but held in RAM for some time, while the needed for this data amount of blocks simply gets reserved. Eventually, it may turn out that there is no need to write it at all. This way, XFS optimizes write performance while reducing file fragmentation.

Preallocation. XFS reserves disk space before blocks of data are actually written. This also helps to avoid file fragmentation as a complete file gets more likely to be written to a contiguous series of blocks on the disk.

Advertisement

Sparse files. If a file contains chunks of zero data, instead of allocating disk space for them, the system writes only some metadata representing those empty blocks and thus avoids wasting storage space on “zeros”.

Disk quotas. XFS supports disk quotas which allow efficiently managing disk resources by restricting the number of files created by a certain user/user group or the amount of storage space used.

Advertisement

Extended attributes. Extended attributes enable the user to attach arbitrary metadata (in the form of a name-value pair) to any file or inode. Unlike regular attributes, which are strictly defined by the file system, they may contain any information like the author of the document or a digital signature.

Advanced Input/Output. The use of multiple allocation groups allows for extremely high-speed parallel I/O operations.

Advertisement

Volume snapshots. Snapshots allow creating a copy of a volume at a specific point in time and when necessary, revert the file system back to that state.

Online defragmentation and resizing. The file system can be defragmented or enlarged while being mounted and active.

Advertisement

Native backup/restore. XFS features native backup and restoration, which can be performed with the help of the inbuilt xfsdump and xfsrestore utilities. Moreover, even the files which, for some reason, failed to receive a backup, contrary to the popular belief, in case of data loss have extremely high chances to be recovered. Although some specialists claim that data lost from XFS is totally unrecoverable, several data recovery tools such as UFS Explorer, Recovery Explorer and Raise Data Recovery have been successfully dealing with this task for many years.

Illustration for article titled The XFS File System Explained for Beginnersem/em
Advertisement

Yet, this file system also has several weaknesses. First of all, a partition formatted with XFS cannot be shrunk, although you still can make a backup, create a new smaller file system and then restore to it. Secondly, XFS doesn’t have any native methods of data compression. Moreover, the file system doesn’t employ checksums to ensure the integrity of stored user data and detect all rotten bits as soon as possible, hence, some files may silently become corrupt, and when this finally gets out, it may already be too late to remedy the problem and massive data loss will be inevitable. Also, XFS does use journaling for metadata, but it doesn’t journal any data changes, therefore, in case of an unexpected system shutdown you are likely to lose the data from files that were open at that moment. In addition, if you have a Windows/Linux dual boot system, Windows won’t be able to read the XFS-formatted partition without any additional tools.

To find out whether it is XFS that powers your disk, use the file command with the -s option, which will show the information about the type of the file system.

Advertisement

Overall, despite being not without a flaw, XFS is a quite reliable and feature-rich file system which excels at managing high-capacity storage media. If you need to store and access large files, XFS is probably your best bet.

Share This Story

Get our newsletter