Operating Systems

What is ext4?

ext4 (Fourth Extended Filesystem) is a modern journaling filesystem for Linux that serves as the successor to ext3, offering improved performance, reliability, and storage capacity through extents-based allocation, delayed allocation, and journal checksumming.

Overview

ext4 is a journaling filesystem that has become the default filesystem for most Linux distributions. It was introduced in 2006 and officially stabilized in 2008 with kernel version 2.6.28. ext4 represents a significant evolution from its predecessor ext3, introducing features that dramatically improve performance and support for larger storage devices while maintaining backward compatibility with ext3.

Historical Context and Evolution

The Extended Filesystem family traces its lineage from the original ext filesystem introduced in 1992. ext2 removed journaling to improve performance, while ext3 added journaling capabilities back to ext2. ext4 takes a different approach by fundamentally redesigning how the filesystem allocates and manages space on disk. Rather than making incremental improvements to ext3's block allocation scheme, ext4 introduces new architectural concepts including extents, delayed allocation, and checksummed journaling.

Key Technical Features

Extents-Based Allocation

Unlike ext3, which uses block bitmaps and indirect blocks for file allocation, ext4 uses extents. An extent is a contiguous range of blocks allocated to a file. Rather than tracking individual block numbers, extents store the starting block and length, significantly reducing metadata overhead and improving lookup performance. This is particularly important for large files, where a single extent can describe millions of contiguous blocks with minimal metadata.

Delayed Allocation

ext4 implements delayed allocation (also called allocate-on-flush), where the filesystem delays assigning disk blocks to files until data is actually written to disk. This provides several benefits: improved performance through better block allocation decisions, reduced disk fragmentation by allowing the filesystem to choose optimal locations, and better write batching. The filesystem can defer allocation decisions until it has more information about upcoming writes, enabling smarter placement decisions.

Journal Checksumming

ext4 introduces CRC32 checksums for journal transactions, providing data integrity checking for the journal itself. This prevents filesystem corruption from occurring during unclean shutdowns and helps detect hardware errors. The checksummed journal improves reliability and recovery procedures.

Extendable Inode Size

ext4 supports larger inode sizes (default 256 bytes, compared to ext3's fixed 128 bytes), allowing additional attributes and metadata to be stored directly in the inode. This can include extended attributes and filesystem features without requiring additional block allocations for metadata.

Storage Capacity Improvements

ext4 dramatically increases maximum filesystem size compared to ext3. Where ext3 was limited to 16TB filesystems, ext4 supports up to 16EB (exabytes) theoretical maximum, though practical limits depend on block size. The maximum file size also increased from 2TB to 16TB. These improvements make ext4 suitable for modern large-scale storage deployments.

Persistent Preallocation

ext4 supports persistent preallocation of space for files, particularly useful for databases and media applications. The fallocate() system call allows applications to reserve disk space without actually writing data, improving performance for applications that need to guarantee storage availability.

How ext4 Works

Journaling Mechanism

ext4 uses a journal to maintain consistency. Before making changes to the main filesystem, changes are first written to a journal (typically a 128MB ring buffer). If the system crashes during a write operation, the journal allows the filesystem to replay unfinished transactions and return to a consistent state. ext4 supports three journal modes: journal (safest but slowest), ordered (default, balanced), and writeback (fastest but riskier).

Block Groups and Allocation

ext4 organizes disk space into block groups, each containing a copy of critical filesystem metadata. Within each group, the filesystem maintains bitmaps tracking free blocks and inodes. The block allocation algorithm attempts to keep files within the same block group to reduce seeking and improve locality.

Inode Structure

Each file and directory is represented by an inode containing metadata: file type, permissions, ownership, timestamps, size, and block location information. ext4's larger inode size allows storing more extended attributes and filesystem feature flags directly in the inode, improving efficiency.

Performance Characteristics

ext4 generally delivers superior performance compared to ext3 through several mechanisms. Delayed allocation reduces I/O operations by batching writes. Extent-based allocation reduces CPU overhead for metadata management. The filesystem also benefits from the Linux kernel's improved I/O scheduling and caching mechanisms. For typical workloads, ext4 shows 5-20% performance improvement over ext3, with greater improvements on high-throughput scenarios.

Use Cases and Applications

Linux Server Deployments

ext4 is the standard choice for Linux servers, providing the reliability and performance needed for production systems. It's widely used in web servers, database servers, and file servers.

Desktop and Laptop Systems

Most Linux desktop distributions use ext4 as their default filesystem, balancing performance, reliability, and ease of use.

Embedded Systems

ext4 is increasingly used in embedded Linux systems, IoT devices, and single-board computers where reliability and performance matter.

Cloud and Virtualization

Cloud providers and virtualization platforms frequently use ext4 for virtual machine images and container storage due to its stability and predictable performance.

Best Practices

Filesystem Creation

When creating ext4 filesystems, consider block size (typically 4KB for most workloads), inode ratio (controls total available inodes), and journal size. Tools like mkfs.ext4 provide sensible defaults for most scenarios.

Mounting Options

Common mount options include relatime (reduce atime updates for performance), discard (enable TRIM support for SSDs), and nodelalloc (disable delayed allocation when needed for specific applications). The data=ordered journal mode provides good balance between safety and performance.

Maintenance

Regular filesystem checks using fsck.ext4 help catch corruption early. ext4 supports online defragmentation using e4defrag, though modern systems rarely need this due to effective allocation algorithms. Enabling the discard mount option on SSDs helps maintain device performance.

Capacity Planning

Keep filesystems below 90% capacity to maintain good allocation performance. Reserve sufficient space for inode allocation and journal operations. Monitor inode usage separately from block usage, as exhausting inodes (even with available blocks) can render a filesystem unusable.

Security Considerations

ext4 provides standard Unix permission and ownership controls. For sensitive data, filesystem-level encryption (using dm-crypt or similar tools) should be layered above ext4 rather than relying on filesystem permissions alone. ext4 itself does not provide built-in encryption, though the Linux kernel's fscrypt feature can provide encryption at the filesystem level.

Comparison with Other Filesystems

While Btrfs and XFS offer advanced features like snapshots and superior scalability, ext4 remains preferred for its stability, broad compatibility, and simplicity. ext4's conservative approach to new features and extensive real-world testing make it the default choice for most Linux distributions.

Future Developments

ext4 continues to receive updates and improvements in the Linux kernel. Recent enhancements include support for timestamps with nanosecond precision, better error handling, and improved compatibility with modern storage devices. The ext4 filesystem continues to be actively maintained and is expected to remain relevant for years to come.

Studying for CompTIA (Operating Systems)?

ExamWizardz turns the official objectives into a guided study plan — with practice tests, real PBQs, and a readiness score. Join the waitlist to be first in when CompTIA A+ launches.