mm/zswap.c | 60 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 13 deletions(-)
From: Hao Jia <jiahao1@lixiang.com>
This series fixes and improves the zswap global shrinker (shrink_worker()):
Patch 1: Fix missing global shrinker when memory cgroup is disabled.
Patch 2: Extend shrink_memcg() to support batch writeback and update its
return value semantics, thereby improving the writeback efficiency
in the shrink_worker() path.
v1->v2:
- Add a reschedule check to the -ENOENT return path in shrink_memcg() to
handle the theoretical issue of prolonged heavy concurrent zswap stores.
- Remove the shrink_memcg() return value changes part, and include a more
detailed test report in the commit message.
[v1] https://lore.kernel.org/all/20260714081510.16895-1-jiahao.kernel@gmail.com
Hao Jia (2):
mm/zswap: Fix global shrinker when memory cgroup is disabled
mm/zswap: Support batch writeback in shrink_memcg()
mm/zswap.c | 60 ++++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 47 insertions(+), 13 deletions(-)
--
2.34.1
On Fri, 17 Jul 2026 16:51:49 +0800 Hao Jia <jiahao.kernel@gmail.com> wrote: > This series fixes and improves the zswap global shrinker (shrink_worker()): > Patch 1: Fix missing global shrinker when memory cgroup is disabled. > Patch 2: Extend shrink_memcg() to support batch writeback and update its > return value semantics, thereby improving the writeback efficiency > in the shrink_worker() path. Thanks. [1/2] is a cc:stable fix so it isn't really appropriate to combine this with [2/2] which doesn't fix any bugs. Because the two patches may take different paths into mainline, with different timings. But that's OK, I can deal with the splitup if needed. The [1/2] changelog lacks a description of how the flaw impacts users. Please describe this fully and maintain that info within the changelogging. This info helps -stable maintainers and others understand why we're proposing a backport and helps myself and others with timing decisions. Finally, AI review might have found an issue: https://sashiko.dev/#/patchset/20260717085151.22822-1-jiahao.kernel@gmail.com
On Fri, Jul 17, 2026 at 6:18 PM Andrew Morton <akpm@linux-foundation.org> wrote: > > On Fri, 17 Jul 2026 16:51:49 +0800 Hao Jia <jiahao.kernel@gmail.com> wrote: > > > This series fixes and improves the zswap global shrinker (shrink_worker()): > > Patch 1: Fix missing global shrinker when memory cgroup is disabled. > > Patch 2: Extend shrink_memcg() to support batch writeback and update its > > return value semantics, thereby improving the writeback efficiency > > in the shrink_worker() path. > > Thanks. > > [1/2] is a cc:stable fix so it isn't really appropriate to combine this > with [2/2] which doesn't fix any bugs. Because the two patches may > take different paths into mainline, with different timings. But that's > OK, I can deal with the splitup if needed. Thank you! > > The [1/2] changelog lacks a description of how the flaw impacts users. > Please describe this fully and maintain that info within the > changelogging. This info helps -stable maintainers and others > understand why we're proposing a backport and helps myself and others > with timing decisions. The first line in the changelog should be sufficient imo: "Zswap writeback on hitting the pool limit is broken when memory cgroup is disabled"
On Fri, 17 Jul 2026 18:28:04 -0700 Yosry Ahmed <yosry@kernel.org> wrote: > > > > The [1/2] changelog lacks a description of how the flaw impacts users. > > Please describe this fully and maintain that info within the > > changelogging. This info helps -stable maintainers and others > > understand why we're proposing a backport and helps myself and others > > with timing decisions. > > The first line in the changelog should be sufficient imo: "Zswap > writeback on hitting the pool limit is broken when memory cgroup is > disabled" "broken"? Perhaps this means "fails to occur". But what is the userspace-visible impact? IOW, why are we proposing a backport?
On 2026/7/18 12:40, Andrew Morton wrote: > On Fri, 17 Jul 2026 18:28:04 -0700 Yosry Ahmed <yosry@kernel.org> wrote: > >>> >>> The [1/2] changelog lacks a description of how the flaw impacts users. >>> Please describe this fully and maintain that info within the >>> changelogging. This info helps -stable maintainers and others >>> understand why we're proposing a backport and helps myself and others >>> with timing decisions. >> >> The first line in the changelog should be sufficient imo: "Zswap >> writeback on hitting the pool limit is broken when memory cgroup is >> disabled" > > "broken"? Perhaps this means "fails to occur". > > But what is the userspace-visible impact? IOW, why are we proposing a > backport? > Perhaps the first paragraph of the commit1 message could be modified as follows? I have added a description of the issues that occur without this patch. Zswap writeback on hitting the pool limit fails to occur when memory cgroup is disabled, because mem_cgroup_iter() always returns NULL. Therefore, the global shrinker shrink_worker() always takes the !memcg branch. After MAX_RECLAIM_RETRIES empty walks, the worker simply gives up, so it fails to write back anything. As a result, once the pool reaches the zswap limit, every subsequent zswap shrink work run is a no-op. This leads to zswap store failures, forcing pages to bypass zswap and be written directly to the backing swap device, which can trigger issues such as LRU inversion. Thanks, Hao
On 2026/7/20 09:26, Hao Jia wrote: > > > On 2026/7/18 12:40, Andrew Morton wrote: >> On Fri, 17 Jul 2026 18:28:04 -0700 Yosry Ahmed <yosry@kernel.org> wrote: >> >>>> >>>> The [1/2] changelog lacks a description of how the flaw impacts users. >>>> Please describe this fully and maintain that info within the >>>> changelogging. This info helps -stable maintainers and others >>>> understand why we're proposing a backport and helps myself and others >>>> with timing decisions. >>> >>> The first line in the changelog should be sufficient imo: "Zswap >>> writeback on hitting the pool limit is broken when memory cgroup is >>> disabled" >> >> "broken"? Perhaps this means "fails to occur". >> >> But what is the userspace-visible impact? IOW, why are we proposing a >> backport? >> > > Perhaps the first paragraph of the commit1 message could be modified as > follows? I have added a description of the issues that occur without > this patch. > Hi Andrew, Yosry, and Nhat, Any thoughts on this change? Thanks, Hao > Zswap writeback on hitting the pool limit fails to occur when memory > cgroup is disabled, because mem_cgroup_iter() always returns NULL. > Therefore, the global shrinker shrink_worker() always takes the !memcg > branch. After MAX_RECLAIM_RETRIES empty walks, the worker simply gives > up, so it fails to write back anything. As a result, once the pool > reaches the zswap limit, every subsequent zswap shrink work run is a > no-op. This leads to zswap store failures, forcing pages to bypass zswap > and be written directly to the backing swap device, which can trigger > issues such as LRU inversion. > > > Thanks, > Hao
On Wed, Jul 22, 2026 at 6:21 PM Hao Jia <jiahao.kernel@gmail.com> wrote: > > > > On 2026/7/20 09:26, Hao Jia wrote: > > > > > > On 2026/7/18 12:40, Andrew Morton wrote: > >> On Fri, 17 Jul 2026 18:28:04 -0700 Yosry Ahmed <yosry@kernel.org> wrote: > >> > >>>> > >>>> The [1/2] changelog lacks a description of how the flaw impacts users. > >>>> Please describe this fully and maintain that info within the > >>>> changelogging. This info helps -stable maintainers and others > >>>> understand why we're proposing a backport and helps myself and others > >>>> with timing decisions. > >>> > >>> The first line in the changelog should be sufficient imo: "Zswap > >>> writeback on hitting the pool limit is broken when memory cgroup is > >>> disabled" > >> > >> "broken"? Perhaps this means "fails to occur". > >> > >> But what is the userspace-visible impact? IOW, why are we proposing a > >> backport? > >> > > > > Perhaps the first paragraph of the commit1 message could be modified as > > follows? I have added a description of the issues that occur without > > this patch. > > > > Hi Andrew, Yosry, and Nhat, > Any thoughts on this change? I would front load the user impact in the first paragraph: Zswap writeback when the global pool limit is hit fails when memory cgroups are disabled. The pool remains full until it is organically drained by swapins or memory freeing, leading to zswap store failures and pages bypassing getting written directly to the backing swap device, causing LRU inversion (hotter pages with higher fault latency). ...
On 2026/7/23 12:49, Yosry Ahmed wrote: > On Wed, Jul 22, 2026 at 6:21 PM Hao Jia <jiahao.kernel@gmail.com> wrote: >> >> >> >> On 2026/7/20 09:26, Hao Jia wrote: >>> >>> >>> On 2026/7/18 12:40, Andrew Morton wrote: >>>> On Fri, 17 Jul 2026 18:28:04 -0700 Yosry Ahmed <yosry@kernel.org> wrote: >>>> >>>>>> >>>>>> The [1/2] changelog lacks a description of how the flaw impacts users. >>>>>> Please describe this fully and maintain that info within the >>>>>> changelogging. This info helps -stable maintainers and others >>>>>> understand why we're proposing a backport and helps myself and others >>>>>> with timing decisions. >>>>> >>>>> The first line in the changelog should be sufficient imo: "Zswap >>>>> writeback on hitting the pool limit is broken when memory cgroup is >>>>> disabled" >>>> >>>> "broken"? Perhaps this means "fails to occur". >>>> >>>> But what is the userspace-visible impact? IOW, why are we proposing a >>>> backport? >>>> >>> >>> Perhaps the first paragraph of the commit1 message could be modified as >>> follows? I have added a description of the issues that occur without >>> this patch. >>> >> >> Hi Andrew, Yosry, and Nhat, >> Any thoughts on this change? > > I would front load the user impact in the first paragraph: > > Zswap writeback when the global pool limit is hit fails when memory > cgroups are disabled. The pool remains full until it is organically > drained by swapins or memory freeing, leading to zswap store failures > and pages bypassing getting written directly to the backing swap device, > causing LRU inversion (hotter pages with higher fault latency). > > ... Will done. Thanks, Hao
On Fri, Jul 17, 2026 at 6:18 PM Andrew Morton <akpm@linux-foundation.org> wrote: > > On Fri, 17 Jul 2026 16:51:49 +0800 Hao Jia <jiahao.kernel@gmail.com> wrote: > > > This series fixes and improves the zswap global shrinker (shrink_worker()): > > Patch 1: Fix missing global shrinker when memory cgroup is disabled. > > Patch 2: Extend shrink_memcg() to support batch writeback and update its > > return value semantics, thereby improving the writeback efficiency > > in the shrink_worker() path. > > Thanks. > > [1/2] is a cc:stable fix so it isn't really appropriate to combine this > with [2/2] which doesn't fix any bugs. Because the two patches may > take different paths into mainline, with different timings. But that's > OK, I can deal with the splitup if needed. > > The [1/2] changelog lacks a description of how the flaw impacts users. > Please describe this fully and maintain that info within the > changelogging. This info helps -stable maintainers and others > understand why we're proposing a backport and helps myself and others > with timing decisions. > > Finally, AI review might have found an issue: > https://sashiko.dev/#/patchset/20260717085151.22822-1-jiahao.kernel@gmail.com We discussed this one in the previous version, it's a theoretical scenario that can already happen today.
© 2016 - 2026 Red Hat, Inc.