erofs-utils: mkfs: skip the redundant write for ztailpacking block
authorYifan Zhao <zhaoyifan@sjtu.edu.cn>
Thu, 18 Apr 2024 12:23:12 +0000 (20:23 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Mon, 22 Apr 2024 00:39:49 +0000 (08:39 +0800)
z_erofs_merge_segment() doesn't consider the ztailpacking block in the
extent list and unnecessarily writes it back to the disk. This patch
fixes this issue by introducing a new `inlined` field in the struct
`z_erofs_inmem_extent`.

Fixes: 830b27bc2334 ("erofs-utils: mkfs: introduce inner-file multi-threaded compression")
Signed-off-by: Yifan Zhao <zhaoyifan@sjtu.edu.cn>
[ Gao Xiang: simplify a bit. ]
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240418122312.99282-1-xiang@kernel.org
include/erofs/dedupe.h
lib/compress.c
lib/dedupe.c

index 153bd4c83ae2731ca12ab2525cf034a65d714765..4cbfb2ccfb590a3f361709f404196869de2c4054 100644 (file)
@@ -16,7 +16,7 @@ struct z_erofs_inmem_extent {
        erofs_blk_t blkaddr;
        unsigned int compressedblks;
        unsigned int length;
-       bool raw, partial;
+       bool raw, partial, inlined;
 };
 
 struct z_erofs_dedupe_ctx {
index 74c57072986a54529c3a48fb7e9a211a5ebd436a..b084446b58be5bd3500e4134a433f59c72fa1bf2 100644 (file)
@@ -305,6 +305,7 @@ static int z_erofs_compress_dedupe(struct z_erofs_compress_sctx *ctx,
                if (z_erofs_dedupe_match(&dctx))
                        break;
 
+               DBG_BUGON(dctx.e.inlined);
                delta = ctx->queue + ctx->head - dctx.cur;
                /*
                 * For big pcluster dedupe, leave two indices at least to store
@@ -519,6 +520,7 @@ static int __z_erofs_compress_one(struct z_erofs_compress_sctx *ctx,
        unsigned int compressedsize;
        int ret;
 
+       *e = (struct z_erofs_inmem_extent){};
        if (len <= ctx->pclustersize) {
                if (!final || !len)
                        return 1;
@@ -553,16 +555,18 @@ static int __z_erofs_compress_one(struct z_erofs_compress_sctx *ctx,
                if (may_inline && len < blksz) {
                        ret = z_erofs_fill_inline_data(inode,
                                        ctx->queue + ctx->head, len, true);
+                       if (ret < 0)
+                               return ret;
+                       e->inlined = true;
                } else {
                        may_inline = false;
                        may_packing = false;
 nocompression:
                        /* TODO: reset clusterofs to 0 if permitted */
                        ret = write_uncompressed_extent(ctx, len, dst);
+                       if (ret < 0)
+                               return ret;
                }
-
-               if (ret < 0)
-                       return ret;
                e->length = ret;
 
                /*
@@ -598,6 +602,7 @@ frag_packing:
                                compressedsize, false);
                if (ret < 0)
                        return ret;
+               e->inlined = true;
                e->compressedblks = 1;
                e->raw = false;
        } else {
@@ -1151,6 +1156,9 @@ int z_erofs_merge_segment(struct z_erofs_compress_ictx *ictx,
                ei->e.blkaddr = sctx->blkaddr;
                sctx->blkaddr += ei->e.compressedblks;
 
+               /* skip write data but leave blkaddr for inline fallback */
+               if (ei->e.inlined)
+                       continue;
                ret2 = blk_write(sbi, sctx->membuf + blkoff * erofs_blksiz(sbi),
                                 ei->e.blkaddr, ei->e.compressedblks);
                blkoff += ei->e.compressedblks;
index 4b0edbfb3047f791c85988d575903dc1eb56c18f..ed20e7b3ebcad75b8a4eb90113a23a679fb9902e 100644 (file)
@@ -141,6 +141,7 @@ int z_erofs_dedupe_match(struct z_erofs_dedupe_ctx *ctx)
                ctx->e.partial = e->partial ||
                        (window_size + extra < e->original_length);
                ctx->e.raw = e->raw;
+               ctx->e.inlined = false;
                ctx->e.blkaddr = e->compressed_blkaddr;
                ctx->e.compressedblks = e->compressed_blks;
                return 0;