[PATCH 0/3] mm/zswap: Implement per-cgroup proactive writeback
From: Hao Jia
Date: Mon May 11 2026 - 06:55:11 EST
From: Hao Jia <jiahao1@xxxxxxxxxxx>
Zswap currently writes back pages to backing swap devices reactively,
triggered either by memory pressure via the shrinker or by the pool
reaching its size limit. However, this reactive approach makes writeback
timing indeterminate and can disrupt latency-sensitive workloads when
eviction happens to coincide with a critical execution window.
Furthermore, in certain scenarios, it is desirable to trigger writeback
in advance to free up memory. For example, users may want to prepare for
an upcoming memory-intensive workload by flushing cold memory to the
backing storage when the system is relatively idle.
To address these issues, this patch series introduces a per-cgroup
interface that allows users to proactively write back cold compressed
pages from zswap to the backing swap device.
Users can trigger writeback by writing to this interface with the following
parameters:
- "max=<bytes>" : Optional. The maximum amount of data to write back.
(default: unlimited).
- "<age>" : Required. The minimum age of the pages to write back
(in seconds). Only pages that have been in the zswap pool for at
least this amount of time will be written back.
Example usage:
# Write back pages older than 1 hour (3600 seconds), max 10MB
echo "max=10M 3600" > memory.zswap.proactive_writeback
Patch 1: Move the global zswap shrink cursor into struct mem_cgroup as a
per-memcg zswap_wb_iter, so patch 2 can scope writeback to a given memcg
and make forward progress across its subtree on repeated invocations.
Patch 2: Add the memory.zswap.proactive_writeback cgroupv2 interface,
allowing users to trigger writeback with optional size limit and
age threshold.
Patch 3: Add a zswpwb_proactive counter to memory.stat and /proc/vmstat
to track the number of writebacks triggered by proactive writeback.
Hao Jia (3):
mm/zswap: Make shrink_worker writeback cursor per-memcg
mm/zswap: Implement proactive writeback
mm/zswap: Add per-memcg stat for proactive writeback
Documentation/admin-guide/cgroup-v2.rst | 28 +++
include/linux/memcontrol.h | 6 +
include/linux/vm_event_item.h | 1 +
include/linux/zswap.h | 17 ++
mm/memcontrol.c | 80 +++++++
mm/vmstat.c | 1 +
mm/zswap.c | 303 ++++++++++++++++++++----
7 files changed, 390 insertions(+), 46 deletions(-)
--
2.34.1