Ext4 Explained

ext4
Full Name:Fourth extended file system
Developer:Mingming Cao, Andreas Dilger, Alex Zhuravlev (Tomas), Dave Kleikamp, Theodore Ts'o, Eric Sandeen, Sam Naghshineh, others
Introduction Os:Linux 2.6.19
Introduction Date:10 October 2006
Preceded By:ext3
Partition Id:

MBR / EBR.

GPT Windows BDP.[1]

GPT Linux filesystem data.

GPT /home partition.[2]

GPT /srv (server data) partition.

Directory Struct:Linked list, hashed B-tree
File Struct:Extents / Bitmap
Bad Blocks Struct:Table
Max Filename Size:255 bytes (fewer for multibyte character encodings such as Unicode)
Max Files No:4 billion (specified at filesystem creation time)
Max Volume Size:1 EiB
Max File Size:16-256 TiB (for 4-64 KiB block size)
Filename Character Set:All bytes except NULL ('\0') and '/' and the special file names "." and ".." which are not forbidden but are always used for a respective special purpose.
Dates Recorded:modification (mtime), data or attribute modification (ctime), access (atime), delete (dtime), create (crtime)
Date Range:14 December 1901 - 10 May 2446[3]
Date Resolution:Nanosecond
Forks Streams:No
Attributes:acl, bh, bsddf, commit=nrsec, data=journal, data=ordered, data=writeback, delalloc, extents, journal_dev, mballoc, minixdf, noacl, nobh, nodelalloc, noextents, nomballoc, nombcache, nouser_xattr, oldalloc, orlov, user_xattr
File System Permissions:Unix permissions, POSIX ACLs
Compression:No
Encryption:Yes
Single Instance Storage:No
License:GPLv2

ext4 (fourth extended filesystem) is a journaling file system for Linux, developed as the successor to ext3.

ext4 was initially a series of backward-compatible extensions to ext3, many of them originally developed by Cluster File Systems for the Lustre file system between 2003 and 2006, meant to extend storage limits and add other performance improvements.[4] However, other Linux kernel developers opposed accepting extensions to ext3 for stability reasons,[5] and proposed to fork the source code of ext3, rename it as ext4, and perform all the development there, without affecting existing ext3 users. This proposal was accepted, and on 28 June 2006, Theodore Ts'o, the ext3 maintainer, announced the new plan of development for ext4.[6]

A preliminary development version of ext4 was included in version 2.6.19[7] of the Linux kernel. On 11 October 2008, the patches that mark ext4 as stable code were merged in the Linux 2.6.28 source code repositories,[8] denoting the end of the development phase and recommending ext4 adoption. Kernel 2.6.28, containing the ext4 filesystem, was finally released on 25 December 2008.[9] On 15 January 2010, Google announced that it would upgrade its storage infrastructure from ext2 to ext4.[10] On 14 December 2010, Google also announced it would use ext4, instead of YAFFS, on Android 2.3.[11]

Adoption

ext4 is the default file system for many Linux distributions including Debian and Ubuntu.[12]

Features

Large file system
  • The ext4 filesystem can support volumes with sizes in theory up to 64 zebibyte (ZiB) and single files with sizes up to 16 tebibytes (TiB) with the standard 4 KiB block size, and volumes with sizes up to 1 yobibyte (YiB) with 64 KiB clusters, though a limitation in the extent format makes 1 exbibyte (EiB) the practical limit.[13] The maximum file, directory, and filesystem size limits grow at least proportionately with the filesystem block size up to the maximum 64 KiB block size available on ARM and PowerPC/Power ISA CPUs.
    Extents
  • Extents replace the traditional block mapping scheme used by ext2 and ext3. An extent is a range of contiguous physical blocks, improving large-file performance and reducing fragmentation. A single extent in ext4 can map up to 128 MiB of contiguous space with a 4 KiB block size. There can be four extents stored directly in the inode. When there are more than four extents to a file, the rest of the extents are indexed in a tree.[14]
    Backward compatibility
  • ext4 is backward-compatible with ext3 and ext2, making it possible to mount ext3 and ext2 as ext4. This will slightly improve performance, because certain new features of the ext4 implementation can also be used with ext3 and ext2, such as the new block allocation algorithm, without affecting the on-disk format.[15]
  • ext3 is partially forward-compatible with ext4. Practically, ext4 will not mount as an ext3 filesystem out of the box, unless certain new features are disabled when creating it, such as ^extent, ^flex_bg, ^huge_file, ^uninit_bg, ^dir_nlink, and ^extra_isize.[16]
    Persistent pre-allocation
  • ext4 can pre-allocate on-disk space for a file. To do this on most file systems, zeroes would be written to the file when created. In ext4 (and some other file systems such as XFS) fallocate, a new system call in the Linux kernel, can be used. The allocated space would be guaranteed and likely contiguous. This situation has applications for media streaming and databases.
    Delayed allocation
  • ext4 uses a performance technique called allocate-on-flush, also known as delayed allocation. That is, ext4 delays block allocation until data is flushed to disk; in contrast, some file systems allocate blocks immediately, even when the data goes into a write cache. Delayed allocation improves performance and reduces fragmentation by effectively allocating larger amounts of data at a time.
    Unlimited number of subdirectories
  • ext4 does not limit the number of subdirectories in a single directory, except by the inherent size limit of the directory itself. (In ext3 a directory can have at most 32,000 subdirectories.)[17] To allow for larger directories and continued performance, ext4 in Linux 2.6.23 and later turns on HTree indices (a specialized version of a B-tree) by default, which allows directories up to approximately 10–12 million entries to be stored in the 2-level HTree index and 2 GB directory size limit for 4 KiB block size, depending on the filename length. In Linux 4.12 and later the large_dir feature enabled a 3-level HTree and directory sizes over 2 GB, allowing approximately 6 billion entries in a single directory.
    Journal checksums
  • ext4 uses checksums[18] in the journal to improve reliability, since the journal is one of the most used files of the disk. This feature has a side benefit: it can safely avoid a disk I/O wait during journaling, improving performance slightly. Journal checksumming was inspired by a research article from the University of Wisconsin, titled IRON File Systems,[19] with modifications within the implementation of compound transactions performed by the IRON file system (originally proposed by Sam Naghshineh in the RedHat summit).
    Metadata checksumming
  • Since Linux kernel 3.5 released in 2012.[20] [21]
  • Faster file-system checking
  • In ext4 unallocated block groups and sections of the inode table are marked as such. This enables e2fsck to skip them entirely and greatly reduces the time it takes to check the file system. Linux 2.6.24 implements this feature.
    Multiblock allocator
  • When ext3 appends to a file, it calls the block allocator, once for each block. Consequently, if there are multiple concurrent writers, files can easily become fragmented on disk. However, ext4 uses delayed allocation, which allows it to buffer data and allocate groups of blocks. Consequently, the multiblock allocator can make better choices about allocating files contiguously on disk. The multiblock allocator can also be used when files are opened in O_DIRECT mode. This feature does not affect the disk format.
    Improved timestamps
  • As computers become faster in general, and as Linux becomes used more for mission-critical applications, the granularity of second-based timestamps becomes insufficient. To solve this, ext4 provides timestamps measured in nanoseconds. In addition, 2 bits of the expanded timestamp field are added to the most significant bits of the seconds field of the timestamps to defer the year 2038 problem for an additional 408 years.[3]
  • ext4 also adds support for time-of-creation timestamps. But, as Theodore Ts'o points out, while it is easy to add an extra creation-date field in the inode (thus technically enabling support for these timestamps in ext4), it is more difficult to modify or add the necessary system calls, like stat (which would probably require a new version) and the various libraries that depend on them (like glibc). These changes will require coordination of many projects.[22] Therefore, the creation date stored by ext4 is currently only available to user programs on Linux via the statx API.[23]
    Project quotas
  • Support for project quotas was added in Linux kernel 4.4 on 8 Jan 2016. This feature allows assigning disk quota limits to a particular project ID. The project ID of a file is a 32-bit number stored on each file and is inherited by all files and subdirectories created beneath a parent directory with an assigned project ID. This allows assigning quota limits to a particular subdirectory tree independent of file access permissions on the file, such as user and project quotas that are dependent on the UID and GID. While this is similar to a directory quota, the main difference is that the same project ID can be assigned to multiple top-level directories and is not strictly hierarchical.[24]
    Transparent encryption
  • Support for transparent encryption was added in Linux kernel 4.1 on June 2015.[25]
    Lazy initialization
  • The lazyinit feature allows cleaning of inode tables in background, speeding initialization when creating a new ext4 file system.[26] It is available since 2010 in Linux kernel version 2.6.37.[27]
    Write barriers
  • ext4 enables write barriers by default. It ensures that file system metadata is correctly written and ordered on disk, even when write caches lose power. This goes with a performance cost especially for applications that use fsync heavily or create and delete many small files. For disks with a battery-backed write cache, disabling barriers (option 'barrier=0') may safely improve performance.[28]

    Limitations

    In 2008, the principal developer of the ext3 and ext4 file systems, Theodore Ts'o, stated that although ext4 has improved features, it is not a major advance, it uses old technology, and is a stop-gap. Ts'o believes that Btrfs is the better direction because "it offers improvements in scalability, reliability, and ease of management".[29] Btrfs also has "a number of the same design ideas that reiser3/4 had".[30] However, ext4 has continued to gain new features such as file encryption and metadata checksums.

    The ext4 file system does not honor the "secure deletion" file attribute, which is supposed to cause overwriting of files upon deletion. A patch to implement secure deletion was proposed in 2011, but did not solve the problem of sensitive data ending up in the file-system journal.[31]

    Delayed allocation and potential data loss

    Because delayed allocation changes the behavior that programmers have been relying on with ext3, the feature poses some additional risk of data loss in cases where the system crashes or loses power before all of the data has been written to disk. Due to this, ext4 in kernel versions 2.6.30 and later automatically handles these cases as ext3 does.

    The typical scenario in which this might occur is a program replacing the contents of a file without forcing a write to the disk with fsync. There are two common ways of replacing the contents of a file on Unix systems:

    In this case, an existing file is truncated at the time of open (due to O_TRUNC flag), then new data is written out. Since the write can take some time, there is an opportunity of losing contents even with ext3, but usually very small. However, because ext4 can delay writing file data for a long time, this opportunity is much greater.

    There are several problems that can arise:

    1. If the write does not succeed (which may be due to error conditions in the writing program, or due to external conditions such as a full disk), then both the original version and the new version of the file will be lost, and the file may be corrupted because only a part of it has been written.
    1. If other processes access the file while it is being written, they see a corrupted version.
    1. If other processes have the file open and do not expect its contents to change, those processes may crash. One notable example is a shared library file which is mapped into running programs.

    Because of these issues, often the following idiom is preferred over the one above:

    A new temporary file ("file.new") 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.

    Using fsync more often to reduce the risk for ext4 could lead to performance penalties on ext3 filesystems mounted with the data=ordered flag (the default on most Linux distributions). Given that both file systems will be in use for some time, this complicates matters for end-user application developers. In response, ext4 in Linux kernels 2.6.30 and newer detect the occurrence of these common cases and force the files to be allocated immediately. For a small cost in performance, this provides semantics similar to ext3 ordered mode and increases the chance that either version of the file will survive the crash. This new behavior is enabled by default, but can be disabled with the "noauto_da_alloc" mount option.[32]

    The new patches have become part of the mainline kernel 2.6.30, but various distributions chose to backport them to 2.6.28 or 2.6.29.[33]

    These patches don't completely prevent potential data loss or help at all with new files. The only way to be safe is to write and use software that does fsync when it needs to. Performance problems can be minimized by limiting crucial disk writes that need fsync to occur less frequently.[34]

    Implementation

    Linux kernel Virtual File System is a subsystem or layer inside of the Linux kernel. It is the result of an attempt to integrate multiple file systems into an orderly single structure. The key idea, which dates back to the pioneering work done by Sun Microsystems employees in 1986,[35] is to abstract out that part of the file system that is common to all file systems and put that code in a separate layer that calls the underlying concrete file systems to actually manage the data.

    All system calls related to files (or pseudo files) are directed to the Linux kernel Virtual File System for initial processing. These calls, coming from user processes, are the standard POSIX calls, such as [[open (system call)|open]], [[read (system call)|read]], [[write (system call)|write]], [[lseek (system call)|lseek]], etc.

    Compatibility with Windows and Macintosh

    Currently, ext4 has full support on non-Linux operating systems.

    Microsoft Windows can access ext4 since Windows 10 Insider Preview Build 20211.[36] [37] [38] It is possible thanks to Windows Subsystem for Linux (WSL) which was introduced with Windows 10 Anniversary Update (version 1607) on 2 August 2016. WSL is available only in 64-bit versions of Windows 10 from version 1607. It is also available in Windows Server 2019. Big changes to the WSL architecture came with the release of WSL 2 on 12 June 2019.[39] WSL 2 requires Windows 10 version 1903 or higher, with build 18362 or higher, for x64 systems, and version 2004 or higher, with build 19041 or higher, for ARM64 systems.[40]

    Paragon offers its commercial product Linux File Systems for Windows[41] which allows read/write capabilities for ext2/3/4 on Windows 7 SP1/8/8.1/10 and Windows Server 2008 R2 SP1/2012/2016.

    macOS has full ext2/3/4 read–write capability through the extFS for Mac by Paragon Software,[42] which is a commercial product. Free software such as ext4fuse has read-only support with limited functionality.

    See also

    External links

    Notes and References

    1. Previously, Linux used the same GUID for the data partitions as Windows (Basic data partition:). Linux never had a separate unique partition type GUID defined for its data partitions. This created problems when dual-booting Linux and Windows in UEFI-GPT setup. The new GUID (Linux filesystem data:) was defined jointly by GPT fdisk and GNU Parted developers. It is identified as type code in GPT fdisk. (See definitions in gdisk's parttypes.cc)
    2. Web site: DiscoverablePartitionsSpec . freedesktop.org . 7 April 2018.
    3. Web site: ext4: Fix handling of extended tv_sec . Linux-stable kernel tree . 2017-02-14.
    4. Web site: The new ext4 filesystem: current status and future plans . Red Hat . Ottawa, ON, CA . 2007 . Proceedings of the Linux Symposium . 2008-01-15 . Avantika . Mathur . MingMing . Cao . Suparna . Bhattacharya . Suparna Bhattacharya . Andreas . Dilger . Alex . Zhuravlev (Tomas) . Laurent . Vivier . dead . https://web.archive.org/web/20100706040230/http://www.linuxsymposium.org/archives/OLS/Reprints-2007/mathur-Reprint.pdf . 2010-07-06.
    5. Web site: extents and 48bit ext3. 2006-06-09 . . Linus . Torvalds .
    6. Web site: Proposal and plan for ext2/3 future development work . . Theodore . Ts'o . 2006-06-28.
    7. News: Thorsten . Leemhuis . Higher and further: The innovations of Linux 2.6.28 (page 2) . dead . https://web.archive.org/web/20090103164710/http://www.heise-online.co.uk/open/Kernel-Log-Higher-and-Further-The-innovations-of-Linux-2-6-28--/features/112299 . 2009-01-03 . Heise Online . 2008-12-23 . 2010-01-09.
    8. Web site: ext4: Rename ext4dev to ext4 . Linus' kernel tree . 2008-10-20 . https://archive.today/20120529150649/http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=03010a3350301baac2154fa66de925ae2981b7e3 . 29 May 2012 . dead.
    9. News: Thorsten . Leemhuis . Higher and further: The innovations of Linux 2.6.28 . Heise Online . 2008-12-23 .
    10. Web site: Ryan . Paul . Google upgrading to Ext4, hires former Linux Foundation CTO . Ars Technica . 2010-01-15 .
    11. News: Android 2.3 Gingerbread to use Ext4 file system . The H Open . 14 December 2010 .
    12. Web site: FileSystem in debian . 14 September 2019.
    13. Web site: ext4 - High Level Design . kernel.org . 8 December 2023.
    14. Web site: Understanding EXT4 (Part 3): Extent Trees . Pomeranz . Hal . 28 March 2011 . SANS Digital Forensics and Incident Response Blog . https://web.archive.org/web/20190818050155/https://digital-forensics.sans.org/blog/2011/03/28/digital-forensics-understanding-ext4-part-3-extent-trees . 18 August 2019.
    15. Web site: Anatomy of ext4 . 2024-05-27 . IMB Developer.
    16. Web site: Mount of ext4 (created without extents) as ext3 fails on RH6.2 . www.linuxquestions.org . 8 December 2023 . live . https://web.archive.org/web/20230805062315/https://www.linuxquestions.org/questions/red-hat-31/mount-of-ext4-created-without-extents-as-ext3-fails-on-rh6-2-a-936813/ . 5 August 2023.
    17. Web site: Ext4 - Linux Kernel Newbies . kernelnewbies.org.
    18. Web site: New ext4 features - Ext4 . ext4.wiki.kernel.org . live . 8 December 2023 . https://web.archive.org/web/20230923124620/https://ext4.wiki.kernel.org/index.php/New_ext4_features#Metadata_Checksums . 23 September 2023.
    19. IRON File Systems . Section 6.1, Paragraph 5 "Transactional Checksums" . Prabhakaran . Vijayan . Bairavasundaram . Lakshmi N. . Agrawal . Nitin . Gunawi . Haryadi S. . Arpaci-Dusseau . Andrea C. . Arpaci-Dusseau . Remzi H. . Symposium on Operating Systems Principles (SOSP '05) . https://www.sigops.org/s/conferences/sosp/2005/default.htm . October 2005 . Brighton, United Kingdom . CS Dept, University of Wisconsin . 8 December 2023.
    20. Web site: Ext4 Metadata Checksums - Ext4 . ext4.wiki.kernel.org . live . 8 December 2023 . https://web.archive.org/web/20231106144434/https://ext4.wiki.kernel.org/index.php/Ext4_Metadata_Checksums . 6 November 2023.
    21. Web site: Linux_3.5 - Linux Kernel Newbies . kernelnewbies.org.
    22. Web site: Re: creation time stamps for ext4 ? . Ts'o . Theodore . 5 October 2006.
    23. Web site: Extending statx . Edge . Jake . 2017-03-31 . live . 8 December 2023 . https://web.archive.org/web/20230920041649/https://lwn.net/Articles/718222/ . 20 September 2023.
    24. ext4: add project quota support . Li . Xi . 12 January 2016 . live . 8 December 2023 . https://web.archive.org/web/20230920042516/https://lwn.net/Articles/671627/ . 20 September 2023.
    25. Web site: Ext4 encryption . Ts'o . Theodore . 8 April 2015 . live . 8 December 2023 . https://web.archive.org/web/20231012232912/https://lwn.net/Articles/639427/ . 12 October 2023.
    26. Web site: Ext4 Filesystem . Thomas-Krenn-Wiki . live . 8 December 2023 . https://web.archive.org/web/20220214022131/https://www.thomas-krenn.com/en/wiki/Ext4_Filesystem . 14 February 2022.
    27. Web site: kernel/git/torvalds/linux.git - Linux kernel source tree . git.kernel.org.
    28. Web site: Ext4 - . ArchWiki.
    29. Web site: Panelists ponder the kernel at Linux Collaboration Summit . Ryan . Paul . 2009-04-14 . 2009-08-22 . Ars Technica.
    30. Re: reiser4 for 2.6.27-rc1 . Theodore Ts'o . 2008-08-01 . 2010-12-31 . linux-kernel.
    31. Web site: Jonathan . Corbet . Securely deleting files from ext4 filesystems . 11 October 2011.
    32. Web site: 2009-03-28 . ext4 documentation in Linux kernel source .
    33. https://bugs.launchpad.net/ubuntu/+source/linux/+bug/317781?comments=all Ubuntu bug #317781
    34. http://thunk.org/tytso/blog/2009/03/12/delayed-allocation-and-the-zero-length-file-problem/ Thoughts by Ted blog entry, 12 March 2009
    35. Kleiman
    36. Web site: Announcing Windows 10 Insider Preview Build 20211 . Brandon LeBlanc . 10 September 2020 . Windows Blogs . 25 May 2021.
    37. Web site: Access Linux filesystems in Windows and WSL 2 . Pierre Boulay . 10 September 2020 . Windows Command Line . 25 May 2021.
    38. Web site: Get started mounting a Linux disk in WSL 2 . Microsoft Docs . 25 May 2021.
    39. Web site: WSL 2 is now available in Windows Insiders . Craig Loewen . 12 June 2019 . Windows Command Line . 25 May 2021.
    40. Web site: Windows Subsystem for Linux Installation Guide for Windows 10 . Windows Docs . 25 May 2021.
    41. Web site: Linux File Systems for Windows . Paragon Software . 25 May 2021.
    42. Web site: extFS for Mac . Paragon Software . 25 May 2021.