* Re: [PATCH v2 2/2] mm/zswap: Support batch writeback in shrink_memcg() [not found] ` <20260717085151.22822-3-jiahao.kernel@gmail.com> @ 2026-07-17 16:45 ` Yosry Ahmed 2026-07-17 16:46 ` Nhat Pham 1 sibling, 0 replies; 6+ messages in thread From: Yosry Ahmed @ 2026-07-17 16:45 UTC (permalink / raw) To: Hao Jia Cc: akpm, tj, hannes, shakeel.butt, mhocko, mkoutny, nphamcs, chengming.zhou, muchun.song, roman.gushchin, linux-mm, linux-kernel, linux-doc, Hao Jia On Fri, Jul 17, 2026 at 04:51:51PM +0800, Hao Jia wrote: > From: Hao Jia <jiahao1@lixiang.com> > > Currently, shrink_memcg() writes back at most one entry per-node during > its traversal. This makes shrink_worker() inefficient, as it must > repeatedly re-enter shrink_memcg() to make any substantial progress. > Under high memory pressure, this can cause the writeback speed to be > too slow to keep up with refaults, leading to zswap store failures and > forcing pages to skip zswap and go directly to disk, which results in > an LRU inversion. > > To address this, extend shrink_memcg() and rewrite its LRU iteration logic > to support batch writeback. Introduce the nr_to_scan parameter to bound how > many pages are scanned per call. This enables batch writeback in the > shrink_worker() path, while maintaining a low scan budget in the > zswap_store() path. > > Test Setup: > - Total memory: 32 GB. > - zswap settings: max_pool_percent=1, accept_threshold_percent=50, > shrinker_enabled=N. > > Test Case 1: > Allocate 512MB of anonymous pages and fill them with random data (to avoid > compression), then use cgroup memory.reclaim to force a large amount of > anonymous pages into zswap. At an interval of 2ms, allocate a 4K anonymous > page where the first 4 bytes are random numbers and the rest are zeros, and > then trigger a reclamation of this 4K anonymous page through cgroup > memory.reclaim. When the pool threshold is reached, shrink_memcg() will > be triggered. > The test data after running for 120s is as follows: > Baseline Patched > shrink_worker wakeups 5,363 85 > shrink_memcg calls 11,373,201 180,928 > written_back pages 40,212 40,236 > zswap_store calls 161,190 168,741 > store succeeded (ret=1) 102,743 127,644 > store rejected (ret=0) 58,447 41,097 > store reject rate ~36% ~24% > pool_limit_hit delta 55,826 14,062 > pswpout 98,659 81,333 > pswpin 2 1 > > Test Case 2: > To consistently force zswap store failures and trigger shrink_worker(), > the following stress-ng command was run for 120 seconds within a cgroup > limited to a memory.max of 1G: > bash -c 'echo $$ > /sys/fs/cgroup/zswaptest/cgroup.procs ; \ > exec stress-ng --vm 4 --vm-bytes 4G --vm-keep --vm-method rand-set -t \ > 120s -q' > The test data after running for 120s is as follows: > Baseline Patched > shrink_worker wakeups 5,640 987 > shrink_memcg calls 8,481,500 2,504,818 > written_back pages 260 768,576 > zswap_store calls 2,742,756 2,301,414 > store succeeded (ret=1) 934,640 1,308,686 > store rejected (ret=0) 1,808,116 992,728 > store reject rate ~66% ~43% > pool_limit_hit delta 1,181,310 101,593 > pswpout 1,808,376 1,761,304 > pswpin 4,288,497 3,902,658 > > Under identical workloads and runtimes, batching the zswap shrinker > exhibits a significant reduction in both shrink_worker wakeups and > shrink_memcg calls. Furthermore, the sharp drop in both pool_limit_hit > and zswap_store rejections demonstrates that batching the zswap shrinker > effectively mitigates zswap_store failures caused by hitting the pool > limit. This significantly prevents pages from bypassing zswap and falling > back directly to disk, thereby reducing LRU inversion. > > Suggested-by: Yosry Ahmed <yosry@kernel.org> > Signed-off-by: Hao Jia <jiahao1@lixiang.com> Acked-by: Yosry Ahmed <yosry@kernel.org> ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 2/2] mm/zswap: Support batch writeback in shrink_memcg() [not found] ` <20260717085151.22822-3-jiahao.kernel@gmail.com> 2026-07-17 16:45 ` [PATCH v2 2/2] mm/zswap: Support batch writeback in shrink_memcg() Yosry Ahmed @ 2026-07-17 16:46 ` Nhat Pham 1 sibling, 0 replies; 6+ messages in thread From: Nhat Pham @ 2026-07-17 16:46 UTC (permalink / raw) To: Hao Jia Cc: akpm, tj, hannes, shakeel.butt, mhocko, yosry, mkoutny, chengming.zhou, muchun.song, roman.gushchin, linux-mm, linux-kernel, linux-doc, Hao Jia On Fri, Jul 17, 2026 at 1:52 AM Hao Jia <jiahao.kernel@gmail.com> wrote: > > From: Hao Jia <jiahao1@lixiang.com> > > Currently, shrink_memcg() writes back at most one entry per-node during > its traversal. This makes shrink_worker() inefficient, as it must > repeatedly re-enter shrink_memcg() to make any substantial progress. > Under high memory pressure, this can cause the writeback speed to be > too slow to keep up with refaults, leading to zswap store failures and > forcing pages to skip zswap and go directly to disk, which results in > an LRU inversion. > > To address this, extend shrink_memcg() and rewrite its LRU iteration logic > to support batch writeback. Introduce the nr_to_scan parameter to bound how > many pages are scanned per call. This enables batch writeback in the > shrink_worker() path, while maintaining a low scan budget in the > zswap_store() path. > > Test Setup: > - Total memory: 32 GB. > - zswap settings: max_pool_percent=1, accept_threshold_percent=50, > shrinker_enabled=N. > > Test Case 1: > Allocate 512MB of anonymous pages and fill them with random data (to avoid > compression), then use cgroup memory.reclaim to force a large amount of > anonymous pages into zswap. At an interval of 2ms, allocate a 4K anonymous > page where the first 4 bytes are random numbers and the rest are zeros, and > then trigger a reclamation of this 4K anonymous page through cgroup > memory.reclaim. When the pool threshold is reached, shrink_memcg() will > be triggered. > The test data after running for 120s is as follows: > Baseline Patched > shrink_worker wakeups 5,363 85 > shrink_memcg calls 11,373,201 180,928 > written_back pages 40,212 40,236 > zswap_store calls 161,190 168,741 > store succeeded (ret=1) 102,743 127,644 > store rejected (ret=0) 58,447 41,097 > store reject rate ~36% ~24% > pool_limit_hit delta 55,826 14,062 > pswpout 98,659 81,333 > pswpin 2 1 > > Test Case 2: > To consistently force zswap store failures and trigger shrink_worker(), > the following stress-ng command was run for 120 seconds within a cgroup > limited to a memory.max of 1G: > bash -c 'echo $$ > /sys/fs/cgroup/zswaptest/cgroup.procs ; \ > exec stress-ng --vm 4 --vm-bytes 4G --vm-keep --vm-method rand-set -t \ > 120s -q' > The test data after running for 120s is as follows: > Baseline Patched > shrink_worker wakeups 5,640 987 > shrink_memcg calls 8,481,500 2,504,818 > written_back pages 260 768,576 > zswap_store calls 2,742,756 2,301,414 > store succeeded (ret=1) 934,640 1,308,686 > store rejected (ret=0) 1,808,116 992,728 > store reject rate ~66% ~43% > pool_limit_hit delta 1,181,310 101,593 > pswpout 1,808,376 1,761,304 > pswpin 4,288,497 3,902,658 > Acked-by: Nhat Pham <nphamcs@gmail.com> ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/2] mm/zswap: Fixes and improves the zswap global shrinker [not found] <20260717085151.22822-1-jiahao.kernel@gmail.com> [not found] ` <20260717085151.22822-3-jiahao.kernel@gmail.com> @ 2026-07-18 1:18 ` Andrew Morton 2026-07-18 1:22 ` Yosry Ahmed 2026-07-18 1:28 ` Yosry Ahmed 1 sibling, 2 replies; 6+ messages in thread From: Andrew Morton @ 2026-07-18 1:18 UTC (permalink / raw) To: Hao Jia Cc: tj, hannes, shakeel.butt, mhocko, yosry, mkoutny, nphamcs, chengming.zhou, muchun.song, roman.gushchin, linux-mm, linux-kernel, linux-doc, Hao Jia 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 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/2] mm/zswap: Fixes and improves the zswap global shrinker 2026-07-18 1:18 ` [PATCH v2 0/2] mm/zswap: Fixes and improves the zswap global shrinker Andrew Morton @ 2026-07-18 1:22 ` Yosry Ahmed 2026-07-18 1:28 ` Yosry Ahmed 1 sibling, 0 replies; 6+ messages in thread From: Yosry Ahmed @ 2026-07-18 1:22 UTC (permalink / raw) To: Andrew Morton Cc: Hao Jia, tj, hannes, shakeel.butt, mhocko, mkoutny, nphamcs, chengming.zhou, muchun.song, roman.gushchin, linux-mm, linux-kernel, linux-doc, Hao Jia 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. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/2] mm/zswap: Fixes and improves the zswap global shrinker 2026-07-18 1:18 ` [PATCH v2 0/2] mm/zswap: Fixes and improves the zswap global shrinker Andrew Morton 2026-07-18 1:22 ` Yosry Ahmed @ 2026-07-18 1:28 ` Yosry Ahmed 2026-07-18 4:40 ` Andrew Morton 1 sibling, 1 reply; 6+ messages in thread From: Yosry Ahmed @ 2026-07-18 1:28 UTC (permalink / raw) To: Andrew Morton Cc: Hao Jia, tj, hannes, shakeel.butt, mhocko, mkoutny, nphamcs, chengming.zhou, muchun.song, roman.gushchin, linux-mm, linux-kernel, linux-doc, Hao Jia 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" ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/2] mm/zswap: Fixes and improves the zswap global shrinker 2026-07-18 1:28 ` Yosry Ahmed @ 2026-07-18 4:40 ` Andrew Morton 0 siblings, 0 replies; 6+ messages in thread From: Andrew Morton @ 2026-07-18 4:40 UTC (permalink / raw) To: Yosry Ahmed Cc: Hao Jia, tj, hannes, shakeel.butt, mhocko, mkoutny, nphamcs, chengming.zhou, muchun.song, roman.gushchin, linux-mm, linux-kernel, linux-doc, Hao Jia 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? ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-07-18 4:40 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20260717085151.22822-1-jiahao.kernel@gmail.com>
[not found] ` <20260717085151.22822-3-jiahao.kernel@gmail.com>
2026-07-17 16:45 ` [PATCH v2 2/2] mm/zswap: Support batch writeback in shrink_memcg() Yosry Ahmed
2026-07-17 16:46 ` Nhat Pham
2026-07-18 1:18 ` [PATCH v2 0/2] mm/zswap: Fixes and improves the zswap global shrinker Andrew Morton
2026-07-18 1:22 ` Yosry Ahmed
2026-07-18 1:28 ` Yosry Ahmed
2026-07-18 4:40 ` Andrew Morton
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox