[PATCH v7 5/5] erofs-utils: mkfs: introduce inner-file multi-threaded compression

Gao Xiang hsiangkao at linux.alibaba.com
Fri Mar 15 14:31:36 AEDT 2024



On 2024/3/15 09:10, Gao Xiang wrote:
> From: Yifan Zhao <zhaoyifan at sjtu.edu.cn>
> 
> Currently, the creation of EROFS compressed image creation is
> single-threaded, which suffers from performance issues. This patch
> attempts to address it by compressing the large file in parallel.
> 
> Specifically, each input file larger than 16MB is splited into segments,
> and each worker thread compresses a segment as if it were a separate
> file. Finally, the main thread merges all the compressed segments.
> 
> Multi-threaded compression is not compatible with -Ededupe,
> -E(all-)fragments and -Eztailpacking for now.
> 
> Signed-off-by: Yifan Zhao <zhaoyifan at sjtu.edu.cn>
> Co-authored-by: Tong Xin <xin_tong at sjtu.edu.cn>
> Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
> ---
> v7:
>   - support -Eztailpacking;

Apply the following diff to fix this:

diff --git a/lib/compress.c b/lib/compress.c
index 0d796c8..7ad48b0 100644
--- a/lib/compress.c
+++ b/lib/compress.c
@@ -509,10 +509,10 @@ static int __z_erofs_compress_one(struct z_erofs_compress_sctx *ctx,
  	struct erofs_compress *const h = ctx->chandle;
  	unsigned int len = ctx->tail - ctx->head;
  	bool is_packed_inode = erofs_is_packed_inode(inode);
-	bool final = !ctx->remaining;
-	bool may_packing = (cfg.c_fragments && final && !is_packed_inode &&
-			    !z_erofs_mt_enabled);
-	bool may_inline = (cfg.c_ztailpacking && final && !may_packing);
+	bool tsg = (ctx->seg_idx + 1 >= ctx->seg_num), final = !ctx->remaining;
+	bool may_packing = (cfg.c_fragments && tsg && final &&
+			    !is_packed_inode && !z_erofs_mt_enabled);
+	bool may_inline = (cfg.c_ztailpacking && tsg && final && !may_packing);
  	unsigned int compressedsize;
  	int ret;

Thanks,
Gao Xiang


More information about the Linux-erofs mailing list