kthread: fall back when no preferred housekeeping CPU is online
PATCH 1/1 kthread: fall back when no preferred housekeeping CPU is online
kthread_fetch_affinity() falls back to the housekeeping mask only when the intersection with the preferred mask is empty.
If the intersection contains only offline CPUs, set_cpus_allowed_ptr() returns -EINVAL and the kthread keeps its previous affinity, which may still include an isolated CPU.
Check whether the intersection contains an online CPU instead. Fall back to the full housekeeping mask when none are online.
---
Tested on x86_64 Linux 7.3.0 with vng/qemu and a kthread with preferred CPUs 1-2.
With CPU 2 offline and CPU 1 isolated, the unpatched kernel kept affinity 1-2 and set_cpus_allowed_ptr() returned -EINVAL. With the fix, affinity changed to 0,2. Bringing CPU 2 online restored affinity to 2, and removing isolation restored 1-2.
kernel/kthread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/kthread.c +1 -1
@@ -343,7 +343,7 @@ static void kthread_fetch_affinity(struct kthread *kthread, struct cpumask *cpum }cpumask_and (cpumask, pref,housekeeping_cpumask (HK_TYPE_DOMAIN )); -if (cpumask_empty (cpumask)) +if (!cpumask_intersects (cpumask, cpu_online_mask))cpumask_copy (cpumask,housekeeping_cpumask (HK_TYPE_DOMAIN )); }
base-commit: f47d223627f80cb7a1eb14c585fe6cb35de5e984
Signature · 1 line
2.43.0
Quoted 30 lines · Avi Weiss
kthread_fetch_affinity()falls back to the housekeeping mask only when the intersection with the preferred mask is empty.If the intersection contains only offline CPUs,
set_cpus_allowed_ptr()returns-EINVALand the kthread keeps its previous affinity, which may still include an isolated CPU.Check whether the intersection contains an online CPU instead. Fall back to the full housekeeping mask when none are online.
Fixes e894f6339808 ("kthread: Honour kthreads preferred affinity after cpuset changes")Signed-off-by Avi Weiss <[email protected]>---
Tested on
x86_64Linux 7.3.0 with vng/qemu and a kthread with preferred CPUs 1-2.With CPU 2 offline and CPU 1 isolated, the unpatched kernel kept affinity 1-2 and
set_cpus_allowed_ptr()returned-EINVAL. With the fix, affinity changed to 0,2. Bringing CPU 2 online restored affinity to 2, and removing isolation restored 1-2.
kernel/kthread.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)kernel/kthread.c +0
-0
kernel/kthread.c static void kthread_fetch_affinity(struct kthread *kthread, struct cpumask *cpum · line 346
Quoted 5 lines
kernel/kthread.c +1
-1@@ -343,7 +343,7 @@ static void kthread_fetch_affinity(struct kthread *kthread, struct cpumask *cpum }cpumask_and (cpumask, pref,housekeeping_cpumask (HK_TYPE_DOMAIN )); -if (cpumask_empty (cpumask)) +if (!cpumask_intersects (cpumask, cpu_online_mask))
Nice catch!
Quoted 6 lines
kernel/kthread.c +0
-0cpumask_copy (cpumask,housekeeping_cpumask (HK_TYPE_DOMAIN )); }base-commit:
f47d223627f80cb7a1eb14c585fe6cb35de5e984
--- Thanks!
"I'm not a very positive person" - Linus torvalds
Quoted 30 lines · Avi Weiss
kthread_fetch_affinity()falls back to the housekeeping mask only when the intersection with the preferred mask is empty.If the intersection contains only offline CPUs,
set_cpus_allowed_ptr()returns-EINVALand the kthread keeps its previous affinity, which may still include an isolated CPU.Check whether the intersection contains an online CPU instead. Fall back to the full housekeeping mask when none are online.
Fixes e894f6339808 ("kthread: Honour kthreads preferred affinity after cpuset changes")Signed-off-by Avi Weiss <[email protected]>---
Tested on
x86_64Linux 7.3.0 with vng/qemu and a kthread with preferred CPUs 1-2.With CPU 2 offline and CPU 1 isolated, the unpatched kernel kept affinity 1-2 and
set_cpus_allowed_ptr()returned-EINVAL. With the fix, affinity changed to 0,2. Bringing CPU 2 online restored affinity to 2, and removing isolation restored 1-2.kernel/kthread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/kthread.c +0
-0
kernel/kthread.c static void kthread_fetch_affinity(struct kthread *kthread, struct cpumask *cpum · line 348
Quoted 7 lines
kernel/kthread.c +1
-1@@ -343,7 +343,7 @@ static void kthread_fetch_affinity(struct kthread *kthread, struct cpumask *cpum }cpumask_and (cpumask, pref,housekeeping_cpumask (HK_TYPE_DOMAIN )); -if (cpumask_empty (cpumask)) +if (!cpumask_intersects (cpumask, cpu_online_mask))cpumask_copy (cpumask,housekeeping_cpumask (HK_TYPE_DOMAIN )); }
Good catch thank you! Queueing it.
Quoted 6 lines
base-commit:
f47d223627f80cb7a1eb14c585fe6cb35de5e984Signature · 1 line
2.43.0
Signature · 2 lines
Frederic Weisbecker SUSE Labs