Skip to content

Commit 46f2e04

Browse files
committed
erofs: update documentation about data compression
Add more description about (NON)HEAD lclusters, and the new big pcluster feature. Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Gao Xiang <[email protected]>
1 parent 1b55767 commit 46f2e04

File tree

1 file changed

+49
-19
lines changed

1 file changed

+49
-19
lines changed

Documentation/filesystems/erofs.rst

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ Here is the main features of EROFS:
5050

5151
- Support POSIX.1e ACLs by using xattrs;
5252

53-
- Support transparent file compression as an option:
54-
LZ4 algorithm with 4 KB fixed-sized output compression for high performance.
53+
- Support transparent data compression as an option:
54+
LZ4 algorithm with the fixed-sized output compression for high performance.
5555

5656
The following git tree provides the file system user-space tools under
5757
development (ex, formatting tool mkfs.erofs):
@@ -210,10 +210,21 @@ Note that apart from the offset of the first filename, nameoff0 also indicates
210210
the total number of directory entries in this block since it is no need to
211211
introduce another on-disk field at all.
212212

213-
Compression
214-
-----------
215-
Currently, EROFS supports 4KB fixed-sized output transparent file compression,
216-
as illustrated below::
213+
Data compression
214+
----------------
215+
EROFS implements LZ4 fixed-sized output compression which generates fixed-sized
216+
compressed data blocks from variable-sized input in contrast to other existing
217+
fixed-sized input solutions. Relatively higher compression ratios can be gotten
218+
by using fixed-sized output compression since nowadays popular data compression
219+
algorithms are mostly LZ77-based and such fixed-sized output approach can be
220+
benefited from the historical dictionary (aka. sliding window).
221+
222+
In details, original (uncompressed) data is turned into several variable-sized
223+
extents and in the meanwhile, compressed into physical clusters (pclusters).
224+
In order to record each variable-sized extent, logical clusters (lclusters) are
225+
introduced as the basic unit of compress indexes to indicate whether a new
226+
extent is generated within the range (HEAD) or not (NONHEAD). Lclusters are now
227+
fixed in block size, as illustrated below::
217228

218229
|<- variable-sized extent ->|<- VLE ->|
219230
clusterofs clusterofs clusterofs
@@ -222,18 +233,37 @@ as illustrated below::
222233
... | . | | . | | . ...
223234
____|____._________|______________|________.___ _|______________|__.________
224235
|-> lcluster <-|-> lcluster <-|-> lcluster <-|-> lcluster <-|
225-
size size size size . .
226-
. . . .
227-
. . . .
228-
. . . .
229-
_______.______________.______________.______________._________________
236+
(HEAD) (NONHEAD) (HEAD) (NONHEAD) .
237+
. CBLKCNT . .
238+
. . .
239+
. . .
240+
_______._____________________________.______________._________________
230241
... | | | | ...
231242
_______|______________|______________|______________|_________________
232-
|-> pcluster <-|-> pcluster <-|-> pcluster <-|
233-
size size size
234-
235-
Currently each on-disk physical cluster can contain 4KB (un)compressed data
236-
at most. For each logical cluster, there is a corresponding on-disk index to
237-
describe its cluster type, physical cluster address, etc.
238-
239-
See "struct z_erofs_vle_decompressed_index" in erofs_fs.h for more details.
243+
|-> big pcluster <-|-> pcluster <-|
244+
245+
A physical cluster can be seen as a container of physical compressed blocks
246+
which contains compressed data. Previously, only lcluster-sized (4KB) pclusters
247+
were supported. After big pcluster feature is introduced (available since
248+
Linux v5.13), pcluster can be a multiple of lcluster size.
249+
250+
For each HEAD lcluster, clusterofs is recorded to indicate where a new extent
251+
starts and blkaddr is used to seek the compressed data. For each NONHEAD
252+
lcluster, delta0 and delta1 are available instead of blkaddr to indicate the
253+
distance to its HEAD lcluster and the next HEAD lcluster. A PLAIN lcluster is
254+
also a HEAD lcluster except that its data is uncompressed. See the comments
255+
around "struct z_erofs_vle_decompressed_index" in erofs_fs.h for more details.
256+
257+
If big pcluster is enabled, pcluster size in lclusters needs to be recorded as
258+
well. Let the delta0 of the first NONHEAD lcluster store the compressed block
259+
count with a special flag as a new called CBLKCNT NONHEAD lcluster. It's easy
260+
to understand its delta0 is constantly 1, as illustrated below::
261+
262+
__________________________________________________________
263+
| HEAD | NONHEAD | NONHEAD | ... | NONHEAD | HEAD | HEAD |
264+
|__:___|_(CBLKCNT)_|_________|_____|_________|__:___|____:_|
265+
|<----- a big pcluster (with CBLKCNT) ------>|<-- -->|
266+
a lcluster-sized pcluster (without CBLKCNT) ^
267+
268+
If another HEAD follows a HEAD lcluster, there is no room to record CBLKCNT,
269+
but it's easy to know the size of such pcluster is 1 lcluster as well.

0 commit comments

Comments
 (0)