From: Xueyuan Chen <xueyuan.chen21@gmail.com>
To: Minchan Kim <minchan@kernel.org>,
Sergey Senozhatsky <senozhatsky@chromium.org>,
Jens Axboe <axboe@kernel.dk>
Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org,
Xueyuan Chen <xueyuan.chen21@gmail.com>
Subject: [PATCH RFC 1/3] zram: allow backends to decompress from two input buffers
Date: Sun, 22 Nov 2026 01:09:24 +0800 [thread overview]
Message-ID: <20261122-zram-split-decomp-mm-rfc-v1-1-4e69b08c0fed@gmail.com> (raw)
In-Reply-To: <20261122-zram-split-decomp-mm-rfc-v1-0-4e69b08c0fed@gmail.com>
Let backends decompress a spanning zsmalloc object directly from its
two scatterlist entries. Keep both fragments mapped for the call.
Use the linear path if the callback is absent or returns -EOPNOTSUPP
before writing output. Propagate other errors.
Signed-off-by: Xueyuan Chen <xueyuan.chen21@gmail.com>
---
drivers/block/zram/zcomp.c | 28 ++++++++++++++++++++++++++++
drivers/block/zram/zcomp.h | 8 ++++++++
2 files changed, 36 insertions(+)
diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c
index 028e2f0f587e..265108b9f332 100644
--- a/drivers/block/zram/zcomp.c
+++ b/drivers/block/zram/zcomp.c
@@ -159,6 +159,28 @@ int zcomp_compress(struct zcomp *comp, struct zcomp_strm *zstrm,
return ret;
}
+static int zcomp_decompress_split(struct zcomp *comp, struct zcomp_strm *zstrm,
+ struct scatterlist *sg, void *dst)
+{
+ struct scatterlist *next = sg_next(sg);
+ /* Each entry from the zsmalloc read path fits within one page. */
+ void *first = kmap_local_page(sg_page(sg));
+ void *second = kmap_local_page(sg_page(next));
+ struct zcomp_req head = {
+ .src = first + sg->offset,
+ .src_len = sg->length,
+ .dst = dst,
+ .dst_len = PAGE_SIZE,
+ };
+ int ret;
+
+ ret = comp->ops->decompress_split(comp->params, &zstrm->ctx, &head,
+ second + next->offset, next->length);
+ kunmap_local(second);
+ kunmap_local(first);
+ return ret;
+}
+
int zcomp_decompress(struct zcomp *comp, struct zcomp_strm *zstrm,
struct scatterlist *sg, unsigned int src_len, void *dst)
{
@@ -177,6 +199,12 @@ int zcomp_decompress(struct zcomp *comp, struct zcomp_strm *zstrm,
src = kmap_local_page(sg_page(sg));
req.src = src + sg->offset;
} else {
+ if (comp->ops->decompress_split) {
+ ret = zcomp_decompress_split(comp, zstrm, sg, dst);
+ if (ret != -EOPNOTSUPP)
+ return ret;
+ }
+
/* the object spans two pages, linearize it into local copy */
sg_copy_to_buffer(sg, 2, zstrm->local_copy, src_len);
req.src = zstrm->local_copy;
diff --git a/drivers/block/zram/zcomp.h b/drivers/block/zram/zcomp.h
index f38fd31f9e4e..92a93630aead 100644
--- a/drivers/block/zram/zcomp.h
+++ b/drivers/block/zram/zcomp.h
@@ -61,6 +61,14 @@ struct zcomp_ops {
struct zcomp_req *req);
int (*decompress)(struct zcomp_params *params, struct zcomp_ctx *ctx,
struct zcomp_req *req);
+ /*
+ * Decode one block from head->src and tail into head->dst. The input
+ * mappings are valid during the call. Return 0 for a complete output
+ * or -EOPNOTSUPP before writing output to request a linear retry.
+ */
+ int (*decompress_split)(struct zcomp_params *params, struct zcomp_ctx *ctx,
+ const struct zcomp_req *head,
+ const void *tail, size_t tail_len);
int (*create_ctx)(struct zcomp_params *params, struct zcomp_ctx *ctx);
void (*destroy_ctx)(struct zcomp_ctx *ctx);
--
2.47.3
next prev parent reply other threads:[~2026-11-21 17:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 17:09 [PATCH RFC 0/3] zram: avoid copying spanning LZ4 objects before decompression Xueyuan Chen
2026-11-21 17:09 ` Xueyuan Chen [this message]
2026-11-21 17:09 ` [PATCH RFC 2/3] lib/lz4: add safe decompression from two input buffers Xueyuan Chen
2026-11-21 17:09 ` [PATCH RFC 3/3] zram: use split-input decompression for LZ4 and LZ4HC Xueyuan Chen
2026-11-21 20:15 ` [PATCH RFC 0/3] zram: avoid copying spanning LZ4 objects before decompression Eric Biggers
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=20261122-zram-split-decomp-mm-rfc-v1-1-4e69b08c0fed@gmail.com \
--to=xueyuan.chen21@gmail.com \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=minchan@kernel.org \
--cc=senozhatsky@chromium.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