ext4, XFS & btrfs

ext4 journal modes, XFS advantages, tune2fs, xfs_repair, btrfs copy-on-write, and filesystem selection.

Overview

Choosing the right filesystem has significant implications for performance, data integrity, and operational complexity. Linux ships three mature general-purpose filesystems, ext4, XFS and btrfs, each with distinct trade-offs.

The ext4 Filesystem

ext4 is the evolution of ext2/ext3 and the default on Debian and Ubuntu systems; RHEL 7 and later default to XFS. Its key features are extents (contiguous block ranges replacing block maps), dir_index (htree-indexed directories for large dirs), a journal for crash consistency, delayed allocation, and online defragmentation.

The journal is what keeps ext4 consistent after a crash. Metadata changes, and in one mode the data too, are first written to the journal as a transaction. Only once that transaction is committed are they copied to their home locations on disk, so a crash leaves either the old state or a committed change that can be replayed. Journal modes control what the journal protects.

  • writeback: only metadata is journaled, and data may be written before or after the metadata. It is the fastest and least safe mode, because it can expose stale data in files after a crash.
  • ordered (default): data is written to disk before the metadata is journaled. This prevents stale data exposure and is a good balance of safety and performance.
  • journal: both data and metadata are journaled. It is the safest mode, but it doubles write I/O, so it is only useful for high-integrity requirements.

Key concepts

  • ext4 journal modes
  • tune2fs
  • XFS allocation groups
  • xfs_repair
  • btrfs COW
  • xfs_freeze

Interview questions

  • How do you inspect and tune an ext4 filesystem? What does tune2fs show you?
  • When would you choose XFS over ext4 for a production server?

Sign up free to read the full topic

More Linux topics

Start free on Cariara · Coding problems · System design studio