All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] blk-mq: add helper for checking if one CPU is mapped to specified hctx
@ 2024-05-17  2:05 Ming Lei
  2024-05-17 15:41 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Ming Lei @ 2024-05-17  2:05 UTC (permalink / raw
  To: Jens Axboe, linux-block; +Cc: Ming Lei, Raju Cheerla

Commit a46c27026da1 ("blk-mq: don't schedule block kworker on isolated CPUs")
rules out isolated CPUs from hctx->cpumask, and hctx->cpumask should only be
used for scheduling kworker.

Add helper blk_mq_cpu_mapped_to_hctx() and apply it into cpuhp handlers.

This patch avoids to forget clearing INACTIVE of hctx state in case that one
isolated CPU becomes online, and fixes hang issue when allocating request
from this hctx's tags.

Cc: Raju Cheerla <rcheerla@redhat.com>
Fixes: a46c27026da1 ("blk-mq: don't schedule block kworker on isolated CPUs")
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---

Will add one blktest to cover this kind of issue.

 block/blk-mq.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 8e01e4b32e10..579921a2f1c6 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -3545,12 +3545,28 @@ static int blk_mq_hctx_notify_offline(unsigned int cpu, struct hlist_node *node)
 	return 0;
 }
 
+/*
+ * Check if one CPU is mapped to the specified hctx
+ *
+ * Isolated CPUs have been ruled out from hctx->cpumask, which is supposed
+ * to be used for scheduling kworker only. For other usage, please call this
+ * helper for checking if one CPU belongs to the specified hctx
+ */
+static bool blk_mq_cpu_mapped_to_hctx(unsigned int cpu,
+		const struct blk_mq_hw_ctx *hctx)
+{
+	struct blk_mq_hw_ctx *mapped_hctx = blk_mq_map_queue_type(hctx->queue,
+			hctx->type, cpu);
+
+	return mapped_hctx == hctx;
+}
+
 static int blk_mq_hctx_notify_online(unsigned int cpu, struct hlist_node *node)
 {
 	struct blk_mq_hw_ctx *hctx = hlist_entry_safe(node,
 			struct blk_mq_hw_ctx, cpuhp_online);
 
-	if (cpumask_test_cpu(cpu, hctx->cpumask))
+	if (blk_mq_cpu_mapped_to_hctx(cpu, hctx))
 		clear_bit(BLK_MQ_S_INACTIVE, &hctx->state);
 	return 0;
 }
@@ -3568,7 +3584,7 @@ static int blk_mq_hctx_notify_dead(unsigned int cpu, struct hlist_node *node)
 	enum hctx_type type;
 
 	hctx = hlist_entry_safe(node, struct blk_mq_hw_ctx, cpuhp_dead);
-	if (!cpumask_test_cpu(cpu, hctx->cpumask))
+	if (!blk_mq_cpu_mapped_to_hctx(cpu, hctx))
 		return 0;
 
 	ctx = __blk_mq_get_ctx(hctx->queue, cpu);
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] blk-mq: add helper for checking if one CPU is mapped to specified hctx
  2024-05-17  2:05 [PATCH] blk-mq: add helper for checking if one CPU is mapped to specified hctx Ming Lei
@ 2024-05-17 15:41 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2024-05-17 15:41 UTC (permalink / raw
  To: linux-block, Ming Lei; +Cc: Raju Cheerla


On Fri, 17 May 2024 10:05:14 +0800, Ming Lei wrote:
> Commit a46c27026da1 ("blk-mq: don't schedule block kworker on isolated CPUs")
> rules out isolated CPUs from hctx->cpumask, and hctx->cpumask should only be
> used for scheduling kworker.
> 
> Add helper blk_mq_cpu_mapped_to_hctx() and apply it into cpuhp handlers.
> 
> This patch avoids to forget clearing INACTIVE of hctx state in case that one
> isolated CPU becomes online, and fixes hang issue when allocating request
> from this hctx's tags.
> 
> [...]

Applied, thanks!

[1/1] blk-mq: add helper for checking if one CPU is mapped to specified hctx
      commit: 7b815817aa58d2e2101feb2fcf64c60cae0b2695

Best regards,
-- 
Jens Axboe




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-05-17 15:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-17  2:05 [PATCH] blk-mq: add helper for checking if one CPU is mapped to specified hctx Ming Lei
2024-05-17 15:41 ` Jens Axboe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.