In this article, I will compare the Ext4 and the Btrfs filesystem. So, if you’re having a hard time deciding whether to use the Ext4 filesystem or the Btrfs filesystem, then
Introduction to the Ext4 and the Btrfs Filesystems:
Ext4 Filesystem: Ext4 is the fourth version of the Ext (Extended) filesystem. It is a successor to the Ext3 filesystem. The first version of the Ext filesystem was release in 1992 for the Minix operating system. It was later ported on Linux operating systems. The Ext4 filesystem was released in 2008. Ext4 is a journaled filesystem.
Btrfs Filesystem: Btrfs or the B-Tree filesystem is a modern Copy-on-Write (CoW) filesystem. It is new compared to the Ext filesystem. It was designed for the Linux operating systems at Oracle Corporation in 2007. In November 2013, the Btrfs filesystem was declared stable for the Linux kernel.
Feature Comparisons of the Ext4 and Btrfs Filesystems:
The Ext4 and Btrfs filesystem was designed to solve different types of problems. So, the design goal of the Ext4 filesystem was different than the Btrfs filesystem. Still, they are filesystems. They do have some similarities that we can compare.
i. Maximum Partition Size: The Ext4 filesystem supports partition sizes up to 1 EiB.
The Btrfs filesystem supports partition sizes up to 16 EiB.
ii. Maximum File Size: The Ext4 filesystem supports file sizes up to 16 TiB (for standard 4 KiB block size).
The Btrfs filesystem supports file sizes up to 16 EiB.
iii. Maximum Filename Length: The Ext4 filesystem supports up to 255 characters (255 bytes) long file names.
The Btrfs filesystem also supports up to 255 characters (255 bytes) long file names.
iv. Allowed Characters in Directory and Filenames: The Ext4 filesystem allows any characters except the / and NULL (\0) characters in directory and file names.
NOTE: You can’t create a file or directory with the name. and .. in either the Ext4 or the Btrfs filesystem.
v. Maximum Path Length: The Ext4 filesystem does not have any limits to the length of the path of a file or directory. So, you can create very very deep directory structures and keep your files there.
The same is true for the Btrfs filesystem.
vi. Max Number of Files: You can create at max 232 (= 4,294,967,296 ~= 4 billion) files in an Ext4 filesystem.
You can create at max 264 (= 18,446,744,073,709,551,616 ~= 18 quintillion) files in a Btrfs filesystem.
vii. inode Allocation Method: An inode is a filesystem data structure that is used to describe a file or a directory. So, a directory or a file requires 1 inode. 2 directories or 2 files will require 2 inodes.
In the Ext4 filesystem, you define the number of inodes the filesystem can supports while you create the filesystem. You can’t change it after the filesystem is created. If you create too many small files, you may have free disk space left on your filesystem, but you won’t be able to create new files/directories unless you have free inodes. This is a big limitation of the Ext4 filesystem.
In the Btrfs filesystem, the inode allocation is flexible. The filesystem can add as many inodes as needed. So, you will never run out of inodes.
viii. Checksum/ECC Support: The Ext4 filesystem does not keep checksum of the data stored on the filesystem.
The Btrfs filesystem keeps crc32c checksum of the data stored on the filesystem. So, in case of any data corruption, the Btrfs filesystem can detect it and recover the corrupted file.
ix. Journal and Copy-on-Write Support: The Ext4 filesystem is a journaling filesystem. It does not have any Copy-on-Write (CoW) support.
The Btrfs filesystem is a Copy-on-Write (CoW) filesystem, and it does not have any journal support.
x. Filesystem Snapshot: The Ext4 filesystem can’t take snapshots of the filesystem.
The Btrfs filesystem can take snapshots. You can take read-only snapshots and writable snapshots.
NOTE: Filesystem snapshot is an important feature. Using this feature, you can take a snapshot of your filesystem before trying out anything risky. If things do not go as planned, you can go back to an early state where everything worked. This is a built-in feature of the Btrfs filesystem. You don’t need any 3rd-party tools/software to do that on a Btrfs filesystem.
xi. Filesystem-level Encryption: The Ext4 filesystem has experimental support for filesystem-level encryption.
The Btrfs filesystem does not have any support for filesystem-level encryption.
xii. Filesystem-level Deduplication: The Ext4 filesystem does not have deduplication support.
The Btrfs filesystem supports deduplication on the filesystem-level. You don’t need any 3rd-party tools/software for that.
NOTE: Depulication is a technique to eliminate/remove duplicate copies of data from the filesystem and keep only one copy of data (unique data) on the filesystem. This technique is used to save disk spaces.
xiii. Multiple Devices Support: The Btrfs filesystem supports multiple devices and has built-in RAID support. The Btrfs filesystem has a built-in logical volume manager (LVM) that is used to add multiple storage devices or partitions to a single Btrfs filesystem. A single Btrfs filesystem can span over multiple disks and partitions.
The Ext4 filesystem does not support multiple devices. You can’t span a single Ext4 filesystem over multiple disks or partitions. To combine multiple storage devices and partitions in an Ext4 filesystem, you have to use 3rd-party logical volume managers like LVM 2. To set up RAID, you have to use 3rd-party tools like DM-RAID or MDADM.
xiv. Filesystem-level Compression: The Ext4 filesystem does not have built-in filesystem-level compression support.
The Btrfs filesystem has built-in filesystem-level compression support. It can compress a single directory or a single file or the entire filesystem to save disk space.
xv. Offline Filesystem Resize Capabilities: The Ext4 filesystem has support for offline filesystem growing (increase filesystem size) and shrinking (decrease filesystem size).
The Btrfs filesystem also supports offline filesystem growing and shrinking.
xvi. Online Filesystem Resize Capabilities: The Ext4 filesystem has support for online growing (increase filesystem size when mounted). But it has no support for online filesystem shrinking (decrease filesystem size when mounted).
You can grow (increase filesystem size) and shrink (decrease filesystem size) Btrfs filesystems online (when mounted).
xvii. Sparse files: Sparse file feature save disk space when small files (smaller than the block size) are stored on the filesystem. The Ext4 and the Btrfs filesystem supports sparse files.
xviii. Block sub-allocation: The Ext4 filesystem does not support block sub-allocation.
The Btrfs filesystem supports 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 does not occupy the entire block. This last block is called the tail block. In the same way, when a lot of small files are stored, they do not occupy the entire block. So, a lot of disk space is wasted. Block sub-allocation is a method to store parts of another file block to the tail block (the last block of another file that did not occupy the entire block) and save disk spaces.
xix. Tail packing: The Ext4 filesystem does not support tail packing.
The Btrfs filesystem supports tail packing.
NOTE: Tail packing is a part of block sub-allocation. As I have already discussed, small files do not occupy an entire file block. So, to efficiently store small files (i.e. program source codes) in the filesystem, the tail block of a small file is used to store other small files. Tail packing improves the filesystem performance and saves a lot of disk space in a filesystem where lots of small files (i.e. program source codes) are stored.
xx. Extent-based Filesystem: Both the Ext4 and the Btrfs filesystems are extent-based filesystems.
NOTE: An extent is a contiguous area of the storage device which is 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.
xxi. Variable file block size: The Ext4 filesystem supports fixed block size. The block size is set before the filesystem is created. Once the filesystem is created, you can’t change the 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.
xxii. Allocate-on-flush: Both the Ext4 and the Btrfs filesystem supports allocate-on-flush.
NOTE: The filesystem allocates some buffer space in the memory of the computer. 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.
xxiii. TRIM support: Both the Ext4 and the Btrfs filesystem support TRIM. It 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 get slower as the SSD is filled with new data.
Advantages of Ext4 over Btrfs:
The Ext4 filesystem is a very old filesystem. It has been used on the Linux operating system for a long, long time. Because of that, the Ext4 filesystem is very stable. The Ext4 filesystem is still the default filesystem in many popular Linux distributions (i.e. Ubuntu/Debian). If you need to store some data as an ordinary Linux user, you can keep your eyes closed and use the Ext4 filesystem. The Ext4 filesystem has journaling support. So, your files should be safe even when there’s a power failure. It’s a good filesystem for everyday use.
Advantages of Btrfs over Ext4:
The Btrfs filesystem is a modern Copy-on-Write (CoW) filesystem that was designed for high-capacity and high-performance storage servers. So, it has a lot of advanced features that the Ext4 filesystem does not have. The Ext4 filesystem was designed to be a simple local filesystem.
The main features of the Btrfs filesystem that are useful to everyday Linux users are:
- Built-in Filesystem-level snapshots.
- Multiple device support.
- Built-in RAID support.
- Flexible inode allocation.
- Optimizations for storing smaller files (sparse files, block sub-allocation, tail packing, variable block size).
- Built-in filesystem-level compression support.
These are the filesystem features for which you may choose to use the Btrfs filesystem over the Ext4 filesystem.
In this article, I have compared the Btrfs and the Ext4 filesystems. I have compared the main features of the Btrfs and Ext4 filesystem. This article should help you decide between the Btrfs and the Ext4 filesystem.
- ext4 – Wikipedia – https://en.wikipedia.org/wiki/Ext4
- Btrfs – Wikipedia – https://en.wikipedia.org/wiki/Btrfs
- kernel/git/torvalds/linux.git – Linux kernel source tree – https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=4204617d142c0887e45fda2562cb5c58097b918e
- Comparison of Filesystems – Wikipedia – https://en.wikipedia.org/wiki/Comparison_of_file_systems
- Data deduplication – Wikipedia – https://en.wikipedia.org/wiki/Data_deduplication
- Sparse file – Wikipedia – https://en.wikipedia.org/wiki/Sparse_file
- Block suballocation – Wikipedia – https://en.wikipedia.org/wiki/Block_suballocation
- Extent (file systems) – Wikipedia – https://en.wikipedia.org/wiki/Extent_(file_systems)
- Allocate-on-flush – Wikipedia – https://en.wikipedia.org/wiki/Allocate-on-flush
- Trim (computing) – Wikipedia – https://en.wikipedia.org/wiki/Trim_(computing)