Skip to content

Commit 306f13e

Browse files
Ming Leiaxboe
authored andcommitted
blk-mq: simplify reallocation of hw ctxs a bit
blk_mq_alloc_and_init_hctx() has already taken reuse into account, so no need to do it outside, then we can simplify blk_mq_realloc_hw_ctxs(). Reviewed-by: Hannes Reinecke <hare@suse.de> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Ming Lei <ming.lei@redhat.com> Link: https://lore.kernel.org/r/20220308073219.91173-3-ming.lei@redhat.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 4d80513 commit 306f13e

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

block/blk-mq.c

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3966,29 +3966,24 @@ static void blk_mq_realloc_hw_ctxs(struct blk_mq_tag_set *set,
39663966
/* protect against switching io scheduler */
39673967
mutex_lock(&q->sysfs_lock);
39683968
for (i = 0; i < set->nr_hw_queues; i++) {
3969+
int old_node;
39693970
int node = blk_mq_get_hctx_node(set, i);
3970-
struct blk_mq_hw_ctx *hctx;
3971+
struct blk_mq_hw_ctx *old_hctx = hctxs[i];
39713972

3972-
/*
3973-
* If the hw queue has been mapped to another numa node,
3974-
* we need to realloc the hctx. If allocation fails, fallback
3975-
* to use the previous one.
3976-
*/
3977-
if (hctxs[i] && (hctxs[i]->numa_node == node))
3978-
continue;
3973+
if (old_hctx) {
3974+
old_node = old_hctx->numa_node;
3975+
blk_mq_exit_hctx(q, set, old_hctx, i);
3976+
}
39793977

3980-
hctx = blk_mq_alloc_and_init_hctx(set, q, i, node);
3981-
if (hctx) {
3982-
if (hctxs[i])
3983-
blk_mq_exit_hctx(q, set, hctxs[i], i);
3984-
hctxs[i] = hctx;
3985-
} else {
3986-
if (hctxs[i])
3987-
pr_warn("Allocate new hctx on node %d fails,\
3988-
fallback to previous one on node %d\n",
3989-
node, hctxs[i]->numa_node);
3990-
else
3978+
hctxs[i] = blk_mq_alloc_and_init_hctx(set, q, i, node);
3979+
if (!hctxs[i]) {
3980+
if (!old_hctx)
39913981
break;
3982+
pr_warn("Allocate new hctx on node %d fails, fallback to previous one on node %d\n",
3983+
node, old_node);
3984+
hctxs[i] = blk_mq_alloc_and_init_hctx(set, q, i,
3985+
old_node);
3986+
WARN_ON_ONCE(!hctxs[i]);
39923987
}
39933988
}
39943989
/*

0 commit comments

Comments
 (0)