diff mbox series

[RFC] blk-mq: avoid housekeeping CPUs scheduling a worker on a non-housekeeping CPU

Message ID 20230223074826.3782643-1-wangxiongfeng@huaweicloud.com (mailing list archive)
State New, archived
Headers show
Series [RFC] blk-mq: avoid housekeeping CPUs scheduling a worker on a non-housekeeping CPU | expand

Commit Message

Xiongfeng Wang Feb. 23, 2023, 7:48 a.m. UTC
From: Xiongfeng Wang <wangxiongfeng2@huawei.com>

When NOHZ_FULL is enabled, such as in HPC situation, CPUs are divided
into housekeeping CPUs and non-housekeeping CPUs. Non-housekeeping CPUs
are NOHZ_FULL CPUs and are often monopolized by the userspace process,
such HPC application process. Any sort of interruption is not expected.

blk_mq_hctx_next_cpu() selects each cpu in 'hctx->cpumask' alternately
to schedule the work thread blk_mq_run_work_fn(). When 'hctx->cpumask'
contains housekeeping CPU and non-housekeeping CPU at the same time, a
housekeeping CPU, which want to request a IO, may schedule a worker on a
non-housekeeping CPU. This may affect the performance of the userspace
application running on non-housekeeping CPUs.

So let's just schedule the worker thread on the current CPU when the
current CPU is housekeeping CPU.

Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
---
 block/blk-mq.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

Comments

Christoph Hellwig Feb. 23, 2023, 3:06 p.m. UTC | #1
On Thu, Feb 23, 2023 at 03:48:26PM +0800, Xiongfeng Wang wrote:
> From: Xiongfeng Wang <wangxiongfeng2@huawei.com>
> 
> When NOHZ_FULL is enabled, such as in HPC situation, CPUs are divided
> into housekeeping CPUs and non-housekeeping CPUs. Non-housekeeping CPUs
> are NOHZ_FULL CPUs and are often monopolized by the userspace process,
> such HPC application process. Any sort of interruption is not expected.
> 
> blk_mq_hctx_next_cpu() selects each cpu in 'hctx->cpumask' alternately
> to schedule the work thread blk_mq_run_work_fn(). When 'hctx->cpumask'
> contains housekeeping CPU and non-housekeeping CPU at the same time, a
> housekeeping CPU, which want to request a IO, may schedule a worker on a
> non-housekeeping CPU. This may affect the performance of the userspace
> application running on non-housekeeping CPUs.
> 
> So let's just schedule the worker thread on the current CPU when the
> current CPU is housekeeping CPU.

This looks like an odd non-systemic bandaid.  Shouldn't we have a more
generic way nothing ever gets onto these non-housekeeping CPUs by making
sure they never show up in the cpumask, and never get completion IPIs?
diff mbox series

Patch

diff --git a/block/blk-mq.c b/block/blk-mq.c
index d3494a796ba8..1e84d393cce3 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -21,6 +21,7 @@ 
 #include <linux/llist.h>
 #include <linux/cpu.h>
 #include <linux/cache.h>
+#include <linux/sched/isolation.h>
 #include <linux/sched/sysctl.h>
 #include <linux/sched/topology.h>
 #include <linux/sched/signal.h>
@@ -2245,6 +2246,8 @@  static int blk_mq_hctx_next_cpu(struct blk_mq_hw_ctx *hctx)
 static void __blk_mq_delay_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async,
 					unsigned long msecs)
 {
+	int work_cpu;
+
 	if (unlikely(blk_mq_hctx_stopped(hctx)))
 		return;
 
@@ -2255,7 +2258,17 @@  static void __blk_mq_delay_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async,
 		}
 	}
 
-	kblockd_mod_delayed_work_on(blk_mq_hctx_next_cpu(hctx), &hctx->run_work,
+	/*
+	 * Avoid housekeeping CPUs scheduling a worker on a non-housekeeping
+	 * CPU
+	 */
+	if (tick_nohz_full_enabled() && housekeeping_cpu(smp_processor_id(),
+							 HK_TYPE_WQ))
+		work_cpu = smp_processor_id();
+	else
+		work_cpu = blk_mq_hctx_next_cpu(hctx);
+
+	kblockd_mod_delayed_work_on(work_cpu, &hctx->run_work,
 				    msecs_to_jiffies(msecs));
 }