mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chen Ridong <chenridong@huaweicloud.com>
To: "Guopeng Zhang" <zhangguopeng@kylinos.cn>,
	"Tejun Heo" <tj@kernel.org>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Michal Koutný" <mkoutny@suse.com>
Cc: Yi Tao <escape@linux.alibaba.com>,
	cgroups@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] cgroup: Keep favordynmods enabled once per-threadgroup rwsem is active
Date: Tue, 12 May 2026 08:46:24 +0800	[thread overview]
Message-ID: <9d20f8f5-dbb4-4b39-af0d-8a4b34d77f9c@huaweicloud.com> (raw)
In-Reply-To: <08ab3e19-38f7-4892-b752-c3a601ed15ba@huaweicloud.com>



On 2026/5/11 20:08, Chen Ridong wrote:
> 
> 
> On 2026/5/11 17:53, Guopeng Zhang wrote:
>>
>>
>> 在 2026/5/11 17:05, Chen Ridong 写道:
>>>
>>>
>>> On 2026/5/11 16:16, Guopeng Zhang wrote:
>>>> cgroup_enable_per_threadgroup_rwsem is a one-way switch. Once it is
>>>> enabled, cgroup.procs writes use the per-threadgroup rwsem and
>>>> cgroup_threadgroup_change_begin()/end() use the same global state to
>>>> decide whether to take and release the per-threadgroup rwsem.
>>>>
>>>> The disable path warned that the per-threadgroup rwsem mechanism could not
>>>> be disabled but still called rcu_sync_exit() and cleared
>>>> CGRP_ROOT_FAVOR_DYNMODS. That partially disabled favordynmods while the
>>>> global per-threadgroup rwsem mode remained enabled: cgroup.procs writes
>>>> would continue to use the per-threadgroup rwsem, while
>>>> cgroup_threadgroup_change_begin()/end() could observe the exited rcu_sync
>>>> state. The root would also no longer report favordynmods.
>>>>
>>>> Make the transition match the documented one-way semantics. Call
>>>> rcu_sync_enter() only for the first favordynmods enable, and make later
>>>> disable attempts a no-op after warning once the per-threadgroup rwsem mode
>>>> has been enabled.
>>>>
>>>> Fixes: 0568f89d4fb8 ("cgroup: replace global percpu_rwsem with per threadgroup resem when writing to cgroup.procs")
>>>> Signed-off-by: Guopeng Zhang <zhangguopeng@kylinos.cn>
>>>> ---
>>>> Manual AB test:
>>>>
>>>> Before this patch:
>>>>   enable favordynmods:
>>>>     cgroup2 opts: rw,relatime,favordynmods
>>>>   disable attempt:
>>>>     cgroup2 opts: rw,relatime
>>>>   dmesg:
>>>>     cgroup: cgroup favordynmods: per threadgroup rwsem mechanism can't be disabled
>>>>
>>>> After this patch:
>>>>   enable favordynmods:
>>>>     cgroup2 opts: rw,relatime,favordynmods
>>>>   disable attempt:
>>>>     cgroup2 opts: rw,relatime,favordynmods
>>>>   dmesg:
>>>>     cgroup: cgroup favordynmods: per threadgroup rwsem mechanism can't be disabled
>>>>
>>>>  kernel/cgroup/cgroup.c | 11 +++++------
>>>>  1 file changed, 5 insertions(+), 6 deletions(-)
>>>>
>>>> diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
>>>> index 6152add0c5eb..fd10fb5b3598 100644
>>>> --- a/kernel/cgroup/cgroup.c
>>>> +++ b/kernel/cgroup/cgroup.c
>>>> @@ -1297,14 +1297,13 @@ void cgroup_favor_dynmods(struct cgroup_root *root, bool favor)
>>>>  	 */
>>>>  	percpu_down_write(&cgroup_threadgroup_rwsem);
>>>>  	if (favor && !favoring) {
>>>> -		cgroup_enable_per_threadgroup_rwsem = true;
>>>> -		rcu_sync_enter(&cgroup_threadgroup_rwsem.rss);
>>>> +		if (!cgroup_enable_per_threadgroup_rwsem) {
>>>
>>> Is this branch redundant? I think if (favor && !favoring) alone should suffice —
>>> or can the outer condition be true twice (i.e., can this block be entered
>>> multiple times)?
>>> Hi Ridong,
>>
>> Thanks for taking a look.
>>
>> I don't think the inner check is redundant. `favoring` is per-root, while
>> `cgroup_enable_per_threadgroup_rwsem` is global.
>>
>> For example, root A may have already enabled favordynmods:
>>
> 
> This functionality is only available for cgroup v2, right?
> 

Sorry for the mistake. I incorrectly recalled that it was only available for v2.
Please ignore that.

-- 
Best regards,
Ridong


      reply	other threads:[~2026-05-12  0:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-11  8:16 Guopeng Zhang
2026-05-11  8:56 ` Tejun Heo
2026-05-11  9:52   ` Guopeng Zhang
2026-05-11  9:05 ` Chen Ridong
2026-05-11  9:53   ` Guopeng Zhang
2026-05-11 12:08     ` Chen Ridong
2026-05-12  0:46       ` Chen Ridong [this message]

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=9d20f8f5-dbb4-4b39-af0d-8a4b34d77f9c@huaweicloud.com \
    --to=chenridong@huaweicloud.com \
    --cc=cgroups@vger.kernel.org \
    --cc=escape@linux.alibaba.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mkoutny@suse.com \
    --cc=tj@kernel.org \
    --cc=zhangguopeng@kylinos.cn \
    /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

all inboxes | Powered by JetHome®