← Documents Documentation/filesystems/ext4/orphan.rst GitHub 원문 ↗

Linux 6.18.37 · Filesystems

Orphan file

unlink·truncate 중인 inode를 crash recovery까지 추적하는 orphan file 형식의 전문 번역입니다.

Source pathDocumentation/filesystems/ext4/orphan.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

orphan.rst:1-42

orphan 추적은 열린 채 unlink된 inode와 중간 단계의 truncate가 crash 뒤 block 누수로 이어지는 것을 막습니다.

핵심 흐름
orphan 등록linked list 또는 orphan file에 기록mount recovery에서 scan정리 후 present flag 제거

문서의 핵심 관계를 짧게 정리합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 Orphan file
4 -----------
5
6 In unix there can inodes that are unlinked from directory hierarchy but that
7 are still alive because they are open. In case of crash the filesystem has to
8 clean up these inodes as otherwise they (and the blocks referenced from them)
9 would leak. Similarly if we truncate or extend the file, we need not be able
10 to perform the operation in a single journalling transaction. In such case we
11 track the inode as orphan so that in case of crash extra blocks allocated to
12 the file get truncated.
13
14 Traditionally ext4 tracks orphan inodes in a form of single linked list where
15 superblock contains the inode number of the last orphan inode (s_last_orphan
16 field) and then each inode contains inode number of the previously orphaned
17 inode (we overload i_dtime inode field for this). However this filesystem
18 global single linked list is a scalability bottleneck for workloads that result
19 in heavy creation of orphan inodes. When orphan file feature
20 (COMPAT_ORPHAN_FILE) is enabled, the filesystem has a special inode
21 (referenced from the superblock through s_orphan_file_inum) with several
22 blocks. Each of these blocks has a structure:
23
24 ============= ================ =============== ===============================
25 Offset Type Name Description
26 ============= ================ =============== ===============================
27 0x0 Array of Orphan inode Each __le32 entry is either
28 __le32 entries entries empty (0) or it contains
29 inode number of an orphan
30 inode.
31 blocksize-8 __le32 ob_magic Magic value stored in orphan
32 block tail (0x0b10ca04)
33 blocksize-4 __le32 ob_checksum Checksum of the orphan block.
34 ============= ================ =============== ===============================
35
36 When a filesystem with orphan file feature is writeably mounted, we set
37 RO_COMPAT_ORPHAN_PRESENT feature in the superblock to indicate there may
38 be valid orphan entries. In case we see this feature when mounting the
39 filesystem, we read the whole orphan file and process all orphan inodes found
40 there as usual. When cleanly unmounting the filesystem we remove the
41 RO_COMPAT_ORPHAN_PRESENT feature to avoid unnecessary scanning of the orphan
42 file and also make the filesystem fully compatible with older kernels.
43

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

orphan inode 추적 목적

1-19

UNIX에서는 directory hierarchy에서 unlink되었어도 process가 열어 두어 살아 있는 inode가 있을 수 있습니다. crash가 나면 이런 inode와 그 inode가 참조하는 block을 정리하지 않을 경우 공간이 누수됩니다.

file truncate나 extend도 하나의 journalling transaction에서 끝내지 못할 수 있습니다. 이 경우 inode를 orphan으로 추적해 crash 뒤 file에 추가로 할당된 block을 truncate할 수 있게 합니다.

전통적인 ext4는 filesystem 전역 single linked list로 orphan inode를 추적합니다. superblock의 `s_last_orphan`에 마지막 orphan inode number를 두고, 각 inode의 `i_dtime`을 이전 orphan inode number로 재사용합니다.

이 전역 단일 list는 orphan inode를 많이 만드는 workload에서 scalability bottleneck이 됩니다. `COMPAT_ORPHAN_FILE` 기능은 superblock의 `s_orphan_file_inum`이 가리키는 여러 block의 특수 inode file로 이를 대체합니다.

orphan inode 복구
열린 inode를 directory에서 unlink하거나 다단계 truncate 시작inode를 orphan list 또는 orphan file에 등록journal transaction으로 작업 진행crash 발생 시 mount recovery가 orphan 추적 정보 읽기남은 inode와 추가 block 정리정상 완료 시 orphan 항목 제거

unlink 또는 부분 truncate 이후 crash가 났을 때 누수를 막는 경로입니다.

.. SPDX-License-Identifier: GPL-2.0

Orphan file
-----------

In unix there can inodes that are unlinked from directory hierarchy but that
are still alive because they are open. In case of crash the filesystem has to
clean up these inodes as otherwise they (and the blocks referenced from them)
would leak. Similarly if we truncate or extend the file, we need not be able
to perform the operation in a single journalling transaction. In such case we
track the inode as orphan so that in case of crash extra blocks allocated to
the file get truncated.

Traditionally ext4 tracks orphan inodes in a form of single linked list where
superblock contains the inode number of the last orphan inode (s_last_orphan
field) and then each inode contains inode number of the previously orphaned
inode (we overload i_dtime inode field for this). However this filesystem
global single linked list is a scalability bottleneck for workloads that result
in heavy creation of orphan inodes. When orphan file feature

orphan file block과 mount 상태

20-42

orphan file의 각 block은 32비트 orphan inode entry 배열과 8바이트 tail로 구성됩니다. 각 `__le32` entry는 0이면 비어 있고, 아니면 orphan inode number입니다.

orphan file block
OffsetTypeName설명
`0x0``__le32[]`orphan inode entries0 또는 orphan inode number
`blocksize - 8``__le32``ob_magic`orphan block tail magic `0x0b10ca04`
`blocksize - 4``__le32``ob_checksum`orphan block checksum

block 끝의 magic과 checksum으로 entry 배열을 보호합니다.

orphan file 기능이 있는 filesystem을 writable mount하면 superblock에 `RO_COMPAT_ORPHAN_PRESENT`를 설정해 유효한 orphan entry가 있을 수 있음을 표시합니다.

mount 중 이 feature를 발견하면 orphan file 전체를 읽고 발견한 모든 orphan inode를 일반적인 방식으로 처리합니다. clean unmount 시 feature를 제거해 불필요한 scan을 피하고 오래된 kernel과 완전히 호환되게 합니다.

orphan file feature 수명
writable mount에서 `RO_COMPAT_ORPHAN_PRESENT` 설정작업 중 orphan entry를 여러 block에 기록recovery mount는 file 전체를 scan하고 inode 처리clean unmount에서 orphan 작업 완료`RO_COMPAT_ORPHAN_PRESENT` 제거

writable mount부터 clean unmount까지 feature bit의 역할입니다.

(COMPAT_ORPHAN_FILE) is enabled, the filesystem has a special inode
(referenced from the superblock through s_orphan_file_inum) with several
blocks. Each of these blocks has a structure:

============= ================ =============== ===============================
Offset        Type             Name            Description
============= ================ =============== ===============================
0x0           Array of         Orphan inode    Each __le32 entry is either
              __le32 entries   entries         empty (0) or it contains
                                               inode number of an orphan
                                               inode.
blocksize-8   __le32           ob_magic        Magic value stored in orphan
                                               block tail (0x0b10ca04)
blocksize-4   __le32           ob_checksum     Checksum of the orphan block.
============= ================ =============== ===============================

When a filesystem with orphan file feature is writeably mounted, we set
RO_COMPAT_ORPHAN_PRESENT feature in the superblock to indicate there may
be valid orphan entries. In case we see this feature when mounting the
filesystem, we read the whole orphan file and process all orphan inodes found
there as usual. When cleanly unmounting the filesystem we remove the
RO_COMPAT_ORPHAN_PRESENT feature to avoid unnecessary scanning of the orphan
file and also make the filesystem fully compatible with older kernels.