block: drain queue before waiting for q_usage_counter becoming zero
PATCH 1/1 block: drain queue before waiting for q_usage_counter becoming zero
Now we track legacy requests with .q_usage_counter in commit 055f6e18e08f ("block: Make q_usage_counter also track legacy requests"), but that commit never runs and drains legacy queue before waiting for this counter becoming zero, then IO hang is caused in the test of pulling disk during IO.
This patch fixes the issue by draining requests before waiting for q_usage_counter becoming zero.
--- block/blk-core.c | 9 +++++++-- block/blk-mq.c | 2 ++ block/blk.h | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-)
block/blk-core.c +7 -2
@@ -562,6 +562,13 @@ static void __blk_drain_queue(struct request_queue *q, bool drain_all) } } +void blk_drain_queue (struct request_queue *q) +{ +spin_lock_irq (q->queue_lock); +__blk_drain_queue (q, true); +spin_unlock_irq (q->queue_lock); +} +/** * blk_queue_bypass_start - enter queue bypass mode * @q: queue of interest
@@ -689,8 +696,6 @@ void blk_cleanup_queue(struct request_queue *q)*/ blk_freeze_queue (q);spin_lock_irq (lock); -if (!q->mq_ops) -__blk_drain_queue (q, true);queue_flag_set (QUEUE_FLAG_DEAD , q);spin_unlock_irq (lock);
block/blk-mq.c +2 -0
@@ -161,6 +161,8 @@ void blk_freeze_queue(struct request_queue *q)* exported to drivers as the only user for unfreeze is blk_mq. */ blk_freeze_queue_start (q); +if (!q->mq_ops) +blk_drain_queue (q);blk_mq_freeze_queue_wait (q); }
block/blk.h +2 -0
@@ -330,4 +330,6 @@ static inline void blk_queue_bounce(struct request_queue *q, struct bio **bio) }#endif /* CONFIG_BOUNCE */ +extern void blk_drain_queue (struct request_queue *q); +#endif /* BLK_INTERNAL_H */
Signature · 1 line
2.9.5
Quoted 63 lines · Ming Lei
Now we track legacy requests with .q_usage_counter in commit
055f6e18e08f("block: Makeq_usage_counteralso track legacy requests"), but that commit never runs and drains legacy queue before waiting for this counter becoming zero, then IO hang is caused in the test of pulling disk during IO.This patch fixes the issue by draining requests before waiting for
q_usage_counterbecoming zero.Fixes 055f6e18e08f("block: Make q_usage_counter also track legacy requests")Cc Wen Xiong <[email protected]>Signed-off-by Ming Lei <[email protected]>--- block/blk-core.c | 9 +++++++-- block/blk-mq.c | 2 ++ block/blk.h | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-)block/blk-core.c +7
-2@@ -562,6 +562,13 @@ static void __blk_drain_queue(struct request_queue *q, bool drain_all) } } +void blk_drain_queue (struct request_queue *q) +{ +spin_lock_irq (q->queue_lock); +__blk_drain_queue (q, true); +spin_unlock_irq (q->queue_lock); +} +/** * blk_queue_bypass_start - enter queue bypass mode * @q: queue of interest @@ -689,8 +696,6 @@ void blk_cleanup_queue(struct request_queue *q)*/ blk_freeze_queue (q);spin_lock_irq (lock); -if (!q->mq_ops) -__blk_drain_queue (q, true);queue_flag_set (QUEUE_FLAG_DEAD , q);spin_unlock_irq (lock);block/blk-mq.c +2
-0@@ -161,6 +161,8 @@ void blk_freeze_queue(struct request_queue *q)* exported to drivers as the only user for unfreeze is blk_mq. */ blk_freeze_queue_start (q); +if (!q->mq_ops) +blk_drain_queue (q);blk_mq_freeze_queue_wait (q); }block/blk.h +0
-0
block/blk.h static inline void blk_queue_bounce(struct request_queue *q, struct bio **bio) · line 335
Quoted 6 lines
block/blk.h +2
-0@@ -330,4 +330,6 @@ static inline void blk_queue_bounce(struct request_queue *q, struct bio **bio) }#endif /* CONFIG_BOUNCE */ +extern void blk_drain_queue (struct request_queue *q); +#endif /* BLK_INTERNAL_H */
I seem to have missed something.
Is blk_drain_queue() ever used?
Cheers,
Hannes
Signature · 5 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG Nürnberg)
Quoted 66 lines · Hannes Reinecke
Quoted 65 lines · Ming Lei
Now we track legacy requests with .q_usage_counter in commit
055f6e18e08f("block: Makeq_usage_counteralso track legacy requests"), but that commit never runs and drains legacy queue before waiting for this counter becoming zero, then IO hang is caused in the test of pulling disk during IO.This patch fixes the issue by draining requests before waiting for
q_usage_counterbecoming zero.Fixes 055f6e18e08f("block: Make q_usage_counter also track legacy requests")Cc Wen Xiong <[email protected]>Signed-off-by Ming Lei <[email protected]>--- block/blk-core.c | 9 +++++++-- block/blk-mq.c | 2 ++ block/blk.h | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-)block/blk-core.c +7
-2@@ -562,6 +562,13 @@ static void __blk_drain_queue(struct request_queue *q, bool drain_all) } } +void blk_drain_queue (struct request_queue *q) +{ +spin_lock_irq (q->queue_lock); +__blk_drain_queue (q, true); +spin_unlock_irq (q->queue_lock); +} +/** * blk_queue_bypass_start - enter queue bypass mode * @q: queue of interest @@ -689,8 +696,6 @@ void blk_cleanup_queue(struct request_queue *q)*/ blk_freeze_queue (q);spin_lock_irq (lock); -if (!q->mq_ops) -__blk_drain_queue (q, true);queue_flag_set (QUEUE_FLAG_DEAD , q);spin_unlock_irq (lock);block/blk-mq.c +2
-0@@ -161,6 +161,8 @@ void blk_freeze_queue(struct request_queue *q)* exported to drivers as the only user for unfreeze is blk_mq. */ blk_freeze_queue_start (q); +if (!q->mq_ops) +blk_drain_queue (q);blk_mq_freeze_queue_wait (q); }block/blk.h +0
-0@@ -330,4 +330,6 @@ static inline void blk_queue_bounce(struct request_queue *q, struct bio **bio) }#endif /* CONFIG_BOUNCE */
Quoted 6 lines
block/blk.h static inline void blk_queue_bounce(struct request_queue *q, struct bio **bio) · line 335
Quoted 4 lines
block/blk.h +2
-0+extern void blk_drain_queue (struct request_queue *q); +#endif /* BLK_INTERNAL_H */ I seem to have missed something.
Isblk_drain_queue()ever used?
It is always called in blk_cleanup_queue().
Before 055f6e18e08f("block: Make q_usage_counter also track legacy requests", the q_usage_counter just works for sync IO(such as dax) because we only hold the refcount when calling q->make_request_fn(), so blk_drain_queue() does do the job always.
Thanks,
Ming
T24gV2VkLCAyMDE3LTExLTIyIGF0IDEzOjExICswODAwLCBNaW5nIEx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hhbiBfX2Jsa19kcmFpbl9xdWV1ZSgpICh3aGlsZSAo Li4uKSBtc2xlZXAoMTApKS4NCg0KQmFydC4=
Quoted 10 lines · Bart Van Assche
Quoted 9 lines · Ming Lei
block/blk-mq.c +1
-0@@ -161,6 +161,8 @@ void blk_freeze_queue(struct request_queue *q)* exported to drivers as the only user for unfreeze is blk_mq. */ blk_freeze_queue_start (q); +if (!q->mq_ops)
Quoted 8 lines
block/blk-mq.c void blk_freeze_queue(struct request_queue *q) · line 167
Quoted 3 lines
block/blk-mq.c +1
-0+blk_drain_queue (q);blk_mq_freeze_queue_wait (q); }Since
q_usage_counternow tracks legacy requests, is there any reason why we still need__blk_drain_queue()? Have you considered to eliminate__blk_drain_queue()and to callblk_run_queue()from insideblk_freeze_queue()instead of callingblk_drain_queue()? I'm asking this because
Yeah, that looks better, I am thinking of that too, will do this way in V2.
Signature · 1 line
Ming