Linux-EROFS Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Gao Xiang <xiang.gao@docker.com>
To: linux-erofs@lists.ozlabs.org
Cc: Gao Xiang <xiang.gao@docker.com>
Subject: [PATCH 2/5] erofs-utils: lib: use positional reads for single-threaded compression
Date: Tue,  3 Nov 2026 01:45:44 +0100	[thread overview]
Message-ID: <20261103004547.15053-2-xiang.gao@docker.com> (raw)
In-Reply-To: <20261103004547.15053-1-xiang.gao@docker.com>

Use explicit offsets when reading compression input. Skip segment-level
fragment matching for the single-threaded context, which handles it
before compression.

Assisted-by: ChatGPT:gpt-6.1-sol
Signed-off-by: Gao Xiang <xiang.gao@docker.com>
---
 lib/compress.c | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/lib/compress.c b/lib/compress.c
index 8305543..aa60f14 100644
--- a/lib/compress.c
+++ b/lib/compress.c
@@ -65,6 +65,8 @@ struct z_erofs_compress_ictx {		/* inode context */
 #endif
 };
 
+static struct z_erofs_compress_ictx g_ictx;
+
 struct z_erofs_compress_sctx {		/* segment context */
 	union {
 		struct list_head extents;
@@ -1345,16 +1347,18 @@ int z_erofs_compress_segment(struct z_erofs_compress_sctx *ctx,
 	struct erofs_vfile *vf = ictx->vf;
 	int ret;
 
-	DBG_BUGON(offset != -1 && frag && inode->fragment_size);
-	if (offset != -1 && frag && !inode->fragment_size &&
-	    params->fragdedupe != EROFS_FRAGDEDUPE_OFF) {
-		ret = erofs_fragment_findmatch(inode, vf, ictx->fpos,
-					       ictx->tofh);
-		if (ret < 0)
-			return ret;
-		if (inode->fragment_size > ctx->remaining)
-			inode->fragment_size = ctx->remaining;
-		ctx->remaining -= inode->fragment_size;
+	if (ictx != &g_ictx && offset != -1 && frag) {
+		DBG_BUGON(inode->fragment_size);
+		if (!inode->fragment_size &&
+		    params->fragdedupe != EROFS_FRAGDEDUPE_OFF) {
+			ret = erofs_fragment_findmatch(inode, vf, ictx->fpos,
+						       ictx->tofh);
+			if (ret < 0)
+				return ret;
+			if (inode->fragment_size > ctx->remaining)
+				inode->fragment_size = ctx->remaining;
+			ctx->remaining -= inode->fragment_size;
+		}
 	}
 
 	ctx->pstart = pstart;
@@ -1579,8 +1583,6 @@ out:
 	return err < 0 ? ERR_PTR(err) : metabuf;
 }
 
-static struct z_erofs_compress_ictx g_ictx;
-
 #ifdef EROFS_MT_ENABLED
 void *z_erofs_mt_wq_tls_alloc(struct erofs_workqueue *wq, void *ptr)
 {
@@ -2169,7 +2171,7 @@ int erofs_write_compressed_file(struct z_erofs_compress_ictx *ictx)
 	};
 	init_list_head(&sctx.extents);
 
-	ret = z_erofs_compress_segment(&sctx, -1, pstart);
+	ret = z_erofs_compress_segment(&sctx, 0, pstart);
 	if (ret)
 		goto err_free_idata;
 
-- 
2.54.0 (Apple Git-157)



  reply	other threads:[~2026-11-03  0:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03  0:45 [PATCH 1/5] erofs-utils: lib: track packed inode position explicitly Gao Xiang
2026-11-03  0:45 ` Gao Xiang [this message]
2026-11-03  0:45 ` [PATCH 3/5] erofs-utils: lib: fix S3 and OCI portability Gao Xiang
2026-11-03  0:45 ` [PATCH 4/5] erofs-utils: add native Windows support Gao Xiang
2026-11-03  0:45 ` [PATCH 5/5] erofs-utils: lib: reject seeks on Windows pipes Gao Xiang
2026-11-03  3:56 ` [PATCH 1/5] erofs-utils: lib: track packed inode position explicitly Yifan Zhao

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=20261103004547.15053-2-xiang.gao@docker.com \
    --to=xiang.gao@docker.com \
    --cc=linux-erofs@lists.ozlabs.org \
    /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