요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
casefold와 마운트 옵션
ext4.rst:101-393디렉터리별 Unicode 대소문자 비구분 조회와 journal, 오류 정책, quota, allocation, discard, DAX, inline encryption 관련 mount option을 설명합니다.
데이터 모드와 관리 인터페이스
ext4.rst:394-613writeback·ordered·journal 모드의 보장과 성능 차이, `/proc/fs/ext4`, `/sys/fs/ext4`, ext4 ioctl 및 참고 경로를 제공합니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
.. SPDX-License-Identifier: GPL-2.0
========================
ext4 General Information
========================
Ext4 is an advanced level of the ext3 filesystem which incorporates
scalability and reliability enhancements for supporting large filesystems
(64 bit) in keeping with increasing disk capacities and state-of-the-art
feature requirements.
Mailing list: [email protected]
Web site: http://ext4.wiki.kernel.org
Quick usage instructions
========================
Note: More extensive information for getting started with ext4 can be
found at the ext4 wiki site at the URL:
http://ext4.wiki.kernel.org/index.php/Ext4_Howto
- The latest version of e2fsprogs can be found at:
https://www.kernel.org/pub/linux/kernel/people/tytso/e2fsprogs/
or
http://sourceforge.net/project/showfiles.php?group_id=2406
or grab the latest git repository from:
https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git
- Create a new filesystem using the ext4 filesystem type:
# mke2fs -t ext4 /dev/hda1
Or to configure an existing ext3 filesystem to support extents:
# tune2fs -O extents /dev/hda1
If the filesystem was created with 128 byte inodes, it can be
converted to use 256 byte for greater efficiency via:
# tune2fs -I 256 /dev/hda1
- Mounting:
# mount -t ext4 /dev/hda1 /wherever
- When comparing performance with other filesystems, it's always
important to try multiple workloads; very often a subtle change in a
workload parameter can completely change the ranking of which
filesystems do well compared to others. When comparing versus ext3,
note that ext4 enables write barriers by default, while ext3 does
not enable write barriers by default. So it is useful to use
explicitly specify whether barriers are enabled or not when via the
'-o barriers=[0|1]' mount option for both ext3 and ext4 filesystems
for a fair comparison. When tuning ext3 for best benchmark numbers,
it is often worthwhile to try changing the data journaling mode; '-o
data=writeback' can be faster for some workloads. (Note however that
running mounted with data=writeback can potentially leave stale data
exposed in recently written files in case of an unclean shutdown,
which could be a security exposure in some situations.) Configuring
the filesystem with a large journal can also be helpful for
metadata-intensive workloads.
Features
========
Currently Available
-------------------
* ability to use filesystems > 16TB (e2fsprogs support not available yet)
* extent format reduces metadata overhead (RAM, IO for access, transactions)
* extent format more robust in face of on-disk corruption due to magics,
* internal redundancy in tree
* improved file allocation (multi-block alloc)
* lift 32000 subdirectory limit imposed by i_links_count[1]
* nsec timestamps for mtime, atime, ctime, create time
* inode version field on disk (NFSv4, Lustre)
* reduced e2fsck time via uninit_bg feature
* journal checksumming for robustness, performance
* persistent file preallocation (e.g for streaming media, databases)
* ability to pack bitmaps and inode tables into larger virtual groups via the
flex_bg feature
* large file support
* inode allocation using large virtual block groups via flex_bg
* delayed allocation
* large block (up to pagesize) support
* efficient new ordered mode in JBD2 and ext4 (avoid using buffer head to force
the ordering)
* Case-insensitive file name lookups
* file-based encryption support (fscrypt)
* file-based verity support (fsverity)
[1] Filesystems with a block size of 1k may see a limit imposed by the
directory hash tree having a maximum depth of two.
case-insensitive file name lookups
======================================================
The case-insensitive file name lookup feature is supported on a
per-directory basis, allowing the user to mix case-insensitive and
case-sensitive directories in the same filesystem. It is enabled by
flipping the +F inode attribute of an empty directory. The
case-insensitive string match operation is only defined when we know how
text in encoded in a byte sequence. For that reason, in order to enable
case-insensitive directories, the filesystem must have the
casefold feature, which stores the filesystem-wide encoding
model used. By default, the charset adopted is the latest version of
Unicode (12.1.0, by the time of this writing), encoded in the UTF-8
form. The comparison algorithm is implemented by normalizing the
strings to the Canonical decomposition form, as defined by Unicode,
followed by a byte per byte comparison.
The case-awareness is name-preserving on the disk, meaning that the file
name provided by userspace is a byte-per-byte match to what is actually
written in the disk. The Unicode normalization format used by the
kernel is thus an internal representation, and not exposed to the
userspace nor to the disk, with the important exception of disk hashes,
used on large case-insensitive directories with DX feature. On DX
directories, the hash must be calculated using the casefolded version of
the filename, meaning that the normalization format used actually has an
impact on where the directory entry is stored.
When we change from viewing filenames as opaque byte sequences to seeing
them as encoded strings we need to address what happens when a program
tries to create a file with an invalid name. The Unicode subsystem
within the kernel leaves the decision of what to do in this case to the
filesystem, which select its preferred behavior by enabling/disabling
the strict mode. When Ext4 encounters one of those strings and the
filesystem did not require strict mode, it falls back to considering the
entire string as an opaque byte sequence, which still allows the user to
operate on that file, but the case-insensitive lookups won't work.
Options
=======
When mounting an ext4 filesystem, the following option are accepted:
(*) == default
ro
Mount filesystem read only. Note that ext4 will replay the journal (and
thus write to the partition) even when mounted "read only". The mount
options "ro,noload" can be used to prevent writes to the filesystem.
journal_checksum
Enable checksumming of the journal transactions. This will allow the
recovery code in e2fsck and the kernel to detect corruption in the
kernel. It is a compatible change and will be ignored by older
kernels.
journal_async_commit
Commit block can be written to disk without waiting for descriptor
blocks. If enabled older kernels cannot mount the device. This will
enable 'journal_checksum' internally.
journal_path=path, journal_dev=devnum
When the external journal device's major/minor numbers have changed,
these options allow the user to specify the new journal location. The
journal device is identified through either its new major/minor numbers
encoded in devnum, or via a path to the device.
norecovery, noload
Don't load the journal on mounting. Note that if the filesystem was
not unmounted cleanly, skipping the journal replay will lead to the
filesystem containing inconsistencies that can lead to any number of
problems.
data=journal
All data are committed into the journal prior to being written into the
main file system. Enabling this mode will disable delayed allocation
and O_DIRECT support.
data=ordered (*)
All data are forced directly out to the main file system prior to its
metadata being committed to the journal.
data=writeback
Data ordering is not preserved, data may be written into the main file
system after its metadata has been committed to the journal.
commit=nrsec (*)
This setting limits the maximum age of the running transaction to
'nrsec' seconds. The default value is 5 seconds. This means that if
you lose your power, you will lose as much as the latest 5 seconds of
metadata changes (your filesystem will not be damaged though, thanks
to the journaling). This default value (or any low value) will hurt
performance, but it's good for data-safety. Setting it to 0 will have
the same effect as leaving it at the default (5 seconds). Setting it
to very large values will improve performance. Note that due to
delayed allocation even older data can be lost on power failure since
writeback of those data begins only after time set in
/proc/sys/vm/dirty_expire_centisecs.
barrier=<0|1(*)>, barrier(*), nobarrier
This enables/disables the use of write barriers in the jbd code.
barrier=0 disables, barrier=1 enables. This also requires an IO stack
which can support barriers, and if jbd gets an error on a barrier
write, it will disable again with a warning. Write barriers enforce
proper on-disk ordering of journal commits, making volatile disk write
caches safe to use, at some performance penalty. If your disks are
battery-backed in one way or another, disabling barriers may safely
improve performance. The mount options "barrier" and "nobarrier" can
also be used to enable or disable barriers, for consistency with other
ext4 mount options.
inode_readahead_blks=n
This tuning parameter controls the maximum number of inode table blocks
that ext4's inode table readahead algorithm will pre-read into the
buffer cache. The default value is 32 blocks.
bsddf (*)
Make 'df' act like BSD.
minixdf
Make 'df' act like Minix.
debug
Extra debugging information is sent to syslog.
abort
Simulate the effects of calling ext4_abort() for debugging purposes.
This is normally used while remounting a filesystem which is already
mounted.
errors=remount-ro
Remount the filesystem read-only on an error.
errors=continue
Keep going on a filesystem error.
errors=panic
Panic and halt the machine if an error occurs. (These mount options
override the errors behavior specified in the superblock, which can be
configured using tune2fs)
data_err=ignore(*)
Just print an error message if an error occurs in a file data buffer.
data_err=abort
Abort the journal if an error occurs in a file data buffer.
grpid | bsdgroups
New objects have the group ID of their parent.
nogrpid (*) | sysvgroups
New objects have the group ID of their creator.
resgid=n
The group ID which may use the reserved blocks.
resuid=n
The user ID which may use the reserved blocks.
sb=
Use alternate superblock at this location.
quota, noquota, grpquota, usrquota
These options are ignored by the filesystem. They are used only by
quota tools to recognize volumes where quota should be turned on. See
documentation in the quota-tools package for more details
(http://sourceforge.net/projects/linuxquota).
jqfmt=<quota type>, usrjquota=<file>, grpjquota=<file>
These options tell filesystem details about quota so that quota
information can be properly updated during journal replay. They replace
the above quota options. See documentation in the quota-tools package
for more details (http://sourceforge.net/projects/linuxquota).
stripe=n
Number of filesystem blocks that mballoc will try to use for allocation
size and alignment. For RAID5/6 systems this should be the number of
data disks * RAID chunk size in file system blocks.
delalloc (*)
Defer block allocation until just before ext4 writes out the block(s)
in question. This allows ext4 to better allocation decisions more
efficiently.
nodelalloc
Disable delayed allocation. Blocks are allocated when the data is
copied from userspace to the page cache, either via the write(2) system
call or when an mmap'ed page which was previously unallocated is
written for the first time.
max_batch_time=usec
Maximum amount of time ext4 should wait for additional filesystem
operations to be batch together with a synchronous write operation.
Since a synchronous write operation is going to force a commit and then
a wait for the I/O complete, it doesn't cost much, and can be a huge
throughput win, we wait for a small amount of time to see if any other
transactions can piggyback on the synchronous write. The algorithm
used is designed to automatically tune for the speed of the disk, by
measuring the amount of time (on average) that it takes to finish
committing a transaction. Call this time the "commit time". If the
time that the transaction has been running is less than the commit
time, ext4 will try sleeping for the commit time to see if other
operations will join the transaction. The commit time is capped by
the max_batch_time, which defaults to 15000us (15ms). This
optimization can be turned off entirely by setting max_batch_time to 0.
min_batch_time=usec
This parameter sets the commit time (as described above) to be at least
min_batch_time. It defaults to zero microseconds. Increasing this
parameter may improve the throughput of multi-threaded, synchronous
workloads on very fast disks, at the cost of increasing latency.
journal_ioprio=prio
The I/O priority (from 0 to 7, where 0 is the highest priority) which
should be used for I/O operations submitted by kjournald2 during a
commit operation. This defaults to 3, which is a slightly higher
priority than the default I/O priority.
auto_da_alloc(*), noauto_da_alloc
Many broken applications don't use fsync() when replacing existing
files via patterns such as fd = open("foo.new")/write(fd,..)/close(fd)/
rename("foo.new", "foo"), or worse yet, fd = open("foo",
O_TRUNC)/write(fd,..)/close(fd). If auto_da_alloc is enabled, ext4
will detect the replace-via-rename and replace-via-truncate patterns
and force that any delayed allocation blocks are allocated such that at
the next journal commit, in the default data=ordered mode, the data
blocks of the new file are forced to disk before the rename() operation
is committed. This provides roughly the same level of guarantees as
ext3, and avoids the "zero-length" problem that can happen when a
system crashes before the delayed allocation blocks are forced to disk.
noinit_itable
Do not initialize any uninitialized inode table blocks in the
background. This feature may be used by installation CD's so that the
install process can complete as quickly as possible; the inode table
initialization process would then be deferred until the next time the
file system is unmounted.
init_itable=n
The lazy itable init code will wait n times the number of milliseconds
it took to zero out the previous block group's inode table. This
minimizes the impact on the system performance while file system's
inode table is being initialized.
discard, nodiscard(*)
Controls whether ext4 should issue discard/TRIM commands to the
underlying block device when blocks are freed. This is useful for SSD
devices and sparse/thinly-provisioned LUNs, but it is off by default
until sufficient testing has been done.
nouid32
Disables 32-bit UIDs and GIDs. This is for interoperability with
older kernels which only store and expect 16-bit values.
block_validity(*), noblock_validity
These options enable or disable the in-kernel facility for tracking
filesystem metadata blocks within internal data structures. This
allows multi- block allocator and other routines to notice bugs or
corrupted allocation bitmaps which cause blocks to be allocated which
overlap with filesystem metadata blocks.
dioread_lock, dioread_nolock
Controls whether or not ext4 should use the DIO read locking. If the
dioread_nolock option is specified ext4 will allocate uninitialized
extent before buffer write and convert the extent to initialized after
IO completes. This approach allows ext4 code to avoid using inode
mutex, which improves scalability on high speed storages. However this
does not work with data journaling and dioread_nolock option will be
ignored with kernel warning. Note that dioread_nolock code path is only
used for extent-based files. Because of the restrictions this options
comprises it is off by default (e.g. dioread_lock).
max_dir_size_kb=n
This limits the size of directories so that any attempt to expand them
beyond the specified limit in kilobytes will cause an ENOSPC error.
This is useful in memory constrained environments, where a very large
directory can cause severe performance problems or even provoke the Out
Of Memory killer. (For example, if there is only 512mb memory
available, a 176mb directory may seriously cramp the system's style.)
i_version
Enable 64-bit inode version support. This option is off by default.
dax
Use direct access (no page cache). See
Documentation/filesystems/dax.rst. Note that this option is
incompatible with data=journal.
inlinecrypt
When possible, encrypt/decrypt the contents of encrypted files using the
blk-crypto framework rather than filesystem-layer encryption. This
allows the use of inline encryption hardware. The on-disk format is
unaffected. For more details, see
Documentation/block/inline-encryption.rst.
Data Mode
=========
There are 3 different data modes:
* writeback mode
In data=writeback mode, ext4 does not journal data at all. This mode provides
a similar level of journaling as that of XFS and JFS in its default
mode - metadata journaling. A crash+recovery can cause incorrect data to
appear in files which were written shortly before the crash. This mode will
typically provide the best ext4 performance.
* ordered mode
In data=ordered mode, ext4 only officially journals metadata, but it logically
groups metadata information related to data changes with the data blocks into
a single unit called a transaction. When it's time to write the new metadata
out to disk, the associated data blocks are written first. In general, this
mode performs slightly slower than writeback but significantly faster than
journal mode.
* journal mode
data=journal mode provides full data and metadata journaling. All new data is
written to the journal first, and then to its final location. In the event of
a crash, the journal can be replayed, bringing both data and metadata into a
consistent state. This mode is the slowest except when data needs to be read
from and written to disk at the same time where it outperforms all others
modes. Enabling this mode will disable delayed allocation and O_DIRECT
support.
/proc entries
=============
Information about mounted ext4 file systems can be found in
/proc/fs/ext4. Each mounted filesystem will have a directory in
/proc/fs/ext4 based on its device name (i.e., /proc/fs/ext4/hdc or
/proc/fs/ext4/dm-0). The files in each per-device directory are shown
in table below.
Files in /proc/fs/ext4/<devname>
mb_groups
details of multiblock allocator buddy cache of free blocks
/sys entries
============
Information about mounted ext4 file systems can be found in
/sys/fs/ext4. Each mounted filesystem will have a directory in
/sys/fs/ext4 based on its device name (i.e., /sys/fs/ext4/hdc or
/sys/fs/ext4/dm-0). The files in each per-device directory are shown
in table below.
Files in /sys/fs/ext4/<devname>:
(see also Documentation/ABI/testing/sysfs-fs-ext4)
delayed_allocation_blocks
This file is read-only and shows the number of blocks that are dirty in
the page cache, but which do not have their location in the filesystem
allocated yet.
inode_goal
Tuning parameter which (if non-zero) controls the goal inode used by
the inode allocator in preference to all other allocation heuristics.
This is intended for debugging use only, and should be 0 on production
systems.
inode_readahead_blks
Tuning parameter which controls the maximum number of inode table
blocks that ext4's inode table readahead algorithm will pre-read into
the buffer cache.
lifetime_write_kbytes
This file is read-only and shows the number of kilobytes of data that
have been written to this filesystem since it was created.
max_writeback_mb_bump
The maximum number of megabytes the writeback code will try to write
out before move on to another inode.
mb_group_prealloc
The multiblock allocator will round up allocation requests to a
multiple of this tuning parameter if the stripe size is not set in the
ext4 superblock
mb_max_to_scan
The maximum number of extents the multiblock allocator will search to
find the best extent.
mb_min_to_scan
The minimum number of extents the multiblock allocator will search to
find the best extent.
mb_order2_req
Tuning parameter which controls the minimum size for requests (as a
power of 2) where the buddy cache is used.
mb_stats
Controls whether the multiblock allocator should collect statistics,
which are shown during the unmount. 1 means to collect statistics, 0
means not to collect statistics.
mb_stream_req
Files which have fewer blocks than this tunable parameter will have
their blocks allocated out of a block group specific preallocation
pool, so that small files are packed closely together. Each large file
will have its blocks allocated out of its own unique preallocation
pool.
session_write_kbytes
This file is read-only and shows the number of kilobytes of data that
have been written to this filesystem since it was mounted.
reserved_clusters
This is RW file and contains number of reserved clusters in the file
system which will be used in the specific situations to avoid costly
zeroout, unexpected ENOSPC, or possible data loss. The default is 2% or
4096 clusters, whichever is smaller and this can be changed however it
can never exceed number of clusters in the file system. If there is not
enough space for the reserved space when mounting the file mount will
_not_ fail.
Ioctls
======
Ext4 implements various ioctls which can be used by applications to access
ext4-specific functionality. An incomplete list of these ioctls is shown in the
table below. This list includes truly ext4-specific ioctls (``EXT4_IOC_*``) as
well as ioctls that may have been ext4-specific originally but are now supported
by some other filesystem(s) too (``FS_IOC_*``).
Table of Ext4 ioctls
FS_IOC_GETFLAGS
Get additional attributes associated with inode. The ioctl argument is
an integer bitfield, with bit values described in ext4.h.
FS_IOC_SETFLAGS
Set additional attributes associated with inode. The ioctl argument is
an integer bitfield, with bit values described in ext4.h.
EXT4_IOC_GETVERSION, EXT4_IOC_GETVERSION_OLD
Get the inode i_generation number stored for each inode. The
i_generation number is normally changed only when new inode is created
and it is particularly useful for network filesystems. The '_OLD'
version of this ioctl is an alias for FS_IOC_GETVERSION.
EXT4_IOC_SETVERSION, EXT4_IOC_SETVERSION_OLD
Set the inode i_generation number stored for each inode. The '_OLD'
version of this ioctl is an alias for FS_IOC_SETVERSION.
EXT4_IOC_GROUP_EXTEND
This ioctl has the same purpose as the resize mount option. It allows
to resize filesystem to the end of the last existing block group,
further resize has to be done with resize2fs, either online, or
offline. The argument points to the unsigned logn number representing
the filesystem new block count.
EXT4_IOC_MOVE_EXT
Move the block extents from orig_fd (the one this ioctl is pointing to)
to the donor_fd (the one specified in move_extent structure passed as
an argument to this ioctl). Then, exchange inode metadata between
orig_fd and donor_fd. This is especially useful for online
defragmentation, because the allocator has the opportunity to allocate
moved blocks better, ideally into one contiguous extent.
EXT4_IOC_GROUP_ADD
Add a new group descriptor to an existing or new group descriptor
block. The new group descriptor is described by ext4_new_group_input
structure, which is passed as an argument to this ioctl. This is
especially useful in conjunction with EXT4_IOC_GROUP_EXTEND, which
allows online resize of the filesystem to the end of the last existing
block group. Those two ioctls combined is used in userspace online
resize tool (e.g. resize2fs).
EXT4_IOC_MIGRATE
This ioctl operates on the filesystem itself. It converts (migrates)
ext3 indirect block mapped inode to ext4 extent mapped inode by walking
through indirect block mapping of the original inode and converting
contiguous block ranges into ext4 extents of the temporary inode. Then,
inodes are swapped. This ioctl might help, when migrating from ext3 to
ext4 filesystem, however suggestion is to create fresh ext4 filesystem
and copy data from the backup. Note, that filesystem has to support
extents for this ioctl to work.
EXT4_IOC_ALLOC_DA_BLKS
Force all of the delay allocated blocks to be allocated to preserve
application-expected ext3 behaviour. Note that this will also start
triggering a write of the data blocks, but this behaviour may change in
the future as it is not necessary and has been done this way only for
sake of simplicity.
EXT4_IOC_RESIZE_FS
Resize the filesystem to a new size. The number of blocks of resized
filesystem is passed in via 64 bit integer argument. The kernel
allocates bitmaps and inode table, the userspace tool thus just passes
the new number of blocks.
EXT4_IOC_SWAP_BOOT
Swap i_blocks and associated attributes (like i_blocks, i_size,
i_flags, ...) from the specified inode with inode EXT4_BOOT_LOADER_INO
(#5). This is typically used to store a boot loader in a secure part of
the filesystem, where it can't be changed by a normal user by accident.
The data blocks of the previous boot loader will be associated with the
given inode.
References
==========
kernel source: <file:fs/ext4/>
<file:fs/jbd2/>
programs: http://e2fsprogs.sourceforge.net/
useful links: https://fedoraproject.org/wiki/ext3-devel
http://www.bullopensource.org/ext4/
http://ext4.wiki.kernel.org/index.php/Main_Page
https://fedoraproject.org/wiki/Features/Ext4
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
ext4 일반 정보
1-15Ext4는 ext3 파일시스템을 발전시킨 고급 파일시스템입니다. 커지는 디스크 용량과 최신 기능 요구에 맞춰 대형 64비트 파일시스템을 지원하도록 확장성과 신뢰성을 개선했습니다.
| 항목 | 주소 |
|---|---|
| 메일링 리스트 | [email protected] |
| 웹 사이트 | http://ext4.wiki.kernel.org |
빠른 사용 방법
16-68ext4 시작 방법에 관한 더 자세한 내용은 `http://ext4.wiki.kernel.org/index.php/Ext4_Howto`에서 볼 수 있습니다.
최신 e2fsprogs는 다음 위치에서 구할 수 있습니다.
- https://www.kernel.org/pub/linux/kernel/people/tytso/e2fsprogs/
- http://sourceforge.net/project/showfiles.php?group_id=2406
- https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git
ext4 형식으로 새 파일시스템을 만듭니다.
# mke2fs -t ext4 /dev/hda1
기존 ext3 파일시스템이 extent를 지원하도록 설정합니다.
# tune2fs -O extents /dev/hda1
파일시스템이 128바이트 inode로 만들어졌다면 다음 명령으로 256바이트 inode로 변환하여 효율을 높일 수 있습니다.
# tune2fs -I 256 /dev/hda1
ext4 파일시스템을 마운트합니다.
# mount -t ext4 /dev/hda1 /wherever
다른 파일시스템과 성능을 비교할 때는 여러 워크로드를 시험해야 합니다. 워크로드 매개변수의 작은 차이만으로도 파일시스템 순위가 완전히 달라지는 일이 흔합니다.
ext3와 비교할 때 ext4는 write barrier를 기본으로 켜지만 ext3는 기본으로 켜지 않는다는 점에 주의해야 합니다. 공정한 비교를 위해 두 파일시스템 모두 `-o barriers=[0|1]`로 barrier 사용 여부를 명시하는 것이 좋습니다.
ext3 벤치마크를 조정할 때는 data journaling 모드 변경도 시험할 가치가 있습니다. 일부 워크로드에서는 `-o data=writeback`이 더 빠를 수 있습니다. 그러나 비정상 종료가 발생하면 최근 기록한 파일에 오래된 데이터가 노출될 수 있어 상황에 따라 보안 문제가 될 수 있습니다. 메타데이터 중심 워크로드에서는 큰 journal을 구성하는 것도 도움이 됩니다.
현재 제공되는 기능
69-100- 16TB보다 큰 파일시스템을 사용할 수 있습니다. 원문 작성 시점에는 e2fsprogs 지원이 아직 제공되지 않았습니다.
- extent 형식으로 메타데이터의 RAM 사용량, 접근 I/O, 트랜잭션 오버헤드를 줄입니다.
- magic 값과 트리 내부 중복성 덕분에 디스크 손상에 더 견고한 extent 형식을 제공합니다.
- multi-block allocation으로 파일 할당을 개선합니다.
- `i_links_count`가 부과하던 32,000개 하위 디렉터리 제한을 없앱니다.
- `mtime`, `atime`, `ctime`, 생성 시간에 나노초 타임스탬프를 지원합니다.
- NFSv4와 Lustre를 위한 디스크상의 inode version 필드를 제공합니다.
- `uninit_bg` 기능으로 `e2fsck` 시간을 줄입니다.
- 견고성과 성능을 위한 journal checksum을 제공합니다.
- 스트리밍 미디어와 데이터베이스 등에 사용할 영구 파일 사전 할당을 제공합니다.
- `flex_bg`로 bitmap과 inode table을 더 큰 가상 그룹에 묶을 수 있습니다.
- 대형 파일을 지원합니다.
- `flex_bg`의 큰 가상 block group을 사용해 inode를 할당합니다.
- delayed allocation을 지원합니다.
- 페이지 크기까지의 큰 블록을 지원합니다.
- JBD2와 ext4의 효율적인 새 ordered mode는 순서를 강제하기 위해 buffer head를 사용하지 않습니다.
- 대소문자를 구분하지 않는 파일 이름 조회를 지원합니다.
- `fscrypt` 기반 파일 단위 암호화를 지원합니다.
- `fsverity` 기반 파일 단위 무결성 검증을 지원합니다.
블록 크기가 1KB인 파일시스템은 directory hash tree의 최대 깊이가 2이므로 별도의 제한을 받을 수 있습니다.
대소문자 비구분 파일 이름 조회
101-137대소문자 비구분 파일 이름 조회는 디렉터리 단위로 지원되므로 한 파일시스템 안에 대소문자를 구분하는 디렉터리와 구분하지 않는 디렉터리를 함께 둘 수 있습니다. 빈 디렉터리의 `+F` inode 속성을 켜서 활성화합니다.
인코딩된 바이트열이 어떤 문자 인코딩인지 알아야만 대소문자 비구분 문자열 일치를 정의할 수 있습니다. 따라서 이 기능을 사용하려면 파일시스템 전체 인코딩 모델을 저장하는 `casefold` 기능이 필요합니다. 기본 문자 집합은 원문 작성 당시 최신 Unicode 12.1.0이며 UTF-8로 인코딩됩니다.
비교 알고리즘은 문자열을 Unicode가 정의한 canonical decomposition form으로 정규화한 뒤 바이트 단위로 비교합니다.
디스크에서는 이름의 대소문자를 보존합니다. 즉 사용자 공간이 제공한 파일 이름이 바이트 단위로 그대로 디스크에 기록됩니다. 커널의 Unicode 정규화 형식은 내부 표현이므로 사용자 공간이나 디스크에 노출되지 않습니다.
중요한 예외는 DX 기능을 사용하는 큰 대소문자 비구분 디렉터리의 디스크 hash입니다. DX 디렉터리에서는 casefold한 파일 이름으로 hash를 계산하므로 사용하는 정규화 형식이 directory entry의 저장 위치에 실제 영향을 줍니다.
파일 이름을 불투명한 바이트열이 아니라 인코딩된 문자열로 해석하면 프로그램이 잘못된 이름을 만들려 할 때의 동작을 정해야 합니다. 커널 Unicode 하위 시스템은 이 결정을 파일시스템에 맡기며 파일시스템은 strict mode를 켜거나 꺼서 선호 동작을 선택합니다.
Ext4가 잘못된 문자열을 만났고 strict mode가 요구되지 않았다면 전체 문자열을 불투명한 바이트열로 취급하는 방식으로 되돌아갑니다. 사용자는 그 파일을 계속 조작할 수 있지만 대소문자 비구분 조회는 동작하지 않습니다.
마운트 옵션: journal과 기본 동작
138-220ext4 파일시스템을 마운트할 때 아래 옵션을 사용할 수 있습니다. `(*)`는 기본값을 뜻합니다.
| 옵션 | 설명 |
|---|---|
| ro | 파일시스템을 읽기 전용으로 마운트합니다. 읽기 전용이어도 ext4는 journal을 재생하므로 파티션에 기록합니다. 기록을 막으려면 `ro,noload`를 사용합니다. |
| journal_checksum | journal transaction checksum을 켭니다. e2fsck와 커널의 복구 코드가 journal 손상을 감지할 수 있습니다. 호환 가능한 변경이므로 오래된 커널은 무시합니다. |
| journal_async_commit | descriptor block을 기다리지 않고 commit block을 디스크에 쓸 수 있습니다. 활성화하면 오래된 커널은 장치를 마운트할 수 없으며 내부적으로 `journal_checksum`도 켭니다. |
| journal_path=path, journal_dev=devnum | 외부 journal 장치의 major/minor가 바뀌었을 때 새 위치를 지정합니다. `devnum`에 인코딩한 새 major/minor 또는 장치 경로로 journal을 식별합니다. |
| norecovery, noload | 마운트할 때 journal을 읽지 않습니다. 파일시스템이 정상적으로 unmount되지 않았다면 journal replay를 건너뛸 때 파일시스템 불일치와 여러 문제가 생깁니다. |
| data=journal | 모든 데이터를 주 파일시스템에 쓰기 전에 journal에 commit합니다. delayed allocation과 `O_DIRECT` 지원을 끕니다. |
| data=ordered (*) | 메타데이터를 journal에 commit하기 전에 모든 관련 데이터를 주 파일시스템에 직접 기록하도록 강제합니다. |
| data=writeback | 데이터 순서를 보존하지 않습니다. 메타데이터를 journal에 commit한 뒤 데이터를 주 파일시스템에 쓸 수 있습니다. |
| commit=nrsec (*) | 실행 중인 transaction의 최대 나이를 `nrsec`초로 제한합니다. 기본값 5초이므로 전원이 끊기면 최근 최대 5초의 메타데이터 변경을 잃을 수 있지만 journaling 덕분에 파일시스템 자체는 손상되지 않습니다. 낮은 값은 성능을 낮추지만 데이터 안전성에 유리합니다. 0은 기본값 5초와 같고 큰 값은 성능을 높입니다. delayed allocation 때문에 `/proc/sys/vm/dirty_expire_centisecs` 뒤에야 writeback을 시작한 더 오래된 데이터도 전원 장애 때 사라질 수 있습니다. |
| barrier=<0|1(*)>, barrier(*), nobarrier | jbd의 write barrier를 제어합니다. 0은 끄고 1은 켭니다. I/O stack이 barrier를 지원해야 하며 barrier write 오류가 나면 jbd는 경고와 함께 다시 끕니다. barrier는 journal commit의 디스크 기록 순서를 보장해 volatile write cache를 안전하게 하지만 성능 비용이 있습니다. 배터리 백업 디스크라면 barrier를 꺼도 안전하게 성능을 높일 수 있습니다. |
| inode_readahead_blks=n | ext4 inode table readahead 알고리즘이 buffer cache로 미리 읽을 inode table block의 최대 수입니다. 기본값은 32블록입니다. |
| bsddf (*) | `df`가 BSD 방식으로 동작하게 합니다. |
| minixdf | `df`가 Minix 방식으로 동작하게 합니다. |
마운트 옵션: 오류·소유권·할당
221-288| 옵션 | 설명 |
|---|---|
| debug | 추가 디버그 정보를 syslog로 보냅니다. |
| abort | 디버깅을 위해 `ext4_abort()` 호출 효과를 흉내 냅니다. 보통 이미 마운트된 파일시스템을 remount할 때 사용합니다. |
| errors=remount-ro | 오류가 나면 읽기 전용으로 다시 마운트합니다. |
| errors=continue | 파일시스템 오류 뒤에도 계속 실행합니다. |
| errors=panic | 오류가 발생하면 panic을 일으키고 시스템을 멈춥니다. 이 `errors` 옵션들은 `tune2fs`로 설정할 수 있는 superblock의 오류 동작을 덮어씁니다. |
| data_err=ignore (*) | 파일 data buffer에서 오류가 발생하면 오류 메시지만 출력합니다. |
| data_err=abort | 파일 data buffer에서 오류가 발생하면 journal을 중단합니다. |
| grpid | bsdgroups | 새 객체가 부모의 group ID를 갖습니다. |
| nogrpid (*) | sysvgroups | 새 객체가 생성자의 group ID를 갖습니다. |
| resgid=n | reserved block을 사용할 수 있는 group ID를 지정합니다. |
| resuid=n | reserved block을 사용할 수 있는 user ID를 지정합니다. |
| sb= | 이 위치의 대체 superblock을 사용합니다. |
| quota, noquota, grpquota, usrquota | 파일시스템 자체는 이 옵션을 무시합니다. quota 도구가 quota를 켜야 하는 volume을 식별하는 데만 사용합니다. 자세한 내용은 quota-tools 문서 `http://sourceforge.net/projects/linuxquota`를 참고합니다. |
| jqfmt=<quota type>, usrjquota=<file>, grpjquota=<file> | journal replay 중 quota 정보를 올바르게 갱신할 수 있도록 파일시스템에 quota 세부 정보를 전달합니다. 위의 quota 옵션을 대체합니다. 자세한 내용은 quota-tools 문서를 참고합니다. |
| stripe=n | mballoc이 할당 크기와 정렬에 사용하려는 파일시스템 block 수입니다. RAID5/6에서는 data disk 수와 RAID chunk size를 파일시스템 block 단위로 곱한 값이어야 합니다. |
| delalloc (*) | ext4가 해당 block을 기록하기 직전까지 block allocation을 미룹니다. 더 효율적이고 나은 할당 결정을 내릴 수 있습니다. |
| nodelalloc | delayed allocation을 끕니다. `write(2)`로 사용자 공간에서 page cache로 데이터를 복사할 때 또는 아직 할당되지 않은 mmap page에 처음 쓸 때 block을 할당합니다. |
마운트 옵션: batching·초기화·I/O 조정
289-393| 옵션 | 설명 |
|---|---|
| max_batch_time=usec | 동기 write와 함께 batch할 추가 파일시스템 작업을 ext4가 기다릴 최대 시간입니다. 동기 write는 commit과 I/O 완료 대기를 강제하므로 잠깐 기다려 다른 transaction을 합치면 처리량이 크게 좋아질 수 있습니다. 알고리즘은 평균 transaction commit 완료 시간을 측정해 디스크 속도에 자동 조정합니다. transaction 실행 시간이 이 commit time보다 짧으면 ext4는 다른 작업이 합류하도록 commit time만큼 sleep을 시도합니다. `max_batch_time`이 상한이며 기본값은 `15000us (15ms)`입니다. 0이면 최적화를 완전히 끕니다. |
| min_batch_time=usec | 앞에서 설명한 commit time의 최솟값을 정합니다. 기본값은 0us입니다. 값을 높이면 매우 빠른 디스크의 다중 스레드 동기 워크로드 처리량이 좋아질 수 있지만 latency가 증가합니다. |
| journal_ioprio=prio | commit 중 `kjournald2`가 제출하는 I/O의 우선순위입니다. 범위는 0~7이며 0이 가장 높습니다. 기본값 3은 기본 I/O 우선순위보다 약간 높습니다. |
| auto_da_alloc (*), noauto_da_alloc | 많은 잘못된 애플리케이션은 기존 파일을 `open("foo.new")`/`write`/`close`/`rename` 또는 `open("foo", O_TRUNC)`/`write`/`close` 패턴으로 바꾸면서 `fsync()`를 호출하지 않습니다. `auto_da_alloc`을 켜면 ext4가 rename/truncate 교체 패턴을 감지하고 delayed allocation block을 할당합니다. 기본 `data=ordered`에서는 다음 journal commit 때 rename을 commit하기 전에 새 파일 data block을 디스크에 기록하도록 강제합니다. ext3와 비슷한 보장을 제공하고 crash 전에 block이 기록되지 않아 파일 길이가 0이 되는 문제를 피합니다. |
| noinit_itable | 초기화되지 않은 inode table block을 background에서 초기화하지 않습니다. 설치 CD가 설치를 빨리 끝낸 뒤 다음 unmount 때 inode table 초기화를 수행하도록 미룰 때 사용할 수 있습니다. |
| init_itable=n | lazy itable 초기화 코드는 이전 block group의 inode table을 0으로 만드는 데 걸린 millisecond의 `n`배만큼 기다립니다. inode table 초기화가 시스템 성능에 주는 영향을 줄입니다. |
| discard, nodiscard (*) | block을 해제할 때 ext4가 하위 block device에 discard/TRIM 명령을 보낼지 제어합니다. SSD와 sparse/thin-provisioned LUN에 유용하지만 충분한 시험이 이루어질 때까지 기본으로 꺼져 있습니다. |
| nouid32 | 32비트 UID와 GID를 끕니다. 16비트 값만 저장하고 기대하는 오래된 커널과의 상호 운용을 위한 옵션입니다. |
| block_validity (*), noblock_validity | 커널 내부 자료구조에서 파일시스템 metadata block을 추적하는 기능을 켜거나 끕니다. multi-block allocator 등이 metadata block과 겹치는 block을 할당하게 만드는 버그나 손상된 allocation bitmap을 감지할 수 있습니다. |
| dioread_lock, dioread_nolock | ext4가 DIO read locking을 사용할지 제어합니다. `dioread_nolock`은 buffer write 전에 uninitialized extent를 할당하고 I/O 완료 뒤 initialized 상태로 바꿔 inode mutex를 피하므로 고속 저장장치 확장성이 좋아집니다. data journaling과 함께 동작하지 않아 이 조합이면 커널 경고와 함께 무시됩니다. extent 기반 파일에만 사용하며 제약 때문에 기본값은 `dioread_lock`입니다. |
| max_dir_size_kb=n | 디렉터리 크기를 KB 단위로 제한하고 이를 넘는 확장은 `ENOSPC` 오류를 냅니다. 메모리가 적은 환경에서 매우 큰 디렉터리가 심각한 성능 저하나 OOM killer를 일으키는 것을 막는 데 유용합니다. 예를 들어 메모리가 512MB뿐일 때 176MB 디렉터리는 시스템을 크게 압박할 수 있습니다. |
| i_version | 64비트 inode version 지원을 켭니다. 기본값은 꺼짐입니다. |
| dax | page cache 없이 direct access를 사용합니다. `Documentation/filesystems/dax.rst`를 참고하십시오. `data=journal`과 호환되지 않습니다. |
| inlinecrypt | 가능하면 암호화 파일 내용을 파일시스템 계층 암호화 대신 blk-crypto framework로 암복호화하여 inline encryption hardware를 사용할 수 있게 합니다. 디스크 형식은 바뀌지 않습니다. 자세한 내용은 `Documentation/block/inline-encryption.rst`를 참고하십시오. |
데이터 모드
394-424ext4에는 세 가지 데이터 모드가 있습니다.
| 모드 | 동작과 특성 |
|---|---|
| writeback (`data=writeback`) | 데이터 자체는 전혀 journal하지 않고 metadata만 journal합니다. 기본 모드의 XFS와 JFS와 비슷한 수준입니다. crash와 복구 뒤 crash 직전에 쓴 파일에 잘못된 데이터가 나타날 수 있지만 보통 ext4 성능이 가장 좋습니다. |
| ordered (`data=ordered`) | 공식적으로는 metadata만 journal하지만 데이터 변경 관련 metadata와 data block을 transaction이라는 논리적 단위로 묶습니다. 새 metadata를 디스크에 쓸 때 관련 data block을 먼저 기록합니다. 일반적으로 writeback보다 약간 느리고 journal mode보다 훨씬 빠릅니다. |
| journal (`data=journal`) | 데이터와 metadata를 모두 journal합니다. 새 데이터는 먼저 journal에 쓰고 최종 위치에 기록합니다. crash 때 journal replay로 둘을 일관된 상태로 복구할 수 있습니다. 보통 가장 느리지만 디스크에서 데이터를 동시에 읽고 써야 하는 경우에는 다른 모드보다 빠릅니다. delayed allocation과 `O_DIRECT` 지원을 끕니다. |
/proc 항목
425-439마운트된 ext4 파일시스템 정보는 `/proc/fs/ext4`에서 볼 수 있습니다. 각 파일시스템에는 장치 이름에 따른 디렉터리, 예를 들어 `/proc/fs/ext4/hdc` 또는 `/proc/fs/ext4/dm-0`가 생깁니다.
| `/proc/fs/ext4/<devname>` 파일 | 설명 |
|---|---|
| mb_groups | free block의 multiblock allocator buddy cache 세부 정보 |
/sys 항목
440-517마운트된 ext4 파일시스템 정보는 `/sys/fs/ext4`에서도 볼 수 있습니다. 각 장치에는 `/sys/fs/ext4/hdc` 또는 `/sys/fs/ext4/dm-0` 같은 디렉터리가 생깁니다. `Documentation/ABI/testing/sysfs-fs-ext4`도 함께 참고하십시오.
| `/sys/fs/ext4/<devname>` 파일 | 설명 |
|---|---|
| delayed_allocation_blocks | 읽기 전용. page cache에서 dirty이지만 파일시스템 위치가 아직 할당되지 않은 block 수입니다. |
| inode_goal | 0이 아니면 다른 모든 allocation heuristic보다 우선해 inode allocator의 목표 inode를 지정합니다. 디버깅 전용이며 production에서는 0이어야 합니다. |
| inode_readahead_blks | inode table readahead 알고리즘이 buffer cache로 미리 읽을 inode table block의 최대 수를 제어합니다. |
| lifetime_write_kbytes | 읽기 전용. 파일시스템을 만든 뒤 지금까지 기록한 데이터의 KB 수입니다. |
| max_writeback_mb_bump | writeback 코드가 다른 inode로 넘어가기 전에 쓰려는 최대 MB 수입니다. |
| mb_group_prealloc | ext4 superblock에 stripe size가 없으면 multiblock allocator가 allocation 요청을 이 값의 배수로 올림합니다. |
| mb_max_to_scan | multiblock allocator가 최적 extent를 찾기 위해 검색할 최대 extent 수입니다. |
| mb_min_to_scan | multiblock allocator가 최적 extent를 찾기 위해 검색할 최소 extent 수입니다. |
| mb_order2_req | buddy cache를 사용하는 요청의 최소 크기를 2의 거듭제곱으로 제어합니다. |
| mb_stats | unmount할 때 표시할 multiblock allocator 통계를 수집할지 제어합니다. 1은 수집, 0은 미수집입니다. |
| mb_stream_req | 이 값보다 block 수가 적은 파일은 block group 전용 preallocation pool에서 할당해 작은 파일을 가까이 묶습니다. 각 큰 파일은 자체 preallocation pool에서 할당합니다. |
| session_write_kbytes | 읽기 전용. 파일시스템을 마운트한 뒤 기록한 데이터의 KB 수입니다. |
| reserved_clusters | 읽고 쓸 수 있습니다. 비싼 zeroout, 예기치 않은 `ENOSPC`, 데이터 손실 가능성을 피하기 위해 특정 상황에 사용할 reserved cluster 수입니다. 기본값은 전체의 2%와 4096 cluster 중 작은 값입니다. 변경할 수 있지만 전체 cluster 수를 넘을 수 없습니다. 마운트 시 reserved 공간이 부족해도 마운트는 실패하지 않습니다. |
Ext4 ioctl
518-601Ext4는 애플리케이션이 ext4 전용 기능에 접근할 여러 ioctl을 구현합니다. 아래 목록은 완전하지 않습니다. 진정한 ext4 전용 `EXT4_IOC_*`와 처음에는 ext4 전용이었으나 현재 다른 파일시스템도 지원하는 `FS_IOC_*`를 함께 포함합니다.
| ioctl | 설명 |
|---|---|
| FS_IOC_GETFLAGS | inode와 연관된 추가 속성을 가져옵니다. 인자는 `ext4.h`에 정의된 bit 값을 사용하는 정수 bitfield입니다. |
| FS_IOC_SETFLAGS | inode와 연관된 추가 속성을 설정합니다. 인자는 `ext4.h`에 정의된 bit 값을 사용하는 정수 bitfield입니다. |
| EXT4_IOC_GETVERSION, EXT4_IOC_GETVERSION_OLD | 각 inode에 저장한 `i_generation` 번호를 가져옵니다. 이 값은 보통 새 inode를 만들 때만 바뀌며 network filesystem에 특히 유용합니다. `_OLD` 버전은 `FS_IOC_GETVERSION`의 별칭입니다. |
| EXT4_IOC_SETVERSION, EXT4_IOC_SETVERSION_OLD | inode의 `i_generation` 번호를 설정합니다. `_OLD` 버전은 `FS_IOC_SETVERSION`의 별칭입니다. |
| EXT4_IOC_GROUP_EXTEND | `resize` mount option과 같은 목적으로 파일시스템을 마지막 기존 block group 끝까지 확장합니다. 더 확장하려면 online 또는 offline `resize2fs`를 사용해야 합니다. 인자는 새 파일시스템 block 수를 나타내는 unsigned long을 가리킵니다. |
| EXT4_IOC_MOVE_EXT | `orig_fd`의 block extent를 인자로 전달한 `move_extent` 구조체의 `donor_fd`로 옮긴 뒤 두 inode의 metadata를 교환합니다. allocator가 옮긴 block을 이상적으로 하나의 연속 extent로 재할당할 기회를 얻으므로 online defragmentation에 유용합니다. |
| EXT4_IOC_GROUP_ADD | 기존 또는 새 group descriptor block에 새 group descriptor를 추가합니다. 인자로 전달한 `ext4_new_group_input` 구조체가 새 group을 설명합니다. `EXT4_IOC_GROUP_EXTEND`와 함께 사용하면 파일시스템을 online resize할 수 있으며 `resize2fs` 같은 사용자 공간 도구가 두 ioctl을 함께 사용합니다. |
| EXT4_IOC_MIGRATE | 파일시스템 자체에 작용해 ext3 indirect block mapped inode를 ext4 extent mapped inode로 변환합니다. 원본 inode의 indirect mapping을 순회해 연속 block 범위를 임시 inode의 ext4 extent로 바꾼 뒤 inode를 교환합니다. ext3에서 ext4로 이동할 때 도움이 될 수 있지만 새 ext4 파일시스템을 만들고 backup에서 데이터를 복사하는 방법을 권장합니다. 파일시스템이 extent를 지원해야 합니다. |
| EXT4_IOC_ALLOC_DA_BLKS | 애플리케이션이 기대하는 ext3 동작을 보존하도록 모든 delayed allocation block을 강제로 할당합니다. data block write도 시작하지만 단순한 구현을 위해 현재 그렇게 할 뿐 필수 동작이 아니므로 향후 바뀔 수 있습니다. |
| EXT4_IOC_RESIZE_FS | 파일시스템을 새 크기로 조정합니다. 새 파일시스템 block 수를 64비트 정수 인자로 전달합니다. 커널이 bitmap과 inode table을 할당하므로 사용자 공간 도구는 새 block 수만 전달합니다. |
| EXT4_IOC_SWAP_BOOT | 지정한 inode의 `i_blocks`, `i_size`, `i_flags` 같은 속성을 `EXT4_BOOT_LOADER_INO`(#5)와 교환합니다. 일반 사용자가 실수로 바꿀 수 없는 파일시스템의 안전한 영역에 부트 로더를 저장할 때 주로 사용합니다. 이전 부트 로더의 data block은 지정한 inode와 연관됩니다. |
참고 자료
602-613| 종류 | 경로 또는 URL |
|---|---|
| 커널 소스 | fs/ext4/ |
| 커널 journal 소스 | fs/jbd2/ |
| 프로그램 | http://e2fsprogs.sourceforge.net/ |
| 유용한 링크 | https://fedoraproject.org/wiki/ext3-devel |
| 유용한 링크 | http://www.bullopensource.org/ext4/ |
| 유용한 링크 | http://ext4.wiki.kernel.org/index.php/Main_Page |
| 유용한 링크 | https://fedoraproject.org/wiki/Features/Ext4 |
사용법과 주요 기능
ext4.rst:1-100ext4 파일시스템을 만들고 ext3에서 변환하는 명령, 공정한 성능 비교 조건과 extent·delayed allocation·암호화·verity 등의 기능을 정리합니다.