From cfe452afa565d00ddda817f8f1d0d8bb28da7773 Mon Sep 17 00:00:00 2001 From: Jiping Ma Date: Mon, 25 Oct 2021 03:25:01 -0400 Subject: [PATCH] workqueue: Affine rescuer threads and unbound wqs This commit ensures that workqueue rescuer threads are affined to the platform CPUs specified by the "kthread_cpus" kernel argument. Prior to this commit, rescuer threads could be bound to any CPU. Rescuer threads are described in "kernel/workqueue.c" as follows: "Regular work processing on a pool may block trying to create a new worker which uses GFP_KERNEL allocation which has slight chance of developing into deadlock if some works currently on the same queue need to be processed to satisfy the GFP_KERNEL allocation. This is the problem rescuer solves. When such condition is possible, the pool summons rescuers of all workqueues which have works queued on the pool and let them process those works so that forward progress can be guaranteed." This commit also affines unbound workqueues to the platform CPUs instead of the housekeeping CPUs, because the latter can be a superset of the former. Verification: Compared the affinity of workqueue thread between before and after the fix, the affinity was 0xff before this commit that mean the thread could be bound to cpu0-7, the affinity was 0x3 after the fix with "kthread_cpus=0, 1", which only could be bound to cpu0, 1. Also checked unbound workqueue such as "writeback" whose affinity also was 0x3 with "kthread_cpus=0, 1". We did not find the commit break anything else. Closes-Bug: #1948639 Signed-off-by: M. Vefa Bicakci Signed-off-by: Jiping Ma Change-Id: I8afd56c8d0d0526d523accf3ea45ee02635b1602 --- kernel-rt/centos/kernel-rt.spec | 1 + ...fine-rescuer-threads-and-unbound-wqs.patch | 55 +++++++++++++++++++ kernel-std/centos/kernel.spec | 1 + ...fine-rescuer-threads-and-unbound-wqs.patch | 55 +++++++++++++++++++ 4 files changed, 112 insertions(+) create mode 100644 kernel-rt/centos/patches/0012-workqueue-Affine-rescuer-threads-and-unbound-wqs.patch create mode 100644 kernel-std/centos/patches/0012-workqueue-Affine-rescuer-threads-and-unbound-wqs.patch diff --git a/kernel-rt/centos/kernel-rt.spec b/kernel-rt/centos/kernel-rt.spec index a4769a93..73d64eae 100644 --- a/kernel-rt/centos/kernel-rt.spec +++ b/kernel-rt/centos/kernel-rt.spec @@ -787,6 +787,7 @@ Patch7: 0008-Allow-dmar-quirks-for-broken-bioses.patch Patch8: 0009-tpm-ignore-burstcount-to-improve-tpm_tis-send-perfor.patch Patch9: 0010-restrict-iSCSI-kthreads-to-CPUs-in-cpu_kthread_mask.patch Patch10: 0011-scsi-smartpqi-Enable-sas_address-sysfs-for-SATA-dev.patch +Patch11: 0012-workqueue-Affine-rescuer-threads-and-unbound-wqs.patch # END OF PATCH DEFINITIONS %endif diff --git a/kernel-rt/centos/patches/0012-workqueue-Affine-rescuer-threads-and-unbound-wqs.patch b/kernel-rt/centos/patches/0012-workqueue-Affine-rescuer-threads-and-unbound-wqs.patch new file mode 100644 index 00000000..0d4c3ee2 --- /dev/null +++ b/kernel-rt/centos/patches/0012-workqueue-Affine-rescuer-threads-and-unbound-wqs.patch @@ -0,0 +1,55 @@ +From 9c5c44019a17897c46a2579a50abcd69f1bcb4a8 Mon Sep 17 00:00:00 2001 +From: "M. Vefa Bicakci" +Date: Thu, 9 Sep 2021 04:56:46 -0400 +Subject: [PATCH] workqueue: Affine rescuer threads and unbound wqs + +This commit ensures that workqueue rescuer threads are affined to the +platform CPUs specified by the "kthread_cpus" kernel argument. Prior to +this commit, rescuer threads could be bound to any CPU. Rescuer threads +are described in "kernel/workqueue.c" as follows: + +"Regular work processing on a pool may block trying to create a new +worker which uses GFP_KERNEL allocation which has slight chance of +developing into deadlock if some works currently on the same queue +need to be processed to satisfy the GFP_KERNEL allocation. This is +the problem rescuer solves. + +When such condition is possible, the pool summons rescuers of all +workqueues which have works queued on the pool and let them process +those works so that forward progress can be guaranteed." + +This commit also affines unbound workqueues to the platform CPUs instead +of the housekeeping CPUs, because the latter can be a superset of the +former. + +Signed-off-by: M. Vefa Bicakci +Signed-off-by: Jiping Ma +--- + kernel/workqueue.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/kernel/workqueue.c b/kernel/workqueue.c +index 1e2ca744dadb..f208096f28f1 100644 +--- a/kernel/workqueue.c ++++ b/kernel/workqueue.c +@@ -4235,7 +4235,7 @@ static int init_rescuer(struct workqueue_struct *wq) + } + + wq->rescuer = rescuer; +- kthread_bind_mask(rescuer->task, cpu_possible_mask); ++ kthread_bind_mask(rescuer->task, cpu_kthread_mask); + wake_up_process(rescuer->task); + + return 0; +@@ -5927,7 +5927,7 @@ void __init workqueue_init_early(void) + BUILD_BUG_ON(__alignof__(struct pool_workqueue) < __alignof__(long long)); + + BUG_ON(!alloc_cpumask_var(&wq_unbound_cpumask, GFP_KERNEL)); +- cpumask_copy(wq_unbound_cpumask, housekeeping_cpumask(hk_flags)); ++ cpumask_copy(wq_unbound_cpumask, cpu_kthread_mask); + + pwq_cache = KMEM_CACHE(pool_workqueue, SLAB_PANIC); + +-- +2.29.2 + diff --git a/kernel-std/centos/kernel.spec b/kernel-std/centos/kernel.spec index 51f53f3b..cc881b82 100644 --- a/kernel-std/centos/kernel.spec +++ b/kernel-std/centos/kernel.spec @@ -820,6 +820,7 @@ Patch7: 0008-Allow-dmar-quirks-for-broken-bioses.patch Patch8: 0009-tpm-ignore-burstcount-to-improve-tpm_tis-send-perfor.patch Patch9: 0010-bpf-cgroups-Fix-cgroup-v2-fallback-on-v1-v2-mixed-mo.patch Patch10: 0011-scsi-smartpqi-Enable-sas_address-sysfs-for-SATA-dev.patch +Patch11: 0012-workqueue-Affine-rescuer-threads-and-unbound-wqs.patch # END OF PATCH DEFINITIONS %endif diff --git a/kernel-std/centos/patches/0012-workqueue-Affine-rescuer-threads-and-unbound-wqs.patch b/kernel-std/centos/patches/0012-workqueue-Affine-rescuer-threads-and-unbound-wqs.patch new file mode 100644 index 00000000..0d4c3ee2 --- /dev/null +++ b/kernel-std/centos/patches/0012-workqueue-Affine-rescuer-threads-and-unbound-wqs.patch @@ -0,0 +1,55 @@ +From 9c5c44019a17897c46a2579a50abcd69f1bcb4a8 Mon Sep 17 00:00:00 2001 +From: "M. Vefa Bicakci" +Date: Thu, 9 Sep 2021 04:56:46 -0400 +Subject: [PATCH] workqueue: Affine rescuer threads and unbound wqs + +This commit ensures that workqueue rescuer threads are affined to the +platform CPUs specified by the "kthread_cpus" kernel argument. Prior to +this commit, rescuer threads could be bound to any CPU. Rescuer threads +are described in "kernel/workqueue.c" as follows: + +"Regular work processing on a pool may block trying to create a new +worker which uses GFP_KERNEL allocation which has slight chance of +developing into deadlock if some works currently on the same queue +need to be processed to satisfy the GFP_KERNEL allocation. This is +the problem rescuer solves. + +When such condition is possible, the pool summons rescuers of all +workqueues which have works queued on the pool and let them process +those works so that forward progress can be guaranteed." + +This commit also affines unbound workqueues to the platform CPUs instead +of the housekeeping CPUs, because the latter can be a superset of the +former. + +Signed-off-by: M. Vefa Bicakci +Signed-off-by: Jiping Ma +--- + kernel/workqueue.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/kernel/workqueue.c b/kernel/workqueue.c +index 1e2ca744dadb..f208096f28f1 100644 +--- a/kernel/workqueue.c ++++ b/kernel/workqueue.c +@@ -4235,7 +4235,7 @@ static int init_rescuer(struct workqueue_struct *wq) + } + + wq->rescuer = rescuer; +- kthread_bind_mask(rescuer->task, cpu_possible_mask); ++ kthread_bind_mask(rescuer->task, cpu_kthread_mask); + wake_up_process(rescuer->task); + + return 0; +@@ -5927,7 +5927,7 @@ void __init workqueue_init_early(void) + BUILD_BUG_ON(__alignof__(struct pool_workqueue) < __alignof__(long long)); + + BUG_ON(!alloc_cpumask_var(&wq_unbound_cpumask, GFP_KERNEL)); +- cpumask_copy(wq_unbound_cpumask, housekeeping_cpumask(hk_flags)); ++ cpumask_copy(wq_unbound_cpumask, cpu_kthread_mask); + + pwq_cache = KMEM_CACHE(pool_workqueue, SLAB_PANIC); + +-- +2.29.2 +