]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
kthread: Comment on the purpose and placement of kthread_affine_node() call
authorFrederic Weisbecker <frederic@kernel.org>
Wed, 18 Jun 2025 14:52:04 +0000 (16:52 +0200)
committerFrederic Weisbecker <frederic@kernel.org>
Tue, 3 Feb 2026 14:23:35 +0000 (15:23 +0100)
It may not appear obvious why kthread_affine_node() is not called before
the kthread creation completion instead of after the first wake-up.

The reason is that kthread_affine_node() applies a default affinity
behaviour that only takes place if no affinity preference have already
been passed by the kthread creation call site.

Add a comment to clarify that.

Reported-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
Cc: Marco Crivellari <marco.crivellari@suse.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Waiman Long <longman@redhat.com>
kernel/kthread.c

index 03008154249c7e9cc3ce503da002133ba39a166a..51f419139dea77a94d440f3bf500644ee27b6928 100644 (file)
@@ -453,6 +453,10 @@ static int kthread(void *_create)
 
        self->started = 1;
 
+       /*
+        * Apply default node affinity if no call to kthread_bind[_mask]() nor
+        * kthread_affine_preferred() was issued before the first wake-up.
+        */
        if (!(current->flags & PF_NO_SETAFFINITY) && !self->preferred_affinity)
                kthread_affine_node();