erofs.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ======================================
  3. EROFS - Enhanced Read-Only File System
  4. ======================================
  5. Overview
  6. ========
  7. EROFS filesystem stands for Enhanced Read-Only File System. It aims to form a
  8. generic read-only filesystem solution for various read-only use cases instead
  9. of just focusing on storage space saving without considering any side effects
  10. of runtime performance.
  11. It is designed to meet the needs of flexibility, feature extendability and user
  12. payload friendly, etc. Apart from those, it is still kept as a simple
  13. random-access friendly high-performance filesystem to get rid of unneeded I/O
  14. amplification and memory-resident overhead compared to similar approaches.
  15. It is implemented to be a better choice for the following scenarios:
  16. - read-only storage media or
  17. - part of a fully trusted read-only solution, which means it needs to be
  18. immutable and bit-for-bit identical to the official golden image for
  19. their releases due to security or other considerations and
  20. - hope to minimize extra storage space with guaranteed end-to-end performance
  21. by using compact layout, transparent file compression and direct access,
  22. especially for those embedded devices with limited memory and high-density
  23. hosts with numerous containers.
  24. Here are the main features of EROFS:
  25. - Little endian on-disk design;
  26. - Block-based distribution and file-based distribution over fscache are
  27. supported;
  28. - Support multiple devices to refer to external blobs, which can be used
  29. for container images;
  30. - 32-bit block addresses for each device, therefore 16TiB address space at
  31. most with 4KiB block size for now;
  32. - Two inode layouts for different requirements:
  33. ===================== ============ ======================================
  34. compact (v1) extended (v2)
  35. ===================== ============ ======================================
  36. Inode metadata size 32 bytes 64 bytes
  37. Max file size 4 GiB 16 EiB (also limited by max. vol size)
  38. Max uids/gids 65536 4294967296
  39. Per-inode timestamp no yes (64 + 32-bit timestamp)
  40. Max hardlinks 65536 4294967296
  41. Metadata reserved 8 bytes 18 bytes
  42. ===================== ============ ======================================
  43. - Support extended attributes as an option;
  44. - Support a bloom filter that speeds up negative extended attribute lookups;
  45. - Support POSIX.1e ACLs by using extended attributes;
  46. - Support transparent data compression as an option:
  47. LZ4, MicroLZMA and DEFLATE algorithms can be used on a per-file basis; In
  48. addition, inplace decompression is also supported to avoid bounce compressed
  49. buffers and unnecessary page cache thrashing.
  50. - Support chunk-based data deduplication and rolling-hash compressed data
  51. deduplication;
  52. - Support tailpacking inline compared to byte-addressed unaligned metadata
  53. or smaller block size alternatives;
  54. - Support merging tail-end data into a special inode as fragments.
  55. - Support large folios to make use of THPs (Transparent Hugepages);
  56. - Support direct I/O on uncompressed files to avoid double caching for loop
  57. devices;
  58. - Support FSDAX on uncompressed images for secure containers and ramdisks in
  59. order to get rid of unnecessary page cache.
  60. - Support file-based on-demand loading with the Fscache infrastructure.
  61. The following git tree provides the file system user-space tools under
  62. development, such as a formatting tool (mkfs.erofs), an on-disk consistency &
  63. compatibility checking tool (fsck.erofs), and a debugging tool (dump.erofs):
  64. - git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git
  65. For more information, please also refer to the documentation site:
  66. - https://erofs.docs.kernel.org
  67. Bugs and patches are welcome, please kindly help us and send to the following
  68. linux-erofs mailing list:
  69. - linux-erofs mailing list <linux-erofs@lists.ozlabs.org>
  70. Mount options
  71. =============
  72. =================== =========================================================
  73. (no)user_xattr Setup Extended User Attributes. Note: xattr is enabled
  74. by default if CONFIG_EROFS_FS_XATTR is selected.
  75. (no)acl Setup POSIX Access Control List. Note: acl is enabled
  76. by default if CONFIG_EROFS_FS_POSIX_ACL is selected.
  77. cache_strategy=%s Select a strategy for cached decompression from now on:
  78. ========== =============================================
  79. disabled In-place I/O decompression only;
  80. readahead Cache the last incomplete compressed physical
  81. cluster for further reading. It still does
  82. in-place I/O decompression for the rest
  83. compressed physical clusters;
  84. readaround Cache the both ends of incomplete compressed
  85. physical clusters for further reading.
  86. It still does in-place I/O decompression
  87. for the rest compressed physical clusters.
  88. ========== =============================================
  89. dax={always,never} Use direct access (no page cache). See
  90. Documentation/filesystems/dax.rst.
  91. dax A legacy option which is an alias for ``dax=always``.
  92. device=%s Specify a path to an extra device to be used together.
  93. fsid=%s Specify a filesystem image ID for Fscache back-end.
  94. domain_id=%s Specify a domain ID in fscache mode so that different images
  95. with the same blobs under a given domain ID can share storage.
  96. =================== =========================================================
  97. Sysfs Entries
  98. =============
  99. Information about mounted erofs file systems can be found in /sys/fs/erofs.
  100. Each mounted filesystem will have a directory in /sys/fs/erofs based on its
  101. device name (i.e., /sys/fs/erofs/sda).
  102. (see also Documentation/ABI/testing/sysfs-fs-erofs)
  103. On-disk details
  104. ===============
  105. Summary
  106. -------
  107. Different from other read-only file systems, an EROFS volume is designed
  108. to be as simple as possible::
  109. |-> aligned with the block size
  110. ____________________________________________________________
  111. | |SB| | ... | Metadata | ... | Data | Metadata | ... | Data |
  112. |_|__|_|_____|__________|_____|______|__________|_____|______|
  113. 0 +1K
  114. All data areas should be aligned with the block size, but metadata areas
  115. may not. All metadatas can be now observed in two different spaces (views):
  116. 1. Inode metadata space
  117. Each valid inode should be aligned with an inode slot, which is a fixed
  118. value (32 bytes) and designed to be kept in line with compact inode size.
  119. Each inode can be directly found with the following formula:
  120. inode offset = meta_blkaddr * block_size + 32 * nid
  121. ::
  122. |-> aligned with 8B
  123. |-> followed closely
  124. + meta_blkaddr blocks |-> another slot
  125. _____________________________________________________________________
  126. | ... | inode | xattrs | extents | data inline | ... | inode ...
  127. |________|_______|(optional)|(optional)|__(optional)_|_____|__________
  128. |-> aligned with the inode slot size
  129. . .
  130. . .
  131. . .
  132. . .
  133. . .
  134. . .
  135. .____________________________________________________|-> aligned with 4B
  136. | xattr_ibody_header | shared xattrs | inline xattrs |
  137. |____________________|_______________|_______________|
  138. |-> 12 bytes <-|->x * 4 bytes<-| .
  139. . . .
  140. . . .
  141. . . .
  142. ._______________________________.______________________.
  143. | id | id | id | id | ... | id | ent | ... | ent| ... |
  144. |____|____|____|____|______|____|_____|_____|____|_____|
  145. |-> aligned with 4B
  146. |-> aligned with 4B
  147. Inode could be 32 or 64 bytes, which can be distinguished from a common
  148. field which all inode versions have -- i_format::
  149. __________________ __________________
  150. | i_format | | i_format |
  151. |__________________| |__________________|
  152. | ... | | ... |
  153. | | | |
  154. |__________________| 32 bytes | |
  155. | |
  156. |__________________| 64 bytes
  157. Xattrs, extents, data inline are placed after the corresponding inode with
  158. proper alignment, and they could be optional for different data mappings.
  159. _currently_ total 5 data layouts are supported:
  160. == ====================================================================
  161. 0 flat file data without data inline (no extent);
  162. 1 fixed-sized output data compression (with non-compacted indexes);
  163. 2 flat file data with tail packing data inline (no extent);
  164. 3 fixed-sized output data compression (with compacted indexes, v5.3+);
  165. 4 chunk-based file (v5.15+).
  166. == ====================================================================
  167. The size of the optional xattrs is indicated by i_xattr_count in inode
  168. header. Large xattrs or xattrs shared by many different files can be
  169. stored in shared xattrs metadata rather than inlined right after inode.
  170. 2. Shared xattrs metadata space
  171. Shared xattrs space is similar to the above inode space, started with
  172. a specific block indicated by xattr_blkaddr, organized one by one with
  173. proper align.
  174. Each share xattr can also be directly found by the following formula:
  175. xattr offset = xattr_blkaddr * block_size + 4 * xattr_id
  176. ::
  177. |-> aligned by 4 bytes
  178. + xattr_blkaddr blocks |-> aligned with 4 bytes
  179. _________________________________________________________________________
  180. | ... | xattr_entry | xattr data | ... | xattr_entry | xattr data ...
  181. |________|_____________|_____________|_____|______________|_______________
  182. Directories
  183. -----------
  184. All directories are now organized in a compact on-disk format. Note that
  185. each directory block is divided into index and name areas in order to support
  186. random file lookup, and all directory entries are _strictly_ recorded in
  187. alphabetical order in order to support improved prefix binary search
  188. algorithm (could refer to the related source code).
  189. ::
  190. ___________________________
  191. / |
  192. / ______________|________________
  193. / / | nameoff1 | nameoffN-1
  194. ____________.______________._______________v________________v__________
  195. | dirent | dirent | ... | dirent | filename | filename | ... | filename |
  196. |___.0___|____1___|_____|___N-1__|____0_____|____1_____|_____|___N-1____|
  197. \ ^
  198. \ | * could have
  199. \ | trailing '\0'
  200. \________________________| nameoff0
  201. Directory block
  202. Note that apart from the offset of the first filename, nameoff0 also indicates
  203. the total number of directory entries in this block since it is no need to
  204. introduce another on-disk field at all.
  205. Chunk-based files
  206. -----------------
  207. In order to support chunk-based data deduplication, a new inode data layout has
  208. been supported since Linux v5.15: Files are split in equal-sized data chunks
  209. with ``extents`` area of the inode metadata indicating how to get the chunk
  210. data: these can be simply as a 4-byte block address array or in the 8-byte
  211. chunk index form (see struct erofs_inode_chunk_index in erofs_fs.h for more
  212. details.)
  213. By the way, chunk-based files are all uncompressed for now.
  214. Long extended attribute name prefixes
  215. -------------------------------------
  216. There are use cases where extended attributes with different values can have
  217. only a few common prefixes (such as overlayfs xattrs). The predefined prefixes
  218. work inefficiently in both image size and runtime performance in such cases.
  219. The long xattr name prefixes feature is introduced to address this issue. The
  220. overall idea is that, apart from the existing predefined prefixes, the xattr
  221. entry could also refer to user-specified long xattr name prefixes, e.g.
  222. "trusted.overlay.".
  223. When referring to a long xattr name prefix, the highest bit (bit 7) of
  224. erofs_xattr_entry.e_name_index is set, while the lower bits (bit 0-6) as a whole
  225. represent the index of the referred long name prefix among all long name
  226. prefixes. Therefore, only the trailing part of the name apart from the long
  227. xattr name prefix is stored in erofs_xattr_entry.e_name, which could be empty if
  228. the full xattr name matches exactly as its long xattr name prefix.
  229. All long xattr prefixes are stored one by one in the packed inode as long as
  230. the packed inode is valid, or in the meta inode otherwise. The
  231. xattr_prefix_count (of the on-disk superblock) indicates the total number of
  232. long xattr name prefixes, while (xattr_prefix_start * 4) indicates the start
  233. offset of long name prefixes in the packed/meta inode. Note that, long extended
  234. attribute name prefixes are disabled if xattr_prefix_count is 0.
  235. Each long name prefix is stored in the format: ALIGN({__le16 len, data}, 4),
  236. where len represents the total size of the data part. The data part is actually
  237. represented by 'struct erofs_xattr_long_prefix', where base_index represents the
  238. index of the predefined xattr name prefix, e.g. EROFS_XATTR_INDEX_TRUSTED for
  239. "trusted.overlay." long name prefix, while the infix string keeps the string
  240. after stripping the short prefix, e.g. "overlay." for the example above.
  241. Data compression
  242. ----------------
  243. EROFS implements fixed-sized output compression which generates fixed-sized
  244. compressed data blocks from variable-sized input in contrast to other existing
  245. fixed-sized input solutions. Relatively higher compression ratios can be gotten
  246. by using fixed-sized output compression since nowadays popular data compression
  247. algorithms are mostly LZ77-based and such fixed-sized output approach can be
  248. benefited from the historical dictionary (aka. sliding window).
  249. In details, original (uncompressed) data is turned into several variable-sized
  250. extents and in the meanwhile, compressed into physical clusters (pclusters).
  251. In order to record each variable-sized extent, logical clusters (lclusters) are
  252. introduced as the basic unit of compress indexes to indicate whether a new
  253. extent is generated within the range (HEAD) or not (NONHEAD). Lclusters are now
  254. fixed in block size, as illustrated below::
  255. |<- variable-sized extent ->|<- VLE ->|
  256. clusterofs clusterofs clusterofs
  257. | | |
  258. _________v_________________________________v_______________________v________
  259. ... | . | | . | | . ...
  260. ____|____._________|______________|________.___ _|______________|__.________
  261. |-> lcluster <-|-> lcluster <-|-> lcluster <-|-> lcluster <-|
  262. (HEAD) (NONHEAD) (HEAD) (NONHEAD) .
  263. . CBLKCNT . .
  264. . . .
  265. . . .
  266. _______._____________________________.______________._________________
  267. ... | | | | ...
  268. _______|______________|______________|______________|_________________
  269. |-> big pcluster <-|-> pcluster <-|
  270. A physical cluster can be seen as a container of physical compressed blocks
  271. which contains compressed data. Previously, only lcluster-sized (4KB) pclusters
  272. were supported. After big pcluster feature is introduced (available since
  273. Linux v5.13), pcluster can be a multiple of lcluster size.
  274. For each HEAD lcluster, clusterofs is recorded to indicate where a new extent
  275. starts and blkaddr is used to seek the compressed data. For each NONHEAD
  276. lcluster, delta0 and delta1 are available instead of blkaddr to indicate the
  277. distance to its HEAD lcluster and the next HEAD lcluster. A PLAIN lcluster is
  278. also a HEAD lcluster except that its data is uncompressed. See the comments
  279. around "struct z_erofs_vle_decompressed_index" in erofs_fs.h for more details.
  280. If big pcluster is enabled, pcluster size in lclusters needs to be recorded as
  281. well. Let the delta0 of the first NONHEAD lcluster store the compressed block
  282. count with a special flag as a new called CBLKCNT NONHEAD lcluster. It's easy
  283. to understand its delta0 is constantly 1, as illustrated below::
  284. __________________________________________________________
  285. | HEAD | NONHEAD | NONHEAD | ... | NONHEAD | HEAD | HEAD |
  286. |__:___|_(CBLKCNT)_|_________|_____|_________|__:___|____:_|
  287. |<----- a big pcluster (with CBLKCNT) ------>|<-- -->|
  288. a lcluster-sized pcluster (without CBLKCNT) ^
  289. If another HEAD follows a HEAD lcluster, there is no room to record CBLKCNT,
  290. but it's easy to know the size of such pcluster is 1 lcluster as well.
  291. Since Linux v6.1, each pcluster can be used for multiple variable-sized extents,
  292. therefore it can be used for compressed data deduplication.