diff mbox series

blk-mq: don't allocate requests when all cpus in a hctx are offline

Message ID 20210630100342.1100-1-hare@suse.de (mailing list archive)
State New, archived
Headers show
Series blk-mq: don't allocate requests when all cpus in a hctx are offline | expand

Commit Message

Hannes Reinecke June 30, 2021, 10:03 a.m. UTC
When all CPUs in a hctx are offline in blk_mq_alloc_request_hctx() we should
not try to allocate the request, as we'll fail later on in blk_mq_get_tag() anyway.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 block/blk-mq.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Ming Lei June 30, 2021, 10:13 a.m. UTC | #1
On Wed, Jun 30, 2021 at 12:03:42PM +0200, Hannes Reinecke wrote:
> When all CPUs in a hctx are offline in blk_mq_alloc_request_hctx() we should
> not try to allocate the request, as we'll fail later on in blk_mq_get_tag() anyway.
> 
> Signed-off-by: Hannes Reinecke <hare@suse.de>
> ---

Please see my yesterday's reply why this way isn't good:

https://lore.kernel.org/lkml/YNrwnWfsxf8cJcoe@T590/
https://lore.kernel.org/lkml/YNrhXFgv%2FgEWbhbl@T590/


Thanks,
Ming
diff mbox series

Patch

diff --git a/block/blk-mq.c b/block/blk-mq.c
index f11d4018ce2e..1622d0cabe3a 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -468,13 +468,16 @@  struct request *blk_mq_alloc_request_hctx(struct request_queue *q,
 	data.hctx = q->queue_hw_ctx[hctx_idx];
 	if (!blk_mq_hw_queue_mapped(data.hctx))
 		goto out_queue_exit;
+	ret = -EWOULDBLOCK;
+	/* all cpus in the hctx are offline, don't try to allocate a tag */
 	cpu = cpumask_first_and(data.hctx->cpumask, cpu_online_mask);
+	if (unlikely(cpu >= nr_cpu_ids))
+		goto out_queue_exit;
 	data.ctx = __blk_mq_get_ctx(q, cpu);
 
 	if (!q->elevator)
 		blk_mq_tag_busy(data.hctx);
 
-	ret = -EWOULDBLOCK;
 	tag = blk_mq_get_tag(&data);
 	if (tag == BLK_MQ_NO_TAG)
 		goto out_queue_exit;