From: Hao Jia <jiahao.kernel@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Yosry Ahmed <yosry@kernel.org>,
nphamcs@gmail.com
Cc: tj@kernel.org, hannes@cmpxchg.org, shakeel.butt@linux.dev,
mhocko@kernel.org, mkoutny@suse.com, chengming.zhou@linux.dev,
muchun.song@linux.dev, roman.gushchin@linux.dev,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
linux-doc@vger.kernel.org, Hao Jia <jiahao1@lixiang.com>,
stable@vger.kernel.org
Subject: Re: [PATCH 1/2] mm/zswap: Fix global shrinker when memory cgroup is disabled
Date: Wed, 15 Jul 2026 20:30:43 +0800 [thread overview]
Message-ID: <7a1fe347-7ca6-4768-9308-420bf1251f54@gmail.com> (raw)
In-Reply-To: <20260714193129.f81711f516504b659d544741@linux-foundation.org>
On 2026/7/15 10:31, Andrew Morton wrote:
> On Tue, 14 Jul 2026 09:52:59 -0700 Yosry Ahmed <yosry@kernel.org> wrote:
>
>>> When memory cgroup is disabled, 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.
>>>
>>> Therefore, when memory cgroup is disabled, fall through with the !memcg
>>> branch and shrink the root memcg directly.
>>>
>>> With memcg disabled, shrink_memcg() only returns -ENOENT when the root
>>> LRU is empty, which means the total pages are already below thr. The
>>> loop then safely bails out via the zswap_total_pages() <= thr check.
>>> For any other return value from shrink_memcg(), the loop is guaranteed
>>> to terminate, either after MAX_RECLAIM_RETRIES failures or once the
>>> threshold is met.
>>>
>>> Fixes: a65b0e7607cc ("zswap: make shrinking memcg-aware")
>>> Cc: stable@vger.kernel.org
>>> Suggested-by: Nhat Pham <nphamcs@gmail.com>
>>> Acked-by: Nhat Pham <nphamcs@gmail.com>
>>> Acked-by: Yosry Ahmed <yosry@kernel.org>
>>> Reported-by: Yosry Ahmed <yosry@kernel.org>
>>> Closes: https://lore.kernel.org/all/CAO9r8zPVzMKFbCixxD-qgtRrkFxWVrHiZZeLc=eyTPKPVQgX4g@mail.gmail.com
>>> Signed-off-by: Hao Jia <jiahao1@lixiang.com>
>>
>> Patch 2 doesn't really depend on this one, right?
>>
>> If that's the case I think this can (and should be) picked up
>> separately as a hotfix. Andrew, WDYT?
>
> Please update the changelog to clearly describe the userspace-visible
> effects of the bug, thanks.
I am not entirely sure if my understanding is correct here, but maybe I
should add something like this to the commit message?
When cgroup_disable=memory is used (or with CONFIG_MEMCG=n), the global
shrinker fails to write back any pages. Consequently, the zswap pool
fills up to its limit and rejects further storage, preventing memory
pressure from being offloaded to the backing swap device.
> Also, AI review has flagged several possible issues, all appear to be
> serious:
> https://sashiko.dev/#/patchset/20260714081510.16895-1-jiahao.kernel@gmail.com
For AI review comments on this patch:
I suspect this scenario might only exist in theory. For zswap LRU to be
empty while zswap_total_pages() > thr holds true, it would require a
prolonged state where there are always more than thr zswap entries on
the zswap LRU whenever zswap_total_pages() > thr is evaluated, yet the
zswap LRU happens to be empty during shrink_memcg(root_memcg).
If we want to fix this, perhaps we could do something like this?
Yosry, Nhat, what are your thoughts on this?
diff --git a/mm/zswap.c b/mm/zswap.c
index b5a17ea20237..ca71b517a58d 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -1356,11 +1356,12 @@ static void shrink_worker(struct work_struct *w)
} while (memcg && !mem_cgroup_tryget_online(memcg));
spin_unlock(&zswap_shrink_lock);
- if (!memcg) {
- /*
- * Continue shrinking without incrementing
failures if
- * we found candidate memcgs in the last tree walk.
- */
+ /*
+ * A NULL memcg ends a full hierarchy pass (except when
memcg is
+ * disabled, where it is always NULL: fall through to
the root LRU).
+ * Count a failure only if the last pass found no
candidates.
+ */
+ if (!memcg && !mem_cgroup_disabled()) {
if (!attempts && ++failures == MAX_RECLAIM_RETRIES)
break;
@@ -1378,8 +1379,15 @@ static void shrink_worker(struct work_struct *w)
* with pages in zswap. Skip this without incrementing
attempts
* and failures.
*/
- if (ret == -ENOENT)
+ if (ret == -ENOENT) {
+ /*
+ * With memcg disabled the root LRU is the only
target, so
+ * we should abort if it has no
writeback-candidate pages.
+ */
+ if (mem_cgroup_disabled())
+ break;
continue;
+ }
++attempts;
if (ret && ++failures == MAX_RECLAIM_RETRIES)
Thanks,
Hao
next prev parent reply other threads:[~2026-07-15 12:31 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-14 8:15 [PATCH 0/2] mm/zswap: Fixes and improves the zswap global shrinker Hao Jia
2026-07-14 8:15 ` [PATCH 1/2] mm/zswap: Fix global shrinker when memory cgroup is disabled Hao Jia
2026-07-14 16:52 ` Yosry Ahmed
2026-07-15 2:31 ` Andrew Morton
2026-07-15 12:30 ` Hao Jia [this message]
2026-07-15 16:13 ` Yosry Ahmed
2026-07-14 8:15 ` [PATCH 2/2] mm/zswap: Support batch writeback in shrink_memcg() Hao Jia
2026-07-14 16:52 ` Yosry Ahmed
2026-07-15 11:28 ` Hao Jia
2026-07-15 16:14 ` Yosry Ahmed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7a1fe347-7ca6-4768-9308-420bf1251f54@gmail.com \
--to=jiahao.kernel@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=chengming.zhou@linux.dev \
--cc=hannes@cmpxchg.org \
--cc=jiahao1@lixiang.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=mkoutny@suse.com \
--cc=muchun.song@linux.dev \
--cc=nphamcs@gmail.com \
--cc=roman.gushchin@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=stable@vger.kernel.org \
--cc=tj@kernel.org \
--cc=yosry@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox