Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kthread: Include unbound kthreads in the managed affinity list

The managed affinity list currently contains only unbound kthreads that
have affinity preferences. Unbound kthreads globally affine by default
are outside of the list because their affinity is automatically managed
by the scheduler (through the fallback housekeeping mask) and by cpuset.

However in order to preserve the preferred affinity of kthreads, cpuset
will delegate the isolated partition update propagation to the
housekeeping and kthread code.

Prepare for that with including all unbound kthreads in the managed
affinity list.

Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
Reviewed-by: Waiman Long <longman@redhat.com>
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>

+41 -29
+41 -29
kernel/kthread.c
··· 365 365 if (kthread->preferred_affinity) { 366 366 pref = kthread->preferred_affinity; 367 367 } else { 368 - if (WARN_ON_ONCE(kthread->node == NUMA_NO_NODE)) 369 - return; 370 - pref = cpumask_of_node(kthread->node); 368 + if (kthread->node == NUMA_NO_NODE) 369 + pref = housekeeping_cpumask(HK_TYPE_KTHREAD); 370 + else 371 + pref = cpumask_of_node(kthread->node); 371 372 } 372 373 373 374 cpumask_and(cpumask, pref, housekeeping_cpumask(HK_TYPE_KTHREAD)); ··· 381 380 struct kthread *kthread = to_kthread(current); 382 381 cpumask_var_t affinity; 383 382 384 - WARN_ON_ONCE(kthread_is_per_cpu(current)); 383 + if (WARN_ON_ONCE(kthread_is_per_cpu(current))) 384 + return; 385 385 386 - if (kthread->node == NUMA_NO_NODE) { 387 - housekeeping_affine(current, HK_TYPE_KTHREAD); 388 - } else { 389 - if (!zalloc_cpumask_var(&affinity, GFP_KERNEL)) { 390 - WARN_ON_ONCE(1); 391 - return; 392 - } 393 - 394 - mutex_lock(&kthread_affinity_lock); 395 - WARN_ON_ONCE(!list_empty(&kthread->affinity_node)); 396 - list_add_tail(&kthread->affinity_node, &kthread_affinity_list); 397 - /* 398 - * The node cpumask is racy when read from kthread() but: 399 - * - a racing CPU going down will either fail on the subsequent 400 - * call to set_cpus_allowed_ptr() or be migrated to housekeepers 401 - * afterwards by the scheduler. 402 - * - a racing CPU going up will be handled by kthreads_online_cpu() 403 - */ 404 - kthread_fetch_affinity(kthread, affinity); 405 - set_cpus_allowed_ptr(current, affinity); 406 - mutex_unlock(&kthread_affinity_lock); 407 - 408 - free_cpumask_var(affinity); 386 + if (!zalloc_cpumask_var(&affinity, GFP_KERNEL)) { 387 + WARN_ON_ONCE(1); 388 + return; 409 389 } 390 + 391 + mutex_lock(&kthread_affinity_lock); 392 + WARN_ON_ONCE(!list_empty(&kthread->affinity_node)); 393 + list_add_tail(&kthread->affinity_node, &kthread_affinity_list); 394 + /* 395 + * The node cpumask is racy when read from kthread() but: 396 + * - a racing CPU going down will either fail on the subsequent 397 + * call to set_cpus_allowed_ptr() or be migrated to housekeepers 398 + * afterwards by the scheduler. 399 + * - a racing CPU going up will be handled by kthreads_online_cpu() 400 + */ 401 + kthread_fetch_affinity(kthread, affinity); 402 + set_cpus_allowed_ptr(current, affinity); 403 + mutex_unlock(&kthread_affinity_lock); 404 + 405 + free_cpumask_var(affinity); 410 406 } 411 407 412 408 static int kthread(void *_create) ··· 917 919 ret = -EINVAL; 918 920 continue; 919 921 } 920 - kthread_fetch_affinity(k, affinity); 921 - set_cpus_allowed_ptr(k->task, affinity); 922 + 923 + /* 924 + * Unbound kthreads without preferred affinity are already affine 925 + * to housekeeping, whether those CPUs are online or not. So no need 926 + * to handle newly online CPUs for them. 927 + * 928 + * But kthreads with a preferred affinity or node are different: 929 + * if none of their preferred CPUs are online and part of 930 + * housekeeping at the same time, they must be affine to housekeeping. 931 + * But as soon as one of their preferred CPU becomes online, they must 932 + * be affine to them. 933 + */ 934 + if (k->preferred_affinity || k->node != NUMA_NO_NODE) { 935 + kthread_fetch_affinity(k, affinity); 936 + set_cpus_allowed_ptr(k->task, affinity); 937 + } 922 938 } 923 939 924 940 free_cpumask_var(affinity);