요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
.. 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
(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.
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
orphan inode 추적 목적
1-19UNIX에서는 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로 이를 대체합니다.
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-42orphan file의 각 block은 32비트 orphan inode entry 배열과 8바이트 tail로 구성됩니다. 각 `__le32` entry는 0이면 비어 있고, 아니면 orphan inode number입니다.
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과 완전히 호환되게 합니다.
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.
요약·해설
orphan.rst:1-42orphan 추적은 열린 채 unlink된 inode와 중간 단계의 truncate가 crash 뒤 block 누수로 이어지는 것을 막습니다.
문서의 핵심 관계를 짧게 정리합니다.