Re: [PATCH 1/2] mm/zswap: batch the writeback IO of consecutive entries
From: Nhat Pham
Date: Fri Oct 09 2026 - 02:43:19 EST
On Wed, Oct 7, 2026 at 5:36 PM Alexandre Ghiti <alex@xxxxxxxx> wrote:
>
> Commit 8f29aa226f82 ("mm/swap: introduce struct swap_io_ctx") introduced a
> simple way to batch the swap writes of folios with consecutive slots into a
> single bio. zswap writeback does not use it: zswap_writeback_entry()
> submits a context of its own for every entry, so every entry written back
> becomes its own IO.
>
> So let the two functions that walk the zswap LRU, zswap_shrinker_scan()
> and shrink_memcg(), own the context and submit it once the walk is done.
>
> 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:
Number looks good to me!
>
> Alone:
>
> unbatched batched
> build time (s) 1066 +- 9 1061 +- 2 -0.5%
> write requests (k) 748 +- 47 596 +- 26 -20.4%
> pages per write request 1.07 +- 0.01 1.30 +- 0.01 +21.2%
> iocost debt (s) 15.0 +- 2.7 12.1 +- 1.2 -19.5%
> iocost wait (s) 7.5 +- 1.2 7.2 +- 1.1 -3.6%
> IO full pressure (s) 19.0 +- 1.8 18.2 +- 0.9 -4.2%
>
> Next to the writer:
>
> unbatched batched
> build time (s) 2269 +- 50 2203 +- 62 -2.9%
> write requests (k) 714 +- 31 605 +- 24 -15.2%
> pages per write request 1.08 +- 0.00 1.30 +- 0.02 +20.3%
The improvement is pretty big, but still only 1.3 :(
Is this because writeback entries are not contiguous in physical swap
space? Physical swap allocation algorithm has a bias for allocating
contiguous slots, but by writeback time we might have already punched
a bunch of holes (refaults etc.).
Ironically, vswap might help a bit here, because we defer physical
swap space allocation to right before writeback time... But who knows
:/
Anyway, I'll take the 20% :)
> iocost debt (s) 685 +- 25 646 +- 26 -5.7%
> iocost wait (s) 655 +- 26 632 +- 23 -3.6%
> IO full pressure (s) 655 +- 31 624 +- 30 -4.7%
>
> Suggested-by: Nhat Pham <nphamcs@xxxxxxxxx>
> Signed-off-by: Alexandre Ghiti <alex@xxxxxxxx>
Looks good to me FWIW:
Acked-by: Nhat Pham <nphamcs@xxxxxxxxx>