From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) (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 5B4A130EF95 for ; Thu, 2 Jul 2026 04:07:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782965280; cv=none; b=g2y+m0ui2uj4fnYDZudDkuSMxW9XSMa+Wyfye6areCW15dFQJKOiYYj5fpvIH8HnahqhR3g4Td6r4m/t/bdqX7wjTVpXkCNDNvnefLas4VCbgDts85ccXh2HOQ8fvmMWdS/bNhqK7tB8yBmpBRoehdnS6nZgRVLkkhie6kCwNH8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782965280; c=relaxed/simple; bh=JO/rc5S23HcLrRND/w9mJoluJz2WSnwOBzliYLmFPBI=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=nqb7fc224whaXNDvnQWh4bqgBINQUagNe5okQxZIADOJUpnhnLGKvv0lkcsPaydbkCZ9xHi8fZ7c263tp7pk67HaRFfJ/iiXCORvCwD0rAuc8BK17SLFJJt2efws5E8H92XwgTtw4nRn0r1mIidKiP5zoC7rY5oSB1iV5ExRHZU= 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=gDo5zERz; arc=none smtp.client-ip=95.215.58.177 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="gDo5zERz" Message-ID: <722b2c40-6d82-4eef-b3f1-245fba465bc0@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1782965267; 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=2AovqoixRJbzgcohmdgNG4ANWv+GPmoDcUmWtAhUG20=; b=gDo5zERzLFG8NimjaDl5AVVRD+XbyUqBW9qln9wmqJ7B033hjFyMZYRZ7Ihcqx6HRX7Ya6 UpEzyT+ZfpzjmeTq5mDWJ6V+NN/2D7HDjTYNOYEvsVaQ3DWx0VT20/FMoiZKD5z9nHMSLK oaHdnT03Ojvn/oOpkyLHgTcj0f068qA= Date: Thu, 2 Jul 2026 12:07:23 +0800 Precedence: bulk X-Mailing-List: cgroups@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Cc: cui.tao@linux.dev, Jiayuan Chen , Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm: memcg: reset zswap settings in css_reset To: Jiayuan Chen , linux-mm@kvack.org References: <20260702024827.353185-1-jiayuan.chen@linux.dev> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Tao Cui In-Reply-To: <20260702024827.353185-1-jiayuan.chen@linux.dev> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT 在 2026/7/2 10:48, Jiayuan Chen 写道: > 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 > Looks good to me. One trivial nit on the commit message (not the patch): # child/memory.swap.max and child/memory.zswam.max disappear zswam -> zswap Reviewed-by: Tao Cui > # 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 > --- > v1 -> v2 : add WRITE_ONCE. > https://lore.kernel.org/linux-mm/20260630100832.107062-1-jiayuan.chen@linux.dev/ > --- > mm/memcontrol.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index d20ffc827306..c20ef3c1d6fe 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 > + WRITE_ONCE(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);