March 6, 2012

How ext4 file system works

How ext4 file system works

How it reduce fragmentation?
It consists of delaying block allocation until the data is going to be written to the disk, unlike some other file systems, which may allocate the necessary blocks before that step. This improves performance and reduces fragmentation by improving block allocation decisions based on the actual file size.

How does it manage read/write on disk?
There are two common ways of replacing the contents of a file on Unix systems:

Either truncate a file and start write it, we can call it “w” or “w+” mode for common understanding

fd=open(“file”, O_TRUNC); write(fd, data); close(fd);

the other one is to create a file and then rename it, then move the updated data chunk in that renamed file as:

fd=open(“”); write(fd, data); close(fd); rename(“”, “file”);

A new temporary file (“”) is created, which initially contains the new contents. Then the new file is renamed over the old one. Replacing files by the “rename” call is guaranteed to be atomic by POSIX standards – i.e. either the old file remains, or it’s overwritten with the new one. Because the ext3 default “ordered” journaling mode guarantees file data is written out on disk before metadata, this technique guarantees that either the old or the new file contents will persist on disk. ext4’s delayed allocation breaks this expectation, because the file write can be delayed for a long time, and the rename is usually carried out before new file contents reach the disk.

(Taken from

It is a good thing that overall results of ext4 are very good without the mount options, it shows that its better than the previous version for sure.

Operating Systems Perspective:
Ext4 does not yet have as much support as ext2 and ext3 on non-linux operating systems. Ext2 and ext3 have stable drivers such as Ext2IFS, which are not yet available for ext4. It is possible to create compatible ext4 filesystems for use in Windows by disabling the extents feature, and sometimes specifying an Inode size. Viewing and copying files from ext4 to Windows, even with extents enabled, is also possible with the Ext2Read software. However, there are no available drivers that provide full read and write compatibility with Windows. Current Macintosh drivers are also read-only. Another option for using ext4 in Windows is to use Ext2Fsd freeware that recently has added support of writing in ext4 under Windows.

Checksumming Technique:
The technique of journal checksumming, which is available in ext4 as a good feature, was inspired by a research paper from the University of Wisconsin titled IRON File Systems (specifically, section 6, called “transaction checksums”) with modifications within the implementation of compound transactions performed by the IRON file system (originally proposed by Sam Naghshineh in the RedHat summit).

Last updated: March 19, 2014