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* Case-insensitive file name lookups 95* 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 the 99directory hash tree having a maximum depth of two. 100 101case-insensitive file name lookups 102====================================================== 103 104The case-insensitive file name lookup feature is supported on a 105per-directory basis, allowing the user to mix case-insensitive and 106case-sensitive directories in the same filesystem. It is enabled by 107flipping the +F inode attribute of an empty directory. The 108case-insensitive string match operation is only defined when we know how 109text in encoded in a byte sequence. For that reason, in order to enable 110case-insensitive directories, the filesystem must have the 111casefold feature, which stores the filesystem-wide encoding 112model used. By default, the charset adopted is the latest version of 113Unicode (12.1.0, by the time of this writing), encoded in the UTF-8 114form. The comparison algorithm is implemented by normalizing the 115strings 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 file 119name provided by userspace is a byte-per-byte match to what is actually 120written in the disk. The Unicode normalization format used by the 121kernel is thus an internal representation, and not exposed to the 122userspace nor to the disk, with the important exception of disk hashes, 123used on large case-insensitive directories with DX feature. On DX 124directories, the hash must be calculated using the casefolded version of 125the filename, meaning that the normalization format used actually has an 126impact on where the directory entry is stored. 127 128When we change from viewing filenames as opaque byte sequences to seeing 129them as encoded strings we need to address what happens when a program 130tries to create a file with an invalid name. The Unicode subsystem 131within the kernel leaves the decision of what to do in this case to the 132filesystem, which select its preferred behavior by enabling/disabling 133the strict mode. When Ext4 encounters one of those strings and the 134filesystem did not require strict mode, it falls back to considering the 135entire string as an opaque byte sequence, which still allows the user to 136operate on that file, but the case-insensitive lookups won't work. 137 138Options 139======= 140 141When mounting an ext4 filesystem, the following option are accepted: 142(*) == default 143 144 ro 145 Mount filesystem read only. Note that ext4 will replay the journal (and 146 thus write to the partition) even when mounted "read only". The mount 147 options "ro,noload" can be used to prevent writes to the filesystem. 148 149 journal_checksum 150 Enable checksumming of the journal transactions. This will allow the 151 recovery code in e2fsck and the kernel to detect corruption in the 152 kernel. It is a compatible change and will be ignored by older 153 kernels. 154 155 journal_async_commit 156 Commit block can be written to disk without waiting for descriptor 157 blocks. If enabled older kernels cannot mount the device. This will 158 enable 'journal_checksum' internally. 159 160 journal_path=path, journal_dev=devnum 161 When the external journal device's major/minor numbers have changed, 162 these options allow the user to specify the new journal location. The 163 journal device is identified through either its new major/minor numbers 164 encoded in devnum, or via a path to the device. 165 166 norecovery, noload 167 Don't load the journal on mounting. Note that if the filesystem was 168 not unmounted cleanly, skipping the journal replay will lead to the 169 filesystem containing inconsistencies that can lead to any number of 170 problems. 171 172 data=journal 173 All data are committed into the journal prior to being written into the 174 main file system. Enabling this mode will disable delayed allocation 175 and O_DIRECT support. 176 177 data=ordered (*) 178 All data are forced directly out to the main file system prior to its 179 metadata being committed to the journal. 180 181 data=writeback 182 Data ordering is not preserved, data may be written into the main file 183 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 to 187 'nrsec' seconds. The default value is 5 seconds. This means that if 188 you lose your power, you will lose as much as the latest 5 seconds of 189 metadata changes (your filesystem will not be damaged though, thanks 190 to the journaling). This default value (or any low value) will hurt 191 performance, but it's good for data-safety. Setting it to 0 will have 192 the same effect as leaving it at the default (5 seconds). Setting it 193 to very large values will improve performance. Note that due to 194 delayed allocation even older data can be lost on power failure since 195 writeback of those data begins only after time set in 196 /proc/sys/vm/dirty_expire_centisecs. 197 198 barrier=<0|1(*)>, barrier(*), nobarrier 199 This enables/disables the use of write barriers in the jbd code. 200 barrier=0 disables, barrier=1 enables. This also requires an IO stack 201 which can support barriers, and if jbd gets an error on a barrier 202 write, it will disable again with a warning. Write barriers enforce 203 proper on-disk ordering of journal commits, making volatile disk write 204 caches safe to use, at some performance penalty. If your disks are 205 battery-backed in one way or another, disabling barriers may safely 206 improve performance. The mount options "barrier" and "nobarrier" can 207 also be used to enable or disable barriers, for consistency with other 208 ext4 mount options. 209 210 inode_readahead_blks=n 211 This tuning parameter controls the maximum number of inode table blocks 212 that ext4's inode table readahead algorithm will pre-read into the 213 buffer cache. The default value is 32 blocks. 214 215 bsddf (*) 216 Make 'df' act like BSD. 217 218 minixdf 219 Make 'df' act like Minix. 220 221 debug 222 Extra debugging information is sent to syslog. 223 224 abort 225 Simulate the effects of calling ext4_abort() for debugging purposes. 226 This is normally used while remounting a filesystem which is already 227 mounted. 228 229 errors=remount-ro 230 Remount the filesystem read-only on an error. 231 232 errors=continue 233 Keep going on a filesystem error. 234 235 errors=panic 236 Panic and halt the machine if an error occurs. (These mount options 237 override the errors behavior specified in the superblock, which can be 238 configured using tune2fs) 239 240 data_err=ignore(*) 241 Just print an error message if an error occurs in a file data buffer. 242 243 data_err=abort 244 Abort the journal if an error occurs in a file data buffer. 245 246 grpid | bsdgroups 247 New objects have the group ID of their parent. 248 249 nogrpid (*) | sysvgroups 250 New objects have the group ID of their creator. 251 252 resgid=n 253 The group ID which may use the reserved blocks. 254 255 resuid=n 256 The user ID which may use the reserved blocks. 257 258 sb= 259 Use alternate superblock at this location. 260 261 quota, noquota, grpquota, usrquota 262 These options are ignored by the filesystem. They are used only by 263 quota tools to recognize volumes where quota should be turned on. See 264 documentation in the quota-tools package for more details 265 (http://sourceforge.net/projects/linuxquota). 266 267 jqfmt=<quota type>, usrjquota=<file>, grpjquota=<file> 268 These options tell filesystem details about quota so that quota 269 information can be properly updated during journal replay. They replace 270 the above quota options. See documentation in the quota-tools package 271 for more details (http://sourceforge.net/projects/linuxquota). 272 273 stripe=n 274 Number of filesystem blocks that mballoc will try to use for allocation 275 size and alignment. For RAID5/6 systems this should be the number of 276 data disks * RAID chunk size in file system blocks. 277 278 delalloc (*) 279 Defer block allocation until just before ext4 writes out the block(s) 280 in question. This allows ext4 to better allocation decisions more 281 efficiently. 282 283 nodelalloc 284 Disable delayed allocation. Blocks are allocated when the data is 285 copied from userspace to the page cache, either via the write(2) system 286 call or when an mmap'ed page which was previously unallocated is 287 written for the first time. 288 289 max_batch_time=usec 290 Maximum amount of time ext4 should wait for additional filesystem 291 operations to be batch together with a synchronous write operation. 292 Since a synchronous write operation is going to force a commit and then 293 a wait for the I/O complete, it doesn't cost much, and can be a huge 294 throughput win, we wait for a small amount of time to see if any other 295 transactions can piggyback on the synchronous write. The algorithm 296 used is designed to automatically tune for the speed of the disk, by 297 measuring the amount of time (on average) that it takes to finish 298 committing a transaction. Call this time the "commit time". If the 299 time that the transaction has been running is less than the commit 300 time, ext4 will try sleeping for the commit time to see if other 301 operations will join the transaction. The commit time is capped by 302 the max_batch_time, which defaults to 15000us (15ms). This 303 optimization can be turned off entirely by setting max_batch_time to 0. 304 305 min_batch_time=usec 306 This parameter sets the commit time (as described above) to be at least 307 min_batch_time. It defaults to zero microseconds. Increasing this 308 parameter may improve the throughput of multi-threaded, synchronous 309 workloads on very fast disks, at the cost of increasing latency. 310 311 journal_ioprio=prio 312 The I/O priority (from 0 to 7, where 0 is the highest priority) which 313 should be used for I/O operations submitted by kjournald2 during a 314 commit operation. This defaults to 3, which is a slightly higher 315 priority than the default I/O priority. 316 317 auto_da_alloc(*), noauto_da_alloc 318 Many broken applications don't use fsync() when replacing existing 319 files via patterns such as fd = open("foo.new")/write(fd,..)/close(fd)/ 320 rename("foo.new", "foo"), or worse yet, fd = open("foo", 321 O_TRUNC)/write(fd,..)/close(fd). If auto_da_alloc is enabled, ext4 322 will detect the replace-via-rename and replace-via-truncate patterns 323 and force that any delayed allocation blocks are allocated such that at 324 the next journal commit, in the default data=ordered mode, the data 325 blocks of the new file are forced to disk before the rename() operation 326 is committed. This provides roughly the same level of guarantees as 327 ext3, and avoids the "zero-length" problem that can happen when a 328 system crashes before the delayed allocation blocks are forced to disk. 329 330 noinit_itable 331 Do not initialize any uninitialized inode table blocks in the 332 background. This feature may be used by installation CD's so that the 333 install process can complete as quickly as possible; the inode table 334 initialization process would then be deferred until the next time the 335 file system is unmounted. 336 337 init_itable=n 338 The lazy itable init code will wait n times the number of milliseconds 339 it took to zero out the previous block group's inode table. This 340 minimizes the impact on the system performance while file system's 341 inode table is being initialized. 342 343 discard, nodiscard(*) 344 Controls whether ext4 should issue discard/TRIM commands to the 345 underlying block device when blocks are freed. This is useful for SSD 346 devices and sparse/thinly-provisioned LUNs, but it is off by default 347 until sufficient testing has been done. 348 349 nouid32 350 Disables 32-bit UIDs and GIDs. This is for interoperability with 351 older kernels which only store and expect 16-bit values. 352 353 block_validity(*), noblock_validity 354 These options enable or disable the in-kernel facility for tracking 355 filesystem metadata blocks within internal data structures. This 356 allows multi- block allocator and other routines to notice bugs or 357 corrupted allocation bitmaps which cause blocks to be allocated which 358 overlap with filesystem metadata blocks. 359 360 dioread_lock, dioread_nolock 361 Controls whether or not ext4 should use the DIO read locking. If the 362 dioread_nolock option is specified ext4 will allocate uninitialized 363 extent before buffer write and convert the extent to initialized after 364 IO completes. This approach allows ext4 code to avoid using inode 365 mutex, which improves scalability on high speed storages. However this 366 does not work with data journaling and dioread_nolock option will be 367 ignored with kernel warning. Note that dioread_nolock code path is only 368 used for extent-based files. Because of the restrictions this options 369 comprises it is off by default (e.g. dioread_lock). 370 371 max_dir_size_kb=n 372 This limits the size of directories so that any attempt to expand them 373 beyond the specified limit in kilobytes will cause an ENOSPC error. 374 This is useful in memory constrained environments, where a very large 375 directory can cause severe performance problems or even provoke the Out 376 Of Memory killer. (For example, if there is only 512mb memory 377 available, a 176mb directory may seriously cramp the system's style.) 378 379 i_version 380 Enable 64-bit inode version support. This option is off by default. 381 382 dax 383 Use direct access (no page cache). See 384 Documentation/filesystems/dax.rst. Note that this option is 385 incompatible with data=journal. 386 387 inlinecrypt 388 When possible, encrypt/decrypt the contents of encrypted files using 389 inline encryption hardware rather than the CPU. For more details, see 390 Documentation/filesystems/fscrypt.rst. 391 392Data Mode 393========= 394There are 3 different data modes: 395 396* writeback mode 397 398 In data=writeback mode, ext4 does not journal data at all. This mode provides 399 a similar level of journaling as that of XFS and JFS in its default 400 mode - metadata journaling. A crash+recovery can cause incorrect data to 401 appear in files which were written shortly before the crash. This mode will 402 typically provide the best ext4 performance. 403 404* ordered mode 405 406 In data=ordered mode, ext4 only officially journals metadata, but it logically 407 groups metadata information related to data changes with the data blocks into 408 a single unit called a transaction. When it's time to write the new metadata 409 out to disk, the associated data blocks are written first. In general, this 410 mode performs slightly slower than writeback but significantly faster than 411 journal mode. 412 413* journal mode 414 415 data=journal mode provides full data and metadata journaling. All new data is 416 written to the journal first, and then to its final location. In the event of 417 a crash, the journal can be replayed, bringing both data and metadata into a 418 consistent state. This mode is the slowest except when data needs to be read 419 from and written to disk at the same time where it outperforms all others 420 modes. Enabling this mode will disable delayed allocation and O_DIRECT 421 support. 422 423/proc entries 424============= 425 426Information about mounted ext4 file systems can be found in 427/proc/fs/ext4. Each mounted filesystem will have a directory in 428/proc/fs/ext4 based on its device name (i.e., /proc/fs/ext4/hdc or 429/proc/fs/ext4/dm-0). The files in each per-device directory are shown 430in table below. 431 432Files in /proc/fs/ext4/<devname> 433 434 mb_groups 435 details of multiblock allocator buddy cache of free blocks 436 437/sys entries 438============ 439 440Information about mounted ext4 file systems can be found in 441/sys/fs/ext4. Each mounted filesystem will have a directory in 442/sys/fs/ext4 based on its device name (i.e., /sys/fs/ext4/hdc or 443/sys/fs/ext4/dm-0). The files in each per-device directory are shown 444in table below. 445 446Files in /sys/fs/ext4/<devname>: 447 448(see also Documentation/ABI/testing/sysfs-fs-ext4) 449 450 delayed_allocation_blocks 451 This file is read-only and shows the number of blocks that are dirty in 452 the page cache, but which do not have their location in the filesystem 453 allocated yet. 454 455 inode_goal 456 Tuning parameter which (if non-zero) controls the goal inode used by 457 the inode allocator in preference to all other allocation heuristics. 458 This is intended for debugging use only, and should be 0 on production 459 systems. 460 461 inode_readahead_blks 462 Tuning parameter which controls the maximum number of inode table 463 blocks that ext4's inode table readahead algorithm will pre-read into 464 the buffer cache. 465 466 lifetime_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 created. 469 470 max_writeback_mb_bump 471 The maximum number of megabytes the writeback code will try to write 472 out before move on to another inode. 473 474 mb_group_prealloc 475 The multiblock allocator will round up allocation requests to a 476 multiple of this tuning parameter if the stripe size is not set in the 477 ext4 superblock 478 479 mb_max_to_scan 480 The maximum number of extents the multiblock allocator will search to 481 find the best extent. 482 483 mb_min_to_scan 484 The minimum number of extents the multiblock allocator will search to 485 find the best extent. 486 487 mb_order2_req 488 Tuning parameter which controls the minimum size for requests (as a 489 power of 2) where the buddy cache is used. 490 491 mb_stats 492 Controls whether the multiblock allocator should collect statistics, 493 which are shown during the unmount. 1 means to collect statistics, 0 494 means not to collect statistics. 495 496 mb_stream_req 497 Files which have fewer blocks than this tunable parameter will have 498 their blocks allocated out of a block group specific preallocation 499 pool, so that small files are packed closely together. Each large file 500 will have its blocks allocated out of its own unique preallocation 501 pool. 502 503 session_write_kbytes 504 This file is read-only and shows the number of kilobytes of data that 505 have been written to this filesystem since it was mounted. 506 507 reserved_clusters 508 This is RW file and contains number of reserved clusters in the file 509 system which will be used in the specific situations to avoid costly 510 zeroout, unexpected ENOSPC, or possible data loss. The default is 2% or 511 4096 clusters, whichever is smaller and this can be changed however it 512 can never exceed number of clusters in the file system. If there is not 513 enough space for the reserved space when mounting the file mount will 514 _not_ fail. 515 516Ioctls 517====== 518 519Ext4 implements various ioctls which can be used by applications to access 520ext4-specific functionality. An incomplete list of these ioctls is shown in the 521table below. This list includes truly ext4-specific ioctls (``EXT4_IOC_*``) as 522well as ioctls that may have been ext4-specific originally but are now supported 523by some other filesystem(s) too (``FS_IOC_*``). 524 525Table of Ext4 ioctls 526 527 FS_IOC_GETFLAGS 528 Get additional attributes associated with inode. The ioctl argument is 529 an integer bitfield, with bit values described in ext4.h. 530 531 FS_IOC_SETFLAGS 532 Set additional attributes associated with inode. The ioctl argument is 533 an integer bitfield, with bit values described in ext4.h. 534 535 EXT4_IOC_GETVERSION, EXT4_IOC_GETVERSION_OLD 536 Get the inode i_generation number stored for each inode. The 537 i_generation number is normally changed only when new inode is created 538 and it is particularly useful for network filesystems. The '_OLD' 539 version of this ioctl is an alias for FS_IOC_GETVERSION. 540 541 EXT4_IOC_SETVERSION, EXT4_IOC_SETVERSION_OLD 542 Set the inode i_generation number stored for each inode. The '_OLD' 543 version of this ioctl is an alias for FS_IOC_SETVERSION. 544 545 EXT4_IOC_GROUP_EXTEND 546 This ioctl has the same purpose as the resize mount option. It allows 547 to resize filesystem to the end of the last existing block group, 548 further resize has to be done with resize2fs, either online, or 549 offline. The argument points to the unsigned logn number representing 550 the filesystem new block count. 551 552 EXT4_IOC_MOVE_EXT 553 Move the block extents from orig_fd (the one this ioctl is pointing to) 554 to the donor_fd (the one specified in move_extent structure passed as 555 an argument to this ioctl). Then, exchange inode metadata between 556 orig_fd and donor_fd. This is especially useful for online 557 defragmentation, because the allocator has the opportunity to allocate 558 moved blocks better, ideally into one contiguous extent. 559 560 EXT4_IOC_GROUP_ADD 561 Add a new group descriptor to an existing or new group descriptor 562 block. The new group descriptor is described by ext4_new_group_input 563 structure, which is passed as an argument to this ioctl. This is 564 especially useful in conjunction with EXT4_IOC_GROUP_EXTEND, which 565 allows online resize of the filesystem to the end of the last existing 566 block group. Those two ioctls combined is used in userspace online 567 resize tool (e.g. resize2fs). 568 569 EXT4_IOC_MIGRATE 570 This ioctl operates on the filesystem itself. It converts (migrates) 571 ext3 indirect block mapped inode to ext4 extent mapped inode by walking 572 through indirect block mapping of the original inode and converting 573 contiguous block ranges into ext4 extents of the temporary inode. Then, 574 inodes are swapped. This ioctl might help, when migrating from ext3 to 575 ext4 filesystem, however suggestion is to create fresh ext4 filesystem 576 and copy data from the backup. Note, that filesystem has to support 577 extents for this ioctl to work. 578 579 EXT4_IOC_ALLOC_DA_BLKS 580 Force all of the delay allocated blocks to be allocated to preserve 581 application-expected ext3 behaviour. Note that this will also start 582 triggering a write of the data blocks, but this behaviour may change in 583 the future as it is not necessary and has been done this way only for 584 sake of simplicity. 585 586 EXT4_IOC_RESIZE_FS 587 Resize the filesystem to a new size. The number of blocks of resized 588 filesystem is passed in via 64 bit integer argument. The kernel 589 allocates bitmaps and inode table, the userspace tool thus just passes 590 the new number of blocks. 591 592 EXT4_IOC_SWAP_BOOT 593 Swap i_blocks and associated attributes (like i_blocks, i_size, 594 i_flags, ...) from the specified inode with inode EXT4_BOOT_LOADER_INO 595 (#5). This is typically used to store a boot loader in a secure part of 596 the filesystem, where it can't be changed by a normal user by accident. 597 The data blocks of the previous boot loader will be associated with the 598 given inode. 599 600References 601========== 602 603kernel source: <file:fs/ext4/> 604 <file:fs/jbd2/> 605 606programs: http://e2fsprogs.sourceforge.net/ 607 608useful links: https://fedoraproject.org/wiki/ext3-devel 609 http://www.bullopensource.org/ext4/ 610 http://ext4.wiki.kernel.org/index.php/Main_Page 611 https://fedoraproject.org/wiki/Features/Ext4 612