Linux-EROFS Archive mirror
 help / color / mirror / Atom feed
From: Noboru Asai <asai@sijam.com>
To: hsiangkao@linux.alibaba.com, zhaoyifan@sjtu.edu.cn
Cc: linux-erofs@lists.ozlabs.org
Subject: [PATCH] erofs-utils: move pclustersize to struct z_erofs_compress_sctx
Date: Thu, 21 Mar 2024 16:02:36 +0900	[thread overview]
Message-ID: <20240321070236.2396573-1-asai@sijam.com> (raw)

With -E(all-)fragments, pclustersize has a different value per segment,
so move it to struct z_erofs_compress_sctx.

Signed-off-by: Noboru Asai <asai@sijam.com>
---
 lib/compress.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/lib/compress.c b/lib/compress.c
index 9eb40b5..0803a63 100644
--- a/lib/compress.c
+++ b/lib/compress.c
@@ -40,7 +40,6 @@ struct z_erofs_extent_item {
 struct z_erofs_compress_ictx {		/* inode context */
 	struct erofs_inode *inode;
 	int fd;
-	unsigned int pclustersize;
 
 	u32 tof_chksum;
 	bool fix_dedupedfrag;
@@ -64,6 +63,7 @@ struct z_erofs_compress_sctx {		/* segment context */
 
 	unsigned int head, tail;
 	erofs_off_t remaining;
+	unsigned int pclustersize;
 	erofs_blk_t blkaddr;		/* pointing to the next blkaddr */
 	u16 clusterofs;
 
@@ -479,7 +479,7 @@ static bool z_erofs_fixup_deduped_fragment(struct z_erofs_compress_sctx *ctx,
 
 	/* try to fix again if it gets larger (should be rare) */
 	if (inode->fragment_size < newsize) {
-		ictx->pclustersize = min_t(erofs_off_t,
+		ctx->pclustersize = min_t(erofs_off_t,
 				z_erofs_get_max_pclustersize(inode),
 				roundup(newsize - inode->fragment_size,
 					erofs_blksiz(sbi)));
@@ -519,12 +519,12 @@ static int __z_erofs_compress_one(struct z_erofs_compress_sctx *ctx,
 	unsigned int compressedsize;
 	int ret;
 
-	if (len <= ictx->pclustersize) {
+	if (len <= ctx->pclustersize) {
 		if (!final || !len)
 			return 1;
 		if (may_packing) {
 			if (inode->fragment_size && !ictx->fix_dedupedfrag) {
-				ictx->pclustersize = roundup(len, blksz);
+				ctx->pclustersize = roundup(len, blksz);
 				goto fix_dedupedfrag;
 			}
 			e->length = len;
@@ -536,7 +536,7 @@ static int __z_erofs_compress_one(struct z_erofs_compress_sctx *ctx,
 
 	e->length = min(len, cfg.c_max_decompressed_extent_bytes);
 	ret = erofs_compress_destsize(h, ctx->queue + ctx->head,
-				      &e->length, dst, ictx->pclustersize);
+				      &e->length, dst, ctx->pclustersize);
 	if (ret <= 0) {
 		erofs_err("failed to compress %s: %s", inode->i_srcpath,
 			  erofs_strerror(ret));
@@ -573,7 +573,7 @@ nocompression:
 		e->compressedblks = 1;
 		e->raw = true;
 	} else if (may_packing && len == e->length &&
-		   compressedsize < ictx->pclustersize &&
+		   compressedsize < ctx->pclustersize &&
 		   (!inode->fragment_size || ictx->fix_dedupedfrag)) {
 frag_packing:
 		ret = z_erofs_pack_fragments(inode, ctx->queue + ctx->head,
@@ -612,7 +612,7 @@ frag_packing:
 		if (may_packing && len == e->length &&
 		    (compressedsize & (blksz - 1)) &&
 		    ctx->tail < Z_EROFS_COMPR_QUEUE_SZ) {
-			ictx->pclustersize = roundup(compressedsize, blksz);
+			ctx->pclustersize = roundup(compressedsize, blksz);
 			goto fix_dedupedfrag;
 		}
 
@@ -1202,6 +1202,7 @@ void z_erofs_mt_workfn(struct erofs_work *work, void *tlsp)
 		goto out;
 	}
 	sctx->memoff = 0;
+	sctx->pclustersize = z_erofs_get_max_pclustersize(sctx->ictx->inode);
 
 	ret = z_erofs_compress_segment(sctx, sctx->seg_idx * cfg.c_segment_size,
 				       EROFS_NULL_ADDR);
@@ -1460,7 +1461,6 @@ int erofs_write_compressed_file(struct erofs_inode *inode, int fd)
 	}
 
 	ctx.inode = inode;
-	ctx.pclustersize = z_erofs_get_max_pclustersize(inode);
 	ctx.metacur = compressmeta + Z_EROFS_LEGACY_MAP_HEADER_SIZE;
 	init_list_head(&ctx.extents);
 	ctx.fd = fd;
@@ -1500,6 +1500,7 @@ int erofs_write_compressed_file(struct erofs_inode *inode, int fd)
 		sctx.seg_num = 1;
 		sctx.seg_idx = 0;
 		sctx.pivot = &dummy_pivot;
+		sctx.pclustersize = z_erofs_get_max_pclustersize(inode);
 
 		ret = z_erofs_compress_segment(&sctx, -1, blkaddr);
 		if (ret)
-- 
2.44.0


             reply	other threads:[~2024-03-21  7:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-21  7:02 Noboru Asai [this message]
2024-03-21  7:09 ` [PATCH] erofs-utils: move pclustersize to struct z_erofs_compress_sctx Gao Xiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240321070236.2396573-1-asai@sijam.com \
    --to=asai@sijam.com \
    --cc=hsiangkao@linux.alibaba.com \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=zhaoyifan@sjtu.edu.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).