615 lines · plain
1.. SPDX-License-Identifier: GPL-2.02 3========================4ext4 General Information5========================6 7Ext4 is an advanced level of the ext3 filesystem which incorporates8scalability and reliability enhancements for supporting large filesystems9(64 bit) in keeping with increasing disk capacities and state-of-the-art10feature requirements.11 12Mailing list: linux-ext4@vger.kernel.org13Web site: http://ext4.wiki.kernel.org14 15 16Quick usage instructions17========================18 19Note: More extensive information for getting started with ext4 can be20found at the ext4 wiki site at the URL:21http://ext4.wiki.kernel.org/index.php/Ext4_Howto22 23 - The latest version of e2fsprogs can be found at:24 25 https://www.kernel.org/pub/linux/kernel/people/tytso/e2fsprogs/26 27 or28 29 http://sourceforge.net/project/showfiles.php?group_id=240630 31 or grab the latest git repository from:32 33 https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git34 35 - Create a new filesystem using the ext4 filesystem type:36 37 # mke2fs -t ext4 /dev/hda138 39 Or to configure an existing ext3 filesystem to support extents:40 41 # tune2fs -O extents /dev/hda142 43 If the filesystem was created with 128 byte inodes, it can be44 converted to use 256 byte for greater efficiency via:45 46 # tune2fs -I 256 /dev/hda147 48 - Mounting:49 50 # mount -t ext4 /dev/hda1 /wherever51 52 - When comparing performance with other filesystems, it's always53 important to try multiple workloads; very often a subtle change in a54 workload parameter can completely change the ranking of which55 filesystems do well compared to others. When comparing versus ext3,56 note that ext4 enables write barriers by default, while ext3 does57 not enable write barriers by default. So it is useful to use58 explicitly specify whether barriers are enabled or not when via the59 '-o barriers=[0|1]' mount option for both ext3 and ext4 filesystems60 for a fair comparison. When tuning ext3 for best benchmark numbers,61 it is often worthwhile to try changing the data journaling mode; '-o62 data=writeback' can be faster for some workloads. (Note however that63 running mounted with data=writeback can potentially leave stale data64 exposed in recently written files in case of an unclean shutdown,65 which could be a security exposure in some situations.) Configuring66 the filesystem with a large journal can also be helpful for67 metadata-intensive workloads.68 69Features70========71 72Currently Available73-------------------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 tree79* 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 time82* inode version field on disk (NFSv4, Lustre)83* reduced e2fsck time via uninit_bg feature84* journal checksumming for robustness, performance85* persistent file preallocation (e.g for streaming media, databases)86* ability to pack bitmaps and inode tables into larger virtual groups via the87 flex_bg feature88* large file support89* inode allocation using large virtual block groups via flex_bg90* delayed allocation91* large block (up to pagesize) support92* efficient new ordered mode in JBD2 and ext4 (avoid using buffer head to force93 the ordering)94* Case-insensitive file name lookups95* file-based encryption support (fscrypt)96* file-based verity support (fsverity)97 98[1] Filesystems with a block size of 1k may see a limit imposed by the99directory hash tree having a maximum depth of two.100 101case-insensitive file name lookups102======================================================103 104The case-insensitive file name lookup feature is supported on a105per-directory basis, allowing the user to mix case-insensitive and106case-sensitive directories in the same filesystem. It is enabled by107flipping the +F inode attribute of an empty directory. The108case-insensitive string match operation is only defined when we know how109text in encoded in a byte sequence. For that reason, in order to enable110case-insensitive directories, the filesystem must have the111casefold feature, which stores the filesystem-wide encoding112model used. By default, the charset adopted is the latest version of113Unicode (12.1.0, by the time of this writing), encoded in the UTF-8114form. The comparison algorithm is implemented by normalizing the115strings to the Canonical decomposition form, as defined by Unicode,116followed by a byte per byte comparison.117 118The case-awareness is name-preserving on the disk, meaning that the file119name provided by userspace is a byte-per-byte match to what is actually120written in the disk. The Unicode normalization format used by the121kernel is thus an internal representation, and not exposed to the122userspace nor to the disk, with the important exception of disk hashes,123used on large case-insensitive directories with DX feature. On DX124directories, the hash must be calculated using the casefolded version of125the filename, meaning that the normalization format used actually has an126impact on where the directory entry is stored.127 128When we change from viewing filenames as opaque byte sequences to seeing129them as encoded strings we need to address what happens when a program130tries to create a file with an invalid name. The Unicode subsystem131within the kernel leaves the decision of what to do in this case to the132filesystem, which select its preferred behavior by enabling/disabling133the strict mode. When Ext4 encounters one of those strings and the134filesystem did not require strict mode, it falls back to considering the135entire string as an opaque byte sequence, which still allows the user to136operate on that file, but the case-insensitive lookups won't work.137 138Options139=======140 141When mounting an ext4 filesystem, the following option are accepted:142(*) == default143 144 ro145 Mount filesystem read only. Note that ext4 will replay the journal (and146 thus write to the partition) even when mounted "read only". The mount147 options "ro,noload" can be used to prevent writes to the filesystem.148 149 journal_checksum150 Enable checksumming of the journal transactions. This will allow the151 recovery code in e2fsck and the kernel to detect corruption in the152 kernel. It is a compatible change and will be ignored by older153 kernels.154 155 journal_async_commit156 Commit block can be written to disk without waiting for descriptor157 blocks. If enabled older kernels cannot mount the device. This will158 enable 'journal_checksum' internally.159 160 journal_path=path, journal_dev=devnum161 When the external journal device's major/minor numbers have changed,162 these options allow the user to specify the new journal location. The163 journal device is identified through either its new major/minor numbers164 encoded in devnum, or via a path to the device.165 166 norecovery, noload167 Don't load the journal on mounting. Note that if the filesystem was168 not unmounted cleanly, skipping the journal replay will lead to the169 filesystem containing inconsistencies that can lead to any number of170 problems.171 172 data=journal173 All data are committed into the journal prior to being written into the174 main file system. Enabling this mode will disable delayed allocation175 and O_DIRECT support.176 177 data=ordered (*)178 All data are forced directly out to the main file system prior to its179 metadata being committed to the journal.180 181 data=writeback182 Data ordering is not preserved, data may be written into the main file183 system after its metadata has been committed to the journal.184 185 commit=nrsec (*)186 This setting limits the maximum age of the running transaction to187 'nrsec' seconds. The default value is 5 seconds. This means that if188 you lose your power, you will lose as much as the latest 5 seconds of189 metadata changes (your filesystem will not be damaged though, thanks190 to the journaling). This default value (or any low value) will hurt191 performance, but it's good for data-safety. Setting it to 0 will have192 the same effect as leaving it at the default (5 seconds). Setting it193 to very large values will improve performance. Note that due to194 delayed allocation even older data can be lost on power failure since195 writeback of those data begins only after time set in196 /proc/sys/vm/dirty_expire_centisecs.197 198 barrier=<0|1(*)>, barrier(*), nobarrier199 This enables/disables the use of write barriers in the jbd code.200 barrier=0 disables, barrier=1 enables. This also requires an IO stack201 which can support barriers, and if jbd gets an error on a barrier202 write, it will disable again with a warning. Write barriers enforce203 proper on-disk ordering of journal commits, making volatile disk write204 caches safe to use, at some performance penalty. If your disks are205 battery-backed in one way or another, disabling barriers may safely206 improve performance. The mount options "barrier" and "nobarrier" can207 also be used to enable or disable barriers, for consistency with other208 ext4 mount options.209 210 inode_readahead_blks=n211 This tuning parameter controls the maximum number of inode table blocks212 that ext4's inode table readahead algorithm will pre-read into the213 buffer cache. The default value is 32 blocks.214 215 bsddf (*)216 Make 'df' act like BSD.217 218 minixdf219 Make 'df' act like Minix.220 221 debug222 Extra debugging information is sent to syslog.223 224 abort225 Simulate the effects of calling ext4_abort() for debugging purposes.226 This is normally used while remounting a filesystem which is already227 mounted.228 229 errors=remount-ro230 Remount the filesystem read-only on an error.231 232 errors=continue233 Keep going on a filesystem error.234 235 errors=panic236 Panic and halt the machine if an error occurs. (These mount options237 override the errors behavior specified in the superblock, which can be238 configured using tune2fs)239 240 data_err=ignore(*)241 Just print an error message if an error occurs in a file data buffer in242 ordered mode.243 data_err=abort244 Abort the journal if an error occurs in a file data buffer in ordered245 mode.246 247 grpid | bsdgroups248 New objects have the group ID of their parent.249 250 nogrpid (*) | sysvgroups251 New objects have the group ID of their creator.252 253 resgid=n254 The group ID which may use the reserved blocks.255 256 resuid=n257 The user ID which may use the reserved blocks.258 259 sb=260 Use alternate superblock at this location.261 262 quota, noquota, grpquota, usrquota263 These options are ignored by the filesystem. They are used only by264 quota tools to recognize volumes where quota should be turned on. See265 documentation in the quota-tools package for more details266 (http://sourceforge.net/projects/linuxquota).267 268 jqfmt=<quota type>, usrjquota=<file>, grpjquota=<file>269 These options tell filesystem details about quota so that quota270 information can be properly updated during journal replay. They replace271 the above quota options. See documentation in the quota-tools package272 for more details (http://sourceforge.net/projects/linuxquota).273 274 stripe=n275 Number of filesystem blocks that mballoc will try to use for allocation276 size and alignment. For RAID5/6 systems this should be the number of277 data disks * RAID chunk size in file system blocks.278 279 delalloc (*)280 Defer block allocation until just before ext4 writes out the block(s)281 in question. This allows ext4 to better allocation decisions more282 efficiently.283 284 nodelalloc285 Disable delayed allocation. Blocks are allocated when the data is286 copied from userspace to the page cache, either via the write(2) system287 call or when an mmap'ed page which was previously unallocated is288 written for the first time.289 290 max_batch_time=usec291 Maximum amount of time ext4 should wait for additional filesystem292 operations to be batch together with a synchronous write operation.293 Since a synchronous write operation is going to force a commit and then294 a wait for the I/O complete, it doesn't cost much, and can be a huge295 throughput win, we wait for a small amount of time to see if any other296 transactions can piggyback on the synchronous write. The algorithm297 used is designed to automatically tune for the speed of the disk, by298 measuring the amount of time (on average) that it takes to finish299 committing a transaction. Call this time the "commit time". If the300 time that the transaction has been running is less than the commit301 time, ext4 will try sleeping for the commit time to see if other302 operations will join the transaction. The commit time is capped by303 the max_batch_time, which defaults to 15000us (15ms). This304 optimization can be turned off entirely by setting max_batch_time to 0.305 306 min_batch_time=usec307 This parameter sets the commit time (as described above) to be at least308 min_batch_time. It defaults to zero microseconds. Increasing this309 parameter may improve the throughput of multi-threaded, synchronous310 workloads on very fast disks, at the cost of increasing latency.311 312 journal_ioprio=prio313 The I/O priority (from 0 to 7, where 0 is the highest priority) which314 should be used for I/O operations submitted by kjournald2 during a315 commit operation. This defaults to 3, which is a slightly higher316 priority than the default I/O priority.317 318 auto_da_alloc(*), noauto_da_alloc319 Many broken applications don't use fsync() when replacing existing320 files via patterns such as fd = open("foo.new")/write(fd,..)/close(fd)/321 rename("foo.new", "foo"), or worse yet, fd = open("foo",322 O_TRUNC)/write(fd,..)/close(fd). If auto_da_alloc is enabled, ext4323 will detect the replace-via-rename and replace-via-truncate patterns324 and force that any delayed allocation blocks are allocated such that at325 the next journal commit, in the default data=ordered mode, the data326 blocks of the new file are forced to disk before the rename() operation327 is committed. This provides roughly the same level of guarantees as328 ext3, and avoids the "zero-length" problem that can happen when a329 system crashes before the delayed allocation blocks are forced to disk.330 331 noinit_itable332 Do not initialize any uninitialized inode table blocks in the333 background. This feature may be used by installation CD's so that the334 install process can complete as quickly as possible; the inode table335 initialization process would then be deferred until the next time the336 file system is unmounted.337 338 init_itable=n339 The lazy itable init code will wait n times the number of milliseconds340 it took to zero out the previous block group's inode table. This341 minimizes the impact on the system performance while file system's342 inode table is being initialized.343 344 discard, nodiscard(*)345 Controls whether ext4 should issue discard/TRIM commands to the346 underlying block device when blocks are freed. This is useful for SSD347 devices and sparse/thinly-provisioned LUNs, but it is off by default348 until sufficient testing has been done.349 350 nouid32351 Disables 32-bit UIDs and GIDs. This is for interoperability with352 older kernels which only store and expect 16-bit values.353 354 block_validity(*), noblock_validity355 These options enable or disable the in-kernel facility for tracking356 filesystem metadata blocks within internal data structures. This357 allows multi- block allocator and other routines to notice bugs or358 corrupted allocation bitmaps which cause blocks to be allocated which359 overlap with filesystem metadata blocks.360 361 dioread_lock, dioread_nolock362 Controls whether or not ext4 should use the DIO read locking. If the363 dioread_nolock option is specified ext4 will allocate uninitialized364 extent before buffer write and convert the extent to initialized after365 IO completes. This approach allows ext4 code to avoid using inode366 mutex, which improves scalability on high speed storages. However this367 does not work with data journaling and dioread_nolock option will be368 ignored with kernel warning. Note that dioread_nolock code path is only369 used for extent-based files. Because of the restrictions this options370 comprises it is off by default (e.g. dioread_lock).371 372 max_dir_size_kb=n373 This limits the size of directories so that any attempt to expand them374 beyond the specified limit in kilobytes will cause an ENOSPC error.375 This is useful in memory constrained environments, where a very large376 directory can cause severe performance problems or even provoke the Out377 Of Memory killer. (For example, if there is only 512mb memory378 available, a 176mb directory may seriously cramp the system's style.)379 380 i_version381 Enable 64-bit inode version support. This option is off by default.382 383 dax384 Use direct access (no page cache). See385 Documentation/filesystems/dax.rst. Note that this option is386 incompatible with data=journal.387 388 inlinecrypt389 When possible, encrypt/decrypt the contents of encrypted files using the390 blk-crypto framework rather than filesystem-layer encryption. This391 allows the use of inline encryption hardware. The on-disk format is392 unaffected. For more details, see393 Documentation/block/inline-encryption.rst.394 395Data Mode396=========397There are 3 different data modes:398 399* writeback mode400 401 In data=writeback mode, ext4 does not journal data at all. This mode provides402 a similar level of journaling as that of XFS, JFS, and ReiserFS in its default403 mode - metadata journaling. A crash+recovery can cause incorrect data to404 appear in files which were written shortly before the crash. This mode will405 typically provide the best ext4 performance.406 407* ordered mode408 409 In data=ordered mode, ext4 only officially journals metadata, but it logically410 groups metadata information related to data changes with the data blocks into411 a single unit called a transaction. When it's time to write the new metadata412 out to disk, the associated data blocks are written first. In general, this413 mode performs slightly slower than writeback but significantly faster than414 journal mode.415 416* journal mode417 418 data=journal mode provides full data and metadata journaling. All new data is419 written to the journal first, and then to its final location. In the event of420 a crash, the journal can be replayed, bringing both data and metadata into a421 consistent state. This mode is the slowest except when data needs to be read422 from and written to disk at the same time where it outperforms all others423 modes. Enabling this mode will disable delayed allocation and O_DIRECT424 support.425 426/proc entries427=============428 429Information about mounted ext4 file systems can be found in430/proc/fs/ext4. Each mounted filesystem will have a directory in431/proc/fs/ext4 based on its device name (i.e., /proc/fs/ext4/hdc or432/proc/fs/ext4/dm-0). The files in each per-device directory are shown433in table below.434 435Files in /proc/fs/ext4/<devname>436 437 mb_groups438 details of multiblock allocator buddy cache of free blocks439 440/sys entries441============442 443Information about mounted ext4 file systems can be found in444/sys/fs/ext4. Each mounted filesystem will have a directory in445/sys/fs/ext4 based on its device name (i.e., /sys/fs/ext4/hdc or446/sys/fs/ext4/dm-0). The files in each per-device directory are shown447in table below.448 449Files in /sys/fs/ext4/<devname>:450 451(see also Documentation/ABI/testing/sysfs-fs-ext4)452 453 delayed_allocation_blocks454 This file is read-only and shows the number of blocks that are dirty in455 the page cache, but which do not have their location in the filesystem456 allocated yet.457 458 inode_goal459 Tuning parameter which (if non-zero) controls the goal inode used by460 the inode allocator in preference to all other allocation heuristics.461 This is intended for debugging use only, and should be 0 on production462 systems.463 464 inode_readahead_blks465 Tuning parameter which controls the maximum number of inode table466 blocks that ext4's inode table readahead algorithm will pre-read into467 the buffer cache.468 469 lifetime_write_kbytes470 This file is read-only and shows the number of kilobytes of data that471 have been written to this filesystem since it was created.472 473 max_writeback_mb_bump474 The maximum number of megabytes the writeback code will try to write475 out before move on to another inode.476 477 mb_group_prealloc478 The multiblock allocator will round up allocation requests to a479 multiple of this tuning parameter if the stripe size is not set in the480 ext4 superblock481 482 mb_max_to_scan483 The maximum number of extents the multiblock allocator will search to484 find the best extent.485 486 mb_min_to_scan487 The minimum number of extents the multiblock allocator will search to488 find the best extent.489 490 mb_order2_req491 Tuning parameter which controls the minimum size for requests (as a492 power of 2) where the buddy cache is used.493 494 mb_stats495 Controls whether the multiblock allocator should collect statistics,496 which are shown during the unmount. 1 means to collect statistics, 0497 means not to collect statistics.498 499 mb_stream_req500 Files which have fewer blocks than this tunable parameter will have501 their blocks allocated out of a block group specific preallocation502 pool, so that small files are packed closely together. Each large file503 will have its blocks allocated out of its own unique preallocation504 pool.505 506 session_write_kbytes507 This file is read-only and shows the number of kilobytes of data that508 have been written to this filesystem since it was mounted.509 510 reserved_clusters511 This is RW file and contains number of reserved clusters in the file512 system which will be used in the specific situations to avoid costly513 zeroout, unexpected ENOSPC, or possible data loss. The default is 2% or514 4096 clusters, whichever is smaller and this can be changed however it515 can never exceed number of clusters in the file system. If there is not516 enough space for the reserved space when mounting the file mount will517 _not_ fail.518 519Ioctls520======521 522Ext4 implements various ioctls which can be used by applications to access523ext4-specific functionality. An incomplete list of these ioctls is shown in the524table below. This list includes truly ext4-specific ioctls (``EXT4_IOC_*``) as525well as ioctls that may have been ext4-specific originally but are now supported526by some other filesystem(s) too (``FS_IOC_*``).527 528Table of Ext4 ioctls529 530 FS_IOC_GETFLAGS531 Get additional attributes associated with inode. The ioctl argument is532 an integer bitfield, with bit values described in ext4.h.533 534 FS_IOC_SETFLAGS535 Set additional attributes associated with inode. The ioctl argument is536 an integer bitfield, with bit values described in ext4.h.537 538 EXT4_IOC_GETVERSION, EXT4_IOC_GETVERSION_OLD539 Get the inode i_generation number stored for each inode. The540 i_generation number is normally changed only when new inode is created541 and it is particularly useful for network filesystems. The '_OLD'542 version of this ioctl is an alias for FS_IOC_GETVERSION.543 544 EXT4_IOC_SETVERSION, EXT4_IOC_SETVERSION_OLD545 Set the inode i_generation number stored for each inode. The '_OLD'546 version of this ioctl is an alias for FS_IOC_SETVERSION.547 548 EXT4_IOC_GROUP_EXTEND549 This ioctl has the same purpose as the resize mount option. It allows550 to resize filesystem to the end of the last existing block group,551 further resize has to be done with resize2fs, either online, or552 offline. The argument points to the unsigned logn number representing553 the filesystem new block count.554 555 EXT4_IOC_MOVE_EXT556 Move the block extents from orig_fd (the one this ioctl is pointing to)557 to the donor_fd (the one specified in move_extent structure passed as558 an argument to this ioctl). Then, exchange inode metadata between559 orig_fd and donor_fd. This is especially useful for online560 defragmentation, because the allocator has the opportunity to allocate561 moved blocks better, ideally into one contiguous extent.562 563 EXT4_IOC_GROUP_ADD564 Add a new group descriptor to an existing or new group descriptor565 block. The new group descriptor is described by ext4_new_group_input566 structure, which is passed as an argument to this ioctl. This is567 especially useful in conjunction with EXT4_IOC_GROUP_EXTEND, which568 allows online resize of the filesystem to the end of the last existing569 block group. Those two ioctls combined is used in userspace online570 resize tool (e.g. resize2fs).571 572 EXT4_IOC_MIGRATE573 This ioctl operates on the filesystem itself. It converts (migrates)574 ext3 indirect block mapped inode to ext4 extent mapped inode by walking575 through indirect block mapping of the original inode and converting576 contiguous block ranges into ext4 extents of the temporary inode. Then,577 inodes are swapped. This ioctl might help, when migrating from ext3 to578 ext4 filesystem, however suggestion is to create fresh ext4 filesystem579 and copy data from the backup. Note, that filesystem has to support580 extents for this ioctl to work.581 582 EXT4_IOC_ALLOC_DA_BLKS583 Force all of the delay allocated blocks to be allocated to preserve584 application-expected ext3 behaviour. Note that this will also start585 triggering a write of the data blocks, but this behaviour may change in586 the future as it is not necessary and has been done this way only for587 sake of simplicity.588 589 EXT4_IOC_RESIZE_FS590 Resize the filesystem to a new size. The number of blocks of resized591 filesystem is passed in via 64 bit integer argument. The kernel592 allocates bitmaps and inode table, the userspace tool thus just passes593 the new number of blocks.594 595 EXT4_IOC_SWAP_BOOT596 Swap i_blocks and associated attributes (like i_blocks, i_size,597 i_flags, ...) from the specified inode with inode EXT4_BOOT_LOADER_INO598 (#5). This is typically used to store a boot loader in a secure part of599 the filesystem, where it can't be changed by a normal user by accident.600 The data blocks of the previous boot loader will be associated with the601 given inode.602 603References604==========605 606kernel source: <file:fs/ext4/>607 <file:fs/jbd2/>608 609programs: http://e2fsprogs.sourceforge.net/610 611useful links: https://fedoraproject.org/wiki/ext3-devel612 http://www.bullopensource.org/ext4/613 http://ext4.wiki.kernel.org/index.php/Main_Page614 https://fedoraproject.org/wiki/Features/Ext4615