Linux Commands

Comparison Between Btrfs and XFS Filesystems

There are many filesystems available for use with Linux. The most common Linux filesystems include Ext4, Btrfs, XFS, and ZFS. Every filesystem has its unique use cases, pros, and cons. Due to the variety of options available, you may have a hard time deciding which filesystem to use.To help you with your choice, this article compares the XFS and the Btrfs filesystems. If you are having a hard time deciding whether to use the XFS filesystem or the Btrfs filesystem, then this article should help. Let us begin!

Introduction to XFS and Btrfs Filesystems

XFS Filesystem: XFS is a high-performance 64-bit journaling filesystem. It was originally developed by Silicon Graphics, Inc. in 1993 for the IRIX operating system and was later ported to the Linux kernel in 2001.

Btrfs Filesystem: Btrfs or the B-Tree filesystem is a modern Copy-on-Write (CoW) filesystem. It is new compared to the Ext filesystem. Btrfs was originally designed for the Linux operating systems by the Oracle Corporation in 2007. In November 2013, the Btrfs filesystem was declared stable for the Linux kernel.

Feature Comparison

The XFS and Btrfs filesystems were designed to solve different types of problems. Though the design goal of the XFS filesystem was different than that of the Btrfs filesystem, because they are both filesystems, we may compare them in depth.

  • Maximum Partition Size: The XFS filesystem supports partition sizes of up to 1 byte less than 8 EiB (8 EiB – 1 byte).
  • The Btrfs filesystem supports partition sizes of up to 16 EiB.
  • Maximum File Size: The XFS filesystem supports file sizes of up to 1 byte and less than 8 EiB (8 EiB – 1 byte).
  • The Btrfs filesystem supports file sizes of up to 16 EiB.
  • Maximum Filename Length: The XFS filesystem supports filenames up to 255 characters (255 bytes) in length.
  • The Btrfs filesystem also supports filenames up to 255 characters (255 bytes) in length.
  • Allowed Characters in Directory and Filenames: The XFS filesystem allows any characters except the / and NULL (\0) characters in directory and file names.
  • The Btrfs filesystem also allows any characters except the / and NULL (\0)characters in directory and file names.

NOTE: You cannot create a file or directory with the name . and .. in either of the XFS or Btrfs filesystems.

  • Maximum Path Length: The XFS filesystem does not have any limits to the length of the path of a file or directory. So, you can create deep directory structures and keep your files in these structures.
  • The same is true for the Btrfs filesystem.
  • Max Number of Files: You can create a maximum of 264 (= 18,446,744,073,709,551,616 ~= 18 quintillion) files in an XFS filesystem.
  • The same is true for the Btrfs filesystem.
  • Inode Allocation Method: An inode is a filesystem data structure used to describe a file or a directory. So, a single directory or file requires one inode, two directories or files will require two inodes, and so on.
  • In the Ext4 filesystem, you define the number of inodes the filesystem can support when creating the filesystem. You cannot change this after the filesystem has been created. If you create too many small files, you may have free disk space left on your filesystem, but you will not be able to create new files/directories unless you have free inodes. This is a major limitation to the Ext4 filesystem.
  • Unlike the Ext4 filesystem, inode allocation is flexible in the XFS filesystem. So, the filesystem can add as many inodes as needed and you will never run out of inodes.
  • The above is also true for the Btrfs filesystem.
  • Checksum/ECC Support: The Btrfs filesystem keeps crc32c checksum of the data and metadata stored in the filesystem. So, in the case of data corruption, the Btrfs filesystem can detect the corruption and recover the corrupted files or metadata.
  • The XFS filesystem only keeps the CRC32 checksum of the metadata. It does not keep a checksum of the data stored in the filesystem, unlike the Btrfs filesystem.
  • Journal and Copy-on-Write Support: The XFS filesystem is a journaling filesystem. It does not have Copy-on-Write (CoW) support.
  • The Btrfs filesystem is a Copy-on-Write (CoW) filesystem and it does not have journal support.
  • Filesystem Snapshot: The XFS filesystem cannot take snapshots of the filesystem.
  • The Btrfs filesystem can take snapshots of the filesystem. With Btrfs, you may take read-only snapshots and writable snapshots of the filesystem.

NOTE: The filesystem snapshot is an important feature. You may take a snapshot of your filesystem using this feature before attempting any risky actions. If things do not go as planned, a snapshot allows you to go back to an earlier state in which everything in the system worked. This is a built-in feature of the Btrfs filesystem. You do not need any third-party tools or software to generate a snapshot of a Btrfs filesystem.

  • Filesystem-level Encryption: The Btrfs filesystem does not support filesystem-level encryption.
  • The same is true for the XFS filesystem.
  • Filesystem-level Deduplication: The Btrfs filesystem supports deduplication at the filesystem level. You do not need any third-party tools or software to use this feature.
  • The XFS filesystem also has deduplication support, but the deduplication feature of the XFS filesystem is still experimental.

NOTE: Depulication is a technique for eliminating duplicate copies of data from the filesystem and keeping only one copy of the data (unique data) in the filesystem. This technique is used to save disk space.

  • Multiple Devices Support: The Btrfs filesystem supports multiple devices and includes built-in RAID support. The Btrfs filesystem has a built-in logical volume manager (LVM) for adding multiple storage devices or partitions to a single Btrfs filesystem. A single Btrfs filesystem can span over multiple disks and partitions.
  • The XFS filesystem does not support multiple devices, meaning that you cannot span a single XFS filesystem over multiple disks or partitions. To combine multiple storage devices and partitions in an XFS filesystem, you must use third-party logical volume managers, such as LVM 2. To set up RAID, you must use third-party tools such as dm-raid or mdadm.
  • The XFS filesystem was designed to execute I/O (input/output) operations in parallel. If you span the XFS filesystem over multiple devices using LVM 2 or a different logical volume manager, the filesystem performance will be increased.
  • Filesystem-level Compression: The XFS filesystem does not include built-in filesystem-level compression support.
  • The Btrfs filesystem includes built-in filesystem-level compression support. This feature allows you to compress a single directory, a single file, or the entire filesystem to save disk space.
  • Offline Filesystem Resize Capabilities: You cannot grow (increase filesystem size) or shrink (decrease filesystem size) an XFS filesystem while the filesystem is not mounted.
  • You can grow (increase filesystem size) or shrink (decrease filesystem size) a Btrfs filesystem while the filesystem is not mounted.
  • Online Filesystem Resize Capabilities: You can grow (increase filesystem size) an XFS filesystem while the filesystem is mounted, but you cannot shrink (decrease filesystem size) an XFS filesystem while the filesystem is mounted.
  • You can grow (increase filesystem size) or shrink (decrease filesystem size) a Btrfs filesystem while the filesystem is mounted.
  • Sparse files: The sparse file feature saves disk space when small files (smaller than the block size) are stored on the filesystem. The XFS and the Btrfs filesystems both support sparse files.
  • Block sub-allocation: The Btrfs filesystem supports block sub-allocation.
  • The XFS filesystem does not support block sub-allocation.

NOTE: When a filesystem stores large files in a filesystem, the large file is broken into blocks, and the blocks are stored in the filesystem. The last block of the file, called the tail block, does not occupy the entire block. When many small files are stored, they do not occupy the entire block, and a lot of disk space is wasted. Block sub-allocation allows you to store parts of another file block in the tail block (the last block of another file that did not occupy the entire block) to save disk space.

  • Tail packing: The Btrfs filesystem supports tail packing.
  • The XFS filesystem does not support tail packing.

NOTE: Tail packing is a part of block sub-allocation. As previously discussed, small files do not occupy an entire file block. To efficiently store small files (e.g., program source codes) in the filesystem, the tail block of a small file is used to store other small files. Tail packing improves filesystem performance and saves disk space in filesystems in which many small files (e.g., program source codes) are stored.

  • Extent-based Filesystem: Both the XFS and Btrfs filesystems are extent-based filesystems.

NOTE: An extent is a contiguous area of the storage device reserved for a file in a filesystem. Extent-based filesystems store large files in a contiguous storage area. This improves filesystem performance and increases storage efficiency.

  • Variable file block size: The block size is set before the filesystem is created. Once the filesystem is created, you cannot change the block size.
  • The XFS filesystem supports fixed block size.
  • The Btrfs filesystem supports variable block size. The filesystem can determine the best possible block size to store a file on the filesystem based on the size of the file. This feature can save a lot of disk space.
  • Allocate-on-flush: Both the XFS and Btrfs filesystems support allocate-on-flush.

NOTE: The filesystem allocates some buffer space in the system memory. When there are disk write requests, the filesystem does not write the data blocks directly on the storage device. Instead, the filesystem stores the data blocks in the buffer memory. When the buffer memory is full, the filesystem writes all the pending data blocks to the storage device at once. This reduces CPU usage, speeds up disk writes, and reduces disk fragmentation.

  • TRIM support: Both the XFS and Btrfs filesystems support TRIM, which is a very important feature for SSD storage devices.

NOTE: When you remove a file from an SSD, the TRIM command notifies the SSD storage device of the pages (file blocks) that are no longer needed. The SSD erases the unnecessary pages (file blocks) from the flash storage and prepares the pages (file blocks) for storing new data. Without TRIM support, the SSD write speed would become progressively slower as the SSD fills with new data.

Advantages of XFS over Btrfs

XFS is a stable 64-bit journaling filesystem for high-capacity storage devices.

You may use the XFS filesystem for the following reasons:

  • Parallel I/O (Input/Output) Support

The XFS filesystem supports parallel I/O and can provide multiple data streams for files due to its design.

  • Large partition support

The XFS filesystem supports partition sizes of up to 8 EiB (up to 8 EiB – 1 byte).

  • Large file support

The XFS filesystem supports file sizes of up to 8 EiB (up to 8 EiB – 1 byte).

  • Journaling Support

Journaling ensures data consistency in the filesystem in the event of a power outage or system crash. In the event of a power outage or system crash, the data stored in the journal will be recovered and applied to the filesystem.

  • Direct I/O

This is an important feature of the XFS filesystem. It is essential for applications that require high read/write speed to storage devices. Direct I/O allows storage devices direct access to the data buffer using DMA (Direct Memory Access) so that the full I/O bandwidth of the storage device can be utilized.

  • Guaranteed-rate I/O

The XFS filesystem can reserve the bandwidth of the storage device for certain applications. This feature is ideal for real-time applications (e.g., video streaming).

Disadvantages of the XFS Filesystem

There are some disadvantages to the XFS filesystem.

Disadvantages of the XFS filesystem include the following:

  • No Built-in LVM Support

Compared to the Btrfs filesystem, the XFS filesystem does not have a built-in logical volume manager. So, you will have to use LVM 2 for logical volume management.

  • No Built-in RAID Support

Compared to the Btrfs filesystem, the XFS filesystem does not have built-in RAID support. So, you will have to use dm-raid or mdadm to configure RAID.

  • No Snapshot Support

The XFS filesystem does not have a filesystem snapshot feature, unlike the Btrfs filesystem.

  • Journaling Cannot Be Disabled

As with some other journaling filesystems, you cannot disable the journaling feature of the XFS filesystem. Journaling is not good for USB flash drives. If you use the XFS filesystem on a USB flash drive, the lifetime of the USB flash disk will be reduced due to the journaling overload.

Advantages of Btrfs over XFS

The Btrfs filesystem is a modern Copy-on-Write (CoW) filesystem designed for high-capacity and high-performance storage servers. XFS is also a high-performance 64-bit journaling filesystem that is also capable of parallel I/O operations. The XFS filesystem contains many important features, including Direct I/O, Guaranteed-rate I/O, and more. Compared to the XFS filesystem, however, the Btrfs filesystem has many advantages.

The advantages of the Btrfs filesystem over the XFS filesystem include the following:

i) Built-in Filesystem-level snapshots.

ii) Multiple device support.

iii) Built-in RAID support.

iv) Flexible inode allocation.

v) Optimizations for storing smaller files (sparse files, block sub-allocation, tail packing, variable block size).

vi) Built-in filesystem-level compression support.

These are the filesystem features that may cause you to choose the Btrfs filesystem over the XFS filesystem.

Conclusion

This article compared the Btrfs and XFS filesystems, including a comparison of the most important features of each filesystem. This article should help you to decide between the Btrfs and XFS filesystems. Choose whichever system works best for you, according to your unique needs and preferences.

References:

  1. XFS – Wikipedia – https://en.wikipedia.org/wiki/XFS
  2. Comparison of file systems – Wikipedia – https://en.wikipedia.org/wiki/Comparison_of_file_systems
  3. XFS – ArchWiki – https://wiki.archlinux.org/index.php/XFS

About the author

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.