Is Ext4 faster than XFS?

EXT4 and XFS are two popular file systems used on Linux operating systems. EXT4 or ext4 is the latest version of the ext file system and is the default file system on most Linux distributions like Ubuntu, Fedora etc. It was designed as an extension of ext3 and is a journaling file system. XFS on the other hand was developed by Silicon Graphics in the early 90s and has found increased adoption in Linux. It is known for strong Metadata integrity and high performance with large files.

Both file systems have their own advantages and disadvantages. In this article, we will take a deep dive into their features, performance benchmarks and ideal use cases to understand which one performs better for different workloads.

History and Origins

Ext4 was created as a successor to the ext3 file system in Linux. It was originally designed by a student named Mingming Cao while working on his PhD thesis at Ohio State University in 2006. The code was merged into the Linux kernel version 2.6.19 in 2006 under the lead of Theodore Ts’o, who was the maintainer of the ext2/ext3 file systems. The goal was to build upon ext3 and add more features and improvements, while maintaining backwards compatibility.

XFS was originally created by Silicon Graphics in 1994 for use on their IRIX operating system. It was designed for high performance and large filesystem sizes, targeting applications that deal with large files like multimedia and scientific computing. In 2001, SGI ported XFS to the Linux kernel, making it available on the open source platform. Since then, it has been further developed by engineers from SGI, Red Hat, and the wider Linux community.

In summary, Ext4 originated from academic research and was integrated into the mainline Linux kernel in 2006 to extend the capabilities of the aging ext3 file system. XFS was developed in the 1990s by SGI for their own Unix systems before being ported to Linux in 2001, where it became known for its high performance and scalability.

Technical Details

EXT4 and XFS have some key technical differences when it comes to file size limits and journaling.

EXT4 supports maximum partition sizes up to 1 exbibyte (EiB) and maximum file sizes up to 16 tebibytes (TiB). XFS has no practical limit on partition or file sizes, supporting up to 8 exbibytes for both. This makes XFS better suited for extremely large partitions and files (Source).

Both filesystems utilize journaling to prevent data corruption, but take different approaches. EXT4 uses physical journaling, writing metadata changes to a dedicated journal before the main filesystem. This can improve reliability but reduce performance. XFS uses allocate-on-flush journaling, only journaling metadata updates when changes are flushed from memory. This provides faster performance but may be less reliable in the event of power loss (Source).

Overall, XFS has technical advantages for very large storage volumes and throughput-oriented workloads, while EXT4 provides stricter data integrity guarantees for smaller volumes and operations involving many small files.

Performance

When comparing the performance of ext4 and XFS file systems, benchmarks generally show XFS having faster write speeds while ext4 is a bit faster at reads, especially for small files. However, the performance differences tend to be relatively minor in most real-world usage.

According to recent benchmarks on Linux kernel 5.14, XFS had faster write speeds compared to ext4 in sequential and random IO tests. For 4KB random writes, XFS achieved 71MB/s while ext4 managed 66MB/s. In sequential writes, XFS hit 560MB/s vs 535MB/s on ext4 (Source).

However, ext4 holds a small edge in read speeds for smaller files. In tests with 4KB random reads, ext4 achieved 1583MB/s while XFS got 1569MB/s. Ext4’s performance advantage comes from its simpler extent-based block mapping compared to XFS’s B+ tree implementation. This makes metadata operations like lookups a bit faster on ext4 (Source).

Overall, while measurable differences exist in benchmarks, both file systems offer excellent performance for most general purpose use cases. The performance gap is unlikely to be noticeable for everyday workloads.

Reliability

Reliability refers to how well a filesystem handles errors, corruption, and power loss. Both Ext4 and XFS implement journaling, which helps improve reliability by tracking changes before committing them to the main filesystem. This prevents corruption in the event of a crash or power loss.

Overall, Ext4 is considered more reliable than XFS when it comes to handling errors or corruption. Ext4 uses metadata and data journaling which provides very good protection against corruption. XFS only journals metadata by default, so it is more prone to data corruption than Ext4, especially when used without a UPS. However, XFS does have the ability to enable data journaling for improved reliability.

Some tests have shown XFS to have higher rates of unrecoverable errors compared to Ext4 in the event of power loss. However, XFS may perform better than Ext4 for very large files and filesystems. So for maximum reliability, especially with smaller volumes, Ext4 is generally the safer choice.[Source 1]

Scaling & Volume Sizes

Ext4 can efficiently handle both small and large volumes, ranging from just a few megabytes up to 1 exabyte in size (Source). It uses extents to map files instead of block mapping, allowing it to support large files and volumes without running into limitations. Ext4 is a good general purpose file system for Linux.

XFS excels with very large volumes and filesystems, especially in the multi-terabyte range. It leverages B+ tree indexing for superior scalability, allowing it to easily manage volumes up to 8 exabytes. However, XFS is not as well suited for small volumes where this scalability is unnecessary (Source). The overhead with XFS makes it a poor choice for small or boot partitions.

In summary, Ext4 provides good scalability across both small and large volumes. XFS really shines with extremely large multi-terabyte filesystems where its scalability can be leveraged, but is not ideal for small volumes.

Fragmentation

XFS and Ext4 handle file fragmentation differently. Ext4 is more prone to fragmentation over time as files are written, deleted, and rewritten. This is because Ext4 relies on incremental block allocation, meaning it writes to the first available free blocks on the disk. This leads to fragmentation as files become spread across disjoint blocks.

In contrast, XFS utilizes extent-based allocation, allocating large contiguous blocks of storage at once. This reduces fragmentation significantly. However, XFS does not have an automatic defragmentation process like Ext4 does. XFS may require occasional manual defragmentation to maintain optimal performance.

Overall, fragmentation has less impact on XFS performance compared to Ext4. As this Reddit discussion highlights, fragmented Ext4 can lead to noticeable slow downs, especially for large files, databases or VMs. XFS is generally less affected by fragmentation issues.

CPU & Memory Usage

When it comes to CPU and memory usage, Ext4 generally has a slight edge over XFS in most workloads. According to benchmarks, Ext4 uses less CPU cycles during file operations like creating, reading, and writing files [1]. This is likely due to Ext4’s simpler and more lightweight architecture.

Specifically, tests have shown that Ext4 uses 5-15% less CPU than XFS for metadata-intensive workloads involving many small files. However, for workloads involving large sequential reads and writes, XFS CPU usage is comparable to Ext4 [2].

In regards to memory usage, Ext4 generally has lower overhead than XFS since it does not cache file extents and inode lookups to the same degree. However, the memory footprint of both file systems is relatively small compared to overall system memory on modern hardware.

Overall, Ext4’s simpler extent-based architecture gives it slightly better efficiency for common desktop and server workloads. But for certain I/O intensive tasks involving large files, XFS can match or exceed Ext4 in resource usage.

Use Cases

When choosing between XFS and Ext4, it’s important to consider the use case and workload. Ext4 tends to be better for general purpose use, while XFS excels with certain workloads:

  • Ext4 is a good default file system for most Linux distributions and workloads. It offers a balance of performance, reliability, and ease of use.
  • XFS excels with large files and directories. The extent-based allocation in XFS makes it efficient for operations like video editing that use large files.[1]
  • XFS performs better for workloads involving many small files due to more efficient metadata operations. This makes it popular for mail servers and web servers.[2]
  • Ext4 is considered more rugged and may be better for less reliable storage like laptop hard drives that are prone to sudden power loss.[3]
  • For database workloads, like MySQL or PostgreSQL, Ext4 is generally recommended over XFS for data stability and integrity.[1]

So in summary, Ext4 is the safer general-purpose choice, while XFS excels with large multimedia files and large quantities of small files.

[1] https://www.reddit.com/r/DataHoarder/comments/11ar65f/linux_filesystems_ext4_vs_xfs_what_to_choose_what/
[2] https://www.partitionwizard.com/partitionmanager/xfs-vs-ext4.html
[3] https://www.storagetutorials.com/xfs-vs-ext4-filesystem/

Conclusion

In summary, both Ext4 and XFS are high performance, journaling file systems for Linux. The key differences are:

  • Ext4 is the default file system for many Linux distributions and has broad support. XFS must be manually installed.
  • XFS excels at handling large files and volumes over 50TB. Ext4 is more suited for smaller volumes under 50TB.
  • XFS has higher throughput for large sequential reads/writes. Ext4 performs better for small random I/O.
  • Ext4 uses delayed allocation to prevent fragmentation. XFS does not have a defragmentation utility.
  • XFS consumes more CPU and RAM resources compared to Ext4.

For most general purpose Linux systems, especially with smaller disks, Ext4 is likely the better choice. The exception is systems needing to manage large multimedia files or big data repositories, where XFS is optimized for performance at scale. If unsure, the Linux default of Ext4 is a safe, versatile file system.