From: Andrew Morton <akpm@linux-foundation.org>
To: Jiayuan Chen <jiayuan.chen@linux.dev>
Cc: linux-mm@kvack.org, Jiayuan Chen <jiayuan.chen@shopee.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@kernel.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Shakeel Butt <shakeel.butt@linux.dev>,
Muchun Song <muchun.song@linux.dev>,
cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
Yosry Ahmed <yosry@kernel.org>, Nhat Pham <nphamcs@gmail.com>,
Chengming Zhou <chengming.zhou@linux.dev>
Subject: Re: [PATCH v2] mm: memcg: reset zswap settings in css_reset
Date: Sun, 5 Jul 2026 14:01:33 -0700 [thread overview]
Message-ID: <20260705140133.e0534a0be91346860fd9056f@linux-foundation.org> (raw)
In-Reply-To: <20260702024827.353185-1-jiayuan.chen@linux.dev>
On Thu, 2 Jul 2026 10:48:25 +0800 Jiayuan Chen <jiayuan.chen@linux.dev> wrote:
> From: Jiayuan Chen <jiayuan.chen@shopee.com>
>
> mem_cgroup_css_reset() is called when the memory controller is disabled
> on a cgroup but the memcg cannot be destroyed because it is pinned by a
> subsystem dependency -- for example, the io controller declares
> .depends_on = 1 << memory_cgrp_id, so memory remains in the cgroup_ss_mask
> and the css is hidden rather than killed.
>
> The purpose of css_reset is to revert the memcg to its vanilla state so
> that no policies are applied and the css can be safely made visible again
> later. Currently, all page counters (memory.max, swap.max, kmem.max,
> tcpmem.max) and other limits (soft_limit, memory.high, swap.high) are
> reset to their defaults, but zswap_max and zswap_writeback are not.
>
> These fields are initialized in css_alloc (zswap_max = PAGE_COUNTER_MAX,
> zswap_writeback inherited from parent) but were missing from css_reset.
> As a result, stale zswap policies remain in effect after css_reset: the
> zswap charge path (obj_cgroup_may_zswap) continues to enforce the old
> zswap_max limit, and the writeback path continues to honor the old
> zswap_writeback setting, even though the memory controller has been
> "disabled" on this cgroup.
>
> Reset zswap_max to PAGE_COUNTER_MAX and zswap_writeback to true, matching
> their defaults in css_alloc.
>
> Test:
> echo "+memory +io" > /sys/fs/cgroup/cgroup.subtree_control
>
> mkdir /sys/fs/cgroup/test
> mkdir /sys/fs/cgroup/test/child
>
> echo "+memory +io" > /sys/fs/cgroup/test/cgroup.subtree_control
> echo 10000 > /sys/fs/cgroup/test/child/memory.zswap.max
>
> # child/memory.swap.max and child/memory.zswam.max disappear
> echo "-memory" > /sys/fs/cgroup/test/cgroup.subtree_control
>
> # re-enable memory control
> echo "+memory" > /sys/fs/cgroup/test/cgroup.subtree_control
>
> # before this patch
> cat /sys/fs/cgroup/test/child/memory.zswap.max
> 8192
>
> # after this patch, same as memory.swap.max
> cat /sys/fs/cgroup/test/child/memory.zswap.max
> max
Thanks.
You convinced me, so I'll queue this for testing.
The problem is old and doesn't sound serious, so I'll target 7.3-rc1,
no cc:stable. If people disagree, please speak up.
AI review suggest that memcg->oom_group is missing similar treatment:
https://sashiko.dev/#/patchset/20260702024827.353185-1-jiayuan.chen@linux.dev
next prev parent reply other threads:[~2026-07-05 21:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-02 2:48 [PATCH v2] mm: memcg: reset zswap settings in css_reset Jiayuan Chen
2026-07-02 4:07 ` Tao Cui
2026-07-05 21:02 ` Andrew Morton
2026-07-05 21:01 ` Andrew Morton [this message]
2026-07-06 6:28 ` Muchun Song
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=20260705140133.e0534a0be91346860fd9056f@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=chengming.zhou@linux.dev \
--cc=hannes@cmpxchg.org \
--cc=jiayuan.chen@linux.dev \
--cc=jiayuan.chen@shopee.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=muchun.song@linux.dev \
--cc=nphamcs@gmail.com \
--cc=roman.gushchin@linux.dev \
--cc=shakeel.butt@linux.dev \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.