Unlocking ext4 Extents: How Linux Filesystems Boost Performance
This article explores the evolution, design, and inner workings of the ext4 extent mechanism in Linux, detailing how it replaces traditional block mapping, improves storage efficiency, reduces fragmentation, and accelerates file I/O through compact data structures and B+‑tree indexing.
In the vast Linux ecosystem, the file system acts like a well‑organized library, managing data storage, access, permissions, and device formatting, directly impacting system performance, reliability, and security.
Part1 Linux Filesystem Overview
The ext4 file system, widely used as the default on Linux, offers excellent performance, stability, and compatibility. Its standout feature is the extent mechanism, which fundamentally reshapes how file data is stored and managed, opening new paths for performance gains.
Part2 What Is ext4 Extent?
Before extents, traditional file systems used direct and indirect block mapping, which caused massive mapping tables, high memory usage, and frequent I/O for large files. Extents group contiguous physical blocks into a single entity, dramatically reducing mapping overhead, saving disk space, and improving read/write speed.
Part3 The Story Behind ext4 Extent
Early file systems like ext2 relied on 12 direct block pointers and up to three levels of indirect pointers, which became inefficient as file sizes grew. Ext3 added journaling but kept the same addressing scheme, leaving large‑file performance issues unresolved. Extents were introduced to address these limitations by storing data in continuous block groups.
Part4 Core Data Structures of ext4 Extent
The inode still holds file metadata, but its i_block array now points to extent structures instead of raw block addresses. An extent records the logical block number (ee_block), the starting physical block (combined ee_start_hi and ee_start_lo), and the length (ee_len). For large files, multiple extents are organized in an extent_tree, a B+‑tree where leaf nodes store extents and internal nodes provide fast indexing.
Part5 ext4 Extent Operation Mechanism
File creation : When a new file is created, ext4 allocates a free inode and searches for a contiguous free region on disk, forming an extent that maps logical blocks to physical blocks.
File reading : The kernel locates the inode, follows the extent tree to find the relevant extent, and reads the contiguous physical blocks, reducing seek time and I/O operations.
File writing : On write, ext4 checks if the file needs to grow; if so, it allocates new extents (preferably contiguous). If sufficient contiguous space is unavailable, it creates additional extents and updates the tree.
File deletion : Deleting a file frees its inode and traverses the extent tree to mark all associated extents as free, returning the blocks to the pool and maintaining filesystem consistency.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Deepin Linux
Research areas: Windows & Linux platforms, C/C++ backend development, embedded systems and Linux kernel, etc.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
