Skip to content

Commit e70feb8

Browse files
Ming Leiaxboe
authored andcommitted
blk-mq: support concurrent queue quiesce/unquiesce
blk_mq_quiesce_queue() has been used a bit wide now, so far we don't support concurrent/nested quiesce. One biggest issue is that unquiesce can happen unexpectedly in case that quiesce/unquiesce are run concurrently from more than one context. This patch introduces q->mq_quiesce_depth to deal concurrent quiesce, and we only unquiesce queue when it is the last/outer-most one of all contexts. Several kernel panic issue has been reported[1][2][3] when running stress quiesce test. And this patch has been verified in these reports. [1] https://lore.kernel.org/linux-block/[email protected]/T/#m1fc52431fad7f33b1ffc3f12c4450e4238540787 [2] https://lore.kernel.org/linux-block/[email protected]/T/#m10ad90afeb9c8cc318334190a7c24c8b5c5e0722 [3] https://listman.redhat.com/archives/dm-devel/2021-September/msg00189.html Signed-off-by: Ming Lei <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 1d35d51 commit e70feb8

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

block/blk-mq.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,12 @@ EXPORT_SYMBOL_GPL(blk_mq_unfreeze_queue);
241241
*/
242242
void blk_mq_quiesce_queue_nowait(struct request_queue *q)
243243
{
244-
blk_queue_flag_set(QUEUE_FLAG_QUIESCED, q);
244+
unsigned long flags;
245+
246+
spin_lock_irqsave(&q->queue_lock, flags);
247+
if (!q->quiesce_depth++)
248+
blk_queue_flag_set(QUEUE_FLAG_QUIESCED, q);
249+
spin_unlock_irqrestore(&q->queue_lock, flags);
245250
}
246251
EXPORT_SYMBOL_GPL(blk_mq_quiesce_queue_nowait);
247252

@@ -282,10 +287,21 @@ EXPORT_SYMBOL_GPL(blk_mq_quiesce_queue);
282287
*/
283288
void blk_mq_unquiesce_queue(struct request_queue *q)
284289
{
285-
blk_queue_flag_clear(QUEUE_FLAG_QUIESCED, q);
290+
unsigned long flags;
291+
bool run_queue = false;
292+
293+
spin_lock_irqsave(&q->queue_lock, flags);
294+
if (WARN_ON_ONCE(q->quiesce_depth <= 0)) {
295+
;
296+
} else if (!--q->quiesce_depth) {
297+
blk_queue_flag_clear(QUEUE_FLAG_QUIESCED, q);
298+
run_queue = true;
299+
}
300+
spin_unlock_irqrestore(&q->queue_lock, flags);
286301

287302
/* dispatch requests which are inserted during quiescing */
288-
blk_mq_run_hw_queues(q, true);
303+
if (run_queue)
304+
blk_mq_run_hw_queues(q, true);
289305
}
290306
EXPORT_SYMBOL_GPL(blk_mq_unquiesce_queue);
291307

include/linux/blkdev.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ struct request_queue {
315315
*/
316316
struct mutex mq_freeze_lock;
317317

318+
int quiesce_depth;
319+
318320
struct blk_mq_tag_set *tag_set;
319321
struct list_head tag_set_list;
320322
struct bio_set bio_split;

0 commit comments

Comments
 (0)