From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-182.mta1.migadu.com (out-182.mta1.migadu.com [95.215.58.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E30503F5BE5 for ; Tue, 30 Jun 2026 10:44:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782816298; cv=none; b=e7S92cHRTdRJBIJZYF20ngWD/uiKfQPuQWFogU0/c2dApj+U7tqnjV1H/STHE3NeMvAPdSszuSSqFLOPnFkNjhItLiO7iIlK6el482376VIxKRIYUBJzO2Gjzb4TvkssyovLRL0jizoCykUieMkv8V2ZRUQl8Q3BJBrWHxjs5yI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782816298; c=relaxed/simple; bh=dNUphZ+P4RvXzyL7+wp/p1ux06KtBOrOaXVEx+ZdBhs=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=lsxMQGs7xxgVDLpFdq/hbtPGI8V+e+v0eVTFzviOSSU2NnHbN6ljG7KAphcGdJ/PfdDf3X3PpUJ7jgO9CBOKfjr7fPwjb1uiq1CIx5PmLvR3T+DJ40my/6ytT8Y8SkfGLOyQAe9hBmve/JKK4Dm3UPwHxsUnMbiCFWim2lH+lHE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=XHYswoBS; arc=none smtp.client-ip=95.215.58.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="XHYswoBS" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1782816292; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pLRS7nAqGz48MGg7TIU1nka9vUVrVauvgr4FneekIG0=; b=XHYswoBSXYGhbmC1LEOvVbk31oj5YII1IAkDH1/MNafvK9SSO+2C3YK+RXrk58DYfS0Qqk /hV+o5FnPxzg+bukyKwurLyVJoggsDPxUfLg5OtO2GvxzyvipgtJydSRyPut3qdySn74/z f+OCW7UiVu659VzjphMQfSqJgWb0NcA= Date: Tue, 30 Jun 2026 18:44:28 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH] mm: memcg: reset zswap settings in css_reset To: linux-mm@kvack.org Cc: Jiayuan Chen , Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org References: <20260630100832.107062-1-jiayuan.chen@linux.dev> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Jiayuan Chen In-Reply-To: <20260630100832.107062-1-jiayuan.chen@linux.dev> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT On 6/30/26 6:08 PM, Jiayuan Chen wrote: > From: Jiayuan Chen > > 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 > > Cc: Jiayuan Chen > Signed-off-by: Jiayuan Chen > --- > mm/memcontrol.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index d20ffc827306..eeeb22a5e8cc 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -4362,6 +4362,10 @@ static void mem_cgroup_css_reset(struct cgroup_subsys_state *css) > > page_counter_set_max(&memcg->memory, PAGE_COUNTER_MAX); > page_counter_set_max(&memcg->swap, PAGE_COUNTER_MAX); > +#ifdef CONFIG_ZSWAP > + memcg->zswap_max = PAGE_COUNTER_MAX; > + WRITE_ONCE(memcg->zswap_writeback, true); > +#endif > #ifdef CONFIG_MEMCG_V1 > page_counter_set_max(&memcg->kmem, PAGE_COUNTER_MAX); > page_counter_set_max(&memcg->tcpmem, PAGE_COUNTER_MAX); https://sashiko.dev/#/patchset/20260630100832.107062-1-jiayuan.chen%40linux.dev Ai is right... Also I'm thinking that should we add a helper instead of using open code in css_alloc and  css_reset ? static void memcg_zswap_reset(struct mem_cgroup *memcg) { #ifdef CONFIG_ZSWAP     WRITE_ONCE(memcg->zswap_max, PAGE_COUNTER_MAX);     WRITE_ONCE(memcg->zswap_writeback, true); #endif } mem_cgroup_css_reset() { ... memcg_zswap_reset() ... } mem_cgroup_css_alloc() { ... memcg_zswap_reset() ... }