Skip to content

Commit 5b20285

Browse files
Jianchao Wangaxboe
authored andcommitted
blk-mq: change gfp flags to GFP_NOIO in blk_mq_realloc_hw_ctxs
blk_mq_realloc_hw_ctxs could be invoked during update hw queues. At the momemt, IO is blocked. Change the gfp flags from GFP_KERNEL to GFP_NOIO to avoid forever hang during memory allocation in blk_mq_realloc_hw_ctxs. Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 477e19d commit 5b20285

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

block/blk-core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ int blk_init_allocated_queue(struct request_queue *q)
11631163
{
11641164
WARN_ON_ONCE(q->mq_ops);
11651165

1166-
q->fq = blk_alloc_flush_queue(q, NUMA_NO_NODE, q->cmd_size);
1166+
q->fq = blk_alloc_flush_queue(q, NUMA_NO_NODE, q->cmd_size, GFP_KERNEL);
11671167
if (!q->fq)
11681168
return -ENOMEM;
11691169

block/blk-flush.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,20 +566,20 @@ int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask,
566566
EXPORT_SYMBOL(blkdev_issue_flush);
567567

568568
struct blk_flush_queue *blk_alloc_flush_queue(struct request_queue *q,
569-
int node, int cmd_size)
569+
int node, int cmd_size, gfp_t flags)
570570
{
571571
struct blk_flush_queue *fq;
572572
int rq_sz = sizeof(struct request);
573573

574-
fq = kzalloc_node(sizeof(*fq), GFP_KERNEL, node);
574+
fq = kzalloc_node(sizeof(*fq), flags, node);
575575
if (!fq)
576576
goto fail;
577577

578578
if (q->mq_ops)
579579
spin_lock_init(&fq->mq_flush_lock);
580580

581581
rq_sz = round_up(rq_sz + cmd_size, cache_line_size());
582-
fq->flush_rq = kzalloc_node(rq_sz, GFP_KERNEL, node);
582+
fq->flush_rq = kzalloc_node(rq_sz, flags, node);
583583
if (!fq->flush_rq)
584584
goto fail_rq;
585585

block/blk-mq.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,12 +2210,12 @@ static int blk_mq_init_hctx(struct request_queue *q,
22102210
* runtime
22112211
*/
22122212
hctx->ctxs = kmalloc_array_node(nr_cpu_ids, sizeof(void *),
2213-
GFP_KERNEL, node);
2213+
GFP_NOIO | __GFP_NOWARN | __GFP_NORETRY, node);
22142214
if (!hctx->ctxs)
22152215
goto unregister_cpu_notifier;
22162216

2217-
if (sbitmap_init_node(&hctx->ctx_map, nr_cpu_ids, ilog2(8), GFP_KERNEL,
2218-
node))
2217+
if (sbitmap_init_node(&hctx->ctx_map, nr_cpu_ids, ilog2(8),
2218+
GFP_NOIO | __GFP_NOWARN | __GFP_NORETRY, node))
22192219
goto free_ctxs;
22202220

22212221
hctx->nr_ctx = 0;
@@ -2228,7 +2228,8 @@ static int blk_mq_init_hctx(struct request_queue *q,
22282228
set->ops->init_hctx(hctx, set->driver_data, hctx_idx))
22292229
goto free_bitmap;
22302230

2231-
hctx->fq = blk_alloc_flush_queue(q, hctx->numa_node, set->cmd_size);
2231+
hctx->fq = blk_alloc_flush_queue(q, hctx->numa_node, set->cmd_size,
2232+
GFP_NOIO | __GFP_NOWARN | __GFP_NORETRY);
22322233
if (!hctx->fq)
22332234
goto exit_hctx;
22342235

@@ -2536,12 +2537,14 @@ static void blk_mq_realloc_hw_ctxs(struct blk_mq_tag_set *set,
25362537

25372538
node = blk_mq_hw_queue_to_node(q->mq_map, i);
25382539
hctxs[i] = kzalloc_node(blk_mq_hw_ctx_size(set),
2539-
GFP_KERNEL, node);
2540+
GFP_NOIO | __GFP_NOWARN | __GFP_NORETRY,
2541+
node);
25402542
if (!hctxs[i])
25412543
break;
25422544

2543-
if (!zalloc_cpumask_var_node(&hctxs[i]->cpumask, GFP_KERNEL,
2544-
node)) {
2545+
if (!zalloc_cpumask_var_node(&hctxs[i]->cpumask,
2546+
GFP_NOIO | __GFP_NOWARN | __GFP_NORETRY,
2547+
node)) {
25452548
kfree(hctxs[i]);
25462549
hctxs[i] = NULL;
25472550
break;

block/blk.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ static inline void __blk_get_queue(struct request_queue *q)
125125
}
126126

127127
struct blk_flush_queue *blk_alloc_flush_queue(struct request_queue *q,
128-
int node, int cmd_size);
128+
int node, int cmd_size, gfp_t flags);
129129
void blk_free_flush_queue(struct blk_flush_queue *q);
130130

131131
int blk_init_rl(struct request_list *rl, struct request_queue *q,

0 commit comments

Comments
 (0)