From: Gao Xiang <xiang@kernel.org>
To: linux-erofs@lists.ozlabs.org
Cc: Gao Xiang <xiang@kernel.org>
Subject: [PATCH v2 2/4] erofs-utils: lib: improve ztailinline fallback
Date: Tue, 15 Sep 2026 14:21:37 +0800 [thread overview]
Message-ID: <20260915062139.54810-2-xiang@kernel.org> (raw)
In-Reply-To: <20260915062139.54810-1-xiang@kernel.org>
Currently, on-disk metadata is dumped in the end,so there is no need
to limit the ztailinline fallback to the last lcluster since we could
adjust the last in-memory extents.
Drop `eof_tailraw` and decompress the inline data instead when
falling back.
Signed-off-by: Gao Xiang <xiang@kernel.org>
---
include/erofs/internal.h | 4 ---
lib/compress.c | 56 +++++++++++++++++++++++++++-------------
lib/inode.c | 10 ++++---
lib/liberofs_compress.h | 2 +-
4 files changed, 45 insertions(+), 27 deletions(-)
diff --git a/include/erofs/internal.h b/include/erofs/internal.h
index 3ca5553..d905077 100644
--- a/include/erofs/internal.h
+++ b/include/erofs/internal.h
@@ -285,10 +285,6 @@ struct erofs_inode {
void *idata;
- /* (ztailpacking) in order to recover uncompressed EOF data */
- void *eof_tailraw;
- unsigned int eof_tailrawsize;
-
union {
void *chunkindexes;
struct {
diff --git a/lib/compress.c b/lib/compress.c
index 3e8f9b6..ef79eaa 100644
--- a/lib/compress.c
+++ b/lib/compress.c
@@ -26,6 +26,7 @@
#include "liberofs_compress.h"
#include "liberofs_fragments.h"
#include "liberofs_metabox.h"
+#include "erofs/decompress.h"
#define Z_EROFS_DESTBUF_SZ (Z_EROFS_PCLUSTER_MAX_SIZE + EROFS_MAX_BLOCK_SIZE * 2)
@@ -688,15 +689,6 @@ frag_packing:
ictx->fragemitted = true;
/* tailpcluster should be less than 1 block */
} else if (may_inline && len == e->length && compressedsize < blksz) {
- if (ctx->clusterofs + len <= blksz) {
- inode->eof_tailraw = malloc(len);
- if (!inode->eof_tailraw)
- return -ENOMEM;
-
- memcpy(inode->eof_tailraw, ctx->queue + ctx->head, len);
- inode->eof_tailrawsize = len;
- }
-
ret = z_erofs_fill_inline_data(inode, dst,
compressedsize, false);
if (ret < 0)
@@ -1267,25 +1259,53 @@ static void z_erofs_write_extents(struct erofs_inode *inode,
DBG_BUGON(metacur - metabuf != inode->extent_isize);
}
-void z_erofs_drop_inline_pcluster(struct erofs_inode *inode)
+int z_erofs_drop_inline_pcluster(struct erofs_inode *inode)
{
+ struct erofs_sb_info *sbi = inode->sbi;
struct z_erofs_metadata_ctx *ctx = inode->compressmeta;
struct z_erofs_extent_item *ei;
+ char raw[EROFS_MAX_BLOCK_SIZE];
+ unsigned int rawsz, encsz;
+ int err;
inode->z_advise &= ~Z_EROFS_ADVISE_INLINE_PCLUSTER;
- if (!inode->eof_tailraw)
- return;
- DBG_BUGON(inode->idata_type == EROFS_IDATA_TYPE_RAW);
+ if (inode->idata_type == EROFS_IDATA_TYPE_RAW ||
+ (inode->z_advise & Z_EROFS_ADVISE_INTERLACED_PCLUSTER))
+ return 0;
ei = list_last_entry(&ctx->extents, struct z_erofs_extent_item, list);
DBG_BUGON(ei->e.raw);
- ei->e.raw = true;
+
+ rawsz = ei->e.length;
+ if (rawsz > erofs_blksiz(sbi))
+ return 0;
+ encsz = inode->idata_size;
+
+ erofs_err("ballooning tail inline data of %s from %u to %u bytes",
+ inode->i_srcpath, encsz, rawsz);
+ err = z_erofs_decompress(&(struct z_erofs_decompress_req) {
+ .sbi = sbi,
+ .in = inode->idata,
+ .out = raw,
+ .decodedskip = 0,
+ .interlaced_offset = 0,
+ .inputsize = encsz,
+ .decodedlength = rawsz,
+ .alg = ei->e.algofmt,
+ .partial_decoding = false,
+ });
+ if (err < 0)
+ return err;
free(inode->idata);
- /* replace idata with prepared uncompressed data */
- inode->idata = inode->eof_tailraw;
- inode->idata_size = inode->eof_tailrawsize;
+ inode->idata_size = 0;
+ inode->idata = malloc(rawsz);
+ if (!inode->idata)
+ return -ENOMEM;
+ memcpy(inode->idata, raw, rawsz);
+ inode->idata_size = rawsz;
inode->idata_type = EROFS_IDATA_TYPE_RAW;
- inode->eof_tailraw = NULL;
+ ei->e.raw = true;
+ return 0;
}
int z_erofs_compress_segment(struct z_erofs_compress_sctx *ctx,
diff --git a/lib/inode.c b/lib/inode.c
index 62958d1..1e497a0 100644
--- a/lib/inode.c
+++ b/lib/inode.c
@@ -150,7 +150,6 @@ unsigned int erofs_iput(struct erofs_inode *inode)
free(d);
z_erofs_free_metadata(inode);
- free(inode->eof_tailraw);
erofs_remove_ihash(inode);
if (!erofs_is_special_identifier(inode->i_srcpath))
free(inode->i_srcpath);
@@ -1050,10 +1049,13 @@ static int erofs_prepare_inode_buffer(struct erofs_importer *im,
if (bh == ERR_PTR(-ENOSPC)) {
int ret;
- if (is_inode_layout_compression(inode))
- z_erofs_drop_inline_pcluster(inode);
- else
+ if (is_inode_layout_compression(inode)) {
+ ret = z_erofs_drop_inline_pcluster(inode);
+ if (ret)
+ return ret;
+ } else {
inode->datalayout = EROFS_INODE_FLAT_PLAIN;
+ }
noinline:
/* expend an extra block for tail-end data */
ret = erofs_prepare_tail_block(inode);
diff --git a/lib/liberofs_compress.h b/lib/liberofs_compress.h
index 50b3804..43227a2 100644
--- a/lib/liberofs_compress.h
+++ b/lib/liberofs_compress.h
@@ -14,7 +14,7 @@
struct z_erofs_compress_ictx;
-void z_erofs_drop_inline_pcluster(struct erofs_inode *inode);
+int z_erofs_drop_inline_pcluster(struct erofs_inode *inode);
void *erofs_prepare_compressed_file(struct erofs_importer *im,
struct erofs_inode *inode);
void erofs_bind_compressed_file_with_fd(struct z_erofs_compress_ictx *ictx,
--
2.47.3
next prev parent reply other threads:[~2026-09-15 6:22 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-15 6:21 [PATCH v2 1/4] erofs-utils: record algorithm id in in-memory compression extents Gao Xiang
2026-09-15 6:21 ` Gao Xiang [this message]
2026-09-15 6:21 ` [PATCH v2 3/4] erofs-utils: lib: switch to use per-inode big pcluster flag Gao Xiang
2026-09-15 6:21 ` [PATCH v2 4/4] erofs-utils: mkfs: support rebuild mode for compressed inodes 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=20260915062139.54810-2-xiang@kernel.org \
--to=xiang@kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.