* [PATCH 1/2] erofs-utils: lib: fix up compact indexes for block size < 4096
@ 2023-11-23 5:22 Gao Xiang
2023-11-23 5:22 ` [PATCH 2/2] erofs-utils: mkfs: support compact indexes for smaller block sizes Gao Xiang
2023-11-23 9:11 ` [PATCH 1/2] erofs-utils: lib: fix up compact indexes for block size < 4096 Yue Hu
0 siblings, 2 replies; 4+ messages in thread
From: Gao Xiang @ 2023-11-23 5:22 UTC (permalink / raw)
To: linux-erofs; +Cc: Gao Xiang
Previously, the block size always equaled to PAGE_SIZE in kernel,
therefore `lclusterbits` couldn't be less than 12.
Since sub-page compressed blocks are now considered, `lobits` for
a lcluster in each pack of compact indexes cannot always be
`lclusterbits` as before. Otherwise, there is no enough room for
the special value `Z_EROFS_LI_D0_CBLKCNT`.
To support smaller block sizes, `lobits` for each compacted lcluster is
now calculated as:
lobits = max(lclusterbits, ilog2(Z_EROFS_LI_D0_CBLKCNT) + 1)
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
lib/zmap.c | 32 ++++++++++++++------------------
1 file changed, 14 insertions(+), 18 deletions(-)
diff --git a/lib/zmap.c b/lib/zmap.c
index 81fa22b..12eb426 100644
--- a/lib/zmap.c
+++ b/lib/zmap.c
@@ -197,29 +197,26 @@ static int legacy_load_cluster_from_disk(struct z_erofs_maprecorder *m,
}
static unsigned int decode_compactedbits(unsigned int lobits,
- unsigned int lomask,
u8 *in, unsigned int pos, u8 *type)
{
const unsigned int v = get_unaligned_le32(in + pos / 8) >> (pos & 7);
- const unsigned int lo = v & lomask;
+ const unsigned int lo = v & ((1 << lobits) - 1);
*type = (v >> lobits) & 3;
return lo;
}
-static int get_compacted_la_distance(unsigned int lclusterbits,
+static int get_compacted_la_distance(unsigned int lobits,
unsigned int encodebits,
unsigned int vcnt, u8 *in, int i)
{
- const unsigned int lomask = (1 << lclusterbits) - 1;
unsigned int lo, d1 = 0;
u8 type;
DBG_BUGON(i >= vcnt);
do {
- lo = decode_compactedbits(lclusterbits, lomask,
- in, encodebits * i, &type);
+ lo = decode_compactedbits(lobits, in, encodebits * i, &type);
if (type != Z_EROFS_LCLUSTER_TYPE_NONHEAD)
return d1;
@@ -238,15 +235,14 @@ static int unpack_compacted_index(struct z_erofs_maprecorder *m,
{
struct erofs_inode *const vi = m->inode;
const unsigned int lclusterbits = vi->z_logical_clusterbits;
- const unsigned int lomask = (1 << lclusterbits) - 1;
- unsigned int vcnt, base, lo, encodebits, nblk, eofs;
+ unsigned int vcnt, base, lo, lobits, encodebits, nblk, eofs;
int i;
u8 *in, type;
bool big_pcluster;
if (1 << amortizedshift == 4 && lclusterbits <= 14)
vcnt = 2;
- else if (1 << amortizedshift == 2 && lclusterbits == 12)
+ else if (1 << amortizedshift == 2 && lclusterbits <= 12)
vcnt = 16;
else
return -EOPNOTSUPP;
@@ -255,6 +251,7 @@ static int unpack_compacted_index(struct z_erofs_maprecorder *m,
m->nextpackoff = round_down(pos, vcnt << amortizedshift) +
(vcnt << amortizedshift);
big_pcluster = vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_1;
+ lobits = max(lclusterbits, ilog2(Z_EROFS_LI_D0_CBLKCNT) + 1U);
encodebits = ((vcnt << amortizedshift) - sizeof(__le32)) * 8 / vcnt;
eofs = erofs_blkoff(vi->sbi, pos);
base = round_down(eofs, vcnt << amortizedshift);
@@ -262,15 +259,14 @@ static int unpack_compacted_index(struct z_erofs_maprecorder *m,
i = (eofs - base) >> amortizedshift;
- lo = decode_compactedbits(lclusterbits, lomask,
- in, encodebits * i, &type);
+ lo = decode_compactedbits(lobits, in, encodebits * i, &type);
m->type = type;
if (type == Z_EROFS_LCLUSTER_TYPE_NONHEAD) {
m->clusterofs = 1 << lclusterbits;
/* figure out lookahead_distance: delta[1] if needed */
if (lookahead)
- m->delta[1] = get_compacted_la_distance(lclusterbits,
+ m->delta[1] = get_compacted_la_distance(lobits,
encodebits, vcnt, in, i);
if (lo & Z_EROFS_LI_D0_CBLKCNT) {
if (!big_pcluster) {
@@ -289,8 +285,8 @@ static int unpack_compacted_index(struct z_erofs_maprecorder *m,
* of which lo saves delta[1] rather than delta[0].
* Hence, get delta[0] by the previous lcluster indirectly.
*/
- lo = decode_compactedbits(lclusterbits, lomask,
- in, encodebits * (i - 1), &type);
+ lo = decode_compactedbits(lobits, in,
+ encodebits * (i - 1), &type);
if (type != Z_EROFS_LCLUSTER_TYPE_NONHEAD)
lo = 0;
else if (lo & Z_EROFS_LI_D0_CBLKCNT)
@@ -305,8 +301,8 @@ static int unpack_compacted_index(struct z_erofs_maprecorder *m,
nblk = 1;
while (i > 0) {
--i;
- lo = decode_compactedbits(lclusterbits, lomask,
- in, encodebits * i, &type);
+ lo = decode_compactedbits(lobits, in,
+ encodebits * i, &type);
if (type == Z_EROFS_LCLUSTER_TYPE_NONHEAD)
i -= lo;
@@ -317,8 +313,8 @@ static int unpack_compacted_index(struct z_erofs_maprecorder *m,
nblk = 0;
while (i > 0) {
--i;
- lo = decode_compactedbits(lclusterbits, lomask,
- in, encodebits * i, &type);
+ lo = decode_compactedbits(lobits, in,
+ encodebits * i, &type);
if (type == Z_EROFS_LCLUSTER_TYPE_NONHEAD) {
if (lo & Z_EROFS_LI_D0_CBLKCNT) {
--i;
--
2.39.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] erofs-utils: mkfs: support compact indexes for smaller block sizes
2023-11-23 5:22 [PATCH 1/2] erofs-utils: lib: fix up compact indexes for block size < 4096 Gao Xiang
@ 2023-11-23 5:22 ` Gao Xiang
2023-11-23 9:12 ` Yue Hu
2023-11-23 9:11 ` [PATCH 1/2] erofs-utils: lib: fix up compact indexes for block size < 4096 Yue Hu
1 sibling, 1 reply; 4+ messages in thread
From: Gao Xiang @ 2023-11-23 5:22 UTC (permalink / raw)
To: linux-erofs; +Cc: Gao Xiang
This commit also adds mkfs support of compact indexes for smaller
block sizes (less than 4096).
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
lib/compress.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/lib/compress.c b/lib/compress.c
index 47f1c1d..61328ed 100644
--- a/lib/compress.c
+++ b/lib/compress.c
@@ -627,19 +627,20 @@ static void *write_compacted_indexes(u8 *out,
struct z_erofs_compressindex_vec *cv,
erofs_blk_t *blkaddr_ret,
unsigned int destsize,
- unsigned int logical_clusterbits,
+ unsigned int lclusterbits,
bool final, bool *dummy_head,
bool update_blkaddr)
{
- unsigned int vcnt, encodebits, pos, i, cblks;
+ unsigned int vcnt, lobits, encodebits, pos, i, cblks;
erofs_blk_t blkaddr;
if (destsize == 4)
vcnt = 2;
- else if (destsize == 2 && logical_clusterbits == 12)
+ else if (destsize == 2 && lclusterbits <= 12)
vcnt = 16;
else
return ERR_PTR(-EINVAL);
+ lobits = max(lclusterbits, ilog2(Z_EROFS_LI_D0_CBLKCNT) + 1U);
encodebits = (vcnt * destsize * 8 - 32) / vcnt;
blkaddr = *blkaddr_ret;
@@ -656,7 +657,7 @@ static void *write_compacted_indexes(u8 *out,
*dummy_head = false;
} else if (i + 1 == vcnt) {
offset = min_t(u16, cv[i].u.delta[1],
- (1 << logical_clusterbits) - 1);
+ (1 << lobits) - 1);
} else {
offset = cv[i].u.delta[0];
}
@@ -676,7 +677,7 @@ static void *write_compacted_indexes(u8 *out,
DBG_BUGON(cv[i].u.blkaddr);
}
}
- v = (cv[i].clustertype << logical_clusterbits) | offset;
+ v = (cv[i].clustertype << lobits) | offset;
rem = pos & 7;
ch = out[pos / 8] & ((1 << rem) - 1);
out[pos / 8] = (v << rem) | ch;
@@ -711,7 +712,7 @@ int z_erofs_convert_to_compacted_format(struct erofs_inode *inode,
bool dummy_head;
bool big_pcluster = erofs_sb_has_big_pcluster(sbi);
- if (logical_clusterbits < sbi->blkszbits || sbi->blkszbits < 12)
+ if (logical_clusterbits < sbi->blkszbits)
return -EINVAL;
if (logical_clusterbits > 14) {
erofs_err("compact format is unsupported for lcluster size %u",
@@ -720,7 +721,7 @@ int z_erofs_convert_to_compacted_format(struct erofs_inode *inode,
}
if (inode->z_advise & Z_EROFS_ADVISE_COMPACTED_2B) {
- if (logical_clusterbits != 12) {
+ if (logical_clusterbits > 12) {
erofs_err("compact 2B is unsupported for lcluster size %u",
1 << logical_clusterbits);
return -EINVAL;
--
2.39.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] erofs-utils: lib: fix up compact indexes for block size < 4096
2023-11-23 5:22 [PATCH 1/2] erofs-utils: lib: fix up compact indexes for block size < 4096 Gao Xiang
2023-11-23 5:22 ` [PATCH 2/2] erofs-utils: mkfs: support compact indexes for smaller block sizes Gao Xiang
@ 2023-11-23 9:11 ` Yue Hu
1 sibling, 0 replies; 4+ messages in thread
From: Yue Hu @ 2023-11-23 9:11 UTC (permalink / raw)
To: Gao Xiang; +Cc: huyue2, linux-erofs
On Thu, 23 Nov 2023 13:22:44 +0800
Gao Xiang <hsiangkao@linux.alibaba.com> wrote:
> Previously, the block size always equaled to PAGE_SIZE in kernel,
> therefore `lclusterbits` couldn't be less than 12.
>
> Since sub-page compressed blocks are now considered, `lobits` for
> a lcluster in each pack of compact indexes cannot always be
> `lclusterbits` as before. Otherwise, there is no enough room for
> the special value `Z_EROFS_LI_D0_CBLKCNT`.
>
> To support smaller block sizes, `lobits` for each compacted lcluster is
> now calculated as:
> lobits = max(lclusterbits, ilog2(Z_EROFS_LI_D0_CBLKCNT) + 1)
>
> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Reviewed-by: Yue Hu <huyue2@coolpad.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] erofs-utils: mkfs: support compact indexes for smaller block sizes
2023-11-23 5:22 ` [PATCH 2/2] erofs-utils: mkfs: support compact indexes for smaller block sizes Gao Xiang
@ 2023-11-23 9:12 ` Yue Hu
0 siblings, 0 replies; 4+ messages in thread
From: Yue Hu @ 2023-11-23 9:12 UTC (permalink / raw)
To: Gao Xiang; +Cc: huyue2, linux-erofs
On Thu, 23 Nov 2023 13:22:45 +0800
Gao Xiang <hsiangkao@linux.alibaba.com> wrote:
> This commit also adds mkfs support of compact indexes for smaller
> block sizes (less than 4096).
>
> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Reviewed-by: Yue Hu <huyue2@coolpad.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-11-23 9:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-23 5:22 [PATCH 1/2] erofs-utils: lib: fix up compact indexes for block size < 4096 Gao Xiang
2023-11-23 5:22 ` [PATCH 2/2] erofs-utils: mkfs: support compact indexes for smaller block sizes Gao Xiang
2023-11-23 9:12 ` Yue Hu
2023-11-23 9:11 ` [PATCH 1/2] erofs-utils: lib: fix up compact indexes for block size < 4096 Yue Hu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox