1.. SPDX-License-Identifier: GPL-2.0
2
3========================
4ext4 General Information
5========================
6
7Ext4 is an advanced level of the ext3 filesystem which incorporates
8scalability and reliability enhancements for supporting large filesystems
9(64 bit) in keeping with increasing disk capacities and state-of-the-art
10feature requirements.
11
12Mailing list:	linux-ext4@vger.kernel.org
13Web site:	http://ext4.wiki.kernel.org
14
15
16Quick usage instructions
17========================
18
19Note: More extensive information for getting started with ext4 can be
20found at the ext4 wiki site at the URL:
21http://ext4.wiki.kernel.org/index.php/Ext4_Howto
22
23  - The latest version of e2fsprogs can be found at:
24
25    https://www.kernel.org/pub/linux/kernel/people/tytso/e2fsprogs/
26
27	or
28
29    http://sourceforge.net/project/showfiles.php?group_id=2406
30
31	or grab the latest git repository from:
32
33   https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git
34
35  - Create a new filesystem using the ext4 filesystem type:
36
37        # mke2fs -t ext4 /dev/hda1
38
39    Or to configure an existing ext3 filesystem to support extents:
40
41	# tune2fs -O extents /dev/hda1
42
43    If the filesystem was created with 128 byte inodes, it can be
44    converted to use 256 byte for greater efficiency via:
45
46        # tune2fs -I 256 /dev/hda1
47
48  - Mounting:
49
50	# mount -t ext4 /dev/hda1 /wherever
51
52  - When comparing performance with other filesystems, it's always
53    important to try multiple workloads; very often a subtle change in a
54    workload parameter can completely change the ranking of which
55    filesystems do well compared to others.  When comparing versus ext3,
56    note that ext4 enables write barriers by default, while ext3 does
57    not enable write barriers by default.  So it is useful to use
58    explicitly specify whether barriers are enabled or not when via the
59    '-o barriers=[0|1]' mount option for both ext3 and ext4 filesystems
60    for a fair comparison.  When tuning ext3 for best benchmark numbers,
61    it is often worthwhile to try changing the data journaling mode; '-o
62    data=writeback' can be faster for some workloads.  (Note however that
63    running mounted with data=writeback can potentially leave stale data
64    exposed in recently written files in case of an unclean shutdown,
65    which could be a security exposure in some situations.)  Configuring
66    the filesystem with a large journal can also be helpful for
67    metadata-intensive workloads.
68
69Features
70========
71
72Currently Available
73-------------------
74
75* ability to use filesystems > 16TB (e2fsprogs support not available yet)
76* extent format reduces metadata overhead (RAM, IO for access, transactions)
77* extent format more robust in face of on-disk corruption due to magics,
78* internal redundancy in tree
79* improved file allocation (multi-block alloc)
80* lift 32000 subdirectory limit imposed by i_links_count[1]
81* nsec timestamps for mtime, atime, ctime, create time
82* inode version field on disk (NFSv4, Lustre)
83* reduced e2fsck time via uninit_bg feature
84* journal checksumming for robustness, performance
85* persistent file preallocation (e.g for streaming media, databases)
86* ability to pack bitmaps and inode tables into larger virtual groups via the
87  flex_bg feature
88* large file support
89* inode allocation using large virtual block groups via flex_bg
90* delayed allocation
91* large block (up to pagesize) support
92* efficient new ordered mode in JBD2 and ext4 (avoid using buffer head to force
93  the ordering)
94
95[1] Filesystems with a block size of 1k may see a limit imposed by the
96directory hash tree having a maximum depth of two.
97
98Options
99=======
100
101When mounting an ext4 filesystem, the following option are accepted:
102(*) == default
103
104  ro
105        Mount filesystem read only. Note that ext4 will replay the journal (and
106        thus write to the partition) even when mounted "read only". The mount
107        options "ro,noload" can be used to prevent writes to the filesystem.
108
109  journal_checksum
110        Enable checksumming of the journal transactions.  This will allow the
111        recovery code in e2fsck and the kernel to detect corruption in the
112        kernel.  It is a compatible change and will be ignored by older
113        kernels.
114
115  journal_async_commit
116        Commit block can be written to disk without waiting for descriptor
117        blocks. If enabled older kernels cannot mount the device. This will
118        enable 'journal_checksum' internally.
119
120  journal_path=path, journal_dev=devnum
121        When the external journal device's major/minor numbers have changed,
122        these options allow the user to specify the new journal location.  The
123        journal device is identified through either its new major/minor numbers
124        encoded in devnum, or via a path to the device.
125
126  norecovery, noload
127        Don't load the journal on mounting.  Note that if the filesystem was
128        not unmounted cleanly, skipping the journal replay will lead to the
129        filesystem containing inconsistencies that can lead to any number of
130        problems.
131
132  data=journal
133        All data are committed into the journal prior to being written into the
134        main file system.  Enabling this mode will disable delayed allocation
135        and O_DIRECT support.
136
137  data=ordered	(*)
138        All data are forced directly out to the main file system prior to its
139        metadata being committed to the journal.
140
141  data=writeback
142        Data ordering is not preserved, data may be written into the main file
143        system after its metadata has been committed to the journal.
144
145  commit=nrsec	(*)
146        Ext4 can be told to sync all its data and metadata every 'nrsec'
147        seconds. The default value is 5 seconds.  This means that if you lose
148        your power, you will lose as much as the latest 5 seconds of work (your
149        filesystem will not be damaged though, thanks to the journaling).  This
150        default value (or any low value) will hurt performance, but it's good
151        for data-safety.  Setting it to 0 will have the same effect as leaving
152        it at the default (5 seconds).  Setting it to very large values will
153        improve performance.
154
155  barrier=<0|1(*)>, barrier(*), nobarrier
156        This enables/disables the use of write barriers in the jbd code.
157        barrier=0 disables, barrier=1 enables.  This also requires an IO stack
158        which can support barriers, and if jbd gets an error on a barrier
159        write, it will disable again with a warning.  Write barriers enforce
160        proper on-disk ordering of journal commits, making volatile disk write
161        caches safe to use, at some performance penalty.  If your disks are
162        battery-backed in one way or another, disabling barriers may safely
163        improve performance.  The mount options "barrier" and "nobarrier" can
164        also be used to enable or disable barriers, for consistency with other
165        ext4 mount options.
166
167  inode_readahead_blks=n
168        This tuning parameter controls the maximum number of inode table blocks
169        that ext4's inode table readahead algorithm will pre-read into the
170        buffer cache.  The default value is 32 blocks.
171
172  nouser_xattr
173        Disables Extended User Attributes.  See the attr(5) manual page for
174        more information about extended attributes.
175
176  noacl
177        This option disables POSIX Access Control List support. If ACL support
178        is enabled in the kernel configuration (CONFIG_EXT4_FS_POSIX_ACL), ACL
179        is enabled by default on mount. See the acl(5) manual page for more
180        information about acl.
181
182  bsddf	(*)
183        Make 'df' act like BSD.
184
185  minixdf
186        Make 'df' act like Minix.
187
188  debug
189        Extra debugging information is sent to syslog.
190
191  abort
192        Simulate the effects of calling ext4_abort() for debugging purposes.
193        This is normally used while remounting a filesystem which is already
194        mounted.
195
196  errors=remount-ro
197        Remount the filesystem read-only on an error.
198
199  errors=continue
200        Keep going on a filesystem error.
201
202  errors=panic
203        Panic and halt the machine if an error occurs.  (These mount options
204        override the errors behavior specified in the superblock, which can be
205        configured using tune2fs)
206
207  data_err=ignore(*)
208        Just print an error message if an error occurs in a file data buffer in
209        ordered mode.
210  data_err=abort
211        Abort the journal if an error occurs in a file data buffer in ordered
212        mode.
213
214  grpid | bsdgroups
215        New objects have the group ID of their parent.
216
217  nogrpid (*) | sysvgroups
218        New objects have the group ID of their creator.
219
220  resgid=n
221        The group ID which may use the reserved blocks.
222
223  resuid=n
224        The user ID which may use the reserved blocks.
225
226  sb=
227        Use alternate superblock at this location.
228
229  quota, noquota, grpquota, usrquota
230        These options are ignored by the filesystem. They are used only by
231        quota tools to recognize volumes where quota should be turned on. See
232        documentation in the quota-tools package for more details
233        (http://sourceforge.net/projects/linuxquota).
234
235  jqfmt=<quota type>, usrjquota=<file>, grpjquota=<file>
236        These options tell filesystem details about quota so that quota
237        information can be properly updated during journal replay. They replace
238        the above quota options. See documentation in the quota-tools package
239        for more details (http://sourceforge.net/projects/linuxquota).
240
241  stripe=n
242        Number of filesystem blocks that mballoc will try to use for allocation
243        size and alignment. For RAID5/6 systems this should be the number of
244        data disks *  RAID chunk size in file system blocks.
245
246  delalloc	(*)
247        Defer block allocation until just before ext4 writes out the block(s)
248        in question.  This allows ext4 to better allocation decisions more
249        efficiently.
250
251  nodelalloc
252        Disable delayed allocation.  Blocks are allocated when the data is
253        copied from userspace to the page cache, either via the write(2) system
254        call or when an mmap'ed page which was previously unallocated is
255        written for the first time.
256
257  max_batch_time=usec
258        Maximum amount of time ext4 should wait for additional filesystem
259        operations to be batch together with a synchronous write operation.
260        Since a synchronous write operation is going to force a commit and then
261        a wait for the I/O complete, it doesn't cost much, and can be a huge
262        throughput win, we wait for a small amount of time to see if any other
263        transactions can piggyback on the synchronous write.   The algorithm
264        used is designed to automatically tune for the speed of the disk, by
265        measuring the amount of time (on average) that it takes to finish
266        committing a transaction.  Call this time the "commit time".  If the
267        time that the transaction has been running is less than the commit
268        time, ext4 will try sleeping for the commit time to see if other
269        operations will join the transaction.   The commit time is capped by
270        the max_batch_time, which defaults to 15000us (15ms).   This
271        optimization can be turned off entirely by setting max_batch_time to 0.
272
273  min_batch_time=usec
274        This parameter sets the commit time (as described above) to be at least
275        min_batch_time.  It defaults to zero microseconds.  Increasing this
276        parameter may improve the throughput of multi-threaded, synchronous
277        workloads on very fast disks, at the cost of increasing latency.
278
279  journal_ioprio=prio
280        The I/O priority (from 0 to 7, where 0 is the highest priority) which
281        should be used for I/O operations submitted by kjournald2 during a
282        commit operation.  This defaults to 3, which is a slightly higher
283        priority than the default I/O priority.
284
285  auto_da_alloc(*), noauto_da_alloc
286        Many broken applications don't use fsync() when replacing existing
287        files via patterns such as fd = open("foo.new")/write(fd,..)/close(fd)/
288        rename("foo.new", "foo"), or worse yet, fd = open("foo",
289        O_TRUNC)/write(fd,..)/close(fd).  If auto_da_alloc is enabled, ext4
290        will detect the replace-via-rename and replace-via-truncate patterns
291        and force that any delayed allocation blocks are allocated such that at
292        the next journal commit, in the default data=ordered mode, the data
293        blocks of the new file are forced to disk before the rename() operation
294        is committed.  This provides roughly the same level of guarantees as
295        ext3, and avoids the "zero-length" problem that can happen when a
296        system crashes before the delayed allocation blocks are forced to disk.
297
298  noinit_itable
299        Do not initialize any uninitialized inode table blocks in the
300        background.  This feature may be used by installation CD's so that the
301        install process can complete as quickly as possible; the inode table
302        initialization process would then be deferred until the next time the
303        file system is unmounted.
304
305  init_itable=n
306        The lazy itable init code will wait n times the number of milliseconds
307        it took to zero out the previous block group's inode table.  This
308        minimizes the impact on the system performance while file system's
309        inode table is being initialized.
310
311  discard, nodiscard(*)
312        Controls whether ext4 should issue discard/TRIM commands to the
313        underlying block device when blocks are freed.  This is useful for SSD
314        devices and sparse/thinly-provisioned LUNs, but it is off by default
315        until sufficient testing has been done.
316
317  nouid32
318        Disables 32-bit UIDs and GIDs.  This is for interoperability  with
319        older kernels which only store and expect 16-bit values.
320
321  block_validity(*), noblock_validity
322        These options enable or disable the in-kernel facility for tracking
323        filesystem metadata blocks within internal data structures.  This
324        allows multi- block allocator and other routines to notice bugs or
325        corrupted allocation bitmaps which cause blocks to be allocated which
326        overlap with filesystem metadata blocks.
327
328  dioread_lock, dioread_nolock
329        Controls whether or not ext4 should use the DIO read locking. If the
330        dioread_nolock option is specified ext4 will allocate uninitialized
331        extent before buffer write and convert the extent to initialized after
332        IO completes. This approach allows ext4 code to avoid using inode
333        mutex, which improves scalability on high speed storages. However this
334        does not work with data journaling and dioread_nolock option will be
335        ignored with kernel warning. Note that dioread_nolock code path is only
336        used for extent-based files.  Because of the restrictions this options
337        comprises it is off by default (e.g. dioread_lock).
338
339  max_dir_size_kb=n
340        This limits the size of directories so that any attempt to expand them
341        beyond the specified limit in kilobytes will cause an ENOSPC error.
342        This is useful in memory constrained environments, where a very large
343        directory can cause severe performance problems or even provoke the Out
344        Of Memory killer.  (For example, if there is only 512mb memory
345        available, a 176mb directory may seriously cramp the system's style.)
346
347  i_version
348        Enable 64-bit inode version support. This option is off by default.
349
350  dax
351        Use direct access (no page cache).  See
352        Documentation/filesystems/dax.txt.  Note that this option is
353        incompatible with data=journal.
354
355Data Mode
356=========
357There are 3 different data modes:
358
359* writeback mode
360
361  In data=writeback mode, ext4 does not journal data at all.  This mode provides
362  a similar level of journaling as that of XFS, JFS, and ReiserFS in its default
363  mode - metadata journaling.  A crash+recovery can cause incorrect data to
364  appear in files which were written shortly before the crash.  This mode will
365  typically provide the best ext4 performance.
366
367* ordered mode
368
369  In data=ordered mode, ext4 only officially journals metadata, but it logically
370  groups metadata information related to data changes with the data blocks into
371  a single unit called a transaction.  When it's time to write the new metadata
372  out to disk, the associated data blocks are written first.  In general, this
373  mode performs slightly slower than writeback but significantly faster than
374  journal mode.
375
376* journal mode
377
378  data=journal mode provides full data and metadata journaling.  All new data is
379  written to the journal first, and then to its final location.  In the event of
380  a crash, the journal can be replayed, bringing both data and metadata into a
381  consistent state.  This mode is the slowest except when data needs to be read
382  from and written to disk at the same time where it outperforms all others
383  modes.  Enabling this mode will disable delayed allocation and O_DIRECT
384  support.
385
386/proc entries
387=============
388
389Information about mounted ext4 file systems can be found in
390/proc/fs/ext4.  Each mounted filesystem will have a directory in
391/proc/fs/ext4 based on its device name (i.e., /proc/fs/ext4/hdc or
392/proc/fs/ext4/dm-0).   The files in each per-device directory are shown
393in table below.
394
395Files in /proc/fs/ext4/<devname>
396
397  mb_groups
398        details of multiblock allocator buddy cache of free blocks
399
400/sys entries
401============
402
403Information about mounted ext4 file systems can be found in
404/sys/fs/ext4.  Each mounted filesystem will have a directory in
405/sys/fs/ext4 based on its device name (i.e., /sys/fs/ext4/hdc or
406/sys/fs/ext4/dm-0).   The files in each per-device directory are shown
407in table below.
408
409Files in /sys/fs/ext4/<devname>:
410
411(see also Documentation/ABI/testing/sysfs-fs-ext4)
412
413  delayed_allocation_blocks
414        This file is read-only and shows the number of blocks that are dirty in
415        the page cache, but which do not have their location in the filesystem
416        allocated yet.
417
418  inode_goal
419        Tuning parameter which (if non-zero) controls the goal inode used by
420        the inode allocator in preference to all other allocation heuristics.
421        This is intended for debugging use only, and should be 0 on production
422        systems.
423
424  inode_readahead_blks
425        Tuning parameter which controls the maximum number of inode table
426        blocks that ext4's inode table readahead algorithm will pre-read into
427        the buffer cache.
428
429  lifetime_write_kbytes
430        This file is read-only and shows the number of kilobytes of data that
431        have been written to this filesystem since it was created.
432
433  max_writeback_mb_bump
434        The maximum number of megabytes the writeback code will try to write
435        out before move on to another inode.
436
437  mb_group_prealloc
438        The multiblock allocator will round up allocation requests to a
439        multiple of this tuning parameter if the stripe size is not set in the
440        ext4 superblock
441
442  mb_max_to_scan
443        The maximum number of extents the multiblock allocator will search to
444        find the best extent.
445
446  mb_min_to_scan
447        The minimum number of extents the multiblock allocator will search to
448        find the best extent.
449
450  mb_order2_req
451        Tuning parameter which controls the minimum size for requests (as a
452        power of 2) where the buddy cache is used.
453
454  mb_stats
455        Controls whether the multiblock allocator should collect statistics,
456        which are shown during the unmount. 1 means to collect statistics, 0
457        means not to collect statistics.
458
459  mb_stream_req
460        Files which have fewer blocks than this tunable parameter will have
461        their blocks allocated out of a block group specific preallocation
462        pool, so that small files are packed closely together.  Each large file
463        will have its blocks allocated out of its own unique preallocation
464        pool.
465
466  session_write_kbytes
467        This file is read-only and shows the number of kilobytes of data that
468        have been written to this filesystem since it was mounted.
469
470  reserved_clusters
471        This is RW file and contains number of reserved clusters in the file
472        system which will be used in the specific situations to avoid costly
473        zeroout, unexpected ENOSPC, or possible data loss. The default is 2% or
474        4096 clusters, whichever is smaller and this can be changed however it
475        can never exceed number of clusters in the file system. If there is not
476        enough space for the reserved space when mounting the file mount will
477        _not_ fail.
478
479Ioctls
480======
481
482There is some Ext4 specific functionality which can be accessed by applications
483through the system call interfaces. The list of all Ext4 specific ioctls are
484shown in the table below.
485
486Table of Ext4 specific ioctls
487
488  EXT4_IOC_GETFLAGS
489        Get additional attributes associated with inode.  The ioctl argument is
490        an integer bitfield, with bit values described in ext4.h. This ioctl is
491        an alias for FS_IOC_GETFLAGS.
492
493  EXT4_IOC_SETFLAGS
494        Set additional attributes associated with inode.  The ioctl argument is
495        an integer bitfield, with bit values described in ext4.h. This ioctl is
496        an alias for FS_IOC_SETFLAGS.
497
498  EXT4_IOC_GETVERSION, EXT4_IOC_GETVERSION_OLD
499        Get the inode i_generation number stored for each inode. The
500        i_generation number is normally changed only when new inode is created
501        and it is particularly useful for network filesystems. The '_OLD'
502        version of this ioctl is an alias for FS_IOC_GETVERSION.
503
504  EXT4_IOC_SETVERSION, EXT4_IOC_SETVERSION_OLD
505        Set the inode i_generation number stored for each inode. The '_OLD'
506        version of this ioctl is an alias for FS_IOC_SETVERSION.
507
508  EXT4_IOC_GROUP_EXTEND
509        This ioctl has the same purpose as the resize mount option. It allows
510        to resize filesystem to the end of the last existing block group,
511        further resize has to be done with resize2fs, either online, or
512        offline. The argument points to the unsigned logn number representing
513        the filesystem new block count.
514
515  EXT4_IOC_MOVE_EXT
516        Move the block extents from orig_fd (the one this ioctl is pointing to)
517        to the donor_fd (the one specified in move_extent structure passed as
518        an argument to this ioctl). Then, exchange inode metadata between
519        orig_fd and donor_fd.  This is especially useful for online
520        defragmentation, because the allocator has the opportunity to allocate
521        moved blocks better, ideally into one contiguous extent.
522
523  EXT4_IOC_GROUP_ADD
524        Add a new group descriptor to an existing or new group descriptor
525        block. The new group descriptor is described by ext4_new_group_input
526        structure, which is passed as an argument to this ioctl. This is
527        especially useful in conjunction with EXT4_IOC_GROUP_EXTEND, which
528        allows online resize of the filesystem to the end of the last existing
529        block group.  Those two ioctls combined is used in userspace online
530        resize tool (e.g. resize2fs).
531
532  EXT4_IOC_MIGRATE
533        This ioctl operates on the filesystem itself.  It converts (migrates)
534        ext3 indirect block mapped inode to ext4 extent mapped inode by walking
535        through indirect block mapping of the original inode and converting
536        contiguous block ranges into ext4 extents of the temporary inode. Then,
537        inodes are swapped. This ioctl might help, when migrating from ext3 to
538        ext4 filesystem, however suggestion is to create fresh ext4 filesystem
539        and copy data from the backup. Note, that filesystem has to support
540        extents for this ioctl to work.
541
542  EXT4_IOC_ALLOC_DA_BLKS
543        Force all of the delay allocated blocks to be allocated to preserve
544        application-expected ext3 behaviour. Note that this will also start
545        triggering a write of the data blocks, but this behaviour may change in
546        the future as it is not necessary and has been done this way only for
547        sake of simplicity.
548
549  EXT4_IOC_RESIZE_FS
550        Resize the filesystem to a new size.  The number of blocks of resized
551        filesystem is passed in via 64 bit integer argument.  The kernel
552        allocates bitmaps and inode table, the userspace tool thus just passes
553        the new number of blocks.
554
555  EXT4_IOC_SWAP_BOOT
556        Swap i_blocks and associated attributes (like i_blocks, i_size,
557        i_flags, ...) from the specified inode with inode EXT4_BOOT_LOADER_INO
558        (#5). This is typically used to store a boot loader in a secure part of
559        the filesystem, where it can't be changed by a normal user by accident.
560        The data blocks of the previous boot loader will be associated with the
561        given inode.
562
563References
564==========
565
566kernel source:	<file:fs/ext4/>
567		<file:fs/jbd2/>
568
569programs:	http://e2fsprogs.sourceforge.net/
570
571useful links:	http://fedoraproject.org/wiki/ext3-devel
572		http://www.bullopensource.org/ext4/
573		http://ext4.wiki.kernel.org/index.php/Main_Page
574		http://fedoraproject.org/wiki/Features/Ext4
575