mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] cgroup/cpuset: Use cpuset_v2() in cpuset_num_cpus()
@ 2026-09-30 15:48 Waiman Long
  2026-09-30 16:13 ` Andrea Righi
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Waiman Long @ 2026-09-30 15:48 UTC (permalink / raw)
  To: Ridong Chen, Tejun Heo, Johannes Weiner, Michal Koutný,
	Peter Zijlstra
  Cc: cgroups, linux-kernel, Andrea Righi, Waiman Long

The cpuset code has 2 different helpers for determining if it is in a
v1 or v2 working environment - cpuset_v2() and is_in_v2_mode().

cpuset_v2() checks the binding of the cpuset subsystem is on a v1
or v2 hierarchy. It can also help to optimize out v1 specific code
if CONFIG_CPUSETS_V1 isn't defined.

is_in_v2_mode() layers on top of cpuset_v2() and returns true if it is in
a v2 hierarchy or in a v1 hierarchy with "cpuset_v2_mode" mount option
enabled to make "cpuset.cpus" and "cpuset.mems" behave in a way similar
to their v2 counterparts. However the cpuset hierarchy may still be a
standalone one separated from the other cgroup hierarchies.

Commit 90ac22ffef48 ("sched/fair: Add cgroup_mode: max") adds a new
cpuset_num_cpus() helper to return the number of effective CPUs in a given
cgroup. It is part of the "sched: Flatten the pick" patch series to help
flatten the cpu cgroup runqueue hierachies. cpuset_num_cpus() currently
uses is_in_v2_mode() to determine if it is in a v2 environment. However
is_in_v2_mode() can be true in a v1 environment where the cpuset and cpu
cgroup subsystems can be in two separate hierachies. The current use
case [1] for cpuset_num_cpus() assumes that it can return the number
of effective CPUs present in the current cpu cgroup which may not be
the case.

Fix that by switching to use cpuset_v2() which signifies that it is in
a unified hierarchy where both cpuset and cpu cgroup subsystems share
the same cgroup hierarchy if it returns true.

[1] https://lore.kernel.org/lkml/20260930081125.GF88198@noisy.programming.kicks-ass.net

Fixes: 90ac22ffef48 ("sched/fair: Add cgroup_mode: max")
Signed-off-by: Waiman Long <longman@redhat.com>
---
 kernel/cgroup/cpuset.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 4a2b6f154609..cbf67ad13874 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -4251,7 +4251,7 @@ int cpuset_num_cpus(struct cgroup *cgrp)
 	int nr = num_online_cpus();
 	struct cpuset *cs;
 
-	if (is_in_v2_mode()) {
+	if (cpuset_v2()) {
 		guard(rcu)();
 		cs = css_cs(cgroup_e_css(cgrp, &cpuset_cgrp_subsys));
 		if (cs)
-- 
2.55.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] cgroup/cpuset: Use cpuset_v2() in cpuset_num_cpus()
  2026-09-30 15:48 [PATCH] cgroup/cpuset: Use cpuset_v2() in cpuset_num_cpus() Waiman Long
@ 2026-09-30 16:13 ` Andrea Righi
  2026-09-30 16:47 ` Michal Koutný
  2026-09-30 17:37 ` Tejun Heo
  2 siblings, 0 replies; 4+ messages in thread
From: Andrea Righi @ 2026-09-30 16:13 UTC (permalink / raw)
  To: Waiman Long
  Cc: Ridong Chen, Tejun Heo, Johannes Weiner, Michal Koutný,
	Peter Zijlstra, cgroups, linux-kernel

Hi Waiman,

On Wed, Sep 30, 2026 at 11:48:00AM -0400, Waiman Long wrote:
> The cpuset code has 2 different helpers for determining if it is in a
> v1 or v2 working environment - cpuset_v2() and is_in_v2_mode().
> 
> cpuset_v2() checks the binding of the cpuset subsystem is on a v1
> or v2 hierarchy. It can also help to optimize out v1 specific code
> if CONFIG_CPUSETS_V1 isn't defined.
> 
> is_in_v2_mode() layers on top of cpuset_v2() and returns true if it is in
> a v2 hierarchy or in a v1 hierarchy with "cpuset_v2_mode" mount option
> enabled to make "cpuset.cpus" and "cpuset.mems" behave in a way similar
> to their v2 counterparts. However the cpuset hierarchy may still be a
> standalone one separated from the other cgroup hierarchies.
> 
> Commit 90ac22ffef48 ("sched/fair: Add cgroup_mode: max") adds a new
> cpuset_num_cpus() helper to return the number of effective CPUs in a given
> cgroup. It is part of the "sched: Flatten the pick" patch series to help
> flatten the cpu cgroup runqueue hierachies. cpuset_num_cpus() currently
> uses is_in_v2_mode() to determine if it is in a v2 environment. However
> is_in_v2_mode() can be true in a v1 environment where the cpuset and cpu
> cgroup subsystems can be in two separate hierachies. The current use
> case [1] for cpuset_num_cpus() assumes that it can return the number
> of effective CPUs present in the current cpu cgroup which may not be
> the case.
> 
> Fix that by switching to use cpuset_v2() which signifies that it is in
> a unified hierarchy where both cpuset and cpu cgroup subsystems share
> the same cgroup hierarchy if it returns true.
> 
> [1] https://lore.kernel.org/lkml/20260930081125.GF88198@noisy.programming.kicks-ass.net
> 
> Fixes: 90ac22ffef48 ("sched/fair: Add cgroup_mode: max")
> Signed-off-by: Waiman Long <longman@redhat.com>

Works for my particular sched_ext use case.

Reviewed-by: Andrea Righi <arighi@nvidia.com>

Thanks,
-Andrea

> ---
>  kernel/cgroup/cpuset.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 4a2b6f154609..cbf67ad13874 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -4251,7 +4251,7 @@ int cpuset_num_cpus(struct cgroup *cgrp)
>  	int nr = num_online_cpus();
>  	struct cpuset *cs;
>  
> -	if (is_in_v2_mode()) {
> +	if (cpuset_v2()) {
>  		guard(rcu)();
>  		cs = css_cs(cgroup_e_css(cgrp, &cpuset_cgrp_subsys));
>  		if (cs)
> -- 
> 2.55.0
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] cgroup/cpuset: Use cpuset_v2() in cpuset_num_cpus()
  2026-09-30 15:48 [PATCH] cgroup/cpuset: Use cpuset_v2() in cpuset_num_cpus() Waiman Long
  2026-09-30 16:13 ` Andrea Righi
@ 2026-09-30 16:47 ` Michal Koutný
  2026-09-30 17:37 ` Tejun Heo
  2 siblings, 0 replies; 4+ messages in thread
From: Michal Koutný @ 2026-09-30 16:47 UTC (permalink / raw)
  To: Waiman Long
  Cc: Ridong Chen, Tejun Heo, Johannes Weiner, Peter Zijlstra, cgroups,
	linux-kernel, Andrea Righi

[-- Attachment #1: Type: text/plain, Size: 2014 bytes --]

On Wed, Sep 30, 2026 at 11:48:00AM -0400, Waiman Long <longman@redhat.com> wrote:
> The cpuset code has 2 different helpers for determining if it is in a
> v1 or v2 working environment - cpuset_v2() and is_in_v2_mode().
> 
> cpuset_v2() checks the binding of the cpuset subsystem is on a v1
> or v2 hierarchy. It can also help to optimize out v1 specific code
> if CONFIG_CPUSETS_V1 isn't defined.
> 
> is_in_v2_mode() layers on top of cpuset_v2() and returns true if it is in
> a v2 hierarchy or in a v1 hierarchy with "cpuset_v2_mode" mount option
> enabled to make "cpuset.cpus" and "cpuset.mems" behave in a way similar
> to their v2 counterparts. However the cpuset hierarchy may still be a
> standalone one separated from the other cgroup hierarchies.
> 
> Commit 90ac22ffef48 ("sched/fair: Add cgroup_mode: max") adds a new
> cpuset_num_cpus() helper to return the number of effective CPUs in a given
> cgroup. It is part of the "sched: Flatten the pick" patch series to help
> flatten the cpu cgroup runqueue hierachies. cpuset_num_cpus() currently
> uses is_in_v2_mode() to determine if it is in a v2 environment. However
> is_in_v2_mode() can be true in a v1 environment where the cpuset and cpu
> cgroup subsystems can be in two separate hierachies. The current use
> case [1] for cpuset_num_cpus() assumes that it can return the number
> of effective CPUs present in the current cpu cgroup which may not be
> the case.
> 
> Fix that by switching to use cpuset_v2() which signifies that it is in
> a unified hierarchy where both cpuset and cpu cgroup subsystems share
> the same cgroup hierarchy if it returns true.
> 
> [1] https://lore.kernel.org/lkml/20260930081125.GF88198@noisy.programming.kicks-ass.net
> 
> Fixes: 90ac22ffef48 ("sched/fair: Add cgroup_mode: max")
> Signed-off-by: Waiman Long <longman@redhat.com>
> ---
>  kernel/cgroup/cpuset.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Thanks!
Reviewed-by: Michal Koutný <mkoutny@suse.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 265 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] cgroup/cpuset: Use cpuset_v2() in cpuset_num_cpus()
  2026-09-30 15:48 [PATCH] cgroup/cpuset: Use cpuset_v2() in cpuset_num_cpus() Waiman Long
  2026-09-30 16:13 ` Andrea Righi
  2026-09-30 16:47 ` Michal Koutný
@ 2026-09-30 17:37 ` Tejun Heo
  2 siblings, 0 replies; 4+ messages in thread
From: Tejun Heo @ 2026-09-30 17:37 UTC (permalink / raw)
  To: Waiman Long
  Cc: Ridong Chen, Johannes Weiner, Michal Koutný,
	Peter Zijlstra, Andrea Righi, cgroups, linux-kernel

Applied to cgroup/for-7.4 with the "hierachies" typos in the description
fixed.

Thanks.

--
tejun

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-09-30 17:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-30 15:48 [PATCH] cgroup/cpuset: Use cpuset_v2() in cpuset_num_cpus() Waiman Long
2026-09-30 16:13 ` Andrea Righi
2026-09-30 16:47 ` Michal Koutný
2026-09-30 17:37 ` Tejun Heo

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®