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