* [merged mm-stable] sched-numa-fix-task-swap-by-skipping-kernel-threads.patch removed from -mm tree
@ 2025-05-21 16:56 Andrew Morton
2025-05-21 19:11 ` Peter Zijlstra
0 siblings, 1 reply; 13+ messages in thread
From: Andrew Morton @ 2025-05-21 16:56 UTC (permalink / raw)
To: mm-commits, yu.c.chen, vineethr, venkat88, tj, tim.c.chen,
shakeel.butt, roman.gushchin, peterz, muchun.song, mkoutny, mingo,
mhocko, mgorman, kprateek.nayak, hannes, corbet, Ayush.jain3,
aubrey.li, libo.chen, akpm
The quilt patch titled
Subject: sched/numa: fix task swap by skipping kernel threads
has been removed from the -mm tree. Its filename was
sched-numa-fix-task-swap-by-skipping-kernel-threads.patch
This patch was dropped because it was merged into the mm-stable branch
of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
------------------------------------------------------
From: Libo Chen <libo.chen@oracle.com>
Subject: sched/numa: fix task swap by skipping kernel threads
Date: Wed, 7 May 2025 19:17:15 +0800
Patch series "sched/numa: add statistics of numa balance task migration",
v4.
Introduce task migration and swap statistics in the following places:
/sys/fs/cgroup/{GROUP}/memory.stat
/proc/{PID}/sched
/proc/vmstat
These statistics facilitate a rapid evaluation of the performance and
resource utilization of the target workload.
This patch (of 2):
Task swapping is triggered when there are no idle CPUs in task A's
preferred node. In this case, the NUMA load balancer chooses a task B on
A's preferred node and swaps B with A. This helps improve NUMA locality
without introducing load imbalance between nodes.
In the current implementation, B's NUMA node preference is not mandatory,
and it aims not to increase load imbalance. That is to say, a kernel
thread might be chosen as B. However, kernel threads are not supposed to
be covered by NUMA balancing because NUMA balancing only considers user
pages via VMAs.
Fix this by not considering kernel threads as swap targets in
task_numa_compare(). This can be extended beyond kernel threads in the
future by checking if a swap candidate has a valid NUMA preference through
checking the candidate's numa_preferred_nid and numa_faults. For now,
keep the code simple.
Link: https://lkml.kernel.org/r/cover.1746611892.git.yu.c.chen@intel.com
Link: https://lkml.kernel.org/r/a541cdf9b97f523f6b8067271847a986db5ba768.1746611892.git.yu.c.chen@intel.com
Signed-off-by: Libo Chen <libo.chen@oracle.com>
Signed-off-by: Chen Yu <yu.c.chen@intel.com>
Suggested-by: Michal Koutny <mkoutny@suse.com>
Tested-by: Ayush Jain <Ayush.jain3@amd.com>
Cc: Aubrey Li <aubrey.li@intel.com>
Cc: "Chen, Tim C" <tim.c.chen@intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
Cc: Mel Gorman <mgorman <mgorman@suse.de>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Tejun Heo <tj@kernel.org>
Cc: Venkat Rao Bagalkote <venkat88@linux.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
kernel/sched/fair.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
--- a/kernel/sched/fair.c~sched-numa-fix-task-swap-by-skipping-kernel-threads
+++ a/kernel/sched/fair.c
@@ -2273,7 +2273,8 @@ static bool task_numa_compare(struct tas
rcu_read_lock();
cur = rcu_dereference(dst_rq->curr);
- if (cur && ((cur->flags & PF_EXITING) || is_idle_task(cur)))
+ if (cur && ((cur->flags & PF_EXITING) || is_idle_task(cur) ||
+ !cur->mm))
cur = NULL;
/*
_
Patches currently in -mm which might be from libo.chen@oracle.com are
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [merged mm-stable] sched-numa-fix-task-swap-by-skipping-kernel-threads.patch removed from -mm tree
2025-05-21 16:56 [merged mm-stable] sched-numa-fix-task-swap-by-skipping-kernel-threads.patch removed from -mm tree Andrew Morton
@ 2025-05-21 19:11 ` Peter Zijlstra
2025-05-21 20:58 ` Andrew Morton
` (2 more replies)
0 siblings, 3 replies; 13+ messages in thread
From: Peter Zijlstra @ 2025-05-21 19:11 UTC (permalink / raw)
To: Andrew Morton
Cc: mm-commits, yu.c.chen, vineethr, venkat88, tj, tim.c.chen,
shakeel.butt, roman.gushchin, muchun.song, mkoutny, mingo, mhocko,
mgorman, kprateek.nayak, hannes, corbet, Ayush.jain3, aubrey.li,
libo.chen
On Wed, May 21, 2025 at 09:56:52AM -0700, Andrew Morton wrote:
> Fix this by not considering kernel threads as swap targets in
> task_numa_compare(). This can be extended beyond kernel threads in the
> future by checking if a swap candidate has a valid NUMA preference through
> checking the candidate's numa_preferred_nid and numa_faults. For now,
> keep the code simple.
> --- a/kernel/sched/fair.c~sched-numa-fix-task-swap-by-skipping-kernel-threads
> +++ a/kernel/sched/fair.c
> @@ -2273,7 +2273,8 @@ static bool task_numa_compare(struct tas
>
> rcu_read_lock();
> cur = rcu_dereference(dst_rq->curr);
> - if (cur && ((cur->flags & PF_EXITING) || is_idle_task(cur)))
> + if (cur && ((cur->flags & PF_EXITING) || is_idle_task(cur) ||
> + !cur->mm))
!->mm is not the right way to determine a kernel thread, PF_KTHREAD is.
Notably, there are kernel threads that have ->mm.
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [merged mm-stable] sched-numa-fix-task-swap-by-skipping-kernel-threads.patch removed from -mm tree
2025-05-21 19:11 ` Peter Zijlstra
@ 2025-05-21 20:58 ` Andrew Morton
2025-05-22 6:31 ` K Prateek Nayak
2025-05-22 8:19 ` Michal Koutný
2025-05-23 5:09 ` Chen, Yu C
2 siblings, 1 reply; 13+ messages in thread
From: Andrew Morton @ 2025-05-21 20:58 UTC (permalink / raw)
To: Peter Zijlstra
Cc: mm-commits, yu.c.chen, vineethr, venkat88, tj, tim.c.chen,
shakeel.butt, roman.gushchin, muchun.song, mkoutny, mingo, mhocko,
mgorman, kprateek.nayak, hannes, corbet, Ayush.jain3, aubrey.li,
libo.chen
On Wed, 21 May 2025 21:11:14 +0200 Peter Zijlstra <peterz@infradead.org> wrote:
> On Wed, May 21, 2025 at 09:56:52AM -0700, Andrew Morton wrote:
>
> > Fix this by not considering kernel threads as swap targets in
> > task_numa_compare(). This can be extended beyond kernel threads in the
> > future by checking if a swap candidate has a valid NUMA preference through
> > checking the candidate's numa_preferred_nid and numa_faults. For now,
> > keep the code simple.
>
> > --- a/kernel/sched/fair.c~sched-numa-fix-task-swap-by-skipping-kernel-threads
> > +++ a/kernel/sched/fair.c
> > @@ -2273,7 +2273,8 @@ static bool task_numa_compare(struct tas
> >
> > rcu_read_lock();
> > cur = rcu_dereference(dst_rq->curr);
> > - if (cur && ((cur->flags & PF_EXITING) || is_idle_task(cur)))
> > + if (cur && ((cur->flags & PF_EXITING) || is_idle_task(cur) ||
> > + !cur->mm))
>
> !->mm is not the right way to determine a kernel thread, PF_KTHREAD is.
> Notably, there are kernel threads that have ->mm.
Thanks, I'll queue this:
From: Andrew Morton <akpm@linux-foundation.org>
Subject: task_numa_compare: fix check for kernel thread
Date: Wed May 21 01:54:00 PM PDT 2025
Peter points out "!cur->mm is not the right way to determine a kernel
thread, PF_KTHREAD is. Notably, there are kernel threads that have ->mm".
Link: https://lkml.kernel.org/r/20250521191114.GE24938@noisy.programming.kicks-ass.net
Fixes: 69cebdfa253b sched/numa: fix task swap by skipping kernel threads
Cc: Aubrey Li <aubrey.li@intel.com>
Cc: Ayush Jain <ayush.jain3@amd.com>
Cc: "Chen, Tim C" <tim.c.chen@intel.com>
Cc: Chen, Yu C <yu.c.chen@intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: Libo Chen <libo.chen@oracle.com>
Cc: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
Cc: Mel Gorman <mgorman <mgorman@suse.de>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Michal Koutný <mkoutny@suse.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
kernel/sched/fair.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- a/kernel/sched/fair.c~task_numa_compare-correct-check-for-kernel-thread
+++ a/kernel/sched/fair.c
@@ -2274,7 +2274,7 @@ static bool task_numa_compare(struct tas
rcu_read_lock();
cur = rcu_dereference(dst_rq->curr);
if (cur && ((cur->flags & PF_EXITING) || is_idle_task(cur) ||
- !cur->mm))
+ !(cur->flags & PF_KTHREAD)))
cur = NULL;
/*
_
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [merged mm-stable] sched-numa-fix-task-swap-by-skipping-kernel-threads.patch removed from -mm tree
2025-05-21 20:58 ` Andrew Morton
@ 2025-05-22 6:31 ` K Prateek Nayak
2025-05-22 10:01 ` Libo Chen
0 siblings, 1 reply; 13+ messages in thread
From: K Prateek Nayak @ 2025-05-22 6:31 UTC (permalink / raw)
To: Andrew Morton, Peter Zijlstra
Cc: mm-commits, yu.c.chen, vineethr, venkat88, tj, tim.c.chen,
shakeel.butt, roman.gushchin, muchun.song, mkoutny, mingo, mhocko,
mgorman, hannes, corbet, Ayush.jain3, aubrey.li, libo.chen
On 5/22/2025 2:28 AM, Andrew Morton wrote:
> --- a/kernel/sched/fair.c~task_numa_compare-correct-check-for-kernel-thread
> +++ a/kernel/sched/fair.c
> @@ -2274,7 +2274,7 @@ static bool task_numa_compare(struct tas
> rcu_read_lock();
> cur = rcu_dereference(dst_rq->curr);
> if (cur && ((cur->flags & PF_EXITING) || is_idle_task(cur) ||
Question: Shouldn't ...
if (cur->flags & (PF_EXITING | PF_KTHREAD))
curr = NULL
... be enough?
is_idle_task() checks for the PF_IDLE flag but looking at
kernel/sched/idle.c:
- play_idle_precise() already ensures PF_KTHREAD is set before adding
PF_IDLE
- cpu_startup_entry() is only called from the startup thread which
should be marked with PF_KTHREAD (based on my understanding looking at
commit cff9b2332ab7 ("kernel/sched: Modify initial boot task idle
setup"))
Also "is_idle_task()" seems to have replaced the "(cur->pid == 0)"
check in commit 1effd9f19324 ("sched/numa: Fix unsafe get_task_struct()
in task_numa_assign()") which should be marked as PF_KTHREAD before
reaching cpu_startup_entry().
Did I missed something?
> - !cur->mm))
> + !(cur->flags & PF_KTHREAD)))
> cur = NULL;
>
> /*
> _
>
--
Thanks and Regards,
Prateek
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [merged mm-stable] sched-numa-fix-task-swap-by-skipping-kernel-threads.patch removed from -mm tree
2025-05-22 6:31 ` K Prateek Nayak
@ 2025-05-22 10:01 ` Libo Chen
2025-05-22 21:56 ` Andrew Morton
0 siblings, 1 reply; 13+ messages in thread
From: Libo Chen @ 2025-05-22 10:01 UTC (permalink / raw)
To: K Prateek Nayak, Andrew Morton, Peter Zijlstra
Cc: mm-commits, yu.c.chen, vineethr, venkat88, tj, tim.c.chen,
shakeel.butt, roman.gushchin, muchun.song, mkoutny, mingo, mhocko,
mgorman, hannes, corbet, Ayush.jain3, aubrey.li
On 5/21/25 23:31, K Prateek Nayak wrote:
> On 5/22/2025 2:28 AM, Andrew Morton wrote:
>> --- a/kernel/sched/fair.c~task_numa_compare-correct-check-for-kernel-thread
>> +++ a/kernel/sched/fair.c
>> @@ -2274,7 +2274,7 @@ static bool task_numa_compare(struct tas
>> rcu_read_lock();
>> cur = rcu_dereference(dst_rq->curr);
>> if (cur && ((cur->flags & PF_EXITING) || is_idle_task(cur) ||
>
> Question: Shouldn't ...
>
> if (cur->flags & (PF_EXITING | PF_KTHREAD))
> curr = NULL
>
> ... be enough?
Good point, idle thread is always a kernel thread. I think we can
remove is_idle_task() in that case
Libo
>
> is_idle_task() checks for the PF_IDLE flag but looking at
> kernel/sched/idle.c:
>
> - play_idle_precise() already ensures PF_KTHREAD is set before adding
> PF_IDLE
>
> - cpu_startup_entry() is only called from the startup thread which
> should be marked with PF_KTHREAD (based on my understanding looking at
> commit cff9b2332ab7 ("kernel/sched: Modify initial boot task idle
> setup"))
>
> Also "is_idle_task()" seems to have replaced the "(cur->pid == 0)"
> check in commit 1effd9f19324 ("sched/numa: Fix unsafe get_task_struct()
> in task_numa_assign()") which should be marked as PF_KTHREAD before
> reaching cpu_startup_entry().
>
> Did I missed something?
>
>> - !cur->mm))
>> + !(cur->flags & PF_KTHREAD)))
>> cur = NULL;
>> /*
>> _
>>
>
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [merged mm-stable] sched-numa-fix-task-swap-by-skipping-kernel-threads.patch removed from -mm tree
2025-05-22 10:01 ` Libo Chen
@ 2025-05-22 21:56 ` Andrew Morton
2025-05-23 7:48 ` Chen, Yu C
0 siblings, 1 reply; 13+ messages in thread
From: Andrew Morton @ 2025-05-22 21:56 UTC (permalink / raw)
To: Libo Chen
Cc: K Prateek Nayak, Peter Zijlstra, mm-commits, yu.c.chen, vineethr,
venkat88, tj, tim.c.chen, shakeel.butt, roman.gushchin,
muchun.song, mkoutny, mingo, mhocko, mgorman, hannes, corbet,
Ayush.jain3, aubrey.li
On Thu, 22 May 2025 03:01:34 -0700 Libo Chen <libo.chen@oracle.com> wrote:
> On 5/21/25 23:31, K Prateek Nayak wrote:
> > On 5/22/2025 2:28 AM, Andrew Morton wrote:
> >> --- a/kernel/sched/fair.c~task_numa_compare-correct-check-for-kernel-thread
> >> +++ a/kernel/sched/fair.c
> >> @@ -2274,7 +2274,7 @@ static bool task_numa_compare(struct tas
> >> rcu_read_lock();
> >> cur = rcu_dereference(dst_rq->curr);
> >> if (cur && ((cur->flags & PF_EXITING) || is_idle_task(cur) ||
> >
> > Question: Shouldn't ...
> >
> > if (cur->flags & (PF_EXITING | PF_KTHREAD))
> > curr = NULL
> >
> > ... be enough?
>
>
> Good point, idle thread is always a kernel thread. I think we can
> remove is_idle_task() in that case
I'll drop the v4 series from mm.git. Let's have a v5, please.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [merged mm-stable] sched-numa-fix-task-swap-by-skipping-kernel-threads.patch removed from -mm tree
2025-05-22 21:56 ` Andrew Morton
@ 2025-05-23 7:48 ` Chen, Yu C
0 siblings, 0 replies; 13+ messages in thread
From: Chen, Yu C @ 2025-05-23 7:48 UTC (permalink / raw)
To: Andrew Morton, Libo Chen
Cc: K Prateek Nayak, Peter Zijlstra, mm-commits, vineethr, venkat88,
tj, tim.c.chen, shakeel.butt, roman.gushchin, muchun.song,
mkoutny, mingo, mhocko, mgorman, hannes, corbet, Ayush.jain3,
aubrey.li
On 5/23/2025 5:56 AM, Andrew Morton wrote:
> On Thu, 22 May 2025 03:01:34 -0700 Libo Chen <libo.chen@oracle.com> wrote:
>
>> On 5/21/25 23:31, K Prateek Nayak wrote:
>>> On 5/22/2025 2:28 AM, Andrew Morton wrote:
>>>> --- a/kernel/sched/fair.c~task_numa_compare-correct-check-for-kernel-thread
>>>> +++ a/kernel/sched/fair.c
>>>> @@ -2274,7 +2274,7 @@ static bool task_numa_compare(struct tas
>>>> rcu_read_lock();
>>>> cur = rcu_dereference(dst_rq->curr);
>>>> if (cur && ((cur->flags & PF_EXITING) || is_idle_task(cur) ||
>>>
>>> Question: Shouldn't ...
>>>
>>> if (cur->flags & (PF_EXITING | PF_KTHREAD))
>>> curr = NULL
>>>
>>> ... be enough?
>>
>>
>> Good point, idle thread is always a kernel thread. I think we can
>> remove is_idle_task() in that case
>
> I'll drop the v4 series from mm.git. Let's have a v5, please.
I'll send the v5, thanks.
thanks,
Chenyu
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [merged mm-stable] sched-numa-fix-task-swap-by-skipping-kernel-threads.patch removed from -mm tree
2025-05-21 19:11 ` Peter Zijlstra
2025-05-21 20:58 ` Andrew Morton
@ 2025-05-22 8:19 ` Michal Koutný
2025-05-22 8:23 ` Peter Zijlstra
2025-05-22 8:36 ` Libo Chen
2025-05-23 5:09 ` Chen, Yu C
2 siblings, 2 replies; 13+ messages in thread
From: Michal Koutný @ 2025-05-22 8:19 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Andrew Morton, mm-commits, yu.c.chen, vineethr, venkat88, tj,
tim.c.chen, shakeel.butt, roman.gushchin, muchun.song, mingo,
mhocko, mgorman, kprateek.nayak, hannes, corbet, Ayush.jain3,
aubrey.li, libo.chen
[-- Attachment #1: Type: text/plain, Size: 673 bytes --]
On Wed, May 21, 2025 at 09:11:14PM +0200, Peter Zijlstra <peterz@infradead.org> wrote:
> > @@ -2273,7 +2273,8 @@ static bool task_numa_compare(struct tas
> >
> > rcu_read_lock();
> > cur = rcu_dereference(dst_rq->curr);
> > - if (cur && ((cur->flags & PF_EXITING) || is_idle_task(cur)))
> > + if (cur && ((cur->flags & PF_EXITING) || is_idle_task(cur) ||
> > + !cur->mm))
>
> !->mm is not the right way to determine a kernel thread, PF_KTHREAD is.
> Notably, there are kernel threads that have ->mm.
How does this compose with the NUMA balancing? Should kernel threads
with ->mm be considered here? (I don't know thus asking.)
Thanks,
Michal
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [merged mm-stable] sched-numa-fix-task-swap-by-skipping-kernel-threads.patch removed from -mm tree
2025-05-22 8:19 ` Michal Koutný
@ 2025-05-22 8:23 ` Peter Zijlstra
2025-05-22 8:36 ` Libo Chen
1 sibling, 0 replies; 13+ messages in thread
From: Peter Zijlstra @ 2025-05-22 8:23 UTC (permalink / raw)
To: Michal Koutný
Cc: Andrew Morton, mm-commits, yu.c.chen, vineethr, venkat88, tj,
tim.c.chen, shakeel.butt, roman.gushchin, muchun.song, mingo,
mhocko, mgorman, kprateek.nayak, hannes, corbet, Ayush.jain3,
aubrey.li, libo.chen
On Thu, May 22, 2025 at 10:19:29AM +0200, Michal Koutný wrote:
> On Wed, May 21, 2025 at 09:11:14PM +0200, Peter Zijlstra <peterz@infradead.org> wrote:
> > > @@ -2273,7 +2273,8 @@ static bool task_numa_compare(struct tas
> > >
> > > rcu_read_lock();
> > > cur = rcu_dereference(dst_rq->curr);
> > > - if (cur && ((cur->flags & PF_EXITING) || is_idle_task(cur)))
> > > + if (cur && ((cur->flags & PF_EXITING) || is_idle_task(cur) ||
> > > + !cur->mm))
> >
> > !->mm is not the right way to determine a kernel thread, PF_KTHREAD is.
> > Notably, there are kernel threads that have ->mm.
>
> How does this compose with the NUMA balancing? Should kernel threads
> with ->mm be considered here? (I don't know thus asking.)
I don't know either -- I've not thought about it, I just reacted to the
difference in changelog/comment and code.
Typically the kthreads with mm are io-uring threads. And I just don't
know enough about those.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [merged mm-stable] sched-numa-fix-task-swap-by-skipping-kernel-threads.patch removed from -mm tree
2025-05-22 8:19 ` Michal Koutný
2025-05-22 8:23 ` Peter Zijlstra
@ 2025-05-22 8:36 ` Libo Chen
1 sibling, 0 replies; 13+ messages in thread
From: Libo Chen @ 2025-05-22 8:36 UTC (permalink / raw)
To: Michal Koutný, Peter Zijlstra
Cc: Andrew Morton, mm-commits, yu.c.chen, vineethr, venkat88, tj,
tim.c.chen, shakeel.butt, roman.gushchin, muchun.song, mingo,
mhocko, mgorman, kprateek.nayak, hannes, corbet, Ayush.jain3,
aubrey.li
On 5/22/25 01:19, Michal Koutný wrote:
> On Wed, May 21, 2025 at 09:11:14PM +0200, Peter Zijlstra <peterz@infradead.org> wrote:
>>> @@ -2273,7 +2273,8 @@ static bool task_numa_compare(struct tas
>>>
>>> rcu_read_lock();
>>> cur = rcu_dereference(dst_rq->curr);
>>> - if (cur && ((cur->flags & PF_EXITING) || is_idle_task(cur)))
>>> + if (cur && ((cur->flags & PF_EXITING) || is_idle_task(cur) ||
>>> + !cur->mm))
>>
>> !->mm is not the right way to determine a kernel thread, PF_KTHREAD is.
>> Notably, there are kernel threads that have ->mm.
>
> How does this compose with the NUMA balancing? Should kernel threads
> with ->mm be considered here? (I don't know thus asking.)
>
Not really, at least not until we change other part of NUMA balancing code.
Kernel threads right now with or without ->mm don't get VMA scanning at all
if you look task_tick_numa(), so they dont have page access stats from hint
page faults.
Libo
> Thanks,
> Michal
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [merged mm-stable] sched-numa-fix-task-swap-by-skipping-kernel-threads.patch removed from -mm tree
2025-05-21 19:11 ` Peter Zijlstra
2025-05-21 20:58 ` Andrew Morton
2025-05-22 8:19 ` Michal Koutný
@ 2025-05-23 5:09 ` Chen, Yu C
2025-05-23 8:21 ` Libo Chen
2 siblings, 1 reply; 13+ messages in thread
From: Chen, Yu C @ 2025-05-23 5:09 UTC (permalink / raw)
To: Peter Zijlstra, Andrew Morton, libo.chen, mkoutny
Cc: mm-commits, vineethr, venkat88, tj, tim.c.chen, shakeel.butt,
roman.gushchin, muchun.song, mingo, mhocko, mgorman,
kprateek.nayak, hannes, corbet, Ayush.jain3, aubrey.li, Chen Yu
On 5/22/2025 3:11 AM, Peter Zijlstra wrote:
> On Wed, May 21, 2025 at 09:56:52AM -0700, Andrew Morton wrote:
>
>> Fix this by not considering kernel threads as swap targets in
>> task_numa_compare(). This can be extended beyond kernel threads in the
>> future by checking if a swap candidate has a valid NUMA preference through
>> checking the candidate's numa_preferred_nid and numa_faults. For now,
>> keep the code simple.
>
>> --- a/kernel/sched/fair.c~sched-numa-fix-task-swap-by-skipping-kernel-threads
>> +++ a/kernel/sched/fair.c
>> @@ -2273,7 +2273,8 @@ static bool task_numa_compare(struct tas
>>
>> rcu_read_lock();
>> cur = rcu_dereference(dst_rq->curr);
>> - if (cur && ((cur->flags & PF_EXITING) || is_idle_task(cur)))
>> + if (cur && ((cur->flags & PF_EXITING) || is_idle_task(cur) ||
>> + !cur->mm))
>
> !->mm is not the right way to determine a kernel thread, PF_KTHREAD is.
> Notably, there are kernel threads that have ->mm.
One question, would removing !->mm be enough here? In the current Numa
balance implementation, neither kernel thread nor user space thread that
does not have mm will be skipped IIUC. As Libo pointed it out in
task_tick_numa():
if (!curr->mm || (curr->flags & (PF_EXITING | PF_KTHREAD)) || work->next
!= work)
return;
If someone uses user_mode_thread()( umh) to create a thread, this
thread does not have PF_KTHREAD set, nor it has a mm_struct. We
don't want to do numa balance for this thread I suppose.
The commit b3f9916d81e8 ("sched: Update task_tick_numa to ignore tasks
without an mm") add this !curr->mm check, and we might also want to
preserve the mm check + PF_KTHREAD check in task_numa_compare()? Do I
miss something?
thanks,
Chenyu
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [merged mm-stable] sched-numa-fix-task-swap-by-skipping-kernel-threads.patch removed from -mm tree
2025-05-23 5:09 ` Chen, Yu C
@ 2025-05-23 8:21 ` Libo Chen
0 siblings, 0 replies; 13+ messages in thread
From: Libo Chen @ 2025-05-23 8:21 UTC (permalink / raw)
To: Chen, Yu C, Peter Zijlstra, Andrew Morton, mkoutny
Cc: mm-commits, vineethr, venkat88, tj, tim.c.chen, shakeel.butt,
roman.gushchin, muchun.song, mingo, mhocko, mgorman,
kprateek.nayak, hannes, corbet, Ayush.jain3, aubrey.li, Chen Yu
On 5/22/25 22:09, Chen, Yu C wrote:
> On 5/22/2025 3:11 AM, Peter Zijlstra wrote:
>> On Wed, May 21, 2025 at 09:56:52AM -0700, Andrew Morton wrote:
>>
>>> Fix this by not considering kernel threads as swap targets in
>>> task_numa_compare(). This can be extended beyond kernel threads in the
>>> future by checking if a swap candidate has a valid NUMA preference through
>>> checking the candidate's numa_preferred_nid and numa_faults. For now,
>>> keep the code simple.
>>
>>> --- a/kernel/sched/fair.c~sched-numa-fix-task-swap-by-skipping-kernel-threads
>>> +++ a/kernel/sched/fair.c
>>> @@ -2273,7 +2273,8 @@ static bool task_numa_compare(struct tas
>>> rcu_read_lock();
>>> cur = rcu_dereference(dst_rq->curr);
>>> - if (cur && ((cur->flags & PF_EXITING) || is_idle_task(cur)))
>>> + if (cur && ((cur->flags & PF_EXITING) || is_idle_task(cur) ||
>>> + !cur->mm))
>>
>> !->mm is not the right way to determine a kernel thread, PF_KTHREAD is.
>> Notably, there are kernel threads that have ->mm.
>
> One question, would removing !->mm be enough here? In the current Numa
Was wondering the same, but I thought it's not possible to create an user
thread without mm_struct...
> balance implementation, neither kernel thread nor user space thread that
> does not have mm will be skipped IIUC. As Libo pointed it out in task_tick_numa():
> if (!curr->mm || (curr->flags & (PF_EXITING | PF_KTHREAD)) || work->next != work)
> return;
>
> If someone uses user_mode_thread()( umh) to create a thread, this
ahhh, didn't know such internal caller exists...
> thread does not have PF_KTHREAD set, nor it has a mm_struct. We
> don't want to do numa balance for this thread I suppose.
> The commit b3f9916d81e8 ("sched: Update task_tick_numa to ignore tasks
> without an mm") add this !curr->mm check, and we might also want to
> preserve the mm check + PF_KTHREAD check in task_numa_compare()? Do I
> miss something?
Yeah, that makes sense to me and perfectly aligns with the condition
that allows tasks to be scanned for hint page faults
Libo
>
> thanks,
> Chenyu
>
>
>
^ permalink raw reply [flat|nested] 13+ messages in thread
* [merged mm-stable] sched-numa-fix-task-swap-by-skipping-kernel-threads.patch removed from -mm tree
@ 2025-06-01 5:47 Andrew Morton
0 siblings, 0 replies; 13+ messages in thread
From: Andrew Morton @ 2025-06-01 5:47 UTC (permalink / raw)
To: mm-commits, yu.c.chen, vineethr, venkat88, tj, tim.c.chen,
shakeel.butt, roman.gushchin, peterz, muchun.song, mkoutny, mingo,
mhocko, mgorman, kprateek.nayak, hannes, corbet, Ayush.jain3,
aubrey.li, libo.chen, akpm
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3978 bytes --]
The quilt patch titled
Subject: sched/numa: fix task swap by skipping kernel threads
has been removed from the -mm tree. Its filename was
sched-numa-fix-task-swap-by-skipping-kernel-threads.patch
This patch was dropped because it was merged into the mm-stable branch
of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
------------------------------------------------------
From: Libo Chen <libo.chen@oracle.com>
Subject: sched/numa: fix task swap by skipping kernel threads
Date: Fri, 23 May 2025 20:51:01 +0800
Patch series "sched/numa: add statistics of numa balance task migration",
v6.
Introduce task migration and swap statistics in the following places:
/sys/fs/cgroup/{GROUP}/memory.stat
/proc/{PID}/sched
/proc/vmstat
These statistics facilitate a rapid evaluation of the performance and
resource utilization of the target workload.
This patch (of 2):
Task swapping is triggered when there are no idle CPUs in task A's
preferred node. In this case, the NUMA load balancer chooses a task B
on A's preferred node and swaps B with A. This helps improve NUMA
locality without introducing load imbalance between nodes. In the
current implementation, B's NUMA node preference is not mandatory.
That is to say, a kernel thread might be incorrectly chosen as B.
However, kernel thread and user space thread that does not have mm are
not supposed to be covered by NUMA balancing because NUMA balancing
only considers user pages via VMAs.
According to Peter's suggestion for fixing this issue, we use
PF_KTHREAD to skip the kernel thread. curr->mm is also checked because
it is possible that user_mode_thread() might create a user thread
without an mm. As per Prateek's analysis, after adding the PF_KTHREAD
check, there is no need to further check the PF_IDLE flag:
: - play_idle_precise() already ensures PF_KTHREAD is set before adding
: PF_IDLE
:
: - cpu_startup_entry() is only called from the startup thread which
: should be marked with PF_KTHREAD (based on my understanding looking at
: commit cff9b2332ab7 ("kernel/sched: Modify initial boot task idle
: setup"))
In summary, the check in task_numa_compare() now aligns with
task_tick_numa().
Link: https://lkml.kernel.org/r/cover.1748493462.git.yu.c.chen@intel.com
Link: https://lkml.kernel.org/r/43d68b356b25d124f0d222ebedf3859e86eefb9f.1748493462.git.yu.c.chen@intel.com
Link: https://lkml.kernel.org/r/cover.1748002400.git.yu.c.chen@intel.com
Link: https://lkml.kernel.org/r/eaacc9c9bd37bac92d43a671867d85b2fdad3b06.1748002400.git.yu.c.chen@intel.com
Signed-off-by: Chen Yu <yu.c.chen@intel.com>
Signed-off-by: Libo Chen <libo.chen@oracle.com>
Suggested-by: Michal Koutný <mkoutny@suse.com>
Tested-by: Ayush Jain <Ayush.jain3@amd.com>
Tested-by: Venkat Rao Bagalkote <venkat88@linux.ibm.com>
Reviewed-by: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Aubrey Li <aubrey.li@intel.com>
Cc: "Chen, Tim C" <tim.c.chen@intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
Cc: Mel Gorman <mgorman <mgorman@suse.de>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
kernel/sched/fair.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
--- a/kernel/sched/fair.c~sched-numa-fix-task-swap-by-skipping-kernel-threads
+++ a/kernel/sched/fair.c
@@ -2273,7 +2273,8 @@ static bool task_numa_compare(struct tas
rcu_read_lock();
cur = rcu_dereference(dst_rq->curr);
- if (cur && ((cur->flags & PF_EXITING) || is_idle_task(cur)))
+ if (cur && ((cur->flags & (PF_EXITING | PF_KTHREAD)) ||
+ !cur->mm))
cur = NULL;
/*
_
Patches currently in -mm which might be from libo.chen@oracle.com are
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2025-06-01 5:47 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-21 16:56 [merged mm-stable] sched-numa-fix-task-swap-by-skipping-kernel-threads.patch removed from -mm tree Andrew Morton
2025-05-21 19:11 ` Peter Zijlstra
2025-05-21 20:58 ` Andrew Morton
2025-05-22 6:31 ` K Prateek Nayak
2025-05-22 10:01 ` Libo Chen
2025-05-22 21:56 ` Andrew Morton
2025-05-23 7:48 ` Chen, Yu C
2025-05-22 8:19 ` Michal Koutný
2025-05-22 8:23 ` Peter Zijlstra
2025-05-22 8:36 ` Libo Chen
2025-05-23 5:09 ` Chen, Yu C
2025-05-23 8:21 ` Libo Chen
-- strict thread matches above, loose matches on Subject: below --
2025-06-01 5:47 Andrew Morton
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.