[PATCH 2/2] mm/zswap: plug the writeback IO of an LRU walk

From: Alexandre Ghiti

Date: Wed Oct 07 2026 - 12:00:00 EST


zswap writeback only appends an entry to the pending bio when its slot
directly follows the previous one, and submits the pending bio
otherwise.

Plug the LRU walk so that the block layer can merge what the batch
cannot.

Kernel build (defconfig, -j4) in a 600M memory.max cgroup with the zswap
shrinker enabled, swapping to an NVMe partition with iocost enabled. It
runs alone, and next to a sibling fio random writer with 10 times its
io.weight so that iocost throttles it. Mean +- stddev, counters from the
build's cgroup:

Alone:

unplugged plugged
build time (s) 1061 +- 2 1057 +- 2 -0.4%
write requests (k) 622 +- 34 579 +- 21 -6.8%
pages per write request 1.30 +- 0.02 1.36 +- 0.05 +4.9%
iocost debt (s) 14.0 +- 2.5 11.0 +- 1.7 -21.6%
iocost wait (s) 7.7 +- 1.8 7.1 +- 1.1 -7.9%
IO full pressure (s) 18.3 +- 1.4 17.5 +- 1.3 -4.5%

Next to the writer:

unplugged plugged
build time (s) 2188 +- 45 2104 +- 75 -3.8%
write requests (k) 594 +- 21 567 +- 24 -4.6%
pages per write request 1.30 +- 0.01 1.35 +- 0.02 +3.6%
iocost debt (s) 648 +- 22 645 +- 29 -0.5%
iocost wait (s) 624 +- 23 633 +- 29 +1.5%
IO full pressure (s) 615 +- 31 550 +- 44 -10.6%

Signed-off-by: Alexandre Ghiti <alex@xxxxxxxx>
---
mm/zswap.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/mm/zswap.c b/mm/zswap.c
index 698fb74c5d47..39c4d891cc86 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -20,6 +20,7 @@
#include <linux/spinlock.h>
#include <linux/types.h>
#include <linux/atomic.h>
+#include <linux/blkdev.h>
#include <linux/swap_ops.h>
#include <linux/crypto.h>
#include <linux/scatterlist.h>
@@ -1225,6 +1226,7 @@ static unsigned long zswap_shrinker_scan(struct shrinker *shrinker,
.encountered_page_in_swapcache = &encountered_page_in_swapcache,
};
unsigned long shrink_ret;
+ struct blk_plug plug;

if (!zswap_shrinker_enabled ||
!mem_cgroup_zswap_writeback_enabled(sc->memcg)) {
@@ -1232,10 +1234,12 @@ static unsigned long zswap_shrinker_scan(struct shrinker *shrinker,
return SHRINK_STOP;
}

+ blk_start_plug(&plug);
shrink_ret = list_lru_shrink_walk(&zswap_list_lru, sc, &shrink_memcg_cb,
&ctl);

swap_write_submit(&ctl.io_ctx);
+ blk_finish_plug(&plug);

if (encountered_page_in_swapcache)
return SHRINK_STOP;
@@ -1343,6 +1347,7 @@ static int shrink_memcg(struct mem_cgroup *memcg)
{
struct zswap_shrink_ctl ctl = {};
int nid, shrunk = 0, scanned = 0;
+ struct blk_plug plug;

if (!mem_cgroup_zswap_writeback_enabled(memcg))
return -ENOENT;
@@ -1354,6 +1359,7 @@ static int shrink_memcg(struct mem_cgroup *memcg)
if (memcg && !mem_cgroup_online(memcg))
return -ENOENT;

+ blk_start_plug(&plug);
for_each_node_state(nid, N_NORMAL_MEMORY) {
unsigned long nr_to_walk = SWAP_CLUSTER_MAX;

@@ -1363,6 +1369,7 @@ static int shrink_memcg(struct mem_cgroup *memcg)
}

swap_write_submit(&ctl.io_ctx);
+ blk_finish_plug(&plug);

/* Nothing was scanned: every LRU under @memcg was empty. */
if (!scanned)
--
2.53.0-Meta