* [PATCH] sched: cgroup: Move task_can_attach() to cpuset.c
@ 2025-10-03 16:14 Steven Rostedt
2025-10-03 16:36 ` Andrea Righi
` (4 more replies)
0 siblings, 5 replies; 10+ messages in thread
From: Steven Rostedt @ 2025-10-03 16:14 UTC (permalink / raw)
To: LKML
Cc: Peter Zijlstra, Ingo Molnar, Juri Lelli, Vincent Guittot,
Waiman Long, Tejun Heo, Johannes Weiner, Michal Koutný,
Andrea Righi, Julia Lawall, Luis Claudio R. Goncalves,
Joseph Salisbury
From: Steven Rostedt <rostedt@goodmis.org>
At our monthly stable meeting, we were talking about documenting non
static functions and randomly picked a function to look at. That was
task_can_attach(). It was then noticed that it's only used by
cgroup/cpuset.c and nothing else. It's a simple function that doesn't
reference anything unique to sched/core.c, hence there's no reason that
function should be there.
Move it to cgroup/cpuset.c as that's the only place it is used. Also make
it a static inline as it is so small.
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
include/linux/sched.h | 1 -
kernel/cgroup/cpuset.c | 19 +++++++++++++++++++
kernel/sched/core.c | 19 -------------------
3 files changed, 19 insertions(+), 20 deletions(-)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index e4ce0a76831e..4ee4fa973eda 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1849,7 +1849,6 @@ current_restore_flags(unsigned long orig_flags, unsigned long flags)
}
extern int cpuset_cpumask_can_shrink(const struct cpumask *cur, const struct cpumask *trial);
-extern int task_can_attach(struct task_struct *p);
extern int dl_bw_alloc(int cpu, u64 dl_bw);
extern void dl_bw_free(int cpu, u64 dl_bw);
diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 27adb04df675..21fe872803e8 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -3009,6 +3009,25 @@ static void reset_migrate_dl_data(struct cpuset *cs)
cs->sum_migrate_dl_bw = 0;
}
+static inline int task_can_attach(struct task_struct *p)
+{
+ int ret = 0;
+
+ /*
+ * Kthreads which disallow setaffinity shouldn't be moved
+ * to a new cpuset; we don't want to change their CPU
+ * affinity and isolating such threads by their set of
+ * allowed nodes is unnecessary. Thus, cpusets are not
+ * applicable for such threads. This prevents checking for
+ * success of set_cpus_allowed_ptr() on all attached tasks
+ * before cpus_mask may be changed.
+ */
+ if (p->flags & PF_NO_SETAFFINITY)
+ ret = -EINVAL;
+
+ return ret;
+}
+
/* Called by cgroups to determine if a cpuset is usable; cpuset_mutex held */
static int cpuset_can_attach(struct cgroup_taskset *tset)
{
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index ccba6fc3c3fe..a195c4b25475 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -8070,25 +8070,6 @@ int cpuset_cpumask_can_shrink(const struct cpumask *cur,
return ret;
}
-int task_can_attach(struct task_struct *p)
-{
- int ret = 0;
-
- /*
- * Kthreads which disallow setaffinity shouldn't be moved
- * to a new cpuset; we don't want to change their CPU
- * affinity and isolating such threads by their set of
- * allowed nodes is unnecessary. Thus, cpusets are not
- * applicable for such threads. This prevents checking for
- * success of set_cpus_allowed_ptr() on all attached tasks
- * before cpus_mask may be changed.
- */
- if (p->flags & PF_NO_SETAFFINITY)
- ret = -EINVAL;
-
- return ret;
-}
-
bool sched_smp_initialized __read_mostly;
#ifdef CONFIG_NUMA_BALANCING
--
2.50.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] sched: cgroup: Move task_can_attach() to cpuset.c
2025-10-03 16:14 [PATCH] sched: cgroup: Move task_can_attach() to cpuset.c Steven Rostedt
@ 2025-10-03 16:36 ` Andrea Righi
2025-10-03 16:43 ` Steven Rostedt
2025-10-03 16:39 ` Waiman Long
` (3 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: Andrea Righi @ 2025-10-03 16:36 UTC (permalink / raw)
To: Steven Rostedt
Cc: LKML, Peter Zijlstra, Ingo Molnar, Juri Lelli, Vincent Guittot,
Waiman Long, Tejun Heo, Johannes Weiner, Michal Koutný,
Julia Lawall, Luis Claudio R. Goncalves, Joseph Salisbury
Hi Steven,
On Fri, Oct 03, 2025 at 12:14:21PM -0400, Steven Rostedt wrote:
> From: Steven Rostedt <rostedt@goodmis.org>
>
> At our monthly stable meeting, we were talking about documenting non
> static functions and randomly picked a function to look at. That was
> task_can_attach(). It was then noticed that it's only used by
> cgroup/cpuset.c and nothing else. It's a simple function that doesn't
> reference anything unique to sched/core.c, hence there's no reason that
> function should be there.
>
> Move it to cgroup/cpuset.c as that's the only place it is used. Also make
> it a static inline as it is so small.
>
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Nice cleanup. :)
Apparently it became that small with commit 2ef269ef1ac00 ("cgroup/cpuset:
Free DL BW in case can_attach() fails"), maybe we can mention that in the
commit message?
> ---
> include/linux/sched.h | 1 -
> kernel/cgroup/cpuset.c | 19 +++++++++++++++++++
> kernel/sched/core.c | 19 -------------------
> 3 files changed, 19 insertions(+), 20 deletions(-)
>
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index e4ce0a76831e..4ee4fa973eda 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -1849,7 +1849,6 @@ current_restore_flags(unsigned long orig_flags, unsigned long flags)
> }
>
> extern int cpuset_cpumask_can_shrink(const struct cpumask *cur, const struct cpumask *trial);
> -extern int task_can_attach(struct task_struct *p);
> extern int dl_bw_alloc(int cpu, u64 dl_bw);
> extern void dl_bw_free(int cpu, u64 dl_bw);
>
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 27adb04df675..21fe872803e8 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -3009,6 +3009,25 @@ static void reset_migrate_dl_data(struct cpuset *cs)
> cs->sum_migrate_dl_bw = 0;
> }
>
> +static inline int task_can_attach(struct task_struct *p)
> +{
> + int ret = 0;
> +
> + /*
> + * Kthreads which disallow setaffinity shouldn't be moved
> + * to a new cpuset; we don't want to change their CPU
> + * affinity and isolating such threads by their set of
> + * allowed nodes is unnecessary. Thus, cpusets are not
> + * applicable for such threads. This prevents checking for
> + * success of set_cpus_allowed_ptr() on all attached tasks
> + * before cpus_mask may be changed.
> + */
> + if (p->flags & PF_NO_SETAFFINITY)
> + ret = -EINVAL;
> +
> + return ret;
As we're cleaning up, we could just return -EINVAL and 0 directly and get
rid of that ret variable.
> +}
> +
> /* Called by cgroups to determine if a cpuset is usable; cpuset_mutex held */
> static int cpuset_can_attach(struct cgroup_taskset *tset)
> {
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index ccba6fc3c3fe..a195c4b25475 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -8070,25 +8070,6 @@ int cpuset_cpumask_can_shrink(const struct cpumask *cur,
> return ret;
> }
>
> -int task_can_attach(struct task_struct *p)
> -{
> - int ret = 0;
> -
> - /*
> - * Kthreads which disallow setaffinity shouldn't be moved
> - * to a new cpuset; we don't want to change their CPU
> - * affinity and isolating such threads by their set of
> - * allowed nodes is unnecessary. Thus, cpusets are not
> - * applicable for such threads. This prevents checking for
> - * success of set_cpus_allowed_ptr() on all attached tasks
> - * before cpus_mask may be changed.
> - */
> - if (p->flags & PF_NO_SETAFFINITY)
> - ret = -EINVAL;
> -
> - return ret;
> -}
> -
> bool sched_smp_initialized __read_mostly;
>
> #ifdef CONFIG_NUMA_BALANCING
> --
> 2.50.1
>
Thanks,
-Andrea
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] sched: cgroup: Move task_can_attach() to cpuset.c
2025-10-03 16:14 [PATCH] sched: cgroup: Move task_can_attach() to cpuset.c Steven Rostedt
2025-10-03 16:36 ` Andrea Righi
@ 2025-10-03 16:39 ` Waiman Long
2025-10-03 17:11 ` Luis Claudio R. Goncalves
` (2 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: Waiman Long @ 2025-10-03 16:39 UTC (permalink / raw)
To: Steven Rostedt, LKML
Cc: Peter Zijlstra, Ingo Molnar, Juri Lelli, Vincent Guittot,
Tejun Heo, Johannes Weiner, Michal Koutný, Andrea Righi,
Julia Lawall, Luis Claudio R. Goncalves, Joseph Salisbury
On 10/3/25 12:14 PM, Steven Rostedt wrote:
> From: Steven Rostedt <rostedt@goodmis.org>
>
> At our monthly stable meeting, we were talking about documenting non
> static functions and randomly picked a function to look at. That was
> task_can_attach(). It was then noticed that it's only used by
> cgroup/cpuset.c and nothing else. It's a simple function that doesn't
> reference anything unique to sched/core.c, hence there's no reason that
> function should be there.
>
> Move it to cgroup/cpuset.c as that's the only place it is used. Also make
> it a static inline as it is so small.
>
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> ---
> include/linux/sched.h | 1 -
> kernel/cgroup/cpuset.c | 19 +++++++++++++++++++
> kernel/sched/core.c | 19 -------------------
> 3 files changed, 19 insertions(+), 20 deletions(-)
>
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index e4ce0a76831e..4ee4fa973eda 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -1849,7 +1849,6 @@ current_restore_flags(unsigned long orig_flags, unsigned long flags)
> }
>
> extern int cpuset_cpumask_can_shrink(const struct cpumask *cur, const struct cpumask *trial);
> -extern int task_can_attach(struct task_struct *p);
> extern int dl_bw_alloc(int cpu, u64 dl_bw);
> extern void dl_bw_free(int cpu, u64 dl_bw);
>
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 27adb04df675..21fe872803e8 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -3009,6 +3009,25 @@ static void reset_migrate_dl_data(struct cpuset *cs)
> cs->sum_migrate_dl_bw = 0;
> }
>
> +static inline int task_can_attach(struct task_struct *p)
> +{
> + int ret = 0;
> +
> + /*
> + * Kthreads which disallow setaffinity shouldn't be moved
> + * to a new cpuset; we don't want to change their CPU
> + * affinity and isolating such threads by their set of
> + * allowed nodes is unnecessary. Thus, cpusets are not
> + * applicable for such threads. This prevents checking for
> + * success of set_cpus_allowed_ptr() on all attached tasks
> + * before cpus_mask may be changed.
> + */
> + if (p->flags & PF_NO_SETAFFINITY)
> + ret = -EINVAL;
> +
> + return ret;
> +}
> +
> /* Called by cgroups to determine if a cpuset is usable; cpuset_mutex held */
> static int cpuset_can_attach(struct cgroup_taskset *tset)
> {
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index ccba6fc3c3fe..a195c4b25475 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -8070,25 +8070,6 @@ int cpuset_cpumask_can_shrink(const struct cpumask *cur,
> return ret;
> }
>
> -int task_can_attach(struct task_struct *p)
> -{
> - int ret = 0;
> -
> - /*
> - * Kthreads which disallow setaffinity shouldn't be moved
> - * to a new cpuset; we don't want to change their CPU
> - * affinity and isolating such threads by their set of
> - * allowed nodes is unnecessary. Thus, cpusets are not
> - * applicable for such threads. This prevents checking for
> - * success of set_cpus_allowed_ptr() on all attached tasks
> - * before cpus_mask may be changed.
> - */
> - if (p->flags & PF_NO_SETAFFINITY)
> - ret = -EINVAL;
> -
> - return ret;
> -}
> -
> bool sched_smp_initialized __read_mostly;
>
> #ifdef CONFIG_NUMA_BALANCING
Acked-by: Waiman Long <longman@redhat.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] sched: cgroup: Move task_can_attach() to cpuset.c
2025-10-03 16:36 ` Andrea Righi
@ 2025-10-03 16:43 ` Steven Rostedt
2025-10-03 16:53 ` Andrea Righi
0 siblings, 1 reply; 10+ messages in thread
From: Steven Rostedt @ 2025-10-03 16:43 UTC (permalink / raw)
To: Andrea Righi
Cc: LKML, Peter Zijlstra, Ingo Molnar, Juri Lelli, Vincent Guittot,
Waiman Long, Tejun Heo, Johannes Weiner, Michal Koutný,
Julia Lawall, Luis Claudio R. Goncalves, Joseph Salisbury
On Fri, 3 Oct 2025 18:36:24 +0200
Andrea Righi <arighi@nvidia.com> wrote:
> Hi Steven,
>
> On Fri, Oct 03, 2025 at 12:14:21PM -0400, Steven Rostedt wrote:
> > From: Steven Rostedt <rostedt@goodmis.org>
> >
> > At our monthly stable meeting, we were talking about documenting non
> > static functions and randomly picked a function to look at. That was
> > task_can_attach(). It was then noticed that it's only used by
> > cgroup/cpuset.c and nothing else. It's a simple function that doesn't
> > reference anything unique to sched/core.c, hence there's no reason that
> > function should be there.
> >
> > Move it to cgroup/cpuset.c as that's the only place it is used. Also make
> > it a static inline as it is so small.
> >
> > Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
>
> Nice cleanup. :)
Thanks, since you also were the first to notice it is only used in one spot.
>
> Apparently it became that small with commit 2ef269ef1ac00 ("cgroup/cpuset:
> Free DL BW in case can_attach() fails"), maybe we can mention that in the
> commit message?
Sure.
>
> > ---
> > include/linux/sched.h | 1 -
> > kernel/cgroup/cpuset.c | 19 +++++++++++++++++++
> > kernel/sched/core.c | 19 -------------------
> > 3 files changed, 19 insertions(+), 20 deletions(-)
> >
> > diff --git a/include/linux/sched.h b/include/linux/sched.h
> > index e4ce0a76831e..4ee4fa973eda 100644
> > --- a/include/linux/sched.h
> > +++ b/include/linux/sched.h
> > @@ -1849,7 +1849,6 @@ current_restore_flags(unsigned long orig_flags, unsigned long flags)
> > }
> >
> > extern int cpuset_cpumask_can_shrink(const struct cpumask *cur, const struct cpumask *trial);
> > -extern int task_can_attach(struct task_struct *p);
> > extern int dl_bw_alloc(int cpu, u64 dl_bw);
> > extern void dl_bw_free(int cpu, u64 dl_bw);
> >
> > diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> > index 27adb04df675..21fe872803e8 100644
> > --- a/kernel/cgroup/cpuset.c
> > +++ b/kernel/cgroup/cpuset.c
> > @@ -3009,6 +3009,25 @@ static void reset_migrate_dl_data(struct cpuset *cs)
> > cs->sum_migrate_dl_bw = 0;
> > }
> >
> > +static inline int task_can_attach(struct task_struct *p)
> > +{
> > + int ret = 0;
> > +
> > + /*
> > + * Kthreads which disallow setaffinity shouldn't be moved
> > + * to a new cpuset; we don't want to change their CPU
> > + * affinity and isolating such threads by their set of
> > + * allowed nodes is unnecessary. Thus, cpusets are not
> > + * applicable for such threads. This prevents checking for
> > + * success of set_cpus_allowed_ptr() on all attached tasks
> > + * before cpus_mask may be changed.
> > + */
> > + if (p->flags & PF_NO_SETAFFINITY)
> > + ret = -EINVAL;
> > +
> > + return ret;
>
> As we're cleaning up, we could just return -EINVAL and 0 directly and get
> rid of that ret variable.
That should be a separate patch. Moves should really not do much else. I
even wondered about making it a static inline too, but figured that wasn't
touching the logic, and the function was going to become static anyway.
-- Steve
>
> > +}
> > +
> > /* Called by cgroups to determine if a cpuset is usable; cpuset_mutex held */
> > static int cpuset_can_attach(struct cgroup_taskset *tset)
> > {
> > diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> > index ccba6fc3c3fe..a195c4b25475 100644
> > --- a/kernel/sched/core.c
> > +++ b/kernel/sched/core.c
> > @@ -8070,25 +8070,6 @@ int cpuset_cpumask_can_shrink(const struct cpumask *cur,
> > return ret;
> > }
> >
> > -int task_can_attach(struct task_struct *p)
> > -{
> > - int ret = 0;
> > -
> > - /*
> > - * Kthreads which disallow setaffinity shouldn't be moved
> > - * to a new cpuset; we don't want to change their CPU
> > - * affinity and isolating such threads by their set of
> > - * allowed nodes is unnecessary. Thus, cpusets are not
> > - * applicable for such threads. This prevents checking for
> > - * success of set_cpus_allowed_ptr() on all attached tasks
> > - * before cpus_mask may be changed.
> > - */
> > - if (p->flags & PF_NO_SETAFFINITY)
> > - ret = -EINVAL;
> > -
> > - return ret;
> > -}
> > -
> > bool sched_smp_initialized __read_mostly;
> >
> > #ifdef CONFIG_NUMA_BALANCING
> > --
> > 2.50.1
> >
>
> Thanks,
> -Andrea
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] sched: cgroup: Move task_can_attach() to cpuset.c
2025-10-03 16:43 ` Steven Rostedt
@ 2025-10-03 16:53 ` Andrea Righi
0 siblings, 0 replies; 10+ messages in thread
From: Andrea Righi @ 2025-10-03 16:53 UTC (permalink / raw)
To: Steven Rostedt
Cc: LKML, Peter Zijlstra, Ingo Molnar, Juri Lelli, Vincent Guittot,
Waiman Long, Tejun Heo, Johannes Weiner, Michal Koutný,
Julia Lawall, Luis Claudio R. Goncalves, Joseph Salisbury
On Fri, Oct 03, 2025 at 12:43:00PM -0400, Steven Rostedt wrote:
...
> > > +static inline int task_can_attach(struct task_struct *p)
> > > +{
> > > + int ret = 0;
> > > +
> > > + /*
> > > + * Kthreads which disallow setaffinity shouldn't be moved
> > > + * to a new cpuset; we don't want to change their CPU
> > > + * affinity and isolating such threads by their set of
> > > + * allowed nodes is unnecessary. Thus, cpusets are not
> > > + * applicable for such threads. This prevents checking for
> > > + * success of set_cpus_allowed_ptr() on all attached tasks
> > > + * before cpus_mask may be changed.
> > > + */
> > > + if (p->flags & PF_NO_SETAFFINITY)
> > > + ret = -EINVAL;
> > > +
> > > + return ret;
> >
> > As we're cleaning up, we could just return -EINVAL and 0 directly and get
> > rid of that ret variable.
>
> That should be a separate patch. Moves should really not do much else. I
> even wondered about making it a static inline too, but figured that wasn't
> touching the logic, and the function was going to become static anyway.
Oh yes, good point. In the meantime, FWIW:
Tested-by: Andrea Righi <arighi@nvidia.com>
Thanks,
-Andrea
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] sched: cgroup: Move task_can_attach() to cpuset.c
2025-10-03 16:14 [PATCH] sched: cgroup: Move task_can_attach() to cpuset.c Steven Rostedt
2025-10-03 16:36 ` Andrea Righi
2025-10-03 16:39 ` Waiman Long
@ 2025-10-03 17:11 ` Luis Claudio R. Goncalves
2025-10-03 19:56 ` [External] : " Joseph Salisbury
2025-10-03 21:38 ` Tejun Heo
4 siblings, 0 replies; 10+ messages in thread
From: Luis Claudio R. Goncalves @ 2025-10-03 17:11 UTC (permalink / raw)
To: Steven Rostedt
Cc: LKML, Peter Zijlstra, Ingo Molnar, Juri Lelli, Vincent Guittot,
Waiman Long, Tejun Heo, Johannes Weiner, Michal Koutný,
Andrea Righi, Julia Lawall, Joseph Salisbury
On Fri, Oct 03, 2025 at 12:14:21PM -0400, Steven Rostedt wrote:
> From: Steven Rostedt <rostedt@goodmis.org>
>
> At our monthly stable meeting, we were talking about documenting non
> static functions and randomly picked a function to look at. That was
> task_can_attach(). It was then noticed that it's only used by
> cgroup/cpuset.c and nothing else. It's a simple function that doesn't
> reference anything unique to sched/core.c, hence there's no reason that
> function should be there.
>
> Move it to cgroup/cpuset.c as that's the only place it is used. Also make
> it a static inline as it is so small.
>
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> ---
> include/linux/sched.h | 1 -
> kernel/cgroup/cpuset.c | 19 +++++++++++++++++++
> kernel/sched/core.c | 19 -------------------
> 3 files changed, 19 insertions(+), 20 deletions(-)
That was a fun exercise. :)
Tested-by: Luis Claudio R. Goncalves <lgoncalv@redhat.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [External] : [PATCH] sched: cgroup: Move task_can_attach() to cpuset.c
2025-10-03 16:14 [PATCH] sched: cgroup: Move task_can_attach() to cpuset.c Steven Rostedt
` (2 preceding siblings ...)
2025-10-03 17:11 ` Luis Claudio R. Goncalves
@ 2025-10-03 19:56 ` Joseph Salisbury
2025-10-03 21:38 ` Tejun Heo
4 siblings, 0 replies; 10+ messages in thread
From: Joseph Salisbury @ 2025-10-03 19:56 UTC (permalink / raw)
To: Steven Rostedt, LKML
Cc: Peter Zijlstra, Ingo Molnar, Juri Lelli, Vincent Guittot,
Waiman Long, Tejun Heo, Johannes Weiner, Michal Koutný,
Andrea Righi, Julia Lawall, Luis Claudio R. Goncalves
On 10/3/25 12:14, Steven Rostedt wrote:
> From: Steven Rostedt <rostedt@goodmis.org>
>
> At our monthly stable meeting, we were talking about documenting non
> static functions and randomly picked a function to look at. That was
> task_can_attach(). It was then noticed that it's only used by
> cgroup/cpuset.c and nothing else. It's a simple function that doesn't
> reference anything unique to sched/core.c, hence there's no reason that
> function should be there.
>
> Move it to cgroup/cpuset.c as that's the only place it is used. Also make
> it a static inline as it is so small.
>
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> ---
> include/linux/sched.h | 1 -
> kernel/cgroup/cpuset.c | 19 +++++++++++++++++++
> kernel/sched/core.c | 19 -------------------
> 3 files changed, 19 insertions(+), 20 deletions(-)
>
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index e4ce0a76831e..4ee4fa973eda 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -1849,7 +1849,6 @@ current_restore_flags(unsigned long orig_flags, unsigned long flags)
> }
>
> extern int cpuset_cpumask_can_shrink(const struct cpumask *cur, const struct cpumask *trial);
> -extern int task_can_attach(struct task_struct *p);
> extern int dl_bw_alloc(int cpu, u64 dl_bw);
> extern void dl_bw_free(int cpu, u64 dl_bw);
>
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 27adb04df675..21fe872803e8 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -3009,6 +3009,25 @@ static void reset_migrate_dl_data(struct cpuset *cs)
> cs->sum_migrate_dl_bw = 0;
> }
>
> +static inline int task_can_attach(struct task_struct *p)
> +{
> + int ret = 0;
> +
> + /*
> + * Kthreads which disallow setaffinity shouldn't be moved
> + * to a new cpuset; we don't want to change their CPU
> + * affinity and isolating such threads by their set of
> + * allowed nodes is unnecessary. Thus, cpusets are not
> + * applicable for such threads. This prevents checking for
> + * success of set_cpus_allowed_ptr() on all attached tasks
> + * before cpus_mask may be changed.
> + */
> + if (p->flags & PF_NO_SETAFFINITY)
> + ret = -EINVAL;
> +
> + return ret;
> +}
> +
> /* Called by cgroups to determine if a cpuset is usable; cpuset_mutex held */
> static int cpuset_can_attach(struct cgroup_taskset *tset)
> {
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index ccba6fc3c3fe..a195c4b25475 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -8070,25 +8070,6 @@ int cpuset_cpumask_can_shrink(const struct cpumask *cur,
> return ret;
> }
>
> -int task_can_attach(struct task_struct *p)
> -{
> - int ret = 0;
> -
> - /*
> - * Kthreads which disallow setaffinity shouldn't be moved
> - * to a new cpuset; we don't want to change their CPU
> - * affinity and isolating such threads by their set of
> - * allowed nodes is unnecessary. Thus, cpusets are not
> - * applicable for such threads. This prevents checking for
> - * success of set_cpus_allowed_ptr() on all attached tasks
> - * before cpus_mask may be changed.
> - */
> - if (p->flags & PF_NO_SETAFFINITY)
> - ret = -EINVAL;
> -
> - return ret;
> -}
> -
> bool sched_smp_initialized __read_mostly;
>
> #ifdef CONFIG_NUMA_BALANCING
Nice beneficial refactoring!
Reviewed-by: Joseph Salisbury <joseph.salisbury@oracle.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] sched: cgroup: Move task_can_attach() to cpuset.c
2025-10-03 16:14 [PATCH] sched: cgroup: Move task_can_attach() to cpuset.c Steven Rostedt
` (3 preceding siblings ...)
2025-10-03 19:56 ` [External] : " Joseph Salisbury
@ 2025-10-03 21:38 ` Tejun Heo
2025-10-06 18:31 ` Peter Zijlstra
4 siblings, 1 reply; 10+ messages in thread
From: Tejun Heo @ 2025-10-03 21:38 UTC (permalink / raw)
To: Steven Rostedt
Cc: LKML, Peter Zijlstra, Ingo Molnar, Juri Lelli, Vincent Guittot,
Waiman Long, Johannes Weiner, Michal Koutný, Andrea Righi,
Julia Lawall, Luis Claudio R. Goncalves, Joseph Salisbury
On Fri, Oct 03, 2025 at 12:14:21PM -0400, Steven Rostedt wrote:
> From: Steven Rostedt <rostedt@goodmis.org>
>
> At our monthly stable meeting, we were talking about documenting non
> static functions and randomly picked a function to look at. That was
> task_can_attach(). It was then noticed that it's only used by
> cgroup/cpuset.c and nothing else. It's a simple function that doesn't
> reference anything unique to sched/core.c, hence there's no reason that
> function should be there.
>
> Move it to cgroup/cpuset.c as that's the only place it is used. Also make
> it a static inline as it is so small.
>
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Peter, if it looks good to you, I can route it through cgroup tree.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] sched: cgroup: Move task_can_attach() to cpuset.c
2025-10-03 21:38 ` Tejun Heo
@ 2025-10-06 18:31 ` Peter Zijlstra
2025-10-06 18:59 ` Tejun Heo
0 siblings, 1 reply; 10+ messages in thread
From: Peter Zijlstra @ 2025-10-06 18:31 UTC (permalink / raw)
To: Tejun Heo
Cc: Steven Rostedt, LKML, Ingo Molnar, Juri Lelli, Vincent Guittot,
Waiman Long, Johannes Weiner, Michal Koutný, Andrea Righi,
Julia Lawall, Luis Claudio R. Goncalves, Joseph Salisbury
On Fri, Oct 03, 2025 at 11:38:09AM -1000, Tejun Heo wrote:
> On Fri, Oct 03, 2025 at 12:14:21PM -0400, Steven Rostedt wrote:
> > From: Steven Rostedt <rostedt@goodmis.org>
> >
> > At our monthly stable meeting, we were talking about documenting non
> > static functions and randomly picked a function to look at. That was
> > task_can_attach(). It was then noticed that it's only used by
> > cgroup/cpuset.c and nothing else. It's a simple function that doesn't
> > reference anything unique to sched/core.c, hence there's no reason that
> > function should be there.
> >
> > Move it to cgroup/cpuset.c as that's the only place it is used. Also make
> > it a static inline as it is so small.
> >
> > Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
>
> Peter, if it looks good to you, I can route it through cgroup tree.
Yeah, I suppose so. But there were suggested changes to the Changelog
and actual patch so perhaps wait for v2?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] sched: cgroup: Move task_can_attach() to cpuset.c
2025-10-06 18:31 ` Peter Zijlstra
@ 2025-10-06 18:59 ` Tejun Heo
0 siblings, 0 replies; 10+ messages in thread
From: Tejun Heo @ 2025-10-06 18:59 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Steven Rostedt, LKML, Ingo Molnar, Juri Lelli, Vincent Guittot,
Waiman Long, Johannes Weiner, Michal Koutný, Andrea Righi,
Julia Lawall, Luis Claudio R. Goncalves, Joseph Salisbury
On Mon, Oct 06, 2025 at 08:31:59PM +0200, Peter Zijlstra wrote:
> On Fri, Oct 03, 2025 at 11:38:09AM -1000, Tejun Heo wrote:
> > On Fri, Oct 03, 2025 at 12:14:21PM -0400, Steven Rostedt wrote:
> > > From: Steven Rostedt <rostedt@goodmis.org>
> > >
> > > At our monthly stable meeting, we were talking about documenting non
> > > static functions and randomly picked a function to look at. That was
> > > task_can_attach(). It was then noticed that it's only used by
> > > cgroup/cpuset.c and nothing else. It's a simple function that doesn't
> > > reference anything unique to sched/core.c, hence there's no reason that
> > > function should be there.
> > >
> > > Move it to cgroup/cpuset.c as that's the only place it is used. Also make
> > > it a static inline as it is so small.
> > >
> > > Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> >
> > Peter, if it looks good to you, I can route it through cgroup tree.
>
> Yeah, I suppose so. But there were suggested changes to the Changelog
> and actual patch so perhaps wait for v2?
Yeah, will wait for v2 and then apply it.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2025-10-06 18:59 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-03 16:14 [PATCH] sched: cgroup: Move task_can_attach() to cpuset.c Steven Rostedt
2025-10-03 16:36 ` Andrea Righi
2025-10-03 16:43 ` Steven Rostedt
2025-10-03 16:53 ` Andrea Righi
2025-10-03 16:39 ` Waiman Long
2025-10-03 17:11 ` Luis Claudio R. Goncalves
2025-10-03 19:56 ` [External] : " Joseph Salisbury
2025-10-03 21:38 ` Tejun Heo
2025-10-06 18:31 ` Peter Zijlstra
2025-10-06 18:59 ` Tejun Heo
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.