Skip to contentSkip to conversation

Block: Fix handling of stopped queues and a plugging issue

PATCH Elias Oltmanns 2 participants 4 messages Oct 2, 2008 – Oct 11, 2008 Block layer

lore
Share & tools
lore
#0 lore raw

Make sure that ->request_fn() really isn't called on queues that are supposed to be stopped. While at it, don't remove the plug in __blk_run_queue() unconditionally since this might lead to system hangs.

---
Applies to your devel tree.

 block/blk-core.c |    6 +++---
 block/elevator.c |   12 +++++++-----
 2 files changed, 10 insertions(+), 8 deletions(-)
block/blk-core.c +3 -3
index 2d053b5..ecc5443 100644
@@ -404,14 +404,14 @@ EXPORT_SYMBOL(blk_sync_queue);
  */
 void __blk_run_queue(struct request_queue *q)
 {
-	blk_remove_plug(q);
-
 	/*
 	 * Only recurse once to avoid overrunning the stack, let the unplug
 	 * handling reinvoke the handler shortly if we already got there.
 	 */
-	if (!elv_queue_empty(q))
+	if (!elv_queue_empty(q) && likely(!blk_queue_stopped(q))) {
+		blk_remove_plug(q);
 		blk_invoke_request_fn(q);
+	}
 }
 EXPORT_SYMBOL(__blk_run_queue);
 
block/elevator.c +7 -5
index 0451892..43a4257 100644
@@ -611,8 +611,10 @@ void elv_insert(struct request_queue *q, struct request *rq, int where)
 		 *   with anything.  There's no point in delaying queue
 		 *   processing.
 		 */
-		blk_remove_plug(q);
-		q->request_fn(q);
+		if (likely(!blk_queue_stopped(q))) {
+			blk_remove_plug(q);
+			q->request_fn(q);
+		}
 		break;
 
 	case ELEVATOR_INSERT_SORT:
@@ -950,7 +952,8 @@ void elv_completed_request(struct request_queue *q, struct request *rq)
 		    blk_ordered_cur_seq(q) == QUEUE_ORDSEQ_DRAIN &&
 		    blk_ordered_req_seq(first_rq) > QUEUE_ORDSEQ_DRAIN) {
 			blk_ordered_complete_seq(q, QUEUE_ORDSEQ_DRAIN, 0);
-			q->request_fn(q);
+			if (likely(!blk_queue_stopped(q)))
+				q->request_fn(q);
 		}
 	}
 }
@@ -1109,8 +1112,7 @@ static int elevator_switch(struct request_queue *q, struct elevator_type *new_e)
 	elv_drain_elevator(q);
 
 	while (q->rq.elvpriv) {
-		blk_remove_plug(q);
-		q->request_fn(q);
+		blk_start_queueing(q);
 		spin_unlock_irq(q->queue_lock);
 		msleep(10);
 		spin_lock_irq(q->queue_lock);
#1 lore raw
Quoted 7 lines · Elias Oltmanns

Make sure that ->request_fn() really isn't called on queues that are supposed to be stopped. While at it, don't remove the plug in __blk_run_queue() unconditionally since this might lead to system hangs.

---
Applies to your devel tree.

Ping. Have you had a chance to look at this yet?

Regards,

Elias

#2 lore raw
In reply to Elias Oltmanns
Quoted 3 lines · Elias Oltmanns

Make sure that ->request_fn() really isn't called on queues that are supposed to be stopped. While at it, don't remove the plug in __blk_run_queue() unconditionally since this might lead to system hangs.

What system hangs, can you detail it?

Quoted 18 lines

---
Applies to your devel tree.

 block/blk-core.c |    6 +++---
 block/elevator.c |   12 +++++++-----
 2 files changed, 10 insertions(+), 8 deletions(-)
block/blk-core.c +0 -1
index 2d053b5..ecc5443 100644
@@ -404,14 +404,14 @@ EXPORT_SYMBOL(blk_sync_queue);
  */
 void __blk_run_queue(struct request_queue *q)
 {
-	blk_remove_plug(q);

block/blk-core.c EXPORT_SYMBOL(blk_sync_queue); · line 414

Quoted 10 lines
block/blk-core.c +3 -2
-
 	/*
 	 * Only recurse once to avoid overrunning the stack, let the unplug
 	 * handling reinvoke the handler shortly if we already got there.
 	 */
-	if (!elv_queue_empty(q))
+	if (!elv_queue_empty(q) && likely(!blk_queue_stopped(q))) {
+		blk_remove_plug(q);
 		blk_invoke_request_fn(q);
+	}

Doing

        if (foo && likely(bar))

doesn't make a lot of sense, you need to move the entire block or just don't do it. Just don't add it :-)

Quoted 21 lines
block/blk-core.c +0 -0
 }
 EXPORT_SYMBOL(__blk_run_queue);
 
block/elevator.c +4 -2
index 0451892..43a4257 100644
@@ -611,8 +611,10 @@ void elv_insert(struct request_queue *q, struct request *rq, int where)
 		 *   with anything.  There's no point in delaying queue
 		 *   processing.
 		 */
-		blk_remove_plug(q);
-		q->request_fn(q);
+		if (likely(!blk_queue_stopped(q))) {
+			blk_remove_plug(q);
+			q->request_fn(q);
+		}
 		break;
 
 	case ELEVATOR_INSERT_SORT:

block/elevator.c void elv_completed_request(struct request_queue *q, struct request *rq) · line 959

Quoted 9 lines
block/elevator.c +2 -1
@@ -950,7 +952,8 @@ void elv_completed_request(struct request_queue *q, struct request *rq)
 		    blk_ordered_cur_seq(q) == QUEUE_ORDSEQ_DRAIN &&
 		    blk_ordered_req_seq(first_rq) > QUEUE_ORDSEQ_DRAIN) {
 			blk_ordered_complete_seq(q, QUEUE_ORDSEQ_DRAIN, 0);
-			q->request_fn(q);
+			if (likely(!blk_queue_stopped(q)))
+				q->request_fn(q);
 		}
 	}
 }

I wonder if most of these should not just be blk_start_queueing(), would clean things up.

block/elevator.c static int elevator_switch(struct request_queue *q, struct elevator_type *new_e) · line 1118

Quoted 10 lines
block/elevator.c +1 -2
@@ -1109,8 +1112,7 @@ static int elevator_switch(struct request_queue *q, struct elevator_type *new_e)
 	elv_drain_elevator(q);
 
 	while (q->rq.elvpriv) {
-		blk_remove_plug(q);
-		q->request_fn(q);
+		blk_start_queueing(q);
 		spin_unlock_irq(q->queue_lock);
 		msleep(10);
 		spin_lock_irq(q->queue_lock);

Like so.

Signature · 1 line
Jens Axboe
#3 lore raw
Quoted 6 lines · Jens Axboe
Quoted 3 lines · Elias Oltmanns

Make sure that ->request_fn() really isn't called on queues that are supposed to be stopped. While at it, don't remove the plug in __blk_run_queue() unconditionally since this might lead to system hangs.

What system hangs, can you detail it?

Good question. As it turns out, I got hold of the wrong end of the stick entirely. Originally, I thought that requests might get enqueued later and not processed in a timely manner because the queue wasn't plugged. However, the olny way to do that is through __elv_add_request() and there it's probably the responsibility of the caller to make sure that the queue either is plugged or processed straight away. I, for one, have fallen into that trap and didn't take that into account in my shock protection code.

Quoted 32 lines
Quoted 19 lines

---
Applies to your devel tree.

 block/blk-core.c |    6 +++---
 block/elevator.c |   12 +++++++-----
 2 files changed, 10 insertions(+), 8 deletions(-)
block/blk-core.c +0 -1
index 2d053b5..ecc5443 100644
@@ -404,14 +404,14 @@ EXPORT_SYMBOL(blk_sync_queue);
  */
 void __blk_run_queue(struct request_queue *q)
 {
-	blk_remove_plug(q);

block/blk-core.c EXPORT_SYMBOL(blk_sync_queue); · line 414

Quoted 10 lines
block/blk-core.c +3 -2
-
 	/*
 	 * Only recurse once to avoid overrunning the stack, let the unplug
 	 * handling reinvoke the handler shortly if we already got there.
 	 */
-	if (!elv_queue_empty(q))
+	if (!elv_queue_empty(q) && likely(!blk_queue_stopped(q))) {
+		blk_remove_plug(q);
 		blk_invoke_request_fn(q);
+	}

Doing

Quoted 4 lines
        if (foo && likely(bar))

doesn't make a lot of sense, you need to move the entire block or just don't do it. Just don't add it :-)

Right. So the change in this function will just be

- if (!elv_queue_empty(q))
+ if (!elv_queue_empty(q) && !blk_queue_stopped(q))

since there is no harm in removing the plug unconditionally after all.

Quoted 20 lines
Quoted 20 lines
block/blk-core.c +0 -0
 }
 EXPORT_SYMBOL(__blk_run_queue);
 
block/elevator.c +4 -2
index 0451892..43a4257 100644
@@ -611,8 +611,10 @@ void elv_insert(struct request_queue *q, struct request *rq, int where)
 		 *   with anything.  There's no point in delaying queue
 		 *   processing.
 		 */
-		blk_remove_plug(q);
-		q->request_fn(q);
+		if (likely(!blk_queue_stopped(q))) {
+			blk_remove_plug(q);
+			q->request_fn(q);
+		}
 		break;
 
Quoted 14 lines

block/elevator.c void elv_completed_request(struct request_queue *q, struct request *rq) · line 959

Quoted 11 lines
block/elevator.c +2 -1
 	case ELEVATOR_INSERT_SORT:
@@ -950,7 +952,8 @@ void elv_completed_request(struct request_queue *q, struct request *rq)
 		    blk_ordered_cur_seq(q) == QUEUE_ORDSEQ_DRAIN &&
 		    blk_ordered_req_seq(first_rq) > QUEUE_ORDSEQ_DRAIN) {
 			blk_ordered_complete_seq(q, QUEUE_ORDSEQ_DRAIN, 0);
-			q->request_fn(q);
+			if (likely(!blk_queue_stopped(q)))
+				q->request_fn(q);
 		}
 	}
 }

I wonder if most of these should not just be blk_start_queueing(), would clean things up.

Yes, I wondered about that too. Especially in the case of elv_insert() though, I wasn't quite sure whether you'd prefer to inline the check there since this seems to be a fast path. If you don't think it worth the extra code, I'll just use blk_start_queueing() in these cases too.

Regards,

Elias