This patch introduces new compacted compression indexes.
In contract to legacy compression indexes that each 4k logical cluster has an 8-byte index, compacted ondisk compression indexes will have amortized 2 bytes for each 4k logical cluster (compacted 2B) amortized 4 bytes for each 4k logical cluster (compacted 4B)
In detail, several continuous clusters will be encoded in a compacted pack with cluster types, offsets, and one blkaddr at the end of the pack to leave 4-byte margin for better decoding performance, as illustrated below: _____________________________________________ |___@_____ encoded bits __________|_ blkaddr _| 0 . amortized * vcnt . . . . amortized * vcnt - 4 . . .___________________. |_type_|_clusterofs_|
Note that compacted 2 / 4B should be aligned with 32 / 8 bytes in order to avoid each pack crossing page boundary.
以下分析参考erofs-utils 1.3。
legacy compression的index是8个字节,对应一个4KB的lcluster:
structz_erofs_vle_decompressed_index { __le16 di_advise; /* where to decompress in the head cluster */ __le16 di_clusterofs;
union { /* for the head cluster */ __le32 blkaddr; /* * for the rest clusters * eg. for 4k page-sized cluster, maximum 4K*64k = 256M) * [0] - pointing to the head cluster * [1] - pointing to the tail cluster */ __le16 delta[2]; } di_u; };
structz_erofs_map_header { __le32 h_reserved1; __le16 h_advise; /* * bit 0-3 : algorithm type of head 1 (logical cluster type 01); * bit 4-7 : algorithm type of head 2 (logical cluster type 11). */ __u8 h_algorithmtype; /* * bit 0-2 : logical cluster bits - 12, e.g. 0 for 4096; * bit 3-7 : reserved. */ __u8 h_clusterbits; };