What is ext4 and What Improvements Does It Bring?
Learn what ext4 improves over ext3 — extents, delayed allocation, HTree, journaling — with OS interview questions answered.
Expected Interview Answer
ext4 is the default Linux file system that improves on ext3 by using extents instead of pure block-mapping for large files, adding delayed allocation and multiblock allocation for better performance, supporting much larger volumes and files, and speeding up crash recovery and directory lookups.
Instead of ext2/ext3's indirect-block pointer scheme, which needs a pointer per block, ext4 uses extents: a single extent record describes a contiguous run of up to 128MB of physically adjacent blocks, drastically reducing metadata overhead and fragmentation-related lookups for large files. Ext4 also delays block allocation until data is actually flushed to disk (delayed allocation), which lets the allocator batch nearby writes together and choose better block placement, and it can allocate multiple blocks in one request rather than one at a time. Directory lookups use HTree, a hashed B-tree structure, making lookups in huge directories far faster than ext2's linear scan. Like ext3, ext4 journals metadata (and optionally data) via JBD2, but it adds checksums to journal blocks so a corrupted journal entry is detected and skipped rather than blindly replayed, and it supports volumes and files up to the exbibyte range, far beyond ext3's limits.
- Extents cut metadata overhead for large, contiguous files
- Delayed and multiblock allocation reduce fragmentation and improve throughput
- HTree indexing speeds up lookups in very large directories
- Journal checksums make crash recovery safer than plain ext3 journaling
AI Mentor Explanation
ext4 is like upgrading a groundskeeping log from listing every single blade of turf individually to writing one entry per contiguous strip: "outfield section, rows 1 through 40, all newly laid," instead of forty separate entries. The groundskeeper also waits until a whole delivery truck of turf arrives before deciding exactly where to lay it (delayed allocation), rather than committing each roll the instant it shows up, so nearby rolls end up laid together. And the pitch report — the record of who touched what — now has a checksum on each entry, so a smudged page is spotted and skipped instead of blindly trusted during a rain-delay review.
Step-by-Step Explanation
Step 1
Write buffered in page cache
Data is written into the page cache but block allocation is deliberately delayed (delayed allocation).
Step 2
Flush triggers allocation
When the kernel flushes dirty pages, ext4's multiblock allocator picks contiguous free blocks for the whole batch at once.
Step 3
Extent recorded
Instead of one pointer per block, a single extent entry records the starting block and length of the contiguous run.
Step 4
Journaled commit
The metadata change is written to the JBD2 journal with a checksum before being committed, so recovery can verify and skip corrupted entries.
What Interviewer Expects
- Understanding of extents vs indirect block pointers as the core structural change
- Knowledge of delayed allocation and multiblock allocation and why they help performance
- Awareness of HTree for fast large-directory lookups
- Knowledge that ext4 journals metadata via JBD2 with checksums for safer recovery
Common Mistakes
- Confusing ext4 extents with NTFS's Master File Table structure
- Thinking ext4 always journals full file data by default (it journals metadata by default; data journaling is an option)
- Not knowing why delayed allocation improves fragmentation and throughput
- Assuming ext4 has the same file/volume size limits as ext3
Best Answer (HR Friendly)
“ext4 is the standard Linux file system, and its big upgrade is treating a large file's data as a few big continuous chunks — called extents — instead of tracking every tiny block separately, which cuts overhead a lot. It also waits until it actually knows what is being written before deciding where to place it, so related data ends up closer together on disk, and it keeps a safer, checksummed change log so recovering from a crash is both faster and more trustworthy than older versions like ext3.”
Code Example
/* ext2/ext3 style: one pointer per block (huge overhead for big files) */
struct indirect_mapping {
unsigned int block_ptr[12]; /* direct pointers, one per block */
unsigned int indirect_ptr; /* points to a block full of more pointers */
};
/* ext4 style: one extent describes a whole contiguous run */
struct ext4_extent {
unsigned int logical_block; /* first logical block this extent covers */
unsigned short len; /* number of contiguous blocks (up to 32768) */
unsigned int physical_block; /* first physical block on disk */
};
/* A large file might need only a handful of extents instead of
thousands of individual block pointers. */Follow-up Questions
- How do extents reduce metadata overhead compared to indirect block pointers?
- What is delayed allocation and what problem does it solve?
- How does HTree speed up lookups in directories with millions of entries?
- What is the difference between metadata-only journaling and full data journaling in ext4?
MCQ Practice
1. What structure does ext4 use to describe contiguous file data, replacing pure indirect block pointers?
Ext4 extents describe a contiguous run of physical blocks in one compact record, cutting metadata overhead versus per-block pointers.
2. What is delayed allocation in ext4?
Delayed allocation waits until flush time to assign physical blocks, allowing better batching and placement decisions.
3. What speeds up lookups in very large ext4 directories?
Ext4 uses HTree, a hashed B-tree structure, to make lookups in directories with huge numbers of entries much faster than a linear scan.
Flash Cards
What replaced indirect block pointers in ext4? — Extents — compact records describing a contiguous run of blocks.
What is delayed allocation? — Postponing block allocation until data is actually flushed, improving placement and reducing fragmentation.
What speeds up large directory lookups in ext4? — HTree, a hashed B-tree index.
How does ext4 journaling improve on ext3? — It adds checksums to journal blocks, so corrupted entries are detected and skipped during recovery.