linux-erofs.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Gao Xiang <xiang@kernel.org>
To: linux-erofs@lists.ozlabs.org, Li Guifu <bluce.liguifu@huawei.com>
Cc: Gao Xiang <xiang@kernel.org>
Subject: [PATCH 1/4] erofs-utils: compress trailing data for big pcluster properly
Date: Mon, 10 May 2021 15:23:00 +0800	[thread overview]
Message-ID: <20210510072303.4628-2-xiang@kernel.org> (raw)
In-Reply-To: <20210510072303.4628-1-xiang@kernel.org>

Compress in smaller pcluster size if the trailing data isn't enough for
maximum pcluster size instead of leaving trailing data uncompressed.

Fixes: b71dc92df6f1 ("erofs-utils: mkfs: support multiple block compression")
Signed-off-by: Gao Xiang <xiang@kernel.org>
---
 lib/compress.c   | 11 ++++++++---
 lib/compressor.c |  5 ++++-
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/lib/compress.c b/lib/compress.c
index deef6a2c8ae3..e146416890f0 100644
--- a/lib/compress.c
+++ b/lib/compress.c
@@ -166,9 +166,12 @@ static int vle_compress_one(struct erofs_inode *inode,
 		bool raw;
 
 		if (len <= pclustersize) {
-			if (final)
-				goto nocompression;
-			break;
+			if (final) {
+				if (len <= EROFS_BLKSIZ)
+					goto nocompression;
+			} else {
+				break;
+			}
 		}
 
 		count = len;
@@ -195,6 +198,8 @@ nocompression:
 					EROFS_BLKSIZ - tailused : 0;
 
 			ctx->compressedblks = DIV_ROUND_UP(ret, EROFS_BLKSIZ);
+			DBG_BUGON(ctx->compressedblks * EROFS_BLKSIZ >= count);
+
 			/* zero out garbage trailing data for non-0padding */
 			if (!erofs_sb_has_lz4_0padding())
 				memset(dst + ret, 0,
diff --git a/lib/compressor.c b/lib/compressor.c
index b2434e0e5418..8836e0c785ba 100644
--- a/lib/compressor.c
+++ b/lib/compressor.c
@@ -28,6 +28,7 @@ int erofs_compress_destsize(struct erofs_compress *c,
 			    void *dst,
 			    unsigned int dstsize)
 {
+	unsigned uncompressed_size;
 	int ret;
 
 	DBG_BUGON(!c->alg);
@@ -40,7 +41,9 @@ int erofs_compress_destsize(struct erofs_compress *c,
 		return ret;
 
 	/* check if there is enough gains to compress */
-	if (*srcsize <= dstsize * c->compress_threshold / 100)
+	uncompressed_size = *srcsize;
+	if (roundup(ret, EROFS_BLKSIZ) >= uncompressed_size *
+	    c->compress_threshold / 100)
 		return -EAGAIN;
 	return ret;
 }
-- 
2.20.1


  reply	other threads:[~2021-05-10  7:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-10  7:22 [PATCH 0/4] erofs-utils: prepare for per-(sub)file compression strategies Gao Xiang
2021-05-10  7:23 ` Gao Xiang [this message]
2021-05-10  7:23 ` [PATCH 2/4] erofs-utils: reserve physical_clusterbits[] Gao Xiang
2021-05-10  7:23 ` [PATCH 3/4] erofs-utils: prepare for per-(sub)file compress strategies Gao Xiang
2021-05-10  7:23 ` [PATCH 4/4] erofs-utils: sync up z_erofs_get_extent_compressedlen() 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=20210510072303.4628-2-xiang@kernel.org \
    --to=xiang@kernel.org \
    --cc=bluce.liguifu@huawei.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;
as well as URLs for NNTP newsgroup(s).