From: Wenchao Hao <haowenchao22@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Barry Song <21cnbao@gmail.com>,
Chengming Zhou <chengming.zhou@linux.dev>,
Jens Axboe <axboe@kernel.dk>,
Johannes Weiner <hannes@cmpxchg.org>,
linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, Minchan Kim <minchan@kernel.org>,
Nhat Pham <nphamcs@gmail.com>,
Sergey Senozhatsky <senozhatsky@chromium.org>,
Yosry Ahmed <yosry@kernel.org>
Cc: Wenchao Hao <haowenchao22@gmail.com>,
Barry Song <baohua@kernel.org>,
Wenchao Hao <haowenchao@xiaomi.com>
Subject: [RFC PATCH v3 3/4] zram: use zsmalloc deferred free callback for async slot free
Date: Fri, 8 May 2026 14:07:23 +0800 [thread overview]
Message-ID: <20260508060724.3810904-4-haowenchao@xiaomi.com> (raw)
In-Reply-To: <20260508060724.3810904-1-haowenchao@xiaomi.com>
From: Barry Song <baohua@kernel.org>
Register zram_deferred_ops with zs_pool_enable_deferred_free() to
defer slot freeing to a WQ_UNBOUND worker. The notify hot path only
stores a u32 slot index into the per-cpu buffer (1024 entries/page).
The drain callback does slot_lock + slot_free + slot_unlock for each
index. On deferred failure (no free page), fallback to synchronous
slot_lock + slot_free + slot_unlock.
Signed-off-by: Barry Song <baohua@kernel.org>
Signed-off-by: Wenchao Hao <haowenchao@xiaomi.com>
---
drivers/block/zram/zram_drv.c | 39 +++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index aebc710f0d6a..0d07f0901e55 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -56,6 +56,7 @@ static size_t huge_class_size;
static const struct block_device_operations zram_devops;
static void slot_free(struct zram *zram, u32 index);
+static const struct zs_deferred_ops zram_deferred_ops;
#define slot_dep_map(zram, index) (&(zram)->table[(index)].dep_map)
static void slot_lock_init(struct zram *zram, u32 index)
@@ -1994,6 +1995,8 @@ static bool zram_meta_alloc(struct zram *zram, u64 disksize)
if (!huge_class_size)
huge_class_size = zs_huge_class_size(zram->mem_pool);
+ zs_pool_enable_deferred_free(zram->mem_pool, &zram_deferred_ops, zram);
+
for (index = 0; index < num_pages; index++)
slot_lock_init(zram, index);
@@ -2784,6 +2787,39 @@ static void zram_submit_bio(struct bio *bio)
}
}
+static enum zs_push_ret zram_deferred_push(void *buf,
+ unsigned int count, unsigned long value)
+{
+ u32 *indices = buf;
+
+ if (count >= PAGE_SIZE / sizeof(u32))
+ return ZS_PUSH_FULL;
+ indices[count] = (u32)value;
+ if (count + 1 >= PAGE_SIZE / sizeof(u32))
+ return ZS_PUSH_FULL_QUEUED;
+ return ZS_PUSH_OK;
+}
+
+static void zram_deferred_drain(void *private, void *buf, unsigned int count)
+{
+ struct zram *zram = private;
+ u32 *indices = buf;
+ unsigned int i;
+
+ for (i = 0; i < count; i++) {
+ u32 index = indices[i];
+
+ slot_lock(zram, index);
+ slot_free(zram, index);
+ slot_unlock(zram, index);
+ }
+}
+
+static const struct zs_deferred_ops zram_deferred_ops = {
+ .push = zram_deferred_push,
+ .drain = zram_deferred_drain,
+};
+
static void zram_slot_free_notify(struct block_device *bdev,
unsigned long index)
{
@@ -2792,6 +2828,9 @@ static void zram_slot_free_notify(struct block_device *bdev,
zram = bdev->bd_disk->private_data;
atomic64_inc(&zram->stats.notify_free);
+ if (zs_free_deferred(zram->mem_pool, (unsigned long)index))
+ return;
+
if (!slot_trylock(zram, index)) {
atomic64_inc(&zram->stats.miss_free);
return;
--
2.34.1
next prev parent reply other threads:[~2026-05-08 6:08 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-08 6:07 [RFC PATCH v3 0/4] mm/zsmalloc: per-cpu deferred free to accelerate swap entry release Wenchao Hao
2026-05-08 6:07 ` [RFC PATCH v3 1/4] mm/zsmalloc: introduce deferred free framework with callback ops Wenchao Hao
2026-05-09 0:29 ` Nhat Pham
2026-05-09 8:47 ` Wenchao Hao
2026-05-08 6:07 ` [RFC PATCH v3 2/4] mm/zswap: use zsmalloc deferred free callback for async invalidate Wenchao Hao
2026-05-08 6:07 ` Wenchao Hao [this message]
2026-05-08 6:07 ` [RFC PATCH v3 4/4] zram: batch clear flags in slot_free with single write Wenchao Hao
2026-05-08 20:12 ` [RFC PATCH v3 0/4] mm/zsmalloc: per-cpu deferred free to accelerate swap entry release Yosry Ahmed
2026-05-09 8:32 ` Wenchao Hao
2026-05-09 8:38 ` Wenchao Hao
2026-05-09 0:08 ` Nhat Pham
2026-05-09 8:45 ` Wenchao Hao
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=20260508060724.3810904-4-haowenchao@xiaomi.com \
--to=haowenchao22@gmail.com \
--cc=21cnbao@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=baohua@kernel.org \
--cc=chengming.zhou@linux.dev \
--cc=hannes@cmpxchg.org \
--cc=haowenchao@xiaomi.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=minchan@kernel.org \
--cc=nphamcs@gmail.com \
--cc=senozhatsky@chromium.org \
--cc=yosry@kernel.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