Which is faster XFS or EXT4?

Linux has a wide variety of file systems to choose from. The two most popular general purpose file systems are XFS and EXT4. XFS was developed by Silicon Graphics in the early 1990s for their IRIX operating system. EXT4 is the latest version of the EXT file system and was introduced in 2008. It is the default file system for many popular Linux distributions.

Comparing XFS and EXT4 allows users to understand the strengths and weaknesses of each file system. This helps determine which file system may be better suited for a particular use case. Factors like performance, reliability, and scalability need to be considered when deciding between XFS and EXT4. This article provides an in-depth comparison between the two file systems.

History of XFS and EXT4

The Ext4 filesystem was created as an extension of the Ext3 filesystem that was initially developed by Stephen Tweedie in 1999. The Ext3 filesystem was designed for Linux to succeed the Ext2 filesystem while adding journaling capabilities to improve reliability. Initially released in 2002, Ext3 gained widespread adoption and served as the default Linux filesystem for years, before being succeeded by Ext4 (https://opensource.com/article/17/5/introduction-ext4-filesystem).

Ext4 originated in 2006 led by developers from major companies including IBM, Google, Red Hat and SUSE. The main goal was to improve upon Ext3 by adding major new features like extents, multiblock allocation, delayed allocation, fast fsck, persistent pre-allocation and more. Ext4 was designed for modern hard drives, higher resolutions and large files. After several years of testing and development, Ext4 was merged into the Linux kernel in 2008 and released in many Linux distributions by 2009 (https://en.wikipedia.org/wiki/Ext4).

In contrast, XFS originated at Silicon Graphics in the mid-1990s for their IRIX operating system. It was designed for maximum performance and very large filesystems. In 2001, XFS gained support in the Linux kernel but lagged behind Ext2/3 in adoption. However, major companies like Red Hat have supported it for enterprise use cases. Over time, XFS has gained greater adoption for its performance advantages but still trails behind Ext4 in overall usage (https://en.wikipedia.org/wiki/XFS).

Technical Differences

XFS and EXT4 have some key technical differences in their on-disk format, journaling, extents vs block mapping, metadata, and scalability.

On-disk format: XFS uses B+ trees to index and organize data, while EXT4 uses traditional block mapping. This gives XFS some performance advantages for workloads involving large files. 1

Journaling: Both XFS and EXT4 utilize journaling to accelerate recovery after crashes or power outages. However, XFS uses write-ahead logging, while EXT4 uses ordered/writeback journaling modes. Write-ahead logging is considered more robust. 2

Extents vs block mapping: XFS uses extents for allocation mapping, allowing contiguous blocks to be tracked as a single extent. This improves performance for large files. Meanwhile, EXT4 uses traditional block mapping, which can lead to fragmentation over time. 3

Metadata: XFS stores metadata in B+ trees, optimizing it for scalability. In contrast, EXT4 has limited scalability for metadata. This impacts performance as metadata operations increase. 1

Scalability: The B+ tree implementation in XFS delivers excellent scalability as filesystems grow to multiple terabytes. EXT4 does not scale as well, since it uses traditional data structures. 2

Performance Benchmarks

Both XFS and EXT4 have been benchmarked extensively to compare their performance in areas like sequential vs random read/write, metadata operations, working with large files, and multithreaded workloads.

For sequential read and write performance, tests generally show XFS outperforming EXT4, especially as file sizes grow larger. In the Cloudflare blog (https://lyon-county-court.bizglow.cfd/), XFS delivered up to 20% faster sequential writes than EXT4 for 1GB files on SSD storage. XFS’s design optimizes sequential I/O, giving it an edge in access patterns like media streaming.

For random read/write operations, XFS and EXT4 tend to deliver comparable performance. In Filebench tests by Phoronix (https://steel-milling-machine-for-sale.turbospark.fun/), the two were neck-and-neck in 4KB random read/write performance on NVMe SSD storage.

When it comes to metadata-intensive operations, EXT4 generally outperforms XFS, as its metadata structures are more lightweight. This advantage is pronounced on systems with slower storage devices.

Both file systems handle large files well and can scale up to support exabyte file sizes. However, XFS may have a slight edge for very large files thanks to its64-bit allocation features.

In multithreaded workloads, XFS shows significantly higher scalability than EXT4. XFS maintains high throughput as concurrent operations increase, while EXT4 performance tends to plateau.

Use Cases

XFS and EXT4 each have advantages for certain use cases:

For media storage and production, XFS is often preferred due to its efficient handling of large files and high throughput for sequential I/O operations like video editing. XFS is optimized to sustain streaming reads and writes with minimal fragmentation.1

For database servers, EXT4 is generally recommended over XFS. EXT4 provides stronger crash consistency and recovery capabilities important for database integrity. The extent-based allocation in XFS can also lead to file system fragmentation over time with frequently updated database files.2

For virtual machines, EXT4 is often preferred. The delayed allocation feature in EXT4 avoids preallocating disk space for the virtual disk image, enabling thin provisioning. EXT4 also handles lots of small files well. XFS shows slower performance in some virtualization use cases.3

As a general purpose file system, EXT4 is recommended by most. It provides a good balance of reliability, performance, and compatibility for a wide range of workloads. XFS advantages like high throughput and large file support tend to be niche needs for general use.2

Reliability

Both XFS and Ext4 are considered reliable modern filesystems, but they take slightly different approaches to ensuring data integrity.

Ext4 uses metadata and data journaling to provide crash consistency. All metadata changes are written to the journal first before the main filesystem, ensuring filesystem consistency even after an unexpected reboot or power loss. However, file data itself is not journaled by default, so file corruption can still occur in some cases of power failure (Source 1).

XFS also uses metadata journaling but takes a more aggressive approach to preventing corruption. It does delayed allocation for file writes, meaning it reserves space on disk first before actually writing the data. This prevents partially written files from appearing in case of a crash. Additionally, XFS uses write barriers to ensure file data is fully persisted to disk before the write is considered complete (Source 2). This can improve data integrity compared to Ext4’s default configuration.

Both filesystems have robust checksumming to detect corruption if it does occur. Overall, XFS may have a slight edge for data integrity, especially when handling unexpected power losses. But both are designed for reliability and are excellent modern options.

Fragmentation

File system fragmentation occurs over time as files are created, modified, and deleted. This leads to storage space being fragmented and scattered across the disk, which can impact performance.

Both XFS and ext4 are susceptible to fragmentation, but handle it differently. Ext4 lacks automatic defragmentation, so over time fragmentation can become a problem. Defragmentation utilities like e4defrag are available but must be manually run. XFS implements delayed allocation to reduce fragmentation, but still sees some over time. However, XFS utilizes builtin defragmentation to optimize the file system in the background without needing manual defrag utilities.

According to this source, XFS exhibits lower fragmentation levels over time than ext4. The automatic defragmentation helps avoid some of the performance impacts of scattering files across the disk. For ext4, manual defragmentation may need to be periodically performed to counteract worsening fragmentation.

Popularity

Although both XFS and EXT4 are commonly used Linux file systems, EXT4 seems to be more widely adopted as the default file system in major Linux distributions. According to a survey on the Cloudera community forum, approximately 80% of respondents reported using EXT4 as the default file system, compared to 20% who reported using XFS (Cloudera). The default file system for Ubuntu, Debian, Fedora, openSUSE, and other distributions is EXT4.

On Reddit and other forums, many users report EXT4 as being their preferred file system over XFS due to its stability and reliability. However, XFS does seem to have a strong following among some advanced Linux users. Ultimately, both file systems have their advantages and disadvantages that make them suitable for different use cases. For most general purpose Linux installations, EXT4 remains the safe, default choice.

Advantages vs Disadvantages

Both XFS and EXT4 have their own sets of pros and cons that make them suitable for different use cases. Some key differences include:

XFS Advantages:

XFS has very high performance for large files and is great for systems that need to handle large multimedia files or large databases. It utilizes parallel I/O operations and metadata logging for faster writes. XFS also efficiently handles Drive arrays (RAID) and utilizes delayed allocation for faster file creation. Overall, XFS offers higher throughput for large files 1.

XFS Disadvantages:

XFS has higher memory requirements and can be slower with many small files. It is also more complex internally and lacks some standard Linux features like fsck for repairs. XFS isn’t quite as battle-tested and widespread as EXT4 2.

EXT4 Advantages:

EXT4 is the default Linux file system with strong community support. It handles small files very efficiently and has lower memory requirements. EXT4 offers reliable performance and is well-tested over decades of use. The EXT4 journal helps ensure file system integrity 3.

EXT4 Disadvantages:

EXT4 has slower performance with large files and is not optimized for parallel I/O. It also lacks some enterprise-grade features like delayed allocation offered by XFS. EXT4 can experience fragmentation over time which can degrade performance 1.

Conclusion

In summary, the key differences between XFS and EXT4 are their on-disk formats and performance optimizations. XFS utilizes allocation trees and has extremely high scalability for large filesystems, while EXT4 improved upon EXT3 with extents, preallocating, delayed allocation, and other features for enhanced performance on smaller filesystems.

In general performance benchmarks, XFS excels at handling large files and high levels of concurrent read/write operations, making it a great choice for large multimedia files and databases. EXT4 performs better with small files and has lower overhead, so it may be better suited for general purpose use cases like web servers and virtual machines.

For most everyday Linux uses, EXT4 is likely the safer, more stable choice. However, for data warehouses, HPC, video editing, and other cases involving substantial large files, XFS is worth considering for its scalability and performance advantages. Just be aware that enabling metadata journaling is recommended to avoid corruption issues.