From: Vlastimil Babka <vbabka@suse.cz>
To: Frederic Weisbecker <frederic@kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Kees Cook <kees@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
Michal Hocko <mhocko@kernel.org>,
linux-mm@kvack.org, "Paul E. McKenney" <paulmck@kernel.org>,
Neeraj Upadhyay <neeraj.upadhyay@kernel.org>,
Joel Fernandes <joel@joelfernandes.org>,
Boqun Feng <boqun.feng@gmail.com>,
Zqiang <qiang.zhang1211@gmail.com>,
rcu@vger.kernel.org
Subject: Re: [RFC PATCH 12/20] kthread: Implement preferred affinity
Date: Mon, 5 Aug 2024 16:53:51 +0200 [thread overview]
Message-ID: <00914d25-f0ae-4b00-9608-2457821c071c@suse.cz> (raw)
In-Reply-To: <ZrDhp3TLz6Kp93BJ@localhost.localdomain>
On 8/5/24 16:28, Frederic Weisbecker wrote:
> Le Tue, Jul 30, 2024 at 05:49:51PM +0200, Vlastimil Babka a écrit :
>> Acked-by: Vlastimil Babka <vbabka@suse.cz>
>>
>> Nit:
>>
>> > +int kthread_affine_preferred(struct task_struct *p, const struct cpumask *mask)
>> > +{
>> > + struct kthread *kthread = to_kthread(p);
>> > + cpumask_var_t affinity;
>> > + unsigned long flags;
>> > + int ret;
>> > +
>> > + if (!wait_task_inactive(p, TASK_UNINTERRUPTIBLE) || kthread->started) {
>> > + WARN_ON(1);
>> > + return -EINVAL;
>> > + }
>> > +
>>
>> Should we also fail if kthread->preferred_affinity already exist? In
>> case somebody calls this twice.
>
> Good point!
>
>>
>> Also for some of the use cases (kswapd, kcompactd) it would make sense
>> to be able to add cpus of a node as they are onlined. Which seems we
>> didn't do, except some corner case handling in kcompactd, but maybe we
>> should? I wonder if the current implementation of onlining a completely
>> new node with cpus does the right thing as a result of the individual
>> onlining operations, or we end up with being affined to a single cpu (or
>> none).
>>
>> But that would need some kind of kthread_affine_preferred_update()
>> implementation?
>
> So you mean that the "for_each_node_state()" loop in kcompactd doesn't
> handle all possible nodes but only those online when it's called? Or
> am I confused?
If you mean the loop in kcompactd_init() then indeed, but we also have a
hook in online_pages() to start new threads on newly onlined nodes, so
that's not a problem.
The problem (I think) I see is cpumask_of_node(pgdat->node_id) is a snapshot
of cpus running on the NUMA node the time, and is never updated later as new
cpus might be brought up.
kcompactd_cpu_online() does try to update that when cpus are onlined (in a
clumsy way), there was nothing like that for kswapd and after your series
this update is also removed for kcompactd.
> If all users of preferred affinity were to use NUMA nodes, it could be
> a good idea to do a flavour of kernel/smpboot.c which would handle
> per-node kthreads instead of per-cpu kthreads. I initially thought
> about that. It would have handled all the lifecycle of those kthreads,
> including creation, against hotplug. Unfortunately RCU doesn't rely on
> per-NUMA nodes but rather use its own tree.
>
> If there be more users of real per NUMA nodes kthreads than kswapd and
> kcompactd, of course that would be much worth considering.
Yeah it's not that compelling, but a way to update the preferred affine mask
in response to cpu hotplug events, that kswapd and kcompactd could use,
would be sufficient. And maybe more widely useful.
I guess there could be a callback defined for kthread to provide a new
preferred_affinity, that you'd call from kthreads_hotplug_update() ?
And kcompactd and kswapd could both use the same callback that interprets
kthread_data() as pgdat and fetches a new cpumask of it?
> Thanks.
next prev parent reply other threads:[~2024-08-05 14:53 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20240726215701.19459-1-frederic@kernel.org>
2024-07-26 21:56 ` [RFC PATCH 11/20] kthread: Make sure kthread hasn't started while binding it Frederic Weisbecker
2024-07-30 15:20 ` Vlastimil Babka
2024-07-26 21:56 ` [RFC PATCH 12/20] kthread: Implement preferred affinity Frederic Weisbecker
2024-07-26 22:31 ` Frederic Weisbecker
2024-07-30 15:49 ` Vlastimil Babka
2024-08-05 14:28 ` Frederic Weisbecker
2024-08-05 14:53 ` Vlastimil Babka [this message]
2024-08-05 16:23 ` Frederic Weisbecker
2024-08-05 21:25 ` Vlastimil Babka
2024-08-05 23:59 ` Frederic Weisbecker
2024-08-06 11:08 ` Vlastimil Babka
2024-07-26 21:56 ` [RFC PATCH 13/20] mm: Make Kcompactd use kthread's " Frederic Weisbecker
2024-07-31 15:03 ` Vlastimil Babka
2024-07-26 21:56 ` [RFC PATCH 14/20] mm: Allocate kcompactd on its node Frederic Weisbecker
2024-07-31 15:07 ` Vlastimil Babka
2024-08-05 14:30 ` Frederic Weisbecker
2024-07-26 21:56 ` [RFC PATCH 15/20] mm: Make kswapd use kthread's preferred affinity Frederic Weisbecker
2024-07-31 15:08 ` Vlastimil Babka
2024-07-26 21:56 ` [RFC PATCH 16/20] mm: Allocate kswapd on its node Frederic Weisbecker
2024-07-31 15:08 ` Vlastimil Babka
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=00914d25-f0ae-4b00-9608-2457821c071c@suse.cz \
--to=vbabka@suse.cz \
--cc=akpm@linux-foundation.org \
--cc=boqun.feng@gmail.com \
--cc=frederic@kernel.org \
--cc=joel@joelfernandes.org \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=neeraj.upadhyay@kernel.org \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=qiang.zhang1211@gmail.com \
--cc=rcu@vger.kernel.org \
--cc=tglx@linutronix.de \
/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