From nobody Sun Feb 8 09:27:00 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5ED1A3E9F81; Wed, 4 Feb 2026 13:48:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770212938; cv=none; b=MIgt6G7n9ZInnrTHL0WvEZVUq2e82ObnXPVYsv+nTOKAe7XpF2fUKZHxk3wLeYsyAEVtXG/Q5toiFNrqIImZaVXu2X7+f/63oXjUW/TJonoflbS6di/5g6P+ck9buPYWlNgSjef58PQ34X0xe4VQJsixC2Z0GPEjuZb5NlG6KuI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770212938; c=relaxed/simple; bh=yI1yoSsOchjOWEAHtf2popxAc8At7+pZlpyuxbns7p0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=q7KDNJuEIVdijZIN2907rmDv6ys58i/VEbDoHAAZ6rrB1plMYqREW6nXzbSGd1jxtKfwD5QjE6sp4S20f+37TpdTH0iDrz2SLmDH2x3M2omPKwtGxGf2OSWc1JDuuxqFvCgFL5FoTLEfO6fdtvq4J21wlCiOCr16pT/V6YUPMK4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RbV6kZ+i; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RbV6kZ+i" Received: by smtp.kernel.org (Postfix) with ESMTPS id E336BC4CEF7; Wed, 4 Feb 2026 13:48:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1770212937; bh=yI1yoSsOchjOWEAHtf2popxAc8At7+pZlpyuxbns7p0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=RbV6kZ+ioHnttpsKJ0DrGQ7og9L4/KwT5U3pxWWYTm74ALcyc0WMd3uTjfhFmyxhe /I00G61/LFLj7clm3zQnElaSoLWd7ELsEaZgqqtLaM7pmdKtLlwkwwInHk1C5ccHMm wDx/dmBTjfm9CIv8CzemKaoULE3g/fYnRuBzYq4rvcAwuJBG5b7IiQ+lfnhInUTIzs 4+L/xAP/kESyfXCP8C9SI9YxsD+LltEYAl6bmXDpJPET4HKlZkUvWBwad0TY/CG0pT uBMzqvzz6h1RUdUBLmh8QIohzYho9YP4AI2pH+S3ez26ilLjxxG/6jRkvhslFMg5eJ fWlQwgrigVurQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA6F8E83F0E; Wed, 4 Feb 2026 13:48:57 +0000 (UTC) From: Jihan LIN via B4 Relay Date: Wed, 04 Feb 2026 13:48:51 +0000 Subject: [PATCH RFC 1/3] zram: Rename zcomp_strm_{init, free}() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260204-b4_zcomp_stream-v1-1-35c06ce1d332@gmail.com> References: <20260204-b4_zcomp_stream-v1-0-35c06ce1d332@gmail.com> In-Reply-To: <20260204-b4_zcomp_stream-v1-0-35c06ce1d332@gmail.com> To: Minchan Kim , Sergey Senozhatsky , Jens Axboe Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Jihan LIN X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1770212935; l=2361; i=linjh22s@gmail.com; s=linjh22s_machine; h=from:subject:message-id; bh=IFvoK5U+khkiAvwSnFIAQSJIRT0dcUrOwkW93SNRf6w=; b=PRv9qw5rfie6P+3wgDGa1Y91Sk+MwawKplgOLzT2zxS5CbI3eCVz/gR2pCSaq3p8C69gRoKHx bPeCX0RrFuJBRrmFtPfiOF+2E2LldwSB5WxN7ZXMx3Eh2i8nLEekB1v X-Developer-Key: i=linjh22s@gmail.com; a=ed25519; pk=MnRQAVFy1t4tiGb8ce7ohJwrN2YFXd+dA7XmzR6GmUc= X-Endpoint-Received: by B4 Relay for linjh22s@gmail.com/linjh22s_machine with auth_id=592 X-Original-From: Jihan LIN Reply-To: linjh22s@gmail.com From: Jihan LIN Currently, zcomp uses a preemptive per-CPU stream model where streams are allocated for each online CPUs and guarded by mutexes. The existing names zcomp_strm_{init, free}() are too generic to explicitly indicate they handle per-CPU streams. Rename them to zcomp_strm_{init, free}_percpu(). This helps distinguish them from future streams that may not be per-CPU based. No functional changes are intended. Signed-off-by: Jihan LIN --- drivers/block/zram/zcomp.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c index b1bd1daa0060a5b437d947d504d9ee6b4a9ac152..1614340e81dd2bebb29373411c9= d180446f78f4c 100644 --- a/drivers/block/zram/zcomp.c +++ b/drivers/block/zram/zcomp.c @@ -43,7 +43,7 @@ static const struct zcomp_ops *backends[] =3D { NULL }; =20 -static void zcomp_strm_free(struct zcomp *comp, struct zcomp_strm *zstrm) +static void zcomp_strm_free_percpu(struct zcomp *comp, struct zcomp_strm *= zstrm) { comp->ops->destroy_ctx(&zstrm->ctx); vfree(zstrm->local_copy); @@ -51,7 +51,7 @@ static void zcomp_strm_free(struct zcomp *comp, struct zc= omp_strm *zstrm) zstrm->buffer =3D NULL; } =20 -static int zcomp_strm_init(struct zcomp *comp, struct zcomp_strm *zstrm) +static int zcomp_strm_init_percpu(struct zcomp *comp, struct zcomp_strm *z= strm) { int ret; =20 @@ -66,7 +66,7 @@ static int zcomp_strm_init(struct zcomp *comp, struct zco= mp_strm *zstrm) */ zstrm->buffer =3D vzalloc(2 * PAGE_SIZE); if (!zstrm->buffer || !zstrm->local_copy) { - zcomp_strm_free(comp, zstrm); + zcomp_strm_free_percpu(comp, zstrm); return -ENOMEM; } return 0; @@ -172,7 +172,7 @@ int zcomp_cpu_up_prepare(unsigned int cpu, struct hlist= _node *node) struct zcomp_strm *zstrm =3D per_cpu_ptr(comp->stream, cpu); int ret; =20 - ret =3D zcomp_strm_init(comp, zstrm); + ret =3D zcomp_strm_init_percpu(comp, zstrm); if (ret) pr_err("Can't allocate a compression stream\n"); return ret; @@ -184,7 +184,7 @@ int zcomp_cpu_dead(unsigned int cpu, struct hlist_node = *node) struct zcomp_strm *zstrm =3D per_cpu_ptr(comp->stream, cpu); =20 mutex_lock(&zstrm->lock); - zcomp_strm_free(comp, zstrm); + zcomp_strm_free_percpu(comp, zstrm); mutex_unlock(&zstrm->lock); return 0; } --=20 2.51.0 From nobody Sun Feb 8 09:27:00 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2BDB723875D; Wed, 4 Feb 2026 13:48:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770212938; cv=none; b=pwSl5NWd3lCA/K3Y4rhX0/aMnCFzGufZzvC9QyICpjqPZwsBP9m6Sg3UIBrIczendeQK9UpDS4dphG0TD4eOG9dL/r6NBMJS1QhAitVHsur5dosfpwA4OyMcS0AsScoMM5AHUJ6udaLDF7HhbGoQFUG5xMhVoPSFVUs1fqwcvQ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770212938; c=relaxed/simple; bh=fM8jUjxxpc2FbZdJxNC58b9xXqH0J9Y13J7XMpg8MVs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Wsq4AB9MsUGoaYI9SWxtMNQQ4CpzCQQoK4odZilhWfWfDtsYHqF4QOmuY69w/y4CBB9RjTjHy2te9UT2ndOzfMXqHp7UERhzvggwQkoF3dJqRBagG9tfIWXH0N5CL2Bl7DR9fGBiBFUlXDYCtvvBhwOtDvGIp7pX/0sg682zYcU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SRqLyBDN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SRqLyBDN" Received: by smtp.kernel.org (Postfix) with ESMTPS id 07397C16AAE; Wed, 4 Feb 2026 13:48:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1770212938; bh=fM8jUjxxpc2FbZdJxNC58b9xXqH0J9Y13J7XMpg8MVs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=SRqLyBDNO+aqAZyBadhHcT7UF5FpLbdfOJ0XxcHyroknU0n0blLHWnnblXH8VRV+E SQUtXJoYdGsBZIs8XmF/AYEfxVnrA8GIDjw0E3/CHotoEHJ8qmOuZhnogQisdFk2DV TOET2WfBn1JObiY1OKrSkeFWOnpuIS7ahL1Qaixf0UuCTQiWMpYyWZkuoXVmy7Rs/N ibAybp7FqOSw9vfiYNznsQ/9KFunPqrmUV34m31kLXr/TRN7mhPhGdyR2PrdDXL0cQ WJPIQ/DL5ImtrLCc0P1iZhZ6TurugYe3dgQVuLPYO+FB/6EH2Czf0SDTJMzS6/fobC 3lncF5j9LwqaA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4B2FE83EF9; Wed, 4 Feb 2026 13:48:57 +0000 (UTC) From: Jihan LIN via B4 Relay Date: Wed, 04 Feb 2026 13:48:52 +0000 Subject: [PATCH RFC 2/3] zram: Introduce zcomp-managed streams Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260204-b4_zcomp_stream-v1-2-35c06ce1d332@gmail.com> References: <20260204-b4_zcomp_stream-v1-0-35c06ce1d332@gmail.com> In-Reply-To: <20260204-b4_zcomp_stream-v1-0-35c06ce1d332@gmail.com> To: Minchan Kim , Sergey Senozhatsky , Jens Axboe Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Jihan LIN X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1770212935; l=7328; i=linjh22s@gmail.com; s=linjh22s_machine; h=from:subject:message-id; bh=oRqOL0lUgKYsttjly5TdUBB6Rs+XQ4mL1OOAVXXVKqE=; b=V+sc5XZD9jWoqC8CA66r/Etd/EIr/XtSX168KZoSdlx3XsC5Jf7z6EsdAD/MeyblZ8LJJ2Qfu nVZNvn5Sy0PA4gRdwvLEJeGHOzCCAvQRkZpVjTRf4jXXABzK0v7XwN7 X-Developer-Key: i=linjh22s@gmail.com; a=ed25519; pk=MnRQAVFy1t4tiGb8ce7ohJwrN2YFXd+dA7XmzR6GmUc= X-Endpoint-Received: by B4 Relay for linjh22s@gmail.com/linjh22s_machine with auth_id=592 X-Original-From: Jihan LIN Reply-To: linjh22s@gmail.com From: Jihan LIN Currently, zcomp uses a per-CPU stream model. This design is restrictive for hardware-accelerated or batched zcomp backends. These backends often need to manage their own resources rather than relying on a generic mutex-protected per-CPU stream for batched operations. This patch introduces a hybrid model, allowing backends to optionally manage their own streams while generic per-CPU streams still remain allocated as a complementary mechanism. Introduce zstrm_mgmt flag to struct zcomp_params. Backends set this flag during zcomp_ops->setup_params() to advertise their capability to manage streams. Add zcomp_ops->{get, put}_stream() to allow zcomp backends to implement their own stream strategies. Modify zcomp_stream_get() to accept a new parameter indicating zcomp-managed streams are preferred, and update zcomp_stream_put() to route a zcomp-managed stream to the backend. If the backends advertise their capability and the caller prefers managed streams, try to get the stream from the backends; otherwise, fall back to the generic per-CPU stream. All existing call sites request the default per-CPU stream to preserve the original behavior. Signed-off-by: Jihan LIN --- drivers/block/zram/zcomp.c | 27 +++++++++++++++++++++++++-- drivers/block/zram/zcomp.h | 23 +++++++++++++++++++++-- drivers/block/zram/zram_drv.c | 6 +++--- 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c index 1614340e81dd2bebb29373411c9d180446f78f4c..86ff6ecb0293d7b95ef4fa82212= 2568cedf78f6e 100644 --- a/drivers/block/zram/zcomp.c +++ b/drivers/block/zram/zcomp.c @@ -69,6 +69,7 @@ static int zcomp_strm_init_percpu(struct zcomp *comp, str= uct zcomp_strm *zstrm) zcomp_strm_free_percpu(comp, zstrm); return -ENOMEM; } + zstrm->zcomp_managed =3D false; return 0; } =20 @@ -107,8 +108,18 @@ ssize_t zcomp_available_show(const char *comp, char *b= uf, ssize_t at) return at; } =20 -struct zcomp_strm *zcomp_stream_get(struct zcomp *comp) +struct zcomp_strm *zcomp_stream_get(struct zcomp *comp, enum zstrm_pref pr= ef) { + if (comp->params->zstrm_mgmt && pref =3D=3D ZSTRM_PREFER_MGMT) { + struct zcomp_strm *zcomp_strm =3D + comp->ops->get_stream(comp->params); + + if (zcomp_strm) { + zcomp_strm->comp =3D comp; + return zcomp_strm; + } + } + for (;;) { struct zcomp_strm *zstrm =3D raw_cpu_ptr(comp->stream); =20 @@ -131,7 +142,11 @@ struct zcomp_strm *zcomp_stream_get(struct zcomp *comp) =20 void zcomp_stream_put(struct zcomp_strm *zstrm) { - mutex_unlock(&zstrm->lock); + if (zstrm->zcomp_managed) { + zstrm->comp->ops->put_stream(zstrm->comp->params, zstrm); + } else { + mutex_unlock(&zstrm->lock); + } } =20 int zcomp_compress(struct zcomp *comp, struct zcomp_strm *zstrm, @@ -197,11 +212,19 @@ static int zcomp_init(struct zcomp *comp, struct zcom= p_params *params) if (!comp->stream) return -ENOMEM; =20 + params->zstrm_mgmt =3D false; comp->params =3D params; ret =3D comp->ops->setup_params(comp->params); if (ret) goto cleanup; =20 + if (params->zstrm_mgmt && + !(comp->ops->get_stream && comp->ops->put_stream)) { + params->zstrm_mgmt =3D false; + pr_warn("Missing managed stream ops in %s, managed stream disabled\n", + comp->ops->name); + } + for_each_possible_cpu(cpu) mutex_init(&per_cpu_ptr(comp->stream, cpu)->lock); =20 diff --git a/drivers/block/zram/zcomp.h b/drivers/block/zram/zcomp.h index eacfd3f7d61d9395694292713fb5da4f0023d6d7..cbe8842ea5352eed4e73e3d45fe= 6c12221ab9f64 100644 --- a/drivers/block/zram/zcomp.h +++ b/drivers/block/zram/zcomp.h @@ -24,6 +24,7 @@ struct zcomp_params { union { struct deflate_params deflate; }; + bool zstrm_mgmt; =20 void *drv_data; }; @@ -31,14 +32,18 @@ struct zcomp_params { /* * Run-time driver context - scratch buffers, etc. It is modified during * request execution (compression/decompression), cannot be shared, so - * it's in per-CPU area. + * it's in per-CPU area or management by backend. */ struct zcomp_ctx { void *context; }; =20 struct zcomp_strm { + bool zcomp_managed; + /* lock used only for per-cpu streams */ struct mutex lock; + /* pointer to zcomp valid only for zcomp-managed streams */ + struct zcomp *comp; /* compression buffer */ void *buffer; /* local copy of handle memory */ @@ -54,6 +59,11 @@ struct zcomp_req { size_t dst_len; }; =20 +enum zstrm_pref { + ZSTRM_DEFAULT, /* always use the generic per-CPU stream */ + ZSTRM_PREFER_MGMT, /* try managed stream; fallback to per-CPU */ +}; + struct zcomp_ops { int (*compress)(struct zcomp_params *params, struct zcomp_ctx *ctx, struct zcomp_req *req); @@ -66,6 +76,15 @@ struct zcomp_ops { int (*setup_params)(struct zcomp_params *params); void (*release_params)(struct zcomp_params *params); =20 + /* + * get_stream() needs to prepare zstrm->ctx, and backend must ensure + * returned stream sets zcomp_managed and match the per-cpu stream + * sizing: local_copy >=3D PAGE_SIZE, buffer >=3D 2 * PAGE_SIZE. + */ + struct zcomp_strm *(*get_stream)(struct zcomp_params *params); + void (*put_stream)(struct zcomp_params *params, + struct zcomp_strm *zstrm); + const char *name; }; =20 @@ -85,7 +104,7 @@ bool zcomp_available_algorithm(const char *comp); struct zcomp *zcomp_create(const char *alg, struct zcomp_params *params); void zcomp_destroy(struct zcomp *comp); =20 -struct zcomp_strm *zcomp_stream_get(struct zcomp *comp); +struct zcomp_strm *zcomp_stream_get(struct zcomp *comp, enum zstrm_pref pr= ef); void zcomp_stream_put(struct zcomp_strm *zstrm); =20 int zcomp_compress(struct zcomp *comp, struct zcomp_strm *zstrm, diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 5759823d631488904189168326fd133549c76141..2e5a1415e9034674e14e619f486= 052cd21098f50 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1966,7 +1966,7 @@ static int read_compressed_page(struct zram *zram, st= ruct page *page, u32 index) size =3D zram_get_obj_size(zram, index); prio =3D zram_get_priority(zram, index); =20 - zstrm =3D zcomp_stream_get(zram->comps[prio]); + zstrm =3D zcomp_stream_get(zram->comps[prio], ZSTRM_DEFAULT); src =3D zs_obj_read_begin(zram->mem_pool, handle, zstrm->local_copy); dst =3D kmap_local_page(page); ret =3D zcomp_decompress(zram->comps[prio], zstrm, src, size, dst); @@ -2121,7 +2121,7 @@ static int zram_write_page(struct zram *zram, struct = page *page, u32 index) if (same_filled) return write_same_filled_page(zram, element, index); =20 - zstrm =3D zcomp_stream_get(zram->comps[ZRAM_PRIMARY_COMP]); + zstrm =3D zcomp_stream_get(zram->comps[ZRAM_PRIMARY_COMP], ZSTRM_DEFAULT); mem =3D kmap_local_page(page); ret =3D zcomp_compress(zram->comps[ZRAM_PRIMARY_COMP], zstrm, mem, &comp_len); @@ -2303,7 +2303,7 @@ static int recompress_slot(struct zram *zram, u32 ind= ex, struct page *page, if (!zram->comps[prio]) continue; =20 - zstrm =3D zcomp_stream_get(zram->comps[prio]); + zstrm =3D zcomp_stream_get(zram->comps[prio], ZSTRM_DEFAULT); src =3D kmap_local_page(page); ret =3D zcomp_compress(zram->comps[prio], zstrm, src, &comp_len_new); --=20 2.51.0 From nobody Sun Feb 8 09:27:00 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B57326D4DD; Wed, 4 Feb 2026 13:48:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770212938; cv=none; b=kB4fEmjlEfwTBCA5yfeBJtwSVZofYATbAv9oU+Jwk37S74x89j+xL3ykW2B72oKMN2fwsPTVaM79L0D1GuzCopdTYPMyy5UmW0FKM5NDBTWTs4UpKLSWpCC8c8v+8GQS4PYN17n3R8K8InccbYyPL1+Eo/dPjKgCGNFFqZ62RZk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770212938; c=relaxed/simple; bh=vDs9ina9bo1CrzxqSRvBldxga3JQ1cDiGOE8LB06p4g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Cwr1zxpQ/Vt4ffNR9uh9csF4PdoUXzCJ1nXBTBuRDjgX0u3+0cYj2WJE4U0sRf9fBjgRgUDHeCn7+kr67KzAywgUMCrSbQgscc38s1kSuOptjXpeKT1IM/VWF62SZrmfTzM4B79udBYA1f6CP9aJb1KMNH4D1GKp10I4q7Dgpuo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=G+uNDLb9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="G+uNDLb9" Received: by smtp.kernel.org (Postfix) with ESMTPS id 17CE8C2BC87; Wed, 4 Feb 2026 13:48:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1770212938; bh=vDs9ina9bo1CrzxqSRvBldxga3JQ1cDiGOE8LB06p4g=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=G+uNDLb9AgyEuqhafL2GYiSJbn/wJL99jPx1Vund3/Kb9i5lTuIto2H75I06O9SMM JIzHCgoYO3LG+XtrSGG651GSBPhaDoBWxhTtJxnEAFxKU7Wb8ro9P7igcqjoyUx4UN Mqnr6X74ltnktho/woYk2lnmOV3fZXgynHO++QL8pZ84GIWZkaHHU8rO4O4j1IAcbZ iXA5e+XTeA4oHDITJoFbo3iYpEzyDKlEGy4swRtDbY3jkP9SWKAULflnD048SeJPQU iXmKYuHCVv7Rn0wuHvY17ejMONdvW/WpeKrEaNf4mAAI2CFkQ0++hZwhJasrImUkYj sXI06DYMkvK8Q== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E1C0E83F11; Wed, 4 Feb 2026 13:48:58 +0000 (UTC) From: Jihan LIN via B4 Relay Date: Wed, 04 Feb 2026 13:48:53 +0000 Subject: [PATCH RFC 3/3] zram: Use zcomp-managed streams for async write requests Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260204-b4_zcomp_stream-v1-3-35c06ce1d332@gmail.com> References: <20260204-b4_zcomp_stream-v1-0-35c06ce1d332@gmail.com> In-Reply-To: <20260204-b4_zcomp_stream-v1-0-35c06ce1d332@gmail.com> To: Minchan Kim , Sergey Senozhatsky , Jens Axboe Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Jihan LIN X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1770212935; l=3979; i=linjh22s@gmail.com; s=linjh22s_machine; h=from:subject:message-id; bh=n49FebibsqQERts1+tv3yx6Io3Tg7uusMwfFkfvmBE0=; b=5iP6q2XsN0scmSU6Ct+S9QgF8jXHJZbhYOQbAjtLTaT/vAif6+MCwR5Xhd6WJvre35Tz3Q7/K EdRzKxAK6D8D/uHscoEyVFhM60tKllsrv3+l1/a+wBi1wR4fG/cmVZh X-Developer-Key: i=linjh22s@gmail.com; a=ed25519; pk=MnRQAVFy1t4tiGb8ce7ohJwrN2YFXd+dA7XmzR6GmUc= X-Endpoint-Received: by B4 Relay for linjh22s@gmail.com/linjh22s_machine with auth_id=592 X-Original-From: Jihan LIN Reply-To: linjh22s@gmail.com From: Jihan LIN Crrent per-CPU streams limit write concurrency to the number of online CPUs. For zcomp backends that support zcomp-managed streams, we can utilize them for async write requests to get better parallelism. Modify zram_write_page() to accept a flag indicating the request is asynchronous. If the bio request is considered as non-synchronous and the backend supports zcomp-managed streams, attempt to acquire a zcomp-managed stream. Although zram_write_page() currently waits for compression to complete, making the operation appear synchronous, using zcomp-managed streams has the potential to improve parallelism for async write requests, provided the backend utilizes efficient streams management or specialized implementations. zcomp_stream_get() handles the fallback to per-CPU streams. zram_read_page() remains using the generic per-CPU streams, since reads are always treated as synchronous in op_is_sync(). Support multiple pages within a single bio request is deferred to keep simple and focused. Signed-off-by: Jihan LIN --- drivers/block/zram/zram_drv.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 2e5a1415e9034674e14e619f486052cd21098f50..655d0e141c621ca38ca1059780c= 1a8a00258c868 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1966,6 +1966,7 @@ static int read_compressed_page(struct zram *zram, st= ruct page *page, u32 index) size =3D zram_get_obj_size(zram, index); prio =3D zram_get_priority(zram, index); =20 + /* Reads are treated as synchronous, see op_is_sync(). */ zstrm =3D zcomp_stream_get(zram->comps[prio], ZSTRM_DEFAULT); src =3D zs_obj_read_begin(zram->mem_pool, handle, zstrm->local_copy); dst =3D kmap_local_page(page); @@ -2105,7 +2106,8 @@ static int write_incompressible_page(struct zram *zra= m, struct page *page, return 0; } =20 -static int zram_write_page(struct zram *zram, struct page *page, u32 index) +static int zram_write_page(struct zram *zram, struct page *page, u32 index, + bool is_async) { int ret =3D 0; unsigned long handle; @@ -2121,7 +2123,19 @@ static int zram_write_page(struct zram *zram, struct= page *page, u32 index) if (same_filled) return write_same_filled_page(zram, element, index); =20 - zstrm =3D zcomp_stream_get(zram->comps[ZRAM_PRIMARY_COMP], ZSTRM_DEFAULT); + /* + * Using zcomp-managed stream and waiting for compress done makes + * this appear synchronous. + * + * At this time, zram_bio_write handles pages one by one. + * However, zcomp-managed streams allow threads to submit jobs + * to zcomp without the lock contention in per-cpu streams. + * This might give us better parallelism than the generic per-cpu + * streams could, assuming zcomp uses efficient streams management + * or utilizes the specialized implementations. + */ + zstrm =3D zcomp_stream_get(zram->comps[ZRAM_PRIMARY_COMP], + is_async ? ZSTRM_PREFER_MGMT : ZSTRM_DEFAULT); mem =3D kmap_local_page(page); ret =3D zcomp_compress(zram->comps[ZRAM_PRIMARY_COMP], zstrm, mem, &comp_len); @@ -2183,7 +2197,8 @@ static int zram_bvec_write_partial(struct zram *zram,= struct bio_vec *bvec, ret =3D zram_read_page(zram, page, index, bio); if (!ret) { memcpy_from_bvec(page_address(page) + offset, bvec); - ret =3D zram_write_page(zram, page, index); + ret =3D zram_write_page(zram, page, index, + !op_is_sync(bio->bi_opf)); } __free_page(page); return ret; @@ -2194,7 +2209,8 @@ static int zram_bvec_write(struct zram *zram, struct = bio_vec *bvec, { if (is_partial_io(bvec)) return zram_bvec_write_partial(zram, bvec, index, offset, bio); - return zram_write_page(zram, bvec->bv_page, index); + return zram_write_page(zram, bvec->bv_page, index, + !op_is_sync(bio->bi_opf)); } =20 #ifdef CONFIG_ZRAM_MULTI_COMP --=20 2.51.0