Skip to contentSkip to conversation

mq-deadline: the dd->dispatch queue follows a FIFO policy

PATCH In review chengkaitao 3 participants 4 messages Dec 8, 2025 – Dec 9, 2025 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mq-deadline: the dd->dispatch queue follows a FIFO policy

From: Chengkaitao <[email protected]>

In the initial implementation, the 'list_add(&rq->queuelist, ...' statement added to the dd_insert_request function was designed to differentiate priorities among various IO-requests within the same linked list. For example, 'Commit 945ffb60c11d ("mq-deadline: add blk-mq adaptation of the deadline IO scheduler")', introduced this 'list_add' operation to ensure that requests with the at_head flag would always be dispatched before requests without the REQ_TYPE_FS flag.

Since 'Commit 7687b38ae470 ("bfq/mq-deadline: remove redundant check for passthrough request")', removed blk_rq_is_passthrough, the dd->dispatch list now contains only requests with the at_head flag. In this context, all at_head requests should be treated as having equal priority, and a first-in-first-out (FIFO) policy better aligns with the current situation. Therefore, replacing list_add with list_add_tail is more appropriate.

---
 block/mq-deadline.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/mq-deadline.c +1 -1
index 3e3719093aec..dcd7f4f1ecd2 100644
@@ -661,7 +661,7 @@ static void dd_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
 	trace_block_rq_insert(rq);
 
 	if (flags & BLK_MQ_INSERT_AT_HEAD) {
-		list_add(&rq->queuelist, &dd->dispatch);
+		list_add_tail(&rq->queuelist, &dd->dispatch);
 		rq->fifo_time = jiffies;
 	} else {
 		deadline_add_rq_rb(per_prio, rq);
Signature · 1 line
2.50.1 (Apple Git-155)
#1 lore raw
Quoted 27 lines · chengkaitao

From: Chengkaitao <[email protected]>

In the initial implementation, the 'list_add(&rq->queuelist, ...' statement added to the dd_insert_request function was designed to differentiate priorities among various IO-requests within the same linked list. For example, 'Commit 945ffb60c11d ("mq-deadline: add blk-mq adaptation of the deadline IO scheduler")', introduced this 'list_add' operation to ensure that requests with the at_head flag would always be dispatched before requests without the REQ_TYPE_FS flag.

Since 'Commit 7687b38ae470 ("bfq/mq-deadline: remove redundant check for passthrough request")', removed blk_rq_is_passthrough, the dd->dispatch list now contains only requests with the at_head flag. In this context, all at_head requests should be treated as having equal priority, and a first-in-first-out (FIFO) policy better aligns with the current situation. Therefore, replacing list_add with list_add_tail is more appropriate.

---
  block/mq-deadline.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
block/mq-deadline.c +0 -0
index 3e3719093aec..dcd7f4f1ecd2 100644

block/mq-deadline.c static void dd_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq, · line 667

Quoted 8 lines
block/mq-deadline.c +1 -1
@@ -661,7 +661,7 @@ static void dd_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
  	trace_block_rq_insert(rq);
 
  	if (flags & BLK_MQ_INSERT_AT_HEAD) {
-		list_add(&rq->queuelist, &dd->dispatch);
+		list_add_tail(&rq->queuelist, &dd->dispatch);
  		rq->fifo_time = jiffies;
  	} else {
  		deadline_add_rq_rb(per_prio, rq);

I think the current behavior (LIFO) is on purpose and also that it only should be changed if there is a strong reason to change it. I don't see a strong reason being mentioned in the patch description.

Bart.

#2 lore raw
Quoted 31 lines · Bart Van Assche
Quoted 29 lines · chengkaitao

From: Chengkaitao <[email protected]>

In the initial implementation, the 'list_add(&rq->queuelist, ...' statement added to the dd_insert_request function was designed to differentiate priorities among various IO-requests within the same linked list. For example, 'Commit 945ffb60c11d ("mq-deadline: add blk-mq adaptation of the deadline IO scheduler")', introduced this 'list_add' operation to ensure that requests with the at_head flag would always be dispatched before requests without the REQ_TYPE_FS flag.

Since 'Commit 7687b38ae470 ("bfq/mq-deadline: remove redundant check for passthrough request")', removed blk_rq_is_passthrough, the dd->dispatch list now contains only requests with the at_head flag. In this context, all at_head requests should be treated as having equal priority, and a first-in-first-out (FIFO) policy better aligns with the current situation. Therefore, replacing list_add with list_add_tail is more appropriate.

---
  block/mq-deadline.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
block/mq-deadline.c +0 -0
index 3e3719093aec..dcd7f4f1ecd2 100644
@@ -661,7 +661,7 @@ static void dd_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
      trace_block_rq_insert(rq);
 
Quoted 11 lines

block/mq-deadline.c static void dd_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq, · line 667

Quoted 6 lines
block/mq-deadline.c +1 -1
      if (flags & BLK_MQ_INSERT_AT_HEAD) {
-             list_add(&rq->queuelist, &dd->dispatch);
+             list_add_tail(&rq->queuelist, &dd->dispatch);
              rq->fifo_time = jiffies;
      } else {
              deadline_add_rq_rb(per_prio, rq);

I think the current behavior (LIFO) is on purpose and also that it only should be changed if there is a strong reason to change it. I don't see a strong reason being mentioned in the patch description.

Previously, the dd->dispatch queue contained both requests with the BLK_MQ_INSERT_AT_HEAD flag and those without it. The implementation placed requests with the BLK_MQ_INSERT_AT_HEAD flag at the head of the dd->dispatch queue, while requests without this flag were placed at the tail. However, now all requests in the dd->dispatch list carry the BLK_MQ_INSERT_AT_HEAD flag, and I can't find any justification for continuing to use a LIFO (last-in-first-out) policy.

Additionally, the dispatch queue has recently been moved from struct dd_per_prio to struct deadline_data, switching back to a single dispatch list. This means more requests will queue in the dispatch list, and continuing with the LIFO policy makes earlier-arriving requests more susceptible to starvation. Could anyone explain the rationale behind maintaining this approach?

Signature · 2 lines
Yours,
Kaitao Cheng
maintainer
#3 lore raw
Quoted 3 lines · Tao pilgrim

However, now all requests in the dd->dispatch list carry the BLK_MQ_INSERT_AT_HEAD flag, and I can't find any justification for continuing to use a LIFO (last-in-first-out) policy.

What if a head insertion requires another TUR or similar before being able to be processed?

I agree with notion that AT_HEAD should generally be issued in order, but let's not make blanket changes like this just because you can't find any immediate justification for why the current behavior is as it is. It'd be different if you were fixing a bug and came across this. But that does not seem to be the case.

Signature · 1 line
Jens Axboe