Why Btrfs is better than Ext4?

Filesystems are a critical component of any operating system, enabling the underlying storage devices to be accessed in an organized hierarchical structure. They provide a layer of abstraction, allowing files and directories to be created, stored, found and manipulated easily and efficiently.

The filesystem organizes the hard disks/partitions into a single directory tree, starting from the root directory (/). All other folders branch off from this root folder. This unified view makes it easy to navigate the file structure irrespective of the underlying physical storage.

On Linux, there are several filesystem options to choose from like ext4, XFS, Btrfs etc. The default filesystem for most Linux distributions has been ext4 for many years now. However, some argue that Btrfs provides compelling benefits over ext4 and may become the new default for Linux filesystems going forward.

What is Btrfs?

Btrfs (pronounced “butter eff ess” or “better eff ess”) stands for B-tree file system and is a modern copy on write (COW) file system for Linux aimed at implementing advanced features while focusing on fault tolerance, repair, and ease of administration (Introduction — BTRFS documentation – Read the Docs). It has been under active development since 2007 by multiple contributors including Chris Mason from Oracle, Josef Bacik from Red Hat, and Facebook.

Some key features of Btrfs include:

  • Writable snapshots and rollbacks – Ability to create lightweight read-only snapshots of a filesystem and restore or rollback changes if needed.
  • Subvolumes – Separate internal filesystem roots that look like regular directories but can have different mount options, permissions etc.
  • RAID support – Support for RAID 0, RAID 1 and RAID 10 configurations.
  • Efficient incremental backups – Uses copy-on-write technique to only copy changed data blocks.
  • Online defragmentation and resizing – Filesystem can be defragmented and resized while mounted and active.
  • Checksumming of data & metadata – Detects silent data corruption issues.
  • In-band deduplication – Detects duplicate blocks and saves space by only referencing one copy.

The development of Btrfs started in 2007 to overcome limitations of existing Linux file systems like ext3/ext4. It is designed to scale well for large storage volumes and enterprise use cases. However, it is still considered experimental and not enabled by default in most distributions (Btrfs – Wikipedia).

What is Ext4?

Ext4 is a journaling file system for Linux, developed as the successor to Ext3. It was designed to overcome some of the limitations of Ext3 and improve performance and reliability (Introduction to Ext4).

Ext4 was introduced in 2008 in the Linux 2.6.28 kernel. It is the default file system for many popular Linux distributions including Ubuntu, RHEL, CentOS, and SUSE (Ext4 Wikipedia).

Some key features of Ext4 include (Ext4 Disk Layout):

  • Backwards compatibility with Ext3
  • Improved performance via delayed allocation, faster filesystem checks, and journal checksumming
  • Larger file sizes – up to 16 TB per file
  • Larger volume sizes – up to 1 EB
  • Extents for reducing fragmentation and improving large file performance
  • Persistent pre-allocation for improved performance

Overall, Ext4 improved on Ext3 by adding new features focused on performance, reliability, and scalability for modern Linux systems.

Performance

When it comes to performance benchmarks, Ext4 generally outperforms Btrfs in tests like dbench, Flexible I/O (FIO), and Compile Bench. However, real-world performance can vary depending on the workload.

According to some benchmark charts, Btrfs has measurably worse performance than Ext4 for everyday tasks like file copying, file compression, and file extraction (source). Ext4’s faster codebase and optimization for common workloads give it an advantage.

However, Btrfs has significantly better performance with small files compared to Ext4. This is because Btrfs is optimized for handling small files, while Ext4 struggles in this area (source).

For gaming and desktop use, benchmarks show Ext4 generally outperforms Btrfs. However, for some specialized workloads involving lots of small files, Btrfs can be faster.

Reliability

Btrfs offers improved reliability over Ext4 through several features like checksums, snapshots, and self-healing.1 Checksums allow Btrfs to detect data corruption, then use replicated metadata and data to self-heal corrupted files. Snapshots provide point-in-time copies of files, directories or entire filesystems with minimal disk space usage. This protects against data loss and allows easy restores.

Overall, Btrfs provides strong reliability tools to detect and recover from disk errors. However, as a more complex filesystem than Ext4, some users have reported instances where Btrfs’ self-healing mechanisms caused further damage.2 So while the features are there, real-world usage indicates reliability is a work-in-progress for Btrfs.

Scalability

Btrfs is designed to scale to very large storage sizes and handle extremely large numbers of files. According to the Btrfs Wikipedia page, “Scaling is not just about addressing the storage but also means being able to administer and to manage it with a clean interface that lets people see what’s happening at a higher level.”1 Btrfs scales to 16 exabytes (EB) of storage and over 2^64 files per file system.2 This massive scalability makes Btrfs well-suited for large storage servers and filesystems.

In comparison, Ext4 scales up to 1 exabyte and limits the number of subdirectories in a single directory to around 32,000. Ext4 hits scalability limits much quicker than Btrfs.

Features

Btrfs offers several advanced features that make it attractive compared to Ext4:

Snapshots – Btrfs supports creating lightweight read-only snapshots of files, directories or the entire filesystem without duplicating the data. Snapshots make backups fast and space efficient.1

Built-in volume management – Btrfs has built-in support for RAID configurations like RAID 0, 1 and 10. It can span multiple devices into a single filesystem pool.2

Compression – Btrfs supports transparent compression to optimize storage space utilization. Both file data and metadata can be compressed.3

Subvolumes – Btrfs enables creating isolated mountable filesystems within a parent filesystem to organize data or control snapshot access. Subvolumes appear as normal directories but are independently mountable.2

Adoption

Btrfs adoption has been mixed among Linux distributions and other major users. According to Wikipedia, in 2015, Btrfs was adopted as the default filesystem for SUSE Linux Enterprise Server (SLE) 12. However, in August 2017, Red Hat announced in the release notes for Red Hat Enterprise Linux 7.4 that it would no longer be supporting Btrfs due to its lack of full repair capabilities and growing maintenance costs.

On the other hand, according to a Red Hat discussion forum post, Fedora has adopted Btrfs as its default filesystem because it wants to utilize Btrfs’ capabilities like diffing of updates and other system facilities. The post speculates that Red Hat Enterprise Linux’s abandonment of Btrfs may have been more related to enterprise requirements for stability over leading-edge features.

Overall, Btrfs adoption among major Linux distributions has been mixed, with some like SUSE embracing it as a next-generation filesystem, while others like Red Hat have retreated from using it by default due to concerns over stability and maintenance costs.

Downsides of Btrfs

While Btrfs offers many advantages over Ext4, it also comes with some downsides worth considering. One key issue is fragmentation. As Btrfs Uses Copy-on-Write for All Files, files end up stored across the disk in pieces rather than in contiguous blocks. This fragmentation can degrade read/write performance over time. Unfortunately Btrfs currently lacks built-in defragmentation tools to optimize and reorganize data.

Btrfs’s snapshotting and copies also result in increased storage overhead compared to Ext4. The filesystem must track and store multiple copies of data. So for some use cases, Btrfs may require more storage capacity than a typical filesystem.

In addition, some users have reported issues with Btrfs and scrubbing. The scrubbing process checks data integrity, but can freeze systems in some scenarios. There are also concerns around Btrfs’s RAID 5 and 6 implementations, with RAID 5 in particular labeled experimental and potentially dangerous.

Overall while mature and stable, Btrfs is a relatively new filesystem compared to seasoned options like Ext4. It may take more time and testing to iron out issues around fragmentation, integrity checking, and RAID support.

Conclusion

In summary, Btrfs has several advantages over Ext4 that make it generally considered the better file system choice for most use cases. Btrfs was designed more recently and incorporates newer features focused on reliability, scalability, and performance. Key advantages of Btrfs include:

  • Improved performance with SSDs and large files due to extents and cloning.
  • More reliability from built-in checksums and self-healing capabilities.
  • Better scalability to large drives and storage pools through flexible allocate-on-demand.
  • More features like snapshots, compression, and subvolumes.

The main downsides of Btrfs include lower performance with small files and less stability/maturity compared to the older Ext4. However, Btrfs continues to improve and has become the default choice for many Linux distributions. For most general home and business use cases today, especially on SSD storage, Btrfs offers a compelling advantage and is considered the better overall modern file system versus Ext4.

Leave a Comment