From nobody Sun Feb 8 10:04:20 2026 Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A17B8245032 for ; Wed, 5 Mar 2025 12:40:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.99 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741178425; cv=none; b=gpWgbKssJ4IWDQoBo5mRRY0RFT6z4qh67/yzsiodinxyKPsUWWAJ5nX1uGJWHCjHYESFrDWFDU5BgOkK/h/bAT/jbWSJ8AXgsNhvnFfS+yqiJ+4doA4YwDXVFdtB8StQChsEEATmvoGvywp1md6Uok17JiRvHpeAOd4xeSkgwRk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741178425; c=relaxed/simple; bh=1EROx++38oiW3cLtJKLBOf0iMT9uBjd3aFi0AgW5vwQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=MoRHuYllLioJ6VCyZ4G+PyfE5CbU29Ex98+1/NBvd25VBwBZgyYzLQO8KOQS5CcLuRlSOjC8VbXZ5ZTIGyLeAcrEXwOKiuHb5ZbiVTwoIoyPT+AMeTFWjRW+rnlzdm8aq269AtbH2ie2SAlRrzxsSvlmCmr7mTbV6+uqjOznGB8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=x+uglXdv; arc=none smtp.client-ip=115.124.30.99 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="x+uglXdv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1741178413; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=cVfb0T8HwHzTaiLekCt8v37S7VbF2szx4FWIxEZYak0=; b=x+uglXdvqWGq0+IhDCkaA4nenM6K4kw2zF+vSEbG7OdXOseCy7S58H76xhJv87xbuKVpIs0ctvQPqVudypaYgHS/ZvVrp0aVGZ7r58XZTfqTcQkx6DDw33luZ9Rx0VP+cIOcFERIgCdQJF4bMijiBvQJKmxu3d/afmnUN15KiQk= Received: from x31i01179.sqa.na131.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0WQlT3Jv_1741178409 cluster:ay36) by smtp.aliyun-inc.com; Wed, 05 Mar 2025 20:40:13 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org Cc: LKML , Gao Xiang Subject: [PATCH] erofs: move {in,out}pages into struct z_erofs_decompress_req Date: Wed, 5 Mar 2025 20:40:07 +0800 Message-ID: <20250305124007.1810731-1-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.43.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It seems that all compressors need those two values, so just move them into the common structure. `struct z_erofs_lz4_decompress_ctx` can be dropped too. Signed-off-by: Gao Xiang Reviewed-by: Chao Yu --- fs/erofs/compress.h | 2 +- fs/erofs/decompressor.c | 93 +++++++++++++-------------------- fs/erofs/decompressor_deflate.c | 8 +-- fs/erofs/decompressor_lzma.c | 8 +-- fs/erofs/decompressor_zstd.c | 8 +-- fs/erofs/zdata.c | 2 + 6 files changed, 41 insertions(+), 80 deletions(-) diff --git a/fs/erofs/compress.h b/fs/erofs/compress.h index 65ff39401020..2704d7a592a5 100644 --- a/fs/erofs/compress.h +++ b/fs/erofs/compress.h @@ -11,6 +11,7 @@ struct z_erofs_decompress_req { struct super_block *sb; struct page **in, **out; + unsigned int inpages, outpages; unsigned short pageofs_in, pageofs_out; unsigned int inputsize, outputsize; =20 @@ -59,7 +60,6 @@ extern const struct z_erofs_decompressor *z_erofs_decomp[= ]; =20 struct z_erofs_stream_dctx { struct z_erofs_decompress_req *rq; - unsigned int inpages, outpages; /* # of {en,de}coded pages */ int no, ni; /* the current {en,de}coded page # */ =20 unsigned int avail_out; /* remaining bytes in the decoded buffer */ diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c index 2b123b070a42..50e350b10f89 100644 --- a/fs/erofs/decompressor.c +++ b/fs/erofs/decompressor.c @@ -9,14 +9,6 @@ =20 #define LZ4_MAX_DISTANCE_PAGES (DIV_ROUND_UP(LZ4_DISTANCE_MAX, PAGE_SIZE) = + 1) =20 -struct z_erofs_lz4_decompress_ctx { - struct z_erofs_decompress_req *rq; - /* # of encoded, decoded pages */ - unsigned int inpages, outpages; - /* decoded block total length (used for in-place decompression) */ - unsigned int oend; -}; - static int z_erofs_load_lz4_config(struct super_block *sb, struct erofs_super_block *dsb, void *data, int size) { @@ -55,10 +47,9 @@ static int z_erofs_load_lz4_config(struct super_block *s= b, * Fill all gaps with bounce pages if it's a sparse page list. Also check = if * all physical pages are consecutive, which can be seen for moderate CR. */ -static int z_erofs_lz4_prepare_dstpages(struct z_erofs_lz4_decompress_ctx = *ctx, +static int z_erofs_lz4_prepare_dstpages(struct z_erofs_decompress_req *rq, struct page **pagepool) { - struct z_erofs_decompress_req *rq =3D ctx->rq; struct page *availables[LZ4_MAX_DISTANCE_PAGES] =3D { NULL }; unsigned long bounced[DIV_ROUND_UP(LZ4_MAX_DISTANCE_PAGES, BITS_PER_LONG)] =3D { 0 }; @@ -68,7 +59,7 @@ static int z_erofs_lz4_prepare_dstpages(struct z_erofs_lz= 4_decompress_ctx *ctx, unsigned int i, j, top; =20 top =3D 0; - for (i =3D j =3D 0; i < ctx->outpages; ++i, ++j) { + for (i =3D j =3D 0; i < rq->outpages; ++i, ++j) { struct page *const page =3D rq->out[i]; struct page *victim; =20 @@ -114,36 +105,36 @@ static int z_erofs_lz4_prepare_dstpages(struct z_erof= s_lz4_decompress_ctx *ctx, return kaddr ? 1 : 0; } =20 -static void *z_erofs_lz4_handle_overlap(struct z_erofs_lz4_decompress_ctx = *ctx, +static void *z_erofs_lz4_handle_overlap(struct z_erofs_decompress_req *rq, void *inpage, void *out, unsigned int *inputmargin, int *maptype, bool may_inplace) { - struct z_erofs_decompress_req *rq =3D ctx->rq; - unsigned int omargin, total, i; + unsigned int oend, omargin, total, i; struct page **in; void *src, *tmp; =20 if (rq->inplace_io) { - omargin =3D PAGE_ALIGN(ctx->oend) - ctx->oend; + oend =3D rq->pageofs_out + rq->outputsize; + omargin =3D PAGE_ALIGN(oend) - oend; if (rq->partial_decoding || !may_inplace || omargin < LZ4_DECOMPRESS_INPLACE_MARGIN(rq->inputsize)) goto docopy; =20 - for (i =3D 0; i < ctx->inpages; ++i) - if (rq->out[ctx->outpages - ctx->inpages + i] !=3D + for (i =3D 0; i < rq->inpages; ++i) + if (rq->out[rq->outpages - rq->inpages + i] !=3D rq->in[i]) goto docopy; kunmap_local(inpage); *maptype =3D 3; - return out + ((ctx->outpages - ctx->inpages) << PAGE_SHIFT); + return out + ((rq->outpages - rq->inpages) << PAGE_SHIFT); } =20 - if (ctx->inpages <=3D 1) { + if (rq->inpages <=3D 1) { *maptype =3D 0; return inpage; } kunmap_local(inpage); - src =3D erofs_vm_map_ram(rq->in, ctx->inpages); + src =3D erofs_vm_map_ram(rq->in, rq->inpages); if (!src) return ERR_PTR(-ENOMEM); *maptype =3D 1; @@ -152,7 +143,7 @@ static void *z_erofs_lz4_handle_overlap(struct z_erofs_= lz4_decompress_ctx *ctx, docopy: /* Or copy compressed data which can be overlapped to per-CPU buffer */ in =3D rq->in; - src =3D z_erofs_get_gbuf(ctx->inpages); + src =3D z_erofs_get_gbuf(rq->inpages); if (!src) { DBG_BUGON(1); kunmap_local(inpage); @@ -197,10 +188,8 @@ int z_erofs_fixup_insize(struct z_erofs_decompress_req= *rq, const char *padbuf, return 0; } =20 -static int z_erofs_lz4_decompress_mem(struct z_erofs_lz4_decompress_ctx *c= tx, - u8 *dst) +static int z_erofs_lz4_decompress_mem(struct z_erofs_decompress_req *rq, u= 8 *dst) { - struct z_erofs_decompress_req *rq =3D ctx->rq; bool support_0padding =3D false, may_inplace =3D false; unsigned int inputmargin; u8 *out, *headpage, *src; @@ -224,7 +213,7 @@ static int z_erofs_lz4_decompress_mem(struct z_erofs_lz= 4_decompress_ctx *ctx, } =20 inputmargin =3D rq->pageofs_in; - src =3D z_erofs_lz4_handle_overlap(ctx, headpage, dst, &inputmargin, + src =3D z_erofs_lz4_handle_overlap(rq, headpage, dst, &inputmargin, &maptype, may_inplace); if (IS_ERR(src)) return PTR_ERR(src); @@ -251,7 +240,7 @@ static int z_erofs_lz4_decompress_mem(struct z_erofs_lz= 4_decompress_ctx *ctx, if (maptype =3D=3D 0) { kunmap_local(headpage); } else if (maptype =3D=3D 1) { - vm_unmap_ram(src, ctx->inpages); + vm_unmap_ram(src, rq->inpages); } else if (maptype =3D=3D 2) { z_erofs_put_gbuf(src); } else if (maptype !=3D 3) { @@ -264,54 +253,42 @@ static int z_erofs_lz4_decompress_mem(struct z_erofs_= lz4_decompress_ctx *ctx, static int z_erofs_lz4_decompress(struct z_erofs_decompress_req *rq, struct page **pagepool) { - struct z_erofs_lz4_decompress_ctx ctx; unsigned int dst_maptype; void *dst; int ret; =20 - ctx.rq =3D rq; - ctx.oend =3D rq->pageofs_out + rq->outputsize; - ctx.outpages =3D PAGE_ALIGN(ctx.oend) >> PAGE_SHIFT; - ctx.inpages =3D PAGE_ALIGN(rq->inputsize) >> PAGE_SHIFT; - /* one optimized fast path only for non bigpcluster cases yet */ - if (ctx.inpages =3D=3D 1 && ctx.outpages =3D=3D 1 && !rq->inplace_io) { + if (rq->inpages =3D=3D 1 && rq->outpages =3D=3D 1 && !rq->inplace_io) { DBG_BUGON(!*rq->out); dst =3D kmap_local_page(*rq->out); dst_maptype =3D 0; - goto dstmap_out; - } - - /* general decoding path which can be used for all cases */ - ret =3D z_erofs_lz4_prepare_dstpages(&ctx, pagepool); - if (ret < 0) { - return ret; - } else if (ret > 0) { - dst =3D page_address(*rq->out); - dst_maptype =3D 1; } else { - dst =3D erofs_vm_map_ram(rq->out, ctx.outpages); - if (!dst) - return -ENOMEM; - dst_maptype =3D 2; + /* general decoding path which can be used for all cases */ + ret =3D z_erofs_lz4_prepare_dstpages(rq, pagepool); + if (ret < 0) + return ret; + if (ret > 0) { + dst =3D page_address(*rq->out); + dst_maptype =3D 1; + } else { + dst =3D erofs_vm_map_ram(rq->out, rq->outpages); + if (!dst) + return -ENOMEM; + dst_maptype =3D 2; + } } - -dstmap_out: - ret =3D z_erofs_lz4_decompress_mem(&ctx, dst); + ret =3D z_erofs_lz4_decompress_mem(rq, dst); if (!dst_maptype) kunmap_local(dst); else if (dst_maptype =3D=3D 2) - vm_unmap_ram(dst, ctx.outpages); + vm_unmap_ram(dst, rq->outpages); return ret; } =20 static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq, struct page **pagepool) { - const unsigned int nrpages_in =3D - PAGE_ALIGN(rq->pageofs_in + rq->inputsize) >> PAGE_SHIFT; - const unsigned int nrpages_out =3D - PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT; + const unsigned int nrpages_in =3D rq->inpages, nrpages_out =3D rq->outpag= es; const unsigned int bs =3D rq->sb->s_blocksize; unsigned int cur =3D 0, ni =3D 0, no, pi, po, insz, cnt; u8 *kin; @@ -373,7 +350,7 @@ int z_erofs_stream_switch_bufs(struct z_erofs_stream_dc= tx *dctx, void **dst, unsigned int j; =20 if (!dctx->avail_out) { - if (++dctx->no >=3D dctx->outpages || !rq->outputsize) { + if (++dctx->no >=3D rq->outpages || !rq->outputsize) { erofs_err(sb, "insufficient space for decompressed data"); return -EFSCORRUPTED; } @@ -401,7 +378,7 @@ int z_erofs_stream_switch_bufs(struct z_erofs_stream_dc= tx *dctx, void **dst, } =20 if (dctx->inbuf_pos =3D=3D dctx->inbuf_sz && rq->inputsize) { - if (++dctx->ni >=3D dctx->inpages) { + if (++dctx->ni >=3D rq->inpages) { erofs_err(sb, "invalid compressed data"); return -EFSCORRUPTED; } @@ -434,7 +411,7 @@ int z_erofs_stream_switch_bufs(struct z_erofs_stream_dc= tx *dctx, void **dst, dctx->bounced =3D true; } =20 - for (j =3D dctx->ni + 1; j < dctx->inpages; ++j) { + for (j =3D dctx->ni + 1; j < rq->inpages; ++j) { if (rq->out[dctx->no] !=3D rq->in[j]) continue; tmppage =3D erofs_allocpage(pgpl, rq->gfp); diff --git a/fs/erofs/decompressor_deflate.c b/fs/erofs/decompressor_deflat= e.c index 5070d2fcc737..c6908a487054 100644 --- a/fs/erofs/decompressor_deflate.c +++ b/fs/erofs/decompressor_deflate.c @@ -101,13 +101,7 @@ static int z_erofs_deflate_decompress(struct z_erofs_d= ecompress_req *rq, struct page **pgpl) { struct super_block *sb =3D rq->sb; - struct z_erofs_stream_dctx dctx =3D { - .rq =3D rq, - .inpages =3D PAGE_ALIGN(rq->inputsize) >> PAGE_SHIFT, - .outpages =3D PAGE_ALIGN(rq->pageofs_out + rq->outputsize) - >> PAGE_SHIFT, - .no =3D -1, .ni =3D 0, - }; + struct z_erofs_stream_dctx dctx =3D { .rq =3D rq, .no =3D -1, .ni =3D 0 }; struct z_erofs_deflate *strm; int zerr, err; =20 diff --git a/fs/erofs/decompressor_lzma.c b/fs/erofs/decompressor_lzma.c index 40666815046f..832cffb83a66 100644 --- a/fs/erofs/decompressor_lzma.c +++ b/fs/erofs/decompressor_lzma.c @@ -150,13 +150,7 @@ static int z_erofs_lzma_decompress(struct z_erofs_deco= mpress_req *rq, struct page **pgpl) { struct super_block *sb =3D rq->sb; - struct z_erofs_stream_dctx dctx =3D { - .rq =3D rq, - .inpages =3D PAGE_ALIGN(rq->inputsize) >> PAGE_SHIFT, - .outpages =3D PAGE_ALIGN(rq->pageofs_out + rq->outputsize) - >> PAGE_SHIFT, - .no =3D -1, .ni =3D 0, - }; + struct z_erofs_stream_dctx dctx =3D { .rq =3D rq, .no =3D -1, .ni =3D 0 }; struct xz_buf buf =3D {}; struct z_erofs_lzma *strm; enum xz_ret xz_err; diff --git a/fs/erofs/decompressor_zstd.c b/fs/erofs/decompressor_zstd.c index 7e177304967e..b4bfe14229f9 100644 --- a/fs/erofs/decompressor_zstd.c +++ b/fs/erofs/decompressor_zstd.c @@ -139,13 +139,7 @@ static int z_erofs_zstd_decompress(struct z_erofs_deco= mpress_req *rq, struct page **pgpl) { struct super_block *sb =3D rq->sb; - struct z_erofs_stream_dctx dctx =3D { - .rq =3D rq, - .inpages =3D PAGE_ALIGN(rq->inputsize) >> PAGE_SHIFT, - .outpages =3D PAGE_ALIGN(rq->pageofs_out + rq->outputsize) - >> PAGE_SHIFT, - .no =3D -1, .ni =3D 0, - }; + struct z_erofs_stream_dctx dctx =3D { .rq =3D rq, .no =3D -1, .ni =3D 0 }; zstd_in_buffer in_buf =3D { NULL, 0, 0 }; zstd_out_buffer out_buf =3D { NULL, 0, 0 }; struct z_erofs_zstd *strm; diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index ad674eee400a..5e4b65070b86 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -1284,6 +1284,8 @@ static int z_erofs_decompress_pcluster(struct z_erofs= _backend *be, int err) .sb =3D be->sb, .in =3D be->compressed_pages, .out =3D be->decompressed_pages, + .inpages =3D pclusterpages, + .outpages =3D be->nr_pages, .pageofs_in =3D pcl->pageofs_in, .pageofs_out =3D pcl->pageofs_out, .inputsize =3D pcl->pclustersize, --=20 2.43.5