orphan.rst 2.4 KB

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