Skip to contentSkip to conversation

Improve I/O priority support

PATCH In review Bart Van Assche 9 participants 65 messages May 27, 2021 – May 28, 2021 Block layer

lore
Share & tools
lore
#0 lore raw

cover Improve I/O priority support

Hi Jens,

A feature that is missing from the Linux kernel for storage devices that support I/O priorities is to set the I/O priority in requests involving page cache writeback. Since the identity of the process that triggers page cache writeback is not known in the writeback code, the priority set by ioprio_set() is ignored. However, an I/O cgroup is associated with writeback requests by certain filesystems. Hence this patch series that implements the following changes for the mq-deadline scheduler:
* Make the I/O priority configurable per I/O cgroup.
* Change the I/O priority of requests to the lower of (request I/O priority, cgroup I/O priority).
* Introduce one queue per I/O priority in the mq-deadline scheduler.

Please consider this patch series for kernel v5.14.

Thanks,

Bart.

Bart Van Assche (9):
block/mq-deadline: Add several comments block/mq-deadline: Add two lockdep_assert_held() statements block/mq-deadline: Remove two local variables block/mq-deadline: Rename dd_init_queue() and dd_exit_queue() block/mq-deadline: Improve compile-time argument checking block/mq-deadline: Reduce the read expiry time for non-rotational
media
block/mq-deadline: Reserve 25% of tags for synchronous requests block/mq-deadline: Add I/O priority support block/mq-deadline: Add cgroup support

 block/Kconfig.iosched      |   6 +
 block/Makefile             |   1 +
 block/mq-deadline-cgroup.c | 206 +++++++++++++++
 block/mq-deadline-cgroup.h |  73 ++++++
 block/mq-deadline.c        | 524 +++++++++++++++++++++++++++++--------
 5 files changed, 695 insertions(+), 115 deletions(-)
 create mode 100644 block/mq-deadline-cgroup.c
 create mode 100644 block/mq-deadline-cgroup.h
#1 lore raw

PATCH 1/9 block/mq-deadline: Add several comments

Make the code easier to read by adding more comments.

Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/mq-deadline.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
block/mq-deadline.c +18 -0
index 8eea2cbf2bf4..64cabbc157ea 100644
@@ -139,6 +139,9 @@ static void dd_request_merged(struct request_queue *q, struct request *req,
 	}
 }
 
+/*
+ * Callback function that is invoked after @next has been merged into @req.
+ */
 static void dd_merged_requests(struct request_queue *q, struct request *req,
 			       struct request *next)
 {
@@ -375,6 +378,8 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
 }
 
 /*
+ * Called from blk_mq_run_hw_queue() -> __blk_mq_sched_dispatch_requests().
+ *
  * One confusing aspect here is that we get called for a specific
  * hardware queue, but we may return a request that is for a
  * different hardware queue. This is because mq-deadline has shared
@@ -438,6 +443,10 @@ static int dd_init_queue(struct request_queue *q, struct elevator_type *e)
 	return 0;
 }
 
+/*
+ * Try to merge @bio into an existing request. If @bio has been merged into
+ * an existing request, store the pointer to that request into *@rq.
+ */
 static int dd_request_merge(struct request_queue *q, struct request **rq,
 			    struct bio *bio)
 {
@@ -461,6 +470,10 @@ static int dd_request_merge(struct request_queue *q, struct request **rq,
 	return ELEVATOR_NO_MERGE;
 }
 
+/*
+ * Attempt to merge a bio into an existing request. This function is called
+ * before @bio is associated with a request.
+ */
 static bool dd_bio_merge(struct request_queue *q, struct bio *bio,
 		unsigned int nr_segs)
 {
@@ -518,6 +531,9 @@ static void dd_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
 	}
 }
 
+/*
+ * Called from blk_mq_sched_insert_request() or blk_mq_sched_insert_requests().
+ */
 static void dd_insert_requests(struct blk_mq_hw_ctx *hctx,
 			       struct list_head *list, bool at_head)
 {
@@ -544,6 +560,8 @@ static void dd_prepare_request(struct request *rq)
 }
 
 /*
+ * Callback function called from inside blk_mq_free_request().
+ *
  * For zoned block devices, write unlock the target zone of
  * completed write requests. Do this while holding the zone lock
  * spinlock so that the zone is never unlocked while deadline_fifo_request()
#3 lore raw

Re: [PATCH 1/9] block/mq-deadline: Add several comments

In reply to Bart Van Assche
Quoted 67 lines · Bart Van Assche

Make the code easier to read by adding more comments.

Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/mq-deadline.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
block/mq-deadline.c +16 -0
index 8eea2cbf2bf4..64cabbc157ea 100644
@@ -139,6 +139,9 @@ static void dd_request_merged(struct request_queue *q, struct request *req,
 	}
 }
 
+/*
+ * Callback function that is invoked after @next has been merged into @req.
+ */
 static void dd_merged_requests(struct request_queue *q, struct request *req,
 			       struct request *next)
 {
@@ -375,6 +378,8 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
 }
 
 /*
+ * Called from blk_mq_run_hw_queue() -> __blk_mq_sched_dispatch_requests().
+ *
  * One confusing aspect here is that we get called for a specific
  * hardware queue, but we may return a request that is for a
  * different hardware queue. This is because mq-deadline has shared
@@ -438,6 +443,10 @@ static int dd_init_queue(struct request_queue *q, struct elevator_type *e)
 	return 0;
 }
 
+/*
+ * Try to merge @bio into an existing request. If @bio has been merged into
+ * an existing request, store the pointer to that request into *@rq.
+ */
 static int dd_request_merge(struct request_queue *q, struct request **rq,
 			    struct bio *bio)
 {
@@ -461,6 +470,10 @@ static int dd_request_merge(struct request_queue *q, struct request **rq,
 	return ELEVATOR_NO_MERGE;
 }
 
+/*
+ * Attempt to merge a bio into an existing request. This function is called
+ * before @bio is associated with a request.
+ */
 static bool dd_bio_merge(struct request_queue *q, struct bio *bio,
 		unsigned int nr_segs)
 {
@@ -518,6 +531,9 @@ static void dd_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
 	}
 }
 
+/*
+ * Called from blk_mq_sched_insert_request() or blk_mq_sched_insert_requests().
+ */
 static void dd_insert_requests(struct blk_mq_hw_ctx *hctx,
 			       struct list_head *list, bool at_head)
 {

block/mq-deadline.c static void dd_prepare_request(struct request *rq) · line 567

Quoted 8 lines
block/mq-deadline.c +2 -0
@@ -544,6 +560,8 @@ static void dd_prepare_request(struct request *rq)
 }
 
 /*
+ * Callback function called from inside blk_mq_free_request().
+ *
  * For zoned block devices, write unlock the target zone of
  * completed write requests. Do this while holding the zone lock
  * spinlock so that the zone is never unlocked while deadline_fifo_request()

Shouldn't these be kernel-doc comments?

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke		        Kernel Storage Architect
[email protected]			               +49 911 74053 688
SUSE Software Solutions Germany GmbH, 90409 Nürnberg
GF: F. Imendörffer, HRB 36809 (AG Nürnberg)
#4 lore raw

Re: [PATCH 1/9] block/mq-deadline: Add several comments

Quoted 9 lines · Hannes Reinecke
Quoted 7 lines · Bart Van Assche

/*
+ * Callback function called from inside blk_mq_free_request().
+ *
* For zoned block devices, write unlock the target zone of
* completed write requests. Do this while holding the zone lock
* spinlock so that the zone is never unlocked while deadline_fifo_request()

Shouldn't these be kernel-doc comments?

Hi Hannes,

When using the kernel-doc format it is required to document the meaning of all function arguments. It seems to me that it is easy to guess what the meaning of the function arguments is in the deadline scheduler?

Bart.

Reviewed-by on v1 1/9
#6 lore raw

Re: [PATCH 1/9] block/mq-deadline: Add several comments

In reply to Bart Van Assche
Quoted 67 lines · Bart Van Assche

Make the code easier to read by adding more comments.

Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
  block/mq-deadline.c | 18 ++++++++++++++++++
  1 file changed, 18 insertions(+)
block/mq-deadline.c +16 -0
index 8eea2cbf2bf4..64cabbc157ea 100644
@@ -139,6 +139,9 @@ static void dd_request_merged(struct request_queue *q, struct request *req,
  	}
  }
 
+/*
+ * Callback function that is invoked after @next has been merged into @req.
+ */
  static void dd_merged_requests(struct request_queue *q, struct request *req,
  			       struct request *next)
  {
@@ -375,6 +378,8 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
  }
 
  /*
+ * Called from blk_mq_run_hw_queue() -> __blk_mq_sched_dispatch_requests().
+ *
   * One confusing aspect here is that we get called for a specific
   * hardware queue, but we may return a request that is for a
   * different hardware queue. This is because mq-deadline has shared
@@ -438,6 +443,10 @@ static int dd_init_queue(struct request_queue *q, struct elevator_type *e)
  	return 0;
  }
 
+/*
+ * Try to merge @bio into an existing request. If @bio has been merged into
+ * an existing request, store the pointer to that request into *@rq.
+ */
  static int dd_request_merge(struct request_queue *q, struct request **rq,
  			    struct bio *bio)
  {
@@ -461,6 +470,10 @@ static int dd_request_merge(struct request_queue *q, struct request **rq,
  	return ELEVATOR_NO_MERGE;
  }
 
+/*
+ * Attempt to merge a bio into an existing request. This function is called
+ * before @bio is associated with a request.
+ */
  static bool dd_bio_merge(struct request_queue *q, struct bio *bio,
  		unsigned int nr_segs)
  {
@@ -518,6 +531,9 @@ static void dd_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
  	}
  }
 
+/*
+ * Called from blk_mq_sched_insert_request() or blk_mq_sched_insert_requests().
+ */
  static void dd_insert_requests(struct blk_mq_hw_ctx *hctx,
  			       struct list_head *list, bool at_head)
  {

block/mq-deadline.c static void dd_prepare_request(struct request *rq) · line 567

Quoted 8 lines
block/mq-deadline.c +2 -0
@@ -544,6 +560,8 @@ static void dd_prepare_request(struct request *rq)
  }
 
  /*
+ * Callback function called from inside blk_mq_free_request().
+ *
   * For zoned block devices, write unlock the target zone of
   * completed write requests. Do this while holding the zone lock
   * spinlock so that the zone is never unlocked while deadline_fifo_request()
Signature · 1 line
Himanshu Madhani                                Oracle Linux Engineering
#7 lore raw

PATCH 2/9 block/mq-deadline: Add two lockdep_assert_held() statements

In reply to Bart Van Assche

Document the locking strategy by adding two lockdep_assert_held() statements.

Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/mq-deadline.c | 4 ++++
 1 file changed, 4 insertions(+)
block/mq-deadline.c +4 -0
index 64cabbc157ea..4da0bd3b9827 100644
@@ -279,6 +279,8 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
 	bool reads, writes;
 	int data_dir;
 
+	lockdep_assert_held(&dd->lock);
+
 	if (!list_empty(&dd->dispatch)) {
 		rq = list_first_entry(&dd->dispatch, struct request, queuelist);
 		list_del_init(&rq->queuelist);
@@ -501,6 +503,8 @@ static void dd_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
 	struct deadline_data *dd = q->elevator->elevator_data;
 	const int data_dir = rq_data_dir(rq);
 
+	lockdep_assert_held(&dd->lock);
+
 	/*
 	 * This may be a requeue of a write request that has locked its
 	 * target zone. If it is the case, this releases the zone lock.
Reviewed-by on v1 2/9
#9 lore raw

Re: [PATCH 2/9] block/mq-deadline: Add two lockdep_assert_held() statements

In reply to Bart Van Assche
Quoted 26 lines · Bart Van Assche

Document the locking strategy by adding two lockdep_assert_held() statements.

Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/mq-deadline.c | 4 ++++
 1 file changed, 4 insertions(+)
block/mq-deadline.c +2 -0
index 64cabbc157ea..4da0bd3b9827 100644
@@ -279,6 +279,8 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
 	bool reads, writes;
 	int data_dir;
 
+	lockdep_assert_held(&dd->lock);
+
 	if (!list_empty(&dd->dispatch)) {
 		rq = list_first_entry(&dd->dispatch, struct request, queuelist);
 		list_del_init(&rq->queuelist);

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

Quoted 8 lines
block/mq-deadline.c +2 -0
@@ -501,6 +503,8 @@ static void dd_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
 	struct deadline_data *dd = q->elevator->elevator_data;
 	const int data_dir = rq_data_dir(rq);
 
+	lockdep_assert_held(&dd->lock);
+
 	/*
 	 * This may be a requeue of a write request that has locked its
 	 * target zone. If it is the case, this releases the zone lock.
Signature · 2 lines
Damien Le Moal
Western Digital Research
Reviewed-by on v1 2/9
#10 lore raw

Re: [PATCH 2/9] block/mq-deadline: Add two lockdep_assert_held() statements

In reply to Bart Van Assche
Quoted 11 lines · Bart Van Assche

Document the locking strategy by adding two lockdep_assert_held() statements.

Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/mq-deadline.c | 4 ++++
 1 file changed, 4 insertions(+)

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke		        Kernel Storage Architect
[email protected]			               +49 911 74053 688
SUSE Software Solutions Germany GmbH, 90409 Nürnberg
GF: F. Imendörffer, HRB 36809 (AG Nürnberg)
Reviewed-by on v1 2/9
#12 lore raw

Re: [PATCH 2/9] block/mq-deadline: Add two lockdep_assert_held() statements

In reply to Bart Van Assche
Quoted 26 lines · Bart Van Assche

Document the locking strategy by adding two lockdep_assert_held() statements.

Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
  block/mq-deadline.c | 4 ++++
  1 file changed, 4 insertions(+)
block/mq-deadline.c +2 -0
index 64cabbc157ea..4da0bd3b9827 100644
@@ -279,6 +279,8 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
  	bool reads, writes;
  	int data_dir;
 
+	lockdep_assert_held(&dd->lock);
+
  	if (!list_empty(&dd->dispatch)) {
  		rq = list_first_entry(&dd->dispatch, struct request, queuelist);
  		list_del_init(&rq->queuelist);

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

Quoted 8 lines
block/mq-deadline.c +2 -0
@@ -501,6 +503,8 @@ static void dd_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
  	struct deadline_data *dd = q->elevator->elevator_data;
  	const int data_dir = rq_data_dir(rq);
 
+	lockdep_assert_held(&dd->lock);
+
  	/*
  	 * This may be a requeue of a write request that has locked its
  	 * target zone. If it is the case, this releases the zone lock.
Signature · 1 line
Himanshu Madhani                                Oracle Linux Engineering
#13 lore raw

PATCH 3/9 block/mq-deadline: Remove two local variables

In reply to Bart Van Assche

Make __dd_dispatch_request() easier to read by removing two local variables.

Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/mq-deadline.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
block/mq-deadline.c +2 -6
index 4da0bd3b9827..cc9d0fc72db2 100644
@@ -276,7 +276,6 @@ deadline_next_request(struct deadline_data *dd, int data_dir)
 static struct request *__dd_dispatch_request(struct deadline_data *dd)
 {
 	struct request *rq, *next_rq;
-	bool reads, writes;
 	int data_dir;
 
 	lockdep_assert_held(&dd->lock);
@@ -287,9 +286,6 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
 		goto done;
 	}
 
-	reads = !list_empty(&dd->fifo_list[READ]);
-	writes = !list_empty(&dd->fifo_list[WRITE]);
-
 	/*
 	 * batches are currently reads XOR writes
 	 */
@@ -306,7 +302,7 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
 	 * data direction (read / write)
 	 */
 
-	if (reads) {
+	if (!list_empty(&dd->fifo_list[READ])) {
 		BUG_ON(RB_EMPTY_ROOT(&dd->sort_list[READ]));
 
 		if (deadline_fifo_request(dd, WRITE) &&
@@ -322,7 +318,7 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
 	 * there are either no reads or writes have been starved
 	 */
 
-	if (writes) {
+	if (!list_empty(&dd->fifo_list[WRITE])) {
 dispatch_writes:
 		BUG_ON(RB_EMPTY_ROOT(&dd->sort_list[WRITE]));
 
Reviewed-by on v1 3/9
#15 lore raw

Re: [PATCH 3/9] block/mq-deadline: Remove two local variables

In reply to Bart Van Assche
Quoted 44 lines · Bart Van Assche

Make __dd_dispatch_request() easier to read by removing two local variables.

Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/mq-deadline.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
block/mq-deadline.c +1 -5
index 4da0bd3b9827..cc9d0fc72db2 100644
@@ -276,7 +276,6 @@ deadline_next_request(struct deadline_data *dd, int data_dir)
 static struct request *__dd_dispatch_request(struct deadline_data *dd)
 {
 	struct request *rq, *next_rq;
-	bool reads, writes;
 	int data_dir;
 
 	lockdep_assert_held(&dd->lock);
@@ -287,9 +286,6 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
 		goto done;
 	}
 
-	reads = !list_empty(&dd->fifo_list[READ]);
-	writes = !list_empty(&dd->fifo_list[WRITE]);
-
 	/*
 	 * batches are currently reads XOR writes
 	 */
@@ -306,7 +302,7 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
 	 * data direction (read / write)
 	 */
 
-	if (reads) {
+	if (!list_empty(&dd->fifo_list[READ])) {
 		BUG_ON(RB_EMPTY_ROOT(&dd->sort_list[READ]));
 
 		if (deadline_fifo_request(dd, WRITE) &&

block/mq-deadline.c static struct request *__dd_dispatch_request(struct deadline_data *dd) · line 324

Quoted 8 lines
block/mq-deadline.c +1 -1
@@ -322,7 +318,7 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
 	 * there are either no reads or writes have been starved
 	 */
 
-	if (writes) {
+	if (!list_empty(&dd->fifo_list[WRITE])) {
 dispatch_writes:
 		BUG_ON(RB_EMPTY_ROOT(&dd->sort_list[WRITE]));
 
Signature · 2 lines
Damien Le Moal
Western Digital Research
Reviewed-by on v1 3/9
#16 lore raw

Re: [PATCH 3/9] block/mq-deadline: Remove two local variables

In reply to Bart Van Assche
Quoted 11 lines · Bart Van Assche

Make __dd_dispatch_request() easier to read by removing two local variables.

Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/mq-deadline.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke		        Kernel Storage Architect
[email protected]			               +49 911 74053 688
SUSE Software Solutions Germany GmbH, 90409 Nürnberg
GF: F. Imendörffer, HRB 36809 (AG Nürnberg)
Reviewed-by on v1 3/9
#18 lore raw

Re: [PATCH 3/9] block/mq-deadline: Remove two local variables

In reply to Bart Van Assche
Quoted 44 lines · Bart Van Assche

Make __dd_dispatch_request() easier to read by removing two local variables.

Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
  block/mq-deadline.c | 8 ++------
  1 file changed, 2 insertions(+), 6 deletions(-)
block/mq-deadline.c +1 -5
index 4da0bd3b9827..cc9d0fc72db2 100644
@@ -276,7 +276,6 @@ deadline_next_request(struct deadline_data *dd, int data_dir)
  static struct request *__dd_dispatch_request(struct deadline_data *dd)
  {
  	struct request *rq, *next_rq;
-	bool reads, writes;
  	int data_dir;
 
  	lockdep_assert_held(&dd->lock);
@@ -287,9 +286,6 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
  		goto done;
  	}
 
-	reads = !list_empty(&dd->fifo_list[READ]);
-	writes = !list_empty(&dd->fifo_list[WRITE]);
-
  	/*
  	 * batches are currently reads XOR writes
  	 */
@@ -306,7 +302,7 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
  	 * data direction (read / write)
  	 */
 
-	if (reads) {
+	if (!list_empty(&dd->fifo_list[READ])) {
  		BUG_ON(RB_EMPTY_ROOT(&dd->sort_list[READ]));
 
  		if (deadline_fifo_request(dd, WRITE) &&

block/mq-deadline.c static struct request *__dd_dispatch_request(struct deadline_data *dd) · line 324

Quoted 8 lines
block/mq-deadline.c +1 -1
@@ -322,7 +318,7 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
  	 * there are either no reads or writes have been starved
  	 */
 
-	if (writes) {
+	if (!list_empty(&dd->fifo_list[WRITE])) {
  dispatch_writes:
  		BUG_ON(RB_EMPTY_ROOT(&dd->sort_list[WRITE]));
 
Signature · 1 line
Himanshu Madhani                                Oracle Linux Engineering
#19 lore raw

PATCH 4/9 block/mq-deadline: Rename dd_init_queue() and dd_exit_queue()

In reply to Bart Van Assche

Change "queue" into "sched" to make the function names reflect better the purpose of these functions.

Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/mq-deadline.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
block/mq-deadline.c +4 -4
index cc9d0fc72db2..c4f51e7884fb 100644
@@ -395,7 +395,7 @@ static struct request *dd_dispatch_request(struct blk_mq_hw_ctx *hctx)
 	return rq;
 }
 
-static void dd_exit_queue(struct elevator_queue *e)
+static void dd_exit_sched(struct elevator_queue *e)
 {
 	struct deadline_data *dd = e->elevator_data;
 
@@ -408,7 +408,7 @@ static void dd_exit_queue(struct elevator_queue *e)
 /*
  * initialize elevator private data (deadline_data).
  */
-static int dd_init_queue(struct request_queue *q, struct elevator_type *e)
+static int dd_init_sched(struct request_queue *q, struct elevator_type *e)
 {
 	struct deadline_data *dd;
 	struct elevator_queue *eq;
@@ -800,8 +800,8 @@ static struct elevator_type mq_deadline = {
 		.requests_merged	= dd_merged_requests,
 		.request_merged		= dd_request_merged,
 		.has_work		= dd_has_work,
-		.init_sched		= dd_init_queue,
-		.exit_sched		= dd_exit_queue,
+		.init_sched		= dd_init_sched,
+		.exit_sched		= dd_exit_sched,
 	},
 
 #ifdef CONFIG_BLK_DEBUG_FS
Reviewed-by on v1 4/9
#20 lore raw

Re: [PATCH 4/9] block/mq-deadline: Rename dd_init_queue() and dd_exit_queue()

Quoted 7 lines · Bart Van Assche

Change "queue" into "sched" to make the function names reflect better the purpose of these functions.

Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>

Looks good.

Reviewed-by on v1 4/9
#21 lore raw

Re: [PATCH 4/9] block/mq-deadline: Rename dd_init_queue() and dd_exit_queue()

In reply to Bart Van Assche
Quoted 2 lines · Bart Van Assche

Change "queue" into "sched" to make the function names reflect better the purpose of these functions.

Nit: may be change this to:

Change "queue" into "sched" to make the function names match the elevator type operation names.

Quoted 33 lines
Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/mq-deadline.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
block/mq-deadline.c +2 -2
index cc9d0fc72db2..c4f51e7884fb 100644
@@ -395,7 +395,7 @@ static struct request *dd_dispatch_request(struct blk_mq_hw_ctx *hctx)
 	return rq;
 }
 
-static void dd_exit_queue(struct elevator_queue *e)
+static void dd_exit_sched(struct elevator_queue *e)
 {
 	struct deadline_data *dd = e->elevator_data;
 
@@ -408,7 +408,7 @@ static void dd_exit_queue(struct elevator_queue *e)
 /*
  * initialize elevator private data (deadline_data).
  */
-static int dd_init_queue(struct request_queue *q, struct elevator_type *e)
+static int dd_init_sched(struct request_queue *q, struct elevator_type *e)
 {
 	struct deadline_data *dd;
 	struct elevator_queue *eq;

block/mq-deadline.c static struct elevator_type mq_deadline = { · line 807

Quoted 10 lines
block/mq-deadline.c +2 -2
@@ -800,8 +800,8 @@ static struct elevator_type mq_deadline = {
 		.requests_merged	= dd_merged_requests,
 		.request_merged		= dd_request_merged,
 		.has_work		= dd_has_work,
-		.init_sched		= dd_init_queue,
-		.exit_sched		= dd_exit_queue,
+		.init_sched		= dd_init_sched,
+		.exit_sched		= dd_exit_sched,
 	},
 
 #ifdef CONFIG_BLK_DEBUG_FS
Signature · 2 lines
Damien Le Moal
Western Digital Research
#22 lore raw

Re: [PATCH 4/9] block/mq-deadline: Rename dd_init_queue() and dd_exit_queue()

Quoted 8 lines · Damien Le Moal
Quoted 2 lines · Bart Van Assche

Change "queue" into "sched" to make the function names reflect better the purpose of these functions.

Nit: may be change this to:

Change "queue" into "sched" to make the function names match the elevator type operation names.

Hi Damien,

The functions dd_init_sched() and dd_exit_sched() initialize a scheduler data structure. To me the names dd_init_queue() / dd_exit_queue() suggest that something in the request queue is initialized which is not the case. Is sufficient as clarification or do you still want me to change the patch description?

Thanks,

Bart.

Reviewed-by on v1 4/9
#23 lore raw

Re: [PATCH 4/9] block/mq-deadline: Rename dd_init_queue() and dd_exit_queue()

In reply to Bart Van Assche
Quoted 11 lines · Bart Van Assche

Change "queue" into "sched" to make the function names reflect better the purpose of these functions.

Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/mq-deadline.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke		        Kernel Storage Architect
[email protected]			               +49 911 74053 688
SUSE Software Solutions Germany GmbH, 90409 Nürnberg
GF: F. Imendörffer, HRB 36809 (AG Nürnberg)
Reviewed-by on v1 4/9
#25 lore raw

Re: [PATCH 4/9] block/mq-deadline: Rename dd_init_queue() and dd_exit_queue()

In reply to Bart Van Assche
Quoted 35 lines · Bart Van Assche

Change "queue" into "sched" to make the function names reflect better the purpose of these functions.

Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
  block/mq-deadline.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
block/mq-deadline.c +2 -2
index cc9d0fc72db2..c4f51e7884fb 100644
@@ -395,7 +395,7 @@ static struct request *dd_dispatch_request(struct blk_mq_hw_ctx *hctx)
  	return rq;
  }
 
-static void dd_exit_queue(struct elevator_queue *e)
+static void dd_exit_sched(struct elevator_queue *e)
  {
  	struct deadline_data *dd = e->elevator_data;
 
@@ -408,7 +408,7 @@ static void dd_exit_queue(struct elevator_queue *e)
  /*
   * initialize elevator private data (deadline_data).
   */
-static int dd_init_queue(struct request_queue *q, struct elevator_type *e)
+static int dd_init_sched(struct request_queue *q, struct elevator_type *e)
  {
  	struct deadline_data *dd;
  	struct elevator_queue *eq;

block/mq-deadline.c static struct elevator_type mq_deadline = { · line 807

Quoted 10 lines
block/mq-deadline.c +2 -2
@@ -800,8 +800,8 @@ static struct elevator_type mq_deadline = {
  		.requests_merged	= dd_merged_requests,
  		.request_merged		= dd_request_merged,
  		.has_work		= dd_has_work,
-		.init_sched		= dd_init_queue,
-		.exit_sched		= dd_exit_queue,
+		.init_sched		= dd_init_sched,
+		.exit_sched		= dd_exit_sched,
  	},
 
  #ifdef CONFIG_BLK_DEBUG_FS
Signature · 1 line
Himanshu Madhani                                Oracle Linux Engineering
#26 lore raw

PATCH 5/9 block/mq-deadline: Improve compile-time argument checking

In reply to Bart Van Assche

Modern compilers complain if an out-of-range value is passed to a function argument that has an enumeration type. Let the compiler detect out-of-range data direction arguments instead of verifying the data_dir argument at runtime.

Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/mq-deadline.c | 96 +++++++++++++++++++++++----------------------
 1 file changed, 49 insertions(+), 47 deletions(-)
block/mq-deadline.c +49 -47
index c4f51e7884fb..dfbc6b77fa71 100644
@@ -35,6 +35,13 @@ static const int writes_starved = 2;    /* max times reads can starve a write */
 static const int fifo_batch = 16;       /* # of sequential requests treated as one
 				     by the above parameters. For throughput. */
 
+enum dd_data_dir {
+	DD_READ		= READ,
+	DD_WRITE	= WRITE,
+} __packed;
+
+enum { DD_DIR_COUNT = 2 };
+
 struct deadline_data {
 	/*
 	 * run time data
@@ -43,20 +50,20 @@ struct deadline_data {
 	/*
 	 * requests (deadline_rq s) are present on both sort_list and fifo_list
 	 */
-	struct rb_root sort_list[2];
-	struct list_head fifo_list[2];
+	struct rb_root sort_list[DD_DIR_COUNT];
+	struct list_head fifo_list[DD_DIR_COUNT];
 
 	/*
 	 * next in sort order. read, write or both are NULL
 	 */
-	struct request *next_rq[2];
+	struct request *next_rq[DD_DIR_COUNT];
 	unsigned int batching;		/* number of sequential requests made */
 	unsigned int starved;		/* times reads have starved writes */
 
 	/*
 	 * settings that change how the i/o scheduler behaves
 	 */
-	int fifo_expire[2];
+	int fifo_expire[DD_DIR_COUNT];
 	int fifo_batch;
 	int writes_starved;
 	int front_merges;
@@ -97,7 +104,7 @@ deadline_add_rq_rb(struct deadline_data *dd, struct request *rq)
 static inline void
 deadline_del_rq_rb(struct deadline_data *dd, struct request *rq)
 {
-	const int data_dir = rq_data_dir(rq);
+	const enum dd_data_dir data_dir = rq_data_dir(rq);
 
 	if (dd->next_rq[data_dir] == rq)
 		dd->next_rq[data_dir] = deadline_latter_request(rq);
@@ -169,10 +176,10 @@ static void dd_merged_requests(struct request_queue *q, struct request *req,
 static void
 deadline_move_request(struct deadline_data *dd, struct request *rq)
 {
-	const int data_dir = rq_data_dir(rq);
+	const enum dd_data_dir data_dir = rq_data_dir(rq);
 
-	dd->next_rq[READ] = NULL;
-	dd->next_rq[WRITE] = NULL;
+	dd->next_rq[DD_READ] = NULL;
+	dd->next_rq[DD_WRITE] = NULL;
 	dd->next_rq[data_dir] = deadline_latter_request(rq);
 
 	/*
@@ -185,9 +192,10 @@ deadline_move_request(struct deadline_data *dd, struct request *rq)
  * deadline_check_fifo returns 0 if there are no expired requests on the fifo,
  * 1 otherwise. Requires !list_empty(&dd->fifo_list[data_dir])
  */
-static inline int deadline_check_fifo(struct deadline_data *dd, int ddir)
+static inline int deadline_check_fifo(struct deadline_data *dd,
+				      enum dd_data_dir data_dir)
 {
-	struct request *rq = rq_entry_fifo(dd->fifo_list[ddir].next);
+	struct request *rq = rq_entry_fifo(dd->fifo_list[data_dir].next);
 
 	/*
 	 * rq is expired!
@@ -203,19 +211,16 @@ static inline int deadline_check_fifo(struct deadline_data *dd, int ddir)
  * dispatch using arrival ordered lists.
  */
 static struct request *
-deadline_fifo_request(struct deadline_data *dd, int data_dir)
+deadline_fifo_request(struct deadline_data *dd, enum dd_data_dir data_dir)
 {
 	struct request *rq;
 	unsigned long flags;
 
-	if (WARN_ON_ONCE(data_dir != READ && data_dir != WRITE))
-		return NULL;
-
 	if (list_empty(&dd->fifo_list[data_dir]))
 		return NULL;
 
 	rq = rq_entry_fifo(dd->fifo_list[data_dir].next);
-	if (data_dir == READ || !blk_queue_is_zoned(rq->q))
+	if (data_dir == DD_READ || !blk_queue_is_zoned(rq->q))
 		return rq;
 
 	/*
@@ -223,7 +228,7 @@ deadline_fifo_request(struct deadline_data *dd, int data_dir)
 	 * an unlocked target zone.
 	 */
 	spin_lock_irqsave(&dd->zone_lock, flags);
-	list_for_each_entry(rq, &dd->fifo_list[WRITE], queuelist) {
+	list_for_each_entry(rq, &dd->fifo_list[DD_WRITE], queuelist) {
 		if (blk_req_can_dispatch_to_zone(rq))
 			goto out;
 	}
@@ -239,19 +244,16 @@ deadline_fifo_request(struct deadline_data *dd, int data_dir)
  * dispatch using sector position sorted lists.
  */
 static struct request *
-deadline_next_request(struct deadline_data *dd, int data_dir)
+deadline_next_request(struct deadline_data *dd, enum dd_data_dir data_dir)
 {
 	struct request *rq;
 	unsigned long flags;
 
-	if (WARN_ON_ONCE(data_dir != READ && data_dir != WRITE))
-		return NULL;
-
 	rq = dd->next_rq[data_dir];
 	if (!rq)
 		return NULL;
 
-	if (data_dir == READ || !blk_queue_is_zoned(rq->q))
+	if (data_dir == DD_READ || !blk_queue_is_zoned(rq->q))
 		return rq;
 
 	/*
@@ -276,7 +278,7 @@ deadline_next_request(struct deadline_data *dd, int data_dir)
 static struct request *__dd_dispatch_request(struct deadline_data *dd)
 {
 	struct request *rq, *next_rq;
-	int data_dir;
+	enum dd_data_dir data_dir;
 
 	lockdep_assert_held(&dd->lock);
 
@@ -289,9 +291,9 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
 	/*
 	 * batches are currently reads XOR writes
 	 */
-	rq = deadline_next_request(dd, WRITE);
+	rq = deadline_next_request(dd, DD_WRITE);
 	if (!rq)
-		rq = deadline_next_request(dd, READ);
+		rq = deadline_next_request(dd, DD_READ);
 
 	if (rq && dd->batching < dd->fifo_batch)
 		/* we have a next request are still entitled to batch */
@@ -302,14 +304,14 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
 	 * data direction (read / write)
 	 */
 
-	if (!list_empty(&dd->fifo_list[READ])) {
-		BUG_ON(RB_EMPTY_ROOT(&dd->sort_list[READ]));
+	if (!list_empty(&dd->fifo_list[DD_READ])) {
+		BUG_ON(RB_EMPTY_ROOT(&dd->sort_list[DD_READ]));
 
-		if (deadline_fifo_request(dd, WRITE) &&
+		if (deadline_fifo_request(dd, DD_WRITE) &&
 		    (dd->starved++ >= dd->writes_starved))
 			goto dispatch_writes;
 
-		data_dir = READ;
+		data_dir = DD_READ;
 
 		goto dispatch_find_request;
 	}
@@ -318,13 +320,13 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
 	 * there are either no reads or writes have been starved
 	 */
 
-	if (!list_empty(&dd->fifo_list[WRITE])) {
+	if (!list_empty(&dd->fifo_list[DD_WRITE])) {
 dispatch_writes:
-		BUG_ON(RB_EMPTY_ROOT(&dd->sort_list[WRITE]));
+		BUG_ON(RB_EMPTY_ROOT(&dd->sort_list[DD_WRITE]));
 
 		dd->starved = 0;
 
-		data_dir = WRITE;
+		data_dir = DD_WRITE;
 
 		goto dispatch_find_request;
 	}
@@ -399,8 +401,8 @@ static void dd_exit_sched(struct elevator_queue *e)
 {
 	struct deadline_data *dd = e->elevator_data;
 
-	BUG_ON(!list_empty(&dd->fifo_list[READ]));
-	BUG_ON(!list_empty(&dd->fifo_list[WRITE]));
+	BUG_ON(!list_empty(&dd->fifo_list[DD_READ]));
+	BUG_ON(!list_empty(&dd->fifo_list[DD_WRITE]));
 
 	kfree(dd);
 }
@@ -424,12 +426,12 @@ static int dd_init_sched(struct request_queue *q, struct elevator_type *e)
 	}
 	eq->elevator_data = dd;
 
-	INIT_LIST_HEAD(&dd->fifo_list[READ]);
-	INIT_LIST_HEAD(&dd->fifo_list[WRITE]);
-	dd->sort_list[READ] = RB_ROOT;
-	dd->sort_list[WRITE] = RB_ROOT;
-	dd->fifo_expire[READ] = read_expire;
-	dd->fifo_expire[WRITE] = write_expire;
+	INIT_LIST_HEAD(&dd->fifo_list[DD_READ]);
+	INIT_LIST_HEAD(&dd->fifo_list[DD_WRITE]);
+	dd->sort_list[DD_READ] = RB_ROOT;
+	dd->sort_list[DD_WRITE] = RB_ROOT;
+	dd->fifo_expire[DD_READ] = read_expire;
+	dd->fifo_expire[DD_WRITE] = write_expire;
 	dd->writes_starved = writes_starved;
 	dd->front_merges = 1;
 	dd->fifo_batch = fifo_batch;
@@ -497,7 +499,7 @@ static void dd_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
 {
 	struct request_queue *q = hctx->queue;
 	struct deadline_data *dd = q->elevator->elevator_data;
-	const int data_dir = rq_data_dir(rq);
+	const enum dd_data_dir data_dir = rq_data_dir(rq);
 
 	lockdep_assert_held(&dd->lock);
 
@@ -585,7 +587,7 @@ static void dd_finish_request(struct request *rq)
 
 		spin_lock_irqsave(&dd->zone_lock, flags);
 		blk_req_zone_write_unlock(rq);
-		if (!list_empty(&dd->fifo_list[WRITE]))
+		if (!list_empty(&dd->fifo_list[DD_WRITE]))
 			blk_mq_sched_mark_restart_hctx(rq->mq_hctx);
 		spin_unlock_irqrestore(&dd->zone_lock, flags);
 	}
@@ -626,8 +628,8 @@ static ssize_t __FUNC(struct elevator_queue *e, char *page)		\
 		__data = jiffies_to_msecs(__data);			\
 	return deadline_var_show(__data, (page));			\
 }
-SHOW_FUNCTION(deadline_read_expire_show, dd->fifo_expire[READ], 1);
-SHOW_FUNCTION(deadline_write_expire_show, dd->fifo_expire[WRITE], 1);
+SHOW_FUNCTION(deadline_read_expire_show, dd->fifo_expire[DD_READ], 1);
+SHOW_FUNCTION(deadline_write_expire_show, dd->fifo_expire[DD_WRITE], 1);
 SHOW_FUNCTION(deadline_writes_starved_show, dd->writes_starved, 0);
 SHOW_FUNCTION(deadline_front_merges_show, dd->front_merges, 0);
 SHOW_FUNCTION(deadline_fifo_batch_show, dd->fifo_batch, 0);
@@ -649,8 +651,8 @@ static ssize_t __FUNC(struct elevator_queue *e, const char *page, size_t count)
 		*(__PTR) = __data;					\
 	return count;							\
 }
-STORE_FUNCTION(deadline_read_expire_store, &dd->fifo_expire[READ], 0, INT_MAX, 1);
-STORE_FUNCTION(deadline_write_expire_store, &dd->fifo_expire[WRITE], 0, INT_MAX, 1);
+STORE_FUNCTION(deadline_read_expire_store, &dd->fifo_expire[DD_READ], 0, INT_MAX, 1);
+STORE_FUNCTION(deadline_write_expire_store, &dd->fifo_expire[DD_WRITE], 0, INT_MAX, 1);
 STORE_FUNCTION(deadline_writes_starved_store, &dd->writes_starved, INT_MIN, INT_MAX, 0);
 STORE_FUNCTION(deadline_front_merges_store, &dd->front_merges, 0, 1, 0);
 STORE_FUNCTION(deadline_fifo_batch_store, &dd->fifo_batch, 0, INT_MAX, 0);
@@ -717,8 +719,8 @@ static int deadline_##name##_next_rq_show(void *data,			\
 		__blk_mq_debugfs_rq_show(m, rq);			\
 	return 0;							\
 }
-DEADLINE_DEBUGFS_DDIR_ATTRS(READ, read)
-DEADLINE_DEBUGFS_DDIR_ATTRS(WRITE, write)
+DEADLINE_DEBUGFS_DDIR_ATTRS(DD_READ, read)
+DEADLINE_DEBUGFS_DDIR_ATTRS(DD_WRITE, write)
 #undef DEADLINE_DEBUGFS_DDIR_ATTRS
 
 static int deadline_batching_show(void *data, struct seq_file *m)
Reviewed-by on v1 5/9
#27 lore raw

Re: [PATCH 5/9] block/mq-deadline: Improve compile-time argument checking

Quoted 9 lines · Bart Van Assche

Modern compilers complain if an out-of-range value is passed to a function argument that has an enumeration type. Let the compiler detect out-of-range data direction arguments instead of verifying the data_dir argument at runtime.

Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>

Looks good.

#28 lore raw

Re: [PATCH 5/9] block/mq-deadline: Improve compile-time argument checking

In reply to Bart Van Assche
Quoted 18 lines · Bart Van Assche

Modern compilers complain if an out-of-range value is passed to a function argument that has an enumeration type. Let the compiler detect out-of-range data direction arguments instead of verifying the data_dir argument at runtime.

Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/mq-deadline.c | 96 +++++++++++++++++++++++----------------------
 1 file changed, 49 insertions(+), 47 deletions(-)
block/mq-deadline.c +0 -0
index c4f51e7884fb..dfbc6b77fa71 100644

block/mq-deadline.c static const int writes_starved = 2; /* max times reads can starve a write */ · line 41

Quoted 7 lines
block/mq-deadline.c +4 -0
@@ -35,6 +35,13 @@ static const int writes_starved = 2;    /* max times reads can starve a write */
 static const int fifo_batch = 16;       /* # of sequential requests treated as one
 				     by the above parameters. For throughput. */
 
+enum dd_data_dir {
+	DD_READ		= READ,
+	DD_WRITE	= WRITE,
+} __packed;

Why the "__packed" here ?

block/mq-deadline.c static const int writes_starved = 2; /* max times reads can starve a write */ · line 43

Quoted 2 lines
block/mq-deadline.c +2 -0
+
+enum { DD_DIR_COUNT = 2 };

Why not a simple #define for this one ?

Quoted 256 lines
block/mq-deadline.c +43 -47
+
 struct deadline_data {
 	/*
 	 * run time data
@@ -43,20 +50,20 @@ struct deadline_data {
 	/*
 	 * requests (deadline_rq s) are present on both sort_list and fifo_list
 	 */
-	struct rb_root sort_list[2];
-	struct list_head fifo_list[2];
+	struct rb_root sort_list[DD_DIR_COUNT];
+	struct list_head fifo_list[DD_DIR_COUNT];
 
 	/*
 	 * next in sort order. read, write or both are NULL
 	 */
-	struct request *next_rq[2];
+	struct request *next_rq[DD_DIR_COUNT];
 	unsigned int batching;		/* number of sequential requests made */
 	unsigned int starved;		/* times reads have starved writes */
 
 	/*
 	 * settings that change how the i/o scheduler behaves
 	 */
-	int fifo_expire[2];
+	int fifo_expire[DD_DIR_COUNT];
 	int fifo_batch;
 	int writes_starved;
 	int front_merges;
@@ -97,7 +104,7 @@ deadline_add_rq_rb(struct deadline_data *dd, struct request *rq)
 static inline void
 deadline_del_rq_rb(struct deadline_data *dd, struct request *rq)
 {
-	const int data_dir = rq_data_dir(rq);
+	const enum dd_data_dir data_dir = rq_data_dir(rq);
 
 	if (dd->next_rq[data_dir] == rq)
 		dd->next_rq[data_dir] = deadline_latter_request(rq);
@@ -169,10 +176,10 @@ static void dd_merged_requests(struct request_queue *q, struct request *req,
 static void
 deadline_move_request(struct deadline_data *dd, struct request *rq)
 {
-	const int data_dir = rq_data_dir(rq);
+	const enum dd_data_dir data_dir = rq_data_dir(rq);
 
-	dd->next_rq[READ] = NULL;
-	dd->next_rq[WRITE] = NULL;
+	dd->next_rq[DD_READ] = NULL;
+	dd->next_rq[DD_WRITE] = NULL;
 	dd->next_rq[data_dir] = deadline_latter_request(rq);
 
 	/*
@@ -185,9 +192,10 @@ deadline_move_request(struct deadline_data *dd, struct request *rq)
  * deadline_check_fifo returns 0 if there are no expired requests on the fifo,
  * 1 otherwise. Requires !list_empty(&dd->fifo_list[data_dir])
  */
-static inline int deadline_check_fifo(struct deadline_data *dd, int ddir)
+static inline int deadline_check_fifo(struct deadline_data *dd,
+				      enum dd_data_dir data_dir)
 {
-	struct request *rq = rq_entry_fifo(dd->fifo_list[ddir].next);
+	struct request *rq = rq_entry_fifo(dd->fifo_list[data_dir].next);
 
 	/*
 	 * rq is expired!
@@ -203,19 +211,16 @@ static inline int deadline_check_fifo(struct deadline_data *dd, int ddir)
  * dispatch using arrival ordered lists.
  */
 static struct request *
-deadline_fifo_request(struct deadline_data *dd, int data_dir)
+deadline_fifo_request(struct deadline_data *dd, enum dd_data_dir data_dir)
 {
 	struct request *rq;
 	unsigned long flags;
 
-	if (WARN_ON_ONCE(data_dir != READ && data_dir != WRITE))
-		return NULL;
-
 	if (list_empty(&dd->fifo_list[data_dir]))
 		return NULL;
 
 	rq = rq_entry_fifo(dd->fifo_list[data_dir].next);
-	if (data_dir == READ || !blk_queue_is_zoned(rq->q))
+	if (data_dir == DD_READ || !blk_queue_is_zoned(rq->q))
 		return rq;
 
 	/*
@@ -223,7 +228,7 @@ deadline_fifo_request(struct deadline_data *dd, int data_dir)
 	 * an unlocked target zone.
 	 */
 	spin_lock_irqsave(&dd->zone_lock, flags);
-	list_for_each_entry(rq, &dd->fifo_list[WRITE], queuelist) {
+	list_for_each_entry(rq, &dd->fifo_list[DD_WRITE], queuelist) {
 		if (blk_req_can_dispatch_to_zone(rq))
 			goto out;
 	}
@@ -239,19 +244,16 @@ deadline_fifo_request(struct deadline_data *dd, int data_dir)
  * dispatch using sector position sorted lists.
  */
 static struct request *
-deadline_next_request(struct deadline_data *dd, int data_dir)
+deadline_next_request(struct deadline_data *dd, enum dd_data_dir data_dir)
 {
 	struct request *rq;
 	unsigned long flags;
 
-	if (WARN_ON_ONCE(data_dir != READ && data_dir != WRITE))
-		return NULL;
-
 	rq = dd->next_rq[data_dir];
 	if (!rq)
 		return NULL;
 
-	if (data_dir == READ || !blk_queue_is_zoned(rq->q))
+	if (data_dir == DD_READ || !blk_queue_is_zoned(rq->q))
 		return rq;
 
 	/*
@@ -276,7 +278,7 @@ deadline_next_request(struct deadline_data *dd, int data_dir)
 static struct request *__dd_dispatch_request(struct deadline_data *dd)
 {
 	struct request *rq, *next_rq;
-	int data_dir;
+	enum dd_data_dir data_dir;
 
 	lockdep_assert_held(&dd->lock);
 
@@ -289,9 +291,9 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
 	/*
 	 * batches are currently reads XOR writes
 	 */
-	rq = deadline_next_request(dd, WRITE);
+	rq = deadline_next_request(dd, DD_WRITE);
 	if (!rq)
-		rq = deadline_next_request(dd, READ);
+		rq = deadline_next_request(dd, DD_READ);
 
 	if (rq && dd->batching < dd->fifo_batch)
 		/* we have a next request are still entitled to batch */
@@ -302,14 +304,14 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
 	 * data direction (read / write)
 	 */
 
-	if (!list_empty(&dd->fifo_list[READ])) {
-		BUG_ON(RB_EMPTY_ROOT(&dd->sort_list[READ]));
+	if (!list_empty(&dd->fifo_list[DD_READ])) {
+		BUG_ON(RB_EMPTY_ROOT(&dd->sort_list[DD_READ]));
 
-		if (deadline_fifo_request(dd, WRITE) &&
+		if (deadline_fifo_request(dd, DD_WRITE) &&
 		    (dd->starved++ >= dd->writes_starved))
 			goto dispatch_writes;
 
-		data_dir = READ;
+		data_dir = DD_READ;
 
 		goto dispatch_find_request;
 	}
@@ -318,13 +320,13 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
 	 * there are either no reads or writes have been starved
 	 */
 
-	if (!list_empty(&dd->fifo_list[WRITE])) {
+	if (!list_empty(&dd->fifo_list[DD_WRITE])) {
 dispatch_writes:
-		BUG_ON(RB_EMPTY_ROOT(&dd->sort_list[WRITE]));
+		BUG_ON(RB_EMPTY_ROOT(&dd->sort_list[DD_WRITE]));
 
 		dd->starved = 0;
 
-		data_dir = WRITE;
+		data_dir = DD_WRITE;
 
 		goto dispatch_find_request;
 	}
@@ -399,8 +401,8 @@ static void dd_exit_sched(struct elevator_queue *e)
 {
 	struct deadline_data *dd = e->elevator_data;
 
-	BUG_ON(!list_empty(&dd->fifo_list[READ]));
-	BUG_ON(!list_empty(&dd->fifo_list[WRITE]));
+	BUG_ON(!list_empty(&dd->fifo_list[DD_READ]));
+	BUG_ON(!list_empty(&dd->fifo_list[DD_WRITE]));
 
 	kfree(dd);
 }
@@ -424,12 +426,12 @@ static int dd_init_sched(struct request_queue *q, struct elevator_type *e)
 	}
 	eq->elevator_data = dd;
 
-	INIT_LIST_HEAD(&dd->fifo_list[READ]);
-	INIT_LIST_HEAD(&dd->fifo_list[WRITE]);
-	dd->sort_list[READ] = RB_ROOT;
-	dd->sort_list[WRITE] = RB_ROOT;
-	dd->fifo_expire[READ] = read_expire;
-	dd->fifo_expire[WRITE] = write_expire;
+	INIT_LIST_HEAD(&dd->fifo_list[DD_READ]);
+	INIT_LIST_HEAD(&dd->fifo_list[DD_WRITE]);
+	dd->sort_list[DD_READ] = RB_ROOT;
+	dd->sort_list[DD_WRITE] = RB_ROOT;
+	dd->fifo_expire[DD_READ] = read_expire;
+	dd->fifo_expire[DD_WRITE] = write_expire;
 	dd->writes_starved = writes_starved;
 	dd->front_merges = 1;
 	dd->fifo_batch = fifo_batch;
@@ -497,7 +499,7 @@ static void dd_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
 {
 	struct request_queue *q = hctx->queue;
 	struct deadline_data *dd = q->elevator->elevator_data;
-	const int data_dir = rq_data_dir(rq);
+	const enum dd_data_dir data_dir = rq_data_dir(rq);>
 	lockdep_assert_held(&dd->lock);
 
@@ -585,7 +587,7 @@ static void dd_finish_request(struct request *rq)
 
 		spin_lock_irqsave(&dd->zone_lock, flags);
 		blk_req_zone_write_unlock(rq);
-		if (!list_empty(&dd->fifo_list[WRITE]))
+		if (!list_empty(&dd->fifo_list[DD_WRITE]))
 			blk_mq_sched_mark_restart_hctx(rq->mq_hctx);
 		spin_unlock_irqrestore(&dd->zone_lock, flags);
 	}
@@ -626,8 +628,8 @@ static ssize_t __FUNC(struct elevator_queue *e, char *page)		\
 		__data = jiffies_to_msecs(__data);			\
 	return deadline_var_show(__data, (page));			\
 }
-SHOW_FUNCTION(deadline_read_expire_show, dd->fifo_expire[READ], 1);
-SHOW_FUNCTION(deadline_write_expire_show, dd->fifo_expire[WRITE], 1);
+SHOW_FUNCTION(deadline_read_expire_show, dd->fifo_expire[DD_READ], 1);
+SHOW_FUNCTION(deadline_write_expire_show, dd->fifo_expire[DD_WRITE], 1);
 SHOW_FUNCTION(deadline_writes_starved_show, dd->writes_starved, 0);
 SHOW_FUNCTION(deadline_front_merges_show, dd->front_merges, 0);
 SHOW_FUNCTION(deadline_fifo_batch_show, dd->fifo_batch, 0);
@@ -649,8 +651,8 @@ static ssize_t __FUNC(struct elevator_queue *e, const char *page, size_t count)
 		*(__PTR) = __data;					\
 	return count;							\
 }
-STORE_FUNCTION(deadline_read_expire_store, &dd->fifo_expire[READ], 0, INT_MAX, 1);
-STORE_FUNCTION(deadline_write_expire_store, &dd->fifo_expire[WRITE], 0, INT_MAX, 1);
+STORE_FUNCTION(deadline_read_expire_store, &dd->fifo_expire[DD_READ], 0, INT_MAX, 1);
+STORE_FUNCTION(deadline_write_expire_store, &dd->fifo_expire[DD_WRITE], 0, INT_MAX, 1);
 STORE_FUNCTION(deadline_writes_starved_store, &dd->writes_starved, INT_MIN, INT_MAX, 0);
 STORE_FUNCTION(deadline_front_merges_store, &dd->front_merges, 0, 1, 0);
 STORE_FUNCTION(deadline_fifo_batch_store, &dd->fifo_batch, 0, INT_MAX, 0);
@@ -717,8 +719,8 @@ static int deadline_##name##_next_rq_show(void *data,			\
 		__blk_mq_debugfs_rq_show(m, rq);			\
 	return 0;							\
 }
-DEADLINE_DEBUGFS_DDIR_ATTRS(READ, read)
-DEADLINE_DEBUGFS_DDIR_ATTRS(WRITE, write)
+DEADLINE_DEBUGFS_DDIR_ATTRS(DD_READ, read)
+DEADLINE_DEBUGFS_DDIR_ATTRS(DD_WRITE, write)
 #undef DEADLINE_DEBUGFS_DDIR_ATTRS
 
 static int deadline_batching_show(void *data, struct seq_file *m)
Signature · 2 lines
Damien Le Moal
Western Digital Research
#29 lore raw

Re: [PATCH 5/9] block/mq-deadline: Improve compile-time argument checking

Quoted 7 lines · Damien Le Moal

block/mq-deadline.c static const int writes_starved = 2; /* max times reads can starve a write */ · line 41

Quoted 4 lines · Bart Van Assche
block/mq-deadline.c +4 -0
+enum dd_data_dir {
+	DD_READ		= READ,
+	DD_WRITE	= WRITE,
+} __packed;

Why the "__packed" here ?

I agree that using __packed here does not have any advantage. I will leave it out.

Quoted 4 lines

block/mq-deadline.c static const int writes_starved = 2; /* max times reads can starve a write */ · line 43

Quoted 2 lines
block/mq-deadline.c +2 -0
+
+enum { DD_DIR_COUNT = 2 };

Why not a simple #define for this one ?

I only use the C preprocessor if there is no other solution. As far as I know there are no rules in the kernel coding style guidelines with regard whether to use a #define or an enum to define a constant?

Thanks,

Bart.

#30 lore raw

Re: [PATCH 5/9] block/mq-deadline: Improve compile-time argument checking

Quoted 12 lines · Bart Van Assche
Quoted 7 lines · Damien Le Moal

block/mq-deadline.c static const int writes_starved = 2; /* max times reads can starve a write */ · line 41

Quoted 4 lines · Bart Van Assche
block/mq-deadline.c +4 -0
+enum dd_data_dir {
+	DD_READ		= READ,
+	DD_WRITE	= WRITE,
+} __packed;

Why the "__packed" here ?

I agree that using __packed here does not have any advantage. I will leave it out.

Quoted 8 lines
Quoted 4 lines

block/mq-deadline.c static const int writes_starved = 2; /* max times reads can starve a write */ · line 43

Quoted 2 lines
block/mq-deadline.c +2 -0
+
+enum { DD_DIR_COUNT = 2 };

Why not a simple #define for this one ?

I only use the C preprocessor if there is no other solution. As far as I know there are no rules in the kernel coding style guidelines with regard whether to use a #define or an enum to define a constant?

It is fine as is. I just find it a little too verbose compared to a simple macro definition. Just a matter of taste I guess :)

Signature · 2 lines
Damien Le Moal
Western Digital Research
Reviewed-by on v1 5/9
#31 lore raw

Re: [PATCH 5/9] block/mq-deadline: Improve compile-time argument checking

In reply to Bart Van Assche
Quoted 5 lines · Bart Van Assche

Modern compilers complain if an out-of-range value is passed to a function argument that has an enumeration type. Let the compiler detect out-of-range data direction arguments instead of verifying the data_dir argument at runtime.

Quoted 8 lines
Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/mq-deadline.c | 96 +++++++++++++++++++++++----------------------
 1 file changed, 49 insertions(+), 47 deletions(-)

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke		        Kernel Storage Architect
[email protected]			               +49 911 74053 688
SUSE Software Solutions Germany GmbH, 90409 Nürnberg
GF: F. Imendörffer, HRB 36809 (AG Nürnberg)
Reviewed-by on v1 5/9
#32 lore raw

Re: [PATCH 5/9] block/mq-deadline: Improve compile-time argument checking

In reply to Bart Van Assche

block/mq-deadline.c static const int writes_starved = 2; /* max times reads can starve a write */ · line 41

Quoted 4 lines · Bart Van Assche
block/mq-deadline.c +4 -0
+enum dd_data_dir {
+	DD_READ		= READ,
+	DD_WRITE	= WRITE,
+} __packed;

I don't think packing the enum is of any value here.

Otherwise

Reviewed-by on v1 5/9
#33 lore raw

Re: [PATCH 5/9] block/mq-deadline: Improve compile-time argument checking

In reply to Bart Van Assche
Quoted 274 lines · Bart Van Assche

Modern compilers complain if an out-of-range value is passed to a function argument that has an enumeration type. Let the compiler detect out-of-range data direction arguments instead of verifying the data_dir argument at runtime.

Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
  block/mq-deadline.c | 96 +++++++++++++++++++++++----------------------
  1 file changed, 49 insertions(+), 47 deletions(-)
block/mq-deadline.c +47 -45
index c4f51e7884fb..dfbc6b77fa71 100644
@@ -35,6 +35,13 @@ static const int writes_starved = 2;    /* max times reads can starve a write */
  static const int fifo_batch = 16;       /* # of sequential requests treated as one
  				     by the above parameters. For throughput. */
 
+enum dd_data_dir {
+	DD_READ		= READ,
+	DD_WRITE	= WRITE,
+} __packed;
+
+enum { DD_DIR_COUNT = 2 };
+
  struct deadline_data {
  	/*
  	 * run time data
@@ -43,20 +50,20 @@ struct deadline_data {
  	/*
  	 * requests (deadline_rq s) are present on both sort_list and fifo_list
  	 */
-	struct rb_root sort_list[2];
-	struct list_head fifo_list[2];
+	struct rb_root sort_list[DD_DIR_COUNT];
+	struct list_head fifo_list[DD_DIR_COUNT];
 
  	/*
  	 * next in sort order. read, write or both are NULL
  	 */
-	struct request *next_rq[2];
+	struct request *next_rq[DD_DIR_COUNT];
  	unsigned int batching;		/* number of sequential requests made */
  	unsigned int starved;		/* times reads have starved writes */
 
  	/*
  	 * settings that change how the i/o scheduler behaves
  	 */
-	int fifo_expire[2];
+	int fifo_expire[DD_DIR_COUNT];
  	int fifo_batch;
  	int writes_starved;
  	int front_merges;
@@ -97,7 +104,7 @@ deadline_add_rq_rb(struct deadline_data *dd, struct request *rq)
  static inline void
  deadline_del_rq_rb(struct deadline_data *dd, struct request *rq)
  {
-	const int data_dir = rq_data_dir(rq);
+	const enum dd_data_dir data_dir = rq_data_dir(rq);
 
  	if (dd->next_rq[data_dir] == rq)
  		dd->next_rq[data_dir] = deadline_latter_request(rq);
@@ -169,10 +176,10 @@ static void dd_merged_requests(struct request_queue *q, struct request *req,
  static void
  deadline_move_request(struct deadline_data *dd, struct request *rq)
  {
-	const int data_dir = rq_data_dir(rq);
+	const enum dd_data_dir data_dir = rq_data_dir(rq);
 
-	dd->next_rq[READ] = NULL;
-	dd->next_rq[WRITE] = NULL;
+	dd->next_rq[DD_READ] = NULL;
+	dd->next_rq[DD_WRITE] = NULL;
  	dd->next_rq[data_dir] = deadline_latter_request(rq);
 
  	/*
@@ -185,9 +192,10 @@ deadline_move_request(struct deadline_data *dd, struct request *rq)
   * deadline_check_fifo returns 0 if there are no expired requests on the fifo,
   * 1 otherwise. Requires !list_empty(&dd->fifo_list[data_dir])
   */
-static inline int deadline_check_fifo(struct deadline_data *dd, int ddir)
+static inline int deadline_check_fifo(struct deadline_data *dd,
+				      enum dd_data_dir data_dir)
  {
-	struct request *rq = rq_entry_fifo(dd->fifo_list[ddir].next);
+	struct request *rq = rq_entry_fifo(dd->fifo_list[data_dir].next);
 
  	/*
  	 * rq is expired!
@@ -203,19 +211,16 @@ static inline int deadline_check_fifo(struct deadline_data *dd, int ddir)
   * dispatch using arrival ordered lists.
   */
  static struct request *
-deadline_fifo_request(struct deadline_data *dd, int data_dir)
+deadline_fifo_request(struct deadline_data *dd, enum dd_data_dir data_dir)
  {
  	struct request *rq;
  	unsigned long flags;
 
-	if (WARN_ON_ONCE(data_dir != READ && data_dir != WRITE))
-		return NULL;
-
  	if (list_empty(&dd->fifo_list[data_dir]))
  		return NULL;
 
  	rq = rq_entry_fifo(dd->fifo_list[data_dir].next);
-	if (data_dir == READ || !blk_queue_is_zoned(rq->q))
+	if (data_dir == DD_READ || !blk_queue_is_zoned(rq->q))
  		return rq;
 
  	/*
@@ -223,7 +228,7 @@ deadline_fifo_request(struct deadline_data *dd, int data_dir)
  	 * an unlocked target zone.
  	 */
  	spin_lock_irqsave(&dd->zone_lock, flags);
-	list_for_each_entry(rq, &dd->fifo_list[WRITE], queuelist) {
+	list_for_each_entry(rq, &dd->fifo_list[DD_WRITE], queuelist) {
  		if (blk_req_can_dispatch_to_zone(rq))
  			goto out;
  	}
@@ -239,19 +244,16 @@ deadline_fifo_request(struct deadline_data *dd, int data_dir)
   * dispatch using sector position sorted lists.
   */
  static struct request *
-deadline_next_request(struct deadline_data *dd, int data_dir)
+deadline_next_request(struct deadline_data *dd, enum dd_data_dir data_dir)
  {
  	struct request *rq;
  	unsigned long flags;
 
-	if (WARN_ON_ONCE(data_dir != READ && data_dir != WRITE))
-		return NULL;
-
  	rq = dd->next_rq[data_dir];
  	if (!rq)
  		return NULL;
 
-	if (data_dir == READ || !blk_queue_is_zoned(rq->q))
+	if (data_dir == DD_READ || !blk_queue_is_zoned(rq->q))
  		return rq;
 
  	/*
@@ -276,7 +278,7 @@ deadline_next_request(struct deadline_data *dd, int data_dir)
  static struct request *__dd_dispatch_request(struct deadline_data *dd)
  {
  	struct request *rq, *next_rq;
-	int data_dir;
+	enum dd_data_dir data_dir;
 
  	lockdep_assert_held(&dd->lock);
 
@@ -289,9 +291,9 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
  	/*
  	 * batches are currently reads XOR writes
  	 */
-	rq = deadline_next_request(dd, WRITE);
+	rq = deadline_next_request(dd, DD_WRITE);
  	if (!rq)
-		rq = deadline_next_request(dd, READ);
+		rq = deadline_next_request(dd, DD_READ);
 
  	if (rq && dd->batching < dd->fifo_batch)
  		/* we have a next request are still entitled to batch */
@@ -302,14 +304,14 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
  	 * data direction (read / write)
  	 */
 
-	if (!list_empty(&dd->fifo_list[READ])) {
-		BUG_ON(RB_EMPTY_ROOT(&dd->sort_list[READ]));
+	if (!list_empty(&dd->fifo_list[DD_READ])) {
+		BUG_ON(RB_EMPTY_ROOT(&dd->sort_list[DD_READ]));
 
-		if (deadline_fifo_request(dd, WRITE) &&
+		if (deadline_fifo_request(dd, DD_WRITE) &&
  		    (dd->starved++ >= dd->writes_starved))
  			goto dispatch_writes;
 
-		data_dir = READ;
+		data_dir = DD_READ;
 
  		goto dispatch_find_request;
  	}
@@ -318,13 +320,13 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
  	 * there are either no reads or writes have been starved
  	 */
 
-	if (!list_empty(&dd->fifo_list[WRITE])) {
+	if (!list_empty(&dd->fifo_list[DD_WRITE])) {
  dispatch_writes:
-		BUG_ON(RB_EMPTY_ROOT(&dd->sort_list[WRITE]));
+		BUG_ON(RB_EMPTY_ROOT(&dd->sort_list[DD_WRITE]));
 
  		dd->starved = 0;
 
-		data_dir = WRITE;
+		data_dir = DD_WRITE;
 
  		goto dispatch_find_request;
  	}
@@ -399,8 +401,8 @@ static void dd_exit_sched(struct elevator_queue *e)
  {
  	struct deadline_data *dd = e->elevator_data;
 
-	BUG_ON(!list_empty(&dd->fifo_list[READ]));
-	BUG_ON(!list_empty(&dd->fifo_list[WRITE]));
+	BUG_ON(!list_empty(&dd->fifo_list[DD_READ]));
+	BUG_ON(!list_empty(&dd->fifo_list[DD_WRITE]));
 
  	kfree(dd);
  }
@@ -424,12 +426,12 @@ static int dd_init_sched(struct request_queue *q, struct elevator_type *e)
  	}
  	eq->elevator_data = dd;
 
-	INIT_LIST_HEAD(&dd->fifo_list[READ]);
-	INIT_LIST_HEAD(&dd->fifo_list[WRITE]);
-	dd->sort_list[READ] = RB_ROOT;
-	dd->sort_list[WRITE] = RB_ROOT;
-	dd->fifo_expire[READ] = read_expire;
-	dd->fifo_expire[WRITE] = write_expire;
+	INIT_LIST_HEAD(&dd->fifo_list[DD_READ]);
+	INIT_LIST_HEAD(&dd->fifo_list[DD_WRITE]);
+	dd->sort_list[DD_READ] = RB_ROOT;
+	dd->sort_list[DD_WRITE] = RB_ROOT;
+	dd->fifo_expire[DD_READ] = read_expire;
+	dd->fifo_expire[DD_WRITE] = write_expire;
  	dd->writes_starved = writes_starved;
  	dd->front_merges = 1;
  	dd->fifo_batch = fifo_batch;
@@ -497,7 +499,7 @@ static void dd_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
  {
  	struct request_queue *q = hctx->queue;
  	struct deadline_data *dd = q->elevator->elevator_data;
-	const int data_dir = rq_data_dir(rq);
+	const enum dd_data_dir data_dir = rq_data_dir(rq);
 
  	lockdep_assert_held(&dd->lock);
 
@@ -585,7 +587,7 @@ static void dd_finish_request(struct request *rq)
 
  		spin_lock_irqsave(&dd->zone_lock, flags);
  		blk_req_zone_write_unlock(rq);
-		if (!list_empty(&dd->fifo_list[WRITE]))
+		if (!list_empty(&dd->fifo_list[DD_WRITE]))
  			blk_mq_sched_mark_restart_hctx(rq->mq_hctx);
  		spin_unlock_irqrestore(&dd->zone_lock, flags);
  	}
@@ -626,8 +628,8 @@ static ssize_t __FUNC(struct elevator_queue *e, char *page)		\
  		__data = jiffies_to_msecs(__data);			\
  	return deadline_var_show(__data, (page));			\
  }
-SHOW_FUNCTION(deadline_read_expire_show, dd->fifo_expire[READ], 1);
-SHOW_FUNCTION(deadline_write_expire_show, dd->fifo_expire[WRITE], 1);
+SHOW_FUNCTION(deadline_read_expire_show, dd->fifo_expire[DD_READ], 1);
+SHOW_FUNCTION(deadline_write_expire_show, dd->fifo_expire[DD_WRITE], 1);
  SHOW_FUNCTION(deadline_writes_starved_show, dd->writes_starved, 0);
  SHOW_FUNCTION(deadline_front_merges_show, dd->front_merges, 0);
  SHOW_FUNCTION(deadline_fifo_batch_show, dd->fifo_batch, 0);
@@ -649,8 +651,8 @@ static ssize_t __FUNC(struct elevator_queue *e, const char *page, size_t count)
  		*(__PTR) = __data;					\
  	return count;							\
  }
-STORE_FUNCTION(deadline_read_expire_store, &dd->fifo_expire[READ], 0, INT_MAX, 1);
-STORE_FUNCTION(deadline_write_expire_store, &dd->fifo_expire[WRITE], 0, INT_MAX, 1);
+STORE_FUNCTION(deadline_read_expire_store, &dd->fifo_expire[DD_READ], 0, INT_MAX, 1);
+STORE_FUNCTION(deadline_write_expire_store, &dd->fifo_expire[DD_WRITE], 0, INT_MAX, 1);
  STORE_FUNCTION(deadline_writes_starved_store, &dd->writes_starved, INT_MIN, INT_MAX, 0);
  STORE_FUNCTION(deadline_front_merges_store, &dd->front_merges, 0, 1, 0);
  STORE_FUNCTION(deadline_fifo_batch_store, &dd->fifo_batch, 0, INT_MAX, 0);

block/mq-deadline.c static int deadline_##name##_next_rq_show(void *data, \ · line 726

Quoted 10 lines
block/mq-deadline.c +2 -2
@@ -717,8 +719,8 @@ static int deadline_##name##_next_rq_show(void *data,			\
  		__blk_mq_debugfs_rq_show(m, rq);			\
  	return 0;							\
  }
-DEADLINE_DEBUGFS_DDIR_ATTRS(READ, read)
-DEADLINE_DEBUGFS_DDIR_ATTRS(WRITE, write)
+DEADLINE_DEBUGFS_DDIR_ATTRS(DD_READ, read)
+DEADLINE_DEBUGFS_DDIR_ATTRS(DD_WRITE, write)
  #undef DEADLINE_DEBUGFS_DDIR_ATTRS
 
  static int deadline_batching_show(void *data, struct seq_file *m)
Signature · 1 line
Himanshu Madhani                                Oracle Linux Engineering
#34 lore raw

PATCH 6/9 block/mq-deadline: Reduce the read expiry time for non-rotational media

In reply to Bart Van Assche

Rotational media (hard disks) benefit more from merging requests than non-rotational media. Reduce the read expire time for non-rotational media to reduce read latency.

Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/mq-deadline.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
block/mq-deadline.c +5 -2
index dfbc6b77fa71..2ab844a4b6b5 100644
@@ -29,7 +29,9 @@
 /*
  * See Documentation/block/deadline-iosched.rst
  */
-static const int read_expire = HZ / 2;  /* max time before a read is submitted. */
+/* max time before a read is submitted. */
+static const int read_expire_rot = HZ / 2;
+static const int read_expire_nonrot = 1;
 static const int write_expire = 5 * HZ; /* ditto for writes, these limits are SOFT! */
 static const int writes_starved = 2;    /* max times reads can starve a write */
 static const int fifo_batch = 16;       /* # of sequential requests treated as one
@@ -430,7 +432,8 @@ static int dd_init_sched(struct request_queue *q, struct elevator_type *e)
 	INIT_LIST_HEAD(&dd->fifo_list[DD_WRITE]);
 	dd->sort_list[DD_READ] = RB_ROOT;
 	dd->sort_list[DD_WRITE] = RB_ROOT;
-	dd->fifo_expire[DD_READ] = read_expire;
+	dd->fifo_expire[DD_READ] = blk_queue_nonrot(q) ? read_expire_nonrot :
+		read_expire_rot;
 	dd->fifo_expire[DD_WRITE] = write_expire;
 	dd->writes_starved = writes_starved;
 	dd->front_merges = 1;
Reviewed-by on v1 6/9
#35 lore raw

Re: [PATCH 6/9] block/mq-deadline: Reduce the read expiry time for non-rotational media

block/mq-deadline.c static int dd_init_sched(struct request_queue *q, struct elevator_type *e) · line 436

Quoted 3 lines · Bart Van Assche
block/mq-deadline.c +2 -1
-	dd->fifo_expire[DD_READ] = read_expire;
+	dd->fifo_expire[DD_READ] = blk_queue_nonrot(q) ? read_expire_nonrot :
+		read_expire_rot;

I've got comments about not using ?:.

Apart from that looks good.

#36 lore raw

Re: [PATCH 6/9] block/mq-deadline: Reduce the read expiry time for non-rotational media

In reply to Bart Van Assche
Quoted 2 lines · Bart Van Assche

Rotational media (hard disks) benefit more from merging requests than non-rotational media. Reduce the read expire time for non-rotational media

"Reduce the read expire time for non-rotational..." -> "Reduce the default read expire time for non-rotational..."

Quoted 1 line

to reduce read latency.

I am not against this, but I wonder if we should not let udev do that with some rules instead of adding totally arbitrary values here...

Quoted 35 lines
Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/mq-deadline.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
block/mq-deadline.c +5 -2
index dfbc6b77fa71..2ab844a4b6b5 100644
@@ -29,7 +29,9 @@
 /*
  * See Documentation/block/deadline-iosched.rst
  */
-static const int read_expire = HZ / 2;  /* max time before a read is submitted. */
+/* max time before a read is submitted. */
+static const int read_expire_rot = HZ / 2;
+static const int read_expire_nonrot = 1;
 static const int write_expire = 5 * HZ; /* ditto for writes, these limits are SOFT! */
 static const int writes_starved = 2;    /* max times reads can starve a write */
 static const int fifo_batch = 16;       /* # of sequential requests treated as one
@@ -430,7 +432,8 @@ static int dd_init_sched(struct request_queue *q, struct elevator_type *e)
 	INIT_LIST_HEAD(&dd->fifo_list[DD_WRITE]);
 	dd->sort_list[DD_READ] = RB_ROOT;
 	dd->sort_list[DD_WRITE] = RB_ROOT;
-	dd->fifo_expire[DD_READ] = read_expire;
+	dd->fifo_expire[DD_READ] = blk_queue_nonrot(q) ? read_expire_nonrot :
+		read_expire_rot;
 	dd->fifo_expire[DD_WRITE] = write_expire;
 	dd->writes_starved = writes_starved;
 	dd->front_merges = 1;
Signature · 2 lines
Damien Le Moal
Western Digital Research
#37 lore raw

Re: [PATCH 6/9] block/mq-deadline: Reduce the read expiry time for non-rotational media

Quoted 11 lines · Damien Le Moal
Quoted 2 lines · Bart Van Assche

Rotational media (hard disks) benefit more from merging requests than non-rotational media. Reduce the read expire time for non-rotational media

"Reduce the read expire time for non-rotational..." -> "Reduce the default read expire time for non-rotational..."

Quoted 1 line

to reduce read latency.

I am not against this, but I wonder if we should not let udev do that with some rules instead of adding totally arbitrary values here...

Hi Damien and Hannes,

I agree that it's better to configure the expiry time via udev so I'm considering to leave this patch out.

Thanks,

Bart.

#38 lore raw

Re: [PATCH 6/9] block/mq-deadline: Reduce the read expiry time for non-rotational media

In reply to Bart Van Assche
Quoted 4 lines · Bart Van Assche

Rotational media (hard disks) benefit more from merging requests than non-rotational media. Reduce the read expire time for non-rotational media to reduce read latency.

Quoted 8 lines
Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/mq-deadline.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Do we get numbers for this? Or is is just code review?

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke		        Kernel Storage Architect
[email protected]			               +49 911 74053 688
SUSE Software Solutions Germany GmbH, 90409 Nürnberg
GF: F. Imendörffer, HRB 36809 (AG Nürnberg)
Reviewed-by on v1 6/9
#39 lore raw

Re: [PATCH 6/9] block/mq-deadline: Reduce the read expiry time for non-rotational media

In reply to Bart Van Assche
Quoted 29 lines · Bart Van Assche

Rotational media (hard disks) benefit more from merging requests than non-rotational media. Reduce the read expire time for non-rotational media to reduce read latency.

Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
  block/mq-deadline.c | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
block/mq-deadline.c +3 -1
index dfbc6b77fa71..2ab844a4b6b5 100644
@@ -29,7 +29,9 @@
  /*
   * See Documentation/block/deadline-iosched.rst
   */
-static const int read_expire = HZ / 2;  /* max time before a read is submitted. */
+/* max time before a read is submitted. */
+static const int read_expire_rot = HZ / 2;
+static const int read_expire_nonrot = 1;
  static const int write_expire = 5 * HZ; /* ditto for writes, these limits are SOFT! */
  static const int writes_starved = 2;    /* max times reads can starve a write */
  static const int fifo_batch = 16;       /* # of sequential requests treated as one

block/mq-deadline.c static int dd_init_sched(struct request_queue *q, struct elevator_type *e) · line 439

Quoted 9 lines
block/mq-deadline.c +2 -1
@@ -430,7 +432,8 @@ static int dd_init_sched(struct request_queue *q, struct elevator_type *e)
  	INIT_LIST_HEAD(&dd->fifo_list[DD_WRITE]);
  	dd->sort_list[DD_READ] = RB_ROOT;
  	dd->sort_list[DD_WRITE] = RB_ROOT;
-	dd->fifo_expire[DD_READ] = read_expire;
+	dd->fifo_expire[DD_READ] = blk_queue_nonrot(q) ? read_expire_nonrot :
+		read_expire_rot;
  	dd->fifo_expire[DD_WRITE] = write_expire;
  	dd->writes_starved = writes_starved;
  	dd->front_merges = 1;
Signature · 1 line
Himanshu Madhani                                Oracle Linux Engineering
#40 lore raw

PATCH 7/9 block/mq-deadline: Reserve 25% of tags for synchronous requests

In reply to Bart Van Assche

For interactive workloads it is important that synchronous requests are not delayed. Hence reserve 25% of tags for synchronous requests. This patch still allows asynchronous requests to fill the hardware queues since blk_mq_init_sched() makes sure that the number of scheduler requests is the double of the hardware queue depth. From blk_mq_init_sched():

	q->nr_requests = 2 * min_t(unsigned int, q->tag_set->queue_depth,
				   BLKDEV_MAX_RQ);
Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/mq-deadline.c | 46 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
block/mq-deadline.c +46 -0
index 2ab844a4b6b5..81f487d77e09 100644
@@ -69,6 +69,7 @@ struct deadline_data {
 	int fifo_batch;
 	int writes_starved;
 	int front_merges;
+	u32 async_depth;
 
 	spinlock_t lock;
 	spinlock_t zone_lock;
@@ -399,6 +400,38 @@ static struct request *dd_dispatch_request(struct blk_mq_hw_ctx *hctx)
 	return rq;
 }
 
+static void dd_limit_depth(unsigned int op, struct blk_mq_alloc_data *data)
+{
+	struct deadline_data *dd = data->q->elevator->elevator_data;
+
+	/* Do not throttle synchronous reads. */
+	if (op_is_sync(op) && !op_is_write(op))
+		return;
+
+	/*
+	 * Throttle asynchronous requests and writes such that these requests
+	 * do not block the allocation of synchronous requests.
+	 */
+	data->shallow_depth = dd->async_depth;
+}
+
+static void dd_depth_updated(struct blk_mq_hw_ctx *hctx)
+{
+	struct request_queue *q = hctx->queue;
+	struct deadline_data *dd = q->elevator->elevator_data;
+	struct blk_mq_tags *tags = hctx->sched_tags;
+
+	dd->async_depth = 3 * q->nr_requests / 4;
+
+	sbitmap_queue_min_shallow_depth(tags->bitmap_tags, dd->async_depth);
+}
+
+static int dd_init_hctx(struct blk_mq_hw_ctx *hctx, unsigned int hctx_idx)
+{
+	dd_depth_updated(hctx);
+	return 0;
+}
+
 static void dd_exit_sched(struct elevator_queue *e)
 {
 	struct deadline_data *dd = e->elevator_data;
@@ -744,6 +777,15 @@ static int deadline_starved_show(void *data, struct seq_file *m)
 	return 0;
 }
 
+static int dd_async_depth_show(void *data, struct seq_file *m)
+{
+	struct request_queue *q = data;
+	struct deadline_data *dd = q->elevator->elevator_data;
+
+	seq_printf(m, "%u\n", dd->async_depth);
+	return 0;
+}
+
 static void *deadline_dispatch_start(struct seq_file *m, loff_t *pos)
 	__acquires(&dd->lock)
 {
@@ -786,6 +828,7 @@ static const struct blk_mq_debugfs_attr deadline_queue_debugfs_attrs[] = {
 	DEADLINE_QUEUE_DDIR_ATTRS(write),
 	{"batching", 0400, deadline_batching_show},
 	{"starved", 0400, deadline_starved_show},
+	{"async_depth", 0400, dd_async_depth_show},
 	{"dispatch", 0400, .seq_ops = &deadline_dispatch_seq_ops},
 	{},
 };
@@ -794,6 +837,8 @@ static const struct blk_mq_debugfs_attr deadline_queue_debugfs_attrs[] = {
 
 static struct elevator_type mq_deadline = {
 	.ops = {
+		.depth_updated		= dd_depth_updated,
+		.limit_depth		= dd_limit_depth,
 		.insert_requests	= dd_insert_requests,
 		.dispatch_request	= dd_dispatch_request,
 		.prepare_request	= dd_prepare_request,
@@ -807,6 +852,7 @@ static struct elevator_type mq_deadline = {
 		.has_work		= dd_has_work,
 		.init_sched		= dd_init_sched,
 		.exit_sched		= dd_exit_sched,
+		.init_hctx		= dd_init_hctx,
 	},
 
 #ifdef CONFIG_BLK_DEBUG_FS
#41 lore raw

Re: [PATCH 7/9] block/mq-deadline: Reserve 25% of tags for synchronous requests

Quoted 2 lines · Bart Van Assche

For interactive workloads it is important that synchronous requests are not delayed. Hence reserve 25% of tags for synchronous requests. This patch

s/tags/scheduler tags

to be clear that we are not talking about the device tags. Same in the patch title may be.

Quoted 28 lines

still allows asynchronous requests to fill the hardware queues since blk_mq_init_sched() makes sure that the number of scheduler requests is the double of the hardware queue depth. From blk_mq_init_sched():

	q->nr_requests = 2 * min_t(unsigned int, q->tag_set->queue_depth,
				   BLKDEV_MAX_RQ);
Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/mq-deadline.c | 46 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
block/mq-deadline.c +1 -0
index 2ab844a4b6b5..81f487d77e09 100644
@@ -69,6 +69,7 @@ struct deadline_data {
 	int fifo_batch;
 	int writes_starved;
 	int front_merges;
+	u32 async_depth;
 
 	spinlock_t lock;
 	spinlock_t zone_lock;

block/mq-deadline.c static struct request *dd_dispatch_request(struct blk_mq_hw_ctx *hctx) · line 403

Quoted 4 lines
block/mq-deadline.c +1 -0
@@ -399,6 +400,38 @@ static struct request *dd_dispatch_request(struct blk_mq_hw_ctx *hctx)
 	return rq;
 }
 
+static void dd_limit_depth(unsigned int op, struct blk_mq_alloc_data *data)

Similarly as you did in patch 1, may be add a comment about this operation and when it is called ?

Quoted 11 lines
block/mq-deadline.c +11 -0
+{
+	struct deadline_data *dd = data->q->elevator->elevator_data;
+
+	/* Do not throttle synchronous reads. */
+	if (op_is_sync(op) && !op_is_write(op))
+		return;
+
+	/*
+	 * Throttle asynchronous requests and writes such that these requests
+	 * do not block the allocation of synchronous requests.
+	 */

block/mq-deadline.c static struct request *dd_dispatch_request(struct blk_mq_hw_ctx *hctx) · line 424

Quoted 10 lines
block/mq-deadline.c +10 -0
+	data->shallow_depth = dd->async_depth;
+}
+
+static void dd_depth_updated(struct blk_mq_hw_ctx *hctx)
+{
+	struct request_queue *q = hctx->queue;
+	struct deadline_data *dd = q->elevator->elevator_data;
+	struct blk_mq_tags *tags = hctx->sched_tags;
+
+	dd->async_depth = 3 * q->nr_requests / 4;

I think that nr_requests is always at least 2, but it may be good to have a sanity check here that we do not end up with async_depth == 0, no ?

Quoted 55 lines
block/mq-deadline.c +23 -0
+
+	sbitmap_queue_min_shallow_depth(tags->bitmap_tags, dd->async_depth);
+}
+
+static int dd_init_hctx(struct blk_mq_hw_ctx *hctx, unsigned int hctx_idx)
+{
+	dd_depth_updated(hctx);
+	return 0;
+}
+
 static void dd_exit_sched(struct elevator_queue *e)
 {
 	struct deadline_data *dd = e->elevator_data;
@@ -744,6 +777,15 @@ static int deadline_starved_show(void *data, struct seq_file *m)
 	return 0;
 }
 
+static int dd_async_depth_show(void *data, struct seq_file *m)
+{
+	struct request_queue *q = data;
+	struct deadline_data *dd = q->elevator->elevator_data;
+
+	seq_printf(m, "%u\n", dd->async_depth);
+	return 0;
+}
+
 static void *deadline_dispatch_start(struct seq_file *m, loff_t *pos)
 	__acquires(&dd->lock)
 {
@@ -786,6 +828,7 @@ static const struct blk_mq_debugfs_attr deadline_queue_debugfs_attrs[] = {
 	DEADLINE_QUEUE_DDIR_ATTRS(write),
 	{"batching", 0400, deadline_batching_show},
 	{"starved", 0400, deadline_starved_show},
+	{"async_depth", 0400, dd_async_depth_show},
 	{"dispatch", 0400, .seq_ops = &deadline_dispatch_seq_ops},
 	{},
 };
@@ -794,6 +837,8 @@ static const struct blk_mq_debugfs_attr deadline_queue_debugfs_attrs[] = {
 
 static struct elevator_type mq_deadline = {
 	.ops = {
+		.depth_updated		= dd_depth_updated,
+		.limit_depth		= dd_limit_depth,
 		.insert_requests	= dd_insert_requests,
 		.dispatch_request	= dd_dispatch_request,
 		.prepare_request	= dd_prepare_request,
@@ -807,6 +852,7 @@ static struct elevator_type mq_deadline = {
 		.has_work		= dd_has_work,
 		.init_sched		= dd_init_sched,
 		.exit_sched		= dd_exit_sched,
+		.init_hctx		= dd_init_hctx,
 	},
 
 #ifdef CONFIG_BLK_DEBUG_FS
Signature · 2 lines
Damien Le Moal
Western Digital Research
#42 lore raw

Re: [PATCH 7/9] block/mq-deadline: Reserve 25% of tags for synchronous requests

Quoted 8 lines · Damien Le Moal
Quoted 2 lines · Bart Van Assche

For interactive workloads it is important that synchronous requests are not delayed. Hence reserve 25% of tags for synchronous requests. This patch

s/tags/scheduler tags

to be clear that we are not talking about the device tags. Same in the patch title may be.

OK.

Quoted 4 lines
Quoted 1 line

+static void dd_limit_depth(unsigned int op, struct blk_mq_alloc_data *data)

Similarly as you did in patch 1, may be add a comment about this operation and when it is called ?

Will do.

Quoted 10 lines

block/mq-deadline.c static struct request *dd_dispatch_request(struct blk_mq_hw_ctx *hctx) · line 424

Quoted 7 lines
block/mq-deadline.c +7 -0
+static void dd_depth_updated(struct blk_mq_hw_ctx *hctx)
+{
+	struct request_queue *q = hctx->queue;
+	struct deadline_data *dd = q->elevator->elevator_data;
+	struct blk_mq_tags *tags = hctx->sched_tags;
+
+	dd->async_depth = 3 * q->nr_requests / 4;

I think that nr_requests is always at least 2, but it may be good to have a sanity check here that we do not end up with async_depth == 0, no ?

OK, I will add a check.

Thanks,

Bart.

#43 lore raw

Re: [PATCH 7/9] block/mq-deadline: Reserve 25% of tags for synchronous requests

In reply to Bart Van Assche
Quoted 9 lines · Bart Van Assche

For interactive workloads it is important that synchronous requests are not delayed. Hence reserve 25% of tags for synchronous requests. This patch still allows asynchronous requests to fill the hardware queues since blk_mq_init_sched() makes sure that the number of scheduler requests is the double of the hardware queue depth. From blk_mq_init_sched():

	q->nr_requests = 2 * min_t(unsigned int, q->tag_set->queue_depth,
				   BLKDEV_MAX_RQ);
Quoted 8 lines
Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/mq-deadline.c | 46 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

I wonder if that's a good idea in general ... I'm thinking of poor SATA

drives which only have 31 tags; setting aside 8 of them for specific use-cases does make a difference one would think.

Do you have testcases for this?

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke		        Kernel Storage Architect
[email protected]			               +49 911 74053 688
SUSE Software Solutions Germany GmbH, 90409 Nürnberg
GF: F. Imendörffer, HRB 36809 (AG Nürnberg)
#44 lore raw

Re: [PATCH 7/9] block/mq-deadline: Reserve 25% of tags for synchronous requests

Quoted 7 lines · Hannes Reinecke
Quoted 6 lines · Bart Van Assche

For interactive workloads it is important that synchronous requests are not delayed. Hence reserve 25% of tags for synchronous requests. This patch still allows asynchronous requests to fill the hardware queues since blk_mq_init_sched() makes sure that the number of scheduler requests is the double of the hardware queue depth. From blk_mq_init_sched():

Quoted 8 lines
Quoted 2 lines
	q->nr_requests = 2 * min_t(unsigned int, q->tag_set->queue_depth,
				   BLKDEV_MAX_RQ);

I wonder if that's a good idea in general ... I'm thinking of poor SATA drives which only have 31 tags; setting aside 8 of them for specific use-cases does make a difference one would think.

Do you have testcases for this?

Hi Hannes,

The mq-deadline scheduler is the only scheduler that does not yet set aside tags for synchronous requests. BFQ and Kyber both implement the .limit_depth I/O scheduler callback function.

Yes, I have a test case for this, namely SCSI UFS devices. The UFS device in my test setup supports a single I/O queue and limits the number of outstanding SCSI commands to 32 (UFSHCD_CAN_QUEUE).

Please note that the limit mentioned above is still above the number of controller tags. For e.g. UFS q->tag_set->queue_depth == 32 and attaching an I/O scheduler increases nr_requests from 32 to 64. Reserving 25% of tags for synchronous requests leaves 3 * 64 / 4 = 48 scheduler tags for asynchronous requests.

Thanks,

Bart.

#45 lore raw

PATCH 8/9 block/mq-deadline: Add I/O priority support

In reply to Bart Van Assche

Maintain one FIFO list per I/O priority: RT, BE and IDLE. Only dispatch requests for a lower priority after all higher priority requests have finished. Maintain statistics for each priority level. Split the debugfs attributes per priority level as follows:

$ ls /sys/kernel/debug/block/.../sched/
async_depth  dispatch2        read_next_rq      write2_fifo_list
batching     read0_fifo_list  starved           write_next_rq
dispatch0    read1_fifo_list  write0_fifo_list
dispatch1    read2_fifo_list  write1_fifo_list
Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/mq-deadline.c | 293 +++++++++++++++++++++++++++++++++-----------
 1 file changed, 223 insertions(+), 70 deletions(-)
block/mq-deadline.c +223 -70
index 81f487d77e09..5a703e1228fa 100644
@@ -44,16 +44,27 @@ enum dd_data_dir {
 
 enum { DD_DIR_COUNT = 2 };
 
+enum dd_prio {
+	DD_RT_PRIO	= 0,
+	DD_BE_PRIO	= 1,
+	DD_IDLE_PRIO	= 2,
+	DD_PRIO_MAX	= 2,
+} __packed;
+
+enum { DD_PRIO_COUNT = 3 };
+
 struct deadline_data {
 	/*
 	 * run time data
 	 */
 
 	/*
-	 * requests (deadline_rq s) are present on both sort_list and fifo_list
+	 * Requests are present on both sort_list[] and fifo_list[][]. The
+	 * first index of fifo_list[][] is the I/O priority class (DD_*_PRIO).
+	 * The second index is the data direction (rq_data_dir(rq)).
 	 */
 	struct rb_root sort_list[DD_DIR_COUNT];
-	struct list_head fifo_list[DD_DIR_COUNT];
+	struct list_head fifo_list[DD_PRIO_COUNT][DD_DIR_COUNT];
 
 	/*
 	 * next in sort order. read, write or both are NULL
@@ -62,6 +73,12 @@ struct deadline_data {
 	unsigned int batching;		/* number of sequential requests made */
 	unsigned int starved;		/* times reads have starved writes */
 
+	/* statistics */
+	atomic_t inserted[DD_PRIO_COUNT];
+	atomic_t dispatched[DD_PRIO_COUNT];
+	atomic_t merged[DD_PRIO_COUNT];
+	atomic_t completed[DD_PRIO_COUNT];
+
 	/*
 	 * settings that change how the i/o scheduler behaves
 	 */
@@ -73,7 +90,15 @@ struct deadline_data {
 
 	spinlock_t lock;
 	spinlock_t zone_lock;
-	struct list_head dispatch;
+	struct list_head dispatch[DD_PRIO_COUNT];
+};
+
+/* Maps an I/O priority class to a deadline scheduler priority. */
+static const enum dd_prio ioprio_class_to_prio[] = {
+	[IOPRIO_CLASS_NONE]	= DD_BE_PRIO,
+	[IOPRIO_CLASS_RT]	= DD_RT_PRIO,
+	[IOPRIO_CLASS_BE]	= DD_BE_PRIO,
+	[IOPRIO_CLASS_IDLE]	= DD_IDLE_PRIO,
 };
 
 static inline struct rb_root *
@@ -149,12 +174,28 @@ static void dd_request_merged(struct request_queue *q, struct request *req,
 	}
 }
 
+/* Returns the I/O class that has been assigned by dd_insert_request(). */
+static u8 dd_rq_ioclass(struct request *rq)
+{
+	return (uintptr_t)rq->elv.priv[1];
+}
+
 /*
  * Callback function that is invoked after @next has been merged into @req.
  */
 static void dd_merged_requests(struct request_queue *q, struct request *req,
 			       struct request *next)
 {
+	struct deadline_data *dd = q->elevator->elevator_data;
+	const u8 ioprio_class = dd_rq_ioclass(next);
+	const enum dd_prio prio = ioprio_class_to_prio[ioprio_class];
+
+	if (next->elv.priv[0]) {
+		atomic_inc(&dd->merged[prio]);
+	} else {
+		WARN_ON_ONCE(true);
+	}
+
 	/*
 	 * if next expires before rq, assign its expire time to rq
 	 * and move into next position (next will be deleted) in fifo
@@ -191,14 +232,22 @@ deadline_move_request(struct deadline_data *dd, struct request *rq)
 	deadline_remove_request(rq->q, rq);
 }
 
+/* Number of requests queued for a given priority level. */
+static u64 dd_queued(struct deadline_data *dd, enum dd_prio prio)
+{
+	return atomic_read(&dd->inserted[prio]) -
+		atomic_read(&dd->completed[prio]);
+}
+
 /*
  * deadline_check_fifo returns 0 if there are no expired requests on the fifo,
  * 1 otherwise. Requires !list_empty(&dd->fifo_list[data_dir])
  */
 static inline int deadline_check_fifo(struct deadline_data *dd,
+				      enum dd_prio prio,
 				      enum dd_data_dir data_dir)
 {
-	struct request *rq = rq_entry_fifo(dd->fifo_list[data_dir].next);
+	struct request *rq = rq_entry_fifo(dd->fifo_list[prio][data_dir].next);
 
 	/*
 	 * rq is expired!
@@ -214,15 +263,16 @@ static inline int deadline_check_fifo(struct deadline_data *dd,
  * dispatch using arrival ordered lists.
  */
 static struct request *
-deadline_fifo_request(struct deadline_data *dd, enum dd_data_dir data_dir)
+deadline_fifo_request(struct deadline_data *dd, enum dd_prio prio,
+		      enum dd_data_dir data_dir)
 {
 	struct request *rq;
 	unsigned long flags;
 
-	if (list_empty(&dd->fifo_list[data_dir]))
+	if (list_empty(&dd->fifo_list[prio][data_dir]))
 		return NULL;
 
-	rq = rq_entry_fifo(dd->fifo_list[data_dir].next);
+	rq = rq_entry_fifo(dd->fifo_list[prio][data_dir].next);
 	if (data_dir == DD_READ || !blk_queue_is_zoned(rq->q))
 		return rq;
 
@@ -231,7 +281,7 @@ deadline_fifo_request(struct deadline_data *dd, enum dd_data_dir data_dir)
 	 * an unlocked target zone.
 	 */
 	spin_lock_irqsave(&dd->zone_lock, flags);
-	list_for_each_entry(rq, &dd->fifo_list[DD_WRITE], queuelist) {
+	list_for_each_entry(rq, &dd->fifo_list[prio][DD_WRITE], queuelist) {
 		if (blk_req_can_dispatch_to_zone(rq))
 			goto out;
 	}
@@ -247,7 +297,8 @@ deadline_fifo_request(struct deadline_data *dd, enum dd_data_dir data_dir)
  * dispatch using sector position sorted lists.
  */
 static struct request *
-deadline_next_request(struct deadline_data *dd, enum dd_data_dir data_dir)
+deadline_next_request(struct deadline_data *dd, enum dd_prio prio,
+		      enum dd_data_dir data_dir)
 {
 	struct request *rq;
 	unsigned long flags;
@@ -278,15 +329,18 @@ deadline_next_request(struct deadline_data *dd, enum dd_data_dir data_dir)
  * deadline_dispatch_requests selects the best request according to
  * read/write expire, fifo_batch, etc
  */
-static struct request *__dd_dispatch_request(struct deadline_data *dd)
+static struct request *__dd_dispatch_request(struct deadline_data *dd,
+					     enum dd_prio prio)
 {
 	struct request *rq, *next_rq;
 	enum dd_data_dir data_dir;
+	u8 ioprio_class;
 
 	lockdep_assert_held(&dd->lock);
 
-	if (!list_empty(&dd->dispatch)) {
-		rq = list_first_entry(&dd->dispatch, struct request, queuelist);
+	if (!list_empty(&dd->dispatch[prio])) {
+		rq = list_first_entry(&dd->dispatch[prio], struct request,
+				      queuelist);
 		list_del_init(&rq->queuelist);
 		goto done;
 	}
@@ -294,9 +348,9 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
 	/*
 	 * batches are currently reads XOR writes
 	 */
-	rq = deadline_next_request(dd, DD_WRITE);
+	rq = deadline_next_request(dd, prio, DD_WRITE);
 	if (!rq)
-		rq = deadline_next_request(dd, DD_READ);
+		rq = deadline_next_request(dd, prio, DD_READ);
 
 	if (rq && dd->batching < dd->fifo_batch)
 		/* we have a next request are still entitled to batch */
@@ -307,10 +361,10 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
 	 * data direction (read / write)
 	 */
 
-	if (!list_empty(&dd->fifo_list[DD_READ])) {
+	if (!list_empty(&dd->fifo_list[prio][DD_READ])) {
 		BUG_ON(RB_EMPTY_ROOT(&dd->sort_list[DD_READ]));
 
-		if (deadline_fifo_request(dd, DD_WRITE) &&
+		if (deadline_fifo_request(dd, prio, DD_WRITE) &&
 		    (dd->starved++ >= dd->writes_starved))
 			goto dispatch_writes;
 
@@ -323,7 +377,7 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
 	 * there are either no reads or writes have been starved
 	 */
 
-	if (!list_empty(&dd->fifo_list[DD_WRITE])) {
+	if (!list_empty(&dd->fifo_list[prio][DD_WRITE])) {
 dispatch_writes:
 		BUG_ON(RB_EMPTY_ROOT(&dd->sort_list[DD_WRITE]));
 
@@ -340,14 +394,14 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
 	/*
 	 * we are not running a batch, find best request for selected data_dir
 	 */
-	next_rq = deadline_next_request(dd, data_dir);
-	if (deadline_check_fifo(dd, data_dir) || !next_rq) {
+	next_rq = deadline_next_request(dd, prio, data_dir);
+	if (deadline_check_fifo(dd, prio, data_dir) || !next_rq) {
 		/*
 		 * A deadline has expired, the last request was in the other
 		 * direction, or we have run out of higher-sectored requests.
 		 * Start again from the request with the earliest expiry time.
 		 */
-		rq = deadline_fifo_request(dd, data_dir);
+		rq = deadline_fifo_request(dd, prio, data_dir);
 	} else {
 		/*
 		 * The last req was the same dir and we have a next request in
@@ -372,6 +426,13 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
 	dd->batching++;
 	deadline_move_request(dd, rq);
 done:
+	ioprio_class = dd_rq_ioclass(rq);
+	prio = ioprio_class_to_prio[ioprio_class];
+	if (rq->elv.priv[0]) {
+		atomic_inc(&dd->dispatched[prio]);
+	} else {
+		WARN_ON_ONCE(true);
+	}
 	/*
 	 * If the request needs its target zone locked, do it.
 	 */
@@ -392,9 +453,14 @@ static struct request *dd_dispatch_request(struct blk_mq_hw_ctx *hctx)
 {
 	struct deadline_data *dd = hctx->queue->elevator->elevator_data;
 	struct request *rq;
+	enum dd_prio prio;
 
 	spin_lock(&dd->lock);
-	rq = __dd_dispatch_request(dd);
+	for (prio = 0; prio <= DD_PRIO_MAX; prio++) {
+		rq = __dd_dispatch_request(dd, prio);
+		if (rq || dd_queued(dd, prio))
+			break;
+	}
 	spin_unlock(&dd->lock);
 
 	return rq;
@@ -435,9 +501,12 @@ static int dd_init_hctx(struct blk_mq_hw_ctx *hctx, unsigned int hctx_idx)
 static void dd_exit_sched(struct elevator_queue *e)
 {
 	struct deadline_data *dd = e->elevator_data;
+	enum dd_prio prio;
 
-	BUG_ON(!list_empty(&dd->fifo_list[DD_READ]));
-	BUG_ON(!list_empty(&dd->fifo_list[DD_WRITE]));
+	for (prio = 0; prio <= DD_PRIO_MAX; prio++) {
+		WARN_ON_ONCE(!list_empty(&dd->fifo_list[prio][DD_READ]));
+		WARN_ON_ONCE(!list_empty(&dd->fifo_list[prio][DD_WRITE]));
+	}
 
 	kfree(dd);
 }
@@ -449,6 +518,7 @@ static int dd_init_sched(struct request_queue *q, struct elevator_type *e)
 {
 	struct deadline_data *dd;
 	struct elevator_queue *eq;
+	enum dd_prio prio;
 
 	eq = elevator_alloc(q, e);
 	if (!eq)
@@ -461,8 +531,11 @@ static int dd_init_sched(struct request_queue *q, struct elevator_type *e)
 	}
 	eq->elevator_data = dd;
 
-	INIT_LIST_HEAD(&dd->fifo_list[DD_READ]);
-	INIT_LIST_HEAD(&dd->fifo_list[DD_WRITE]);
+	for (prio = 0; prio <= DD_PRIO_MAX; prio++) {
+		INIT_LIST_HEAD(&dd->fifo_list[prio][DD_READ]);
+		INIT_LIST_HEAD(&dd->fifo_list[prio][DD_WRITE]);
+		INIT_LIST_HEAD(&dd->dispatch[prio]);
+	}
 	dd->sort_list[DD_READ] = RB_ROOT;
 	dd->sort_list[DD_WRITE] = RB_ROOT;
 	dd->fifo_expire[DD_READ] = blk_queue_nonrot(q) ? read_expire_nonrot :
@@ -473,7 +546,6 @@ static int dd_init_sched(struct request_queue *q, struct elevator_type *e)
 	dd->fifo_batch = fifo_batch;
 	spin_lock_init(&dd->lock);
 	spin_lock_init(&dd->zone_lock);
-	INIT_LIST_HEAD(&dd->dispatch);
 
 	q->elevator = eq;
 	return 0;
@@ -536,6 +608,9 @@ static void dd_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
 	struct request_queue *q = hctx->queue;
 	struct deadline_data *dd = q->elevator->elevator_data;
 	const enum dd_data_dir data_dir = rq_data_dir(rq);
+	u16 ioprio = req_get_ioprio(rq);
+	u8 ioprio_class = IOPRIO_PRIO_CLASS(ioprio);
+	enum dd_prio prio;
 
 	lockdep_assert_held(&dd->lock);
 
@@ -545,13 +620,19 @@ static void dd_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
 	 */
 	blk_req_zone_write_unlock(rq);
 
+	prio = ioprio_class_to_prio[ioprio_class];
+	atomic_inc(&dd->inserted[prio]);
+	WARN_ON_ONCE(rq->elv.priv[0]);
+	rq->elv.priv[0] = (void *)1ULL;
+	rq->elv.priv[1] = (void *)(uintptr_t)ioprio_class;
+
 	if (blk_mq_sched_try_insert_merge(q, rq))
 		return;
 
 	trace_block_rq_insert(rq);
 
 	if (at_head) {
-		list_add(&rq->queuelist, &dd->dispatch);
+		list_add(&rq->queuelist, &dd->dispatch[prio]);
 	} else {
 		deadline_add_rq_rb(dd, rq);
 
@@ -565,7 +646,7 @@ static void dd_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
 		 * set expire time and add to fifo list
 		 */
 		rq->fifo_time = jiffies + dd->fifo_expire[data_dir];
-		list_add_tail(&rq->queuelist, &dd->fifo_list[data_dir]);
+		list_add_tail(&rq->queuelist, &dd->fifo_list[prio][data_dir]);
 	}
 }
 
@@ -589,12 +670,10 @@ static void dd_insert_requests(struct blk_mq_hw_ctx *hctx,
 	spin_unlock(&dd->lock);
 }
 
-/*
- * Nothing to do here. This is defined only to ensure that .finish_request
- * method is called upon request completion.
- */
+/* Callback function called from inside blk_mq_rq_ctx_init(). */
 static void dd_prepare_request(struct request *rq)
 {
+	rq->elv.priv[0] = NULL;
 }
 
 /*
@@ -616,26 +695,41 @@ static void dd_prepare_request(struct request *rq)
 static void dd_finish_request(struct request *rq)
 {
 	struct request_queue *q = rq->q;
+	struct deadline_data *dd = q->elevator->elevator_data;
+	const u8 ioprio_class = dd_rq_ioclass(rq);
+	const enum dd_prio prio = ioprio_class_to_prio[ioprio_class];
+
+	if (rq->elv.priv[0])
+		atomic_inc(&dd->completed[prio]);
 
 	if (blk_queue_is_zoned(q)) {
-		struct deadline_data *dd = q->elevator->elevator_data;
 		unsigned long flags;
 
 		spin_lock_irqsave(&dd->zone_lock, flags);
 		blk_req_zone_write_unlock(rq);
-		if (!list_empty(&dd->fifo_list[DD_WRITE]))
+		if (!list_empty(&dd->fifo_list[prio][DD_WRITE]))
 			blk_mq_sched_mark_restart_hctx(rq->mq_hctx);
 		spin_unlock_irqrestore(&dd->zone_lock, flags);
 	}
 }
 
+static bool dd_has_work_for_prio(struct deadline_data *dd, enum dd_prio prio)
+{
+	return !list_empty_careful(&dd->dispatch[prio]) ||
+		!list_empty_careful(&dd->fifo_list[prio][DD_READ]) ||
+		!list_empty_careful(&dd->fifo_list[prio][DD_WRITE]);
+}
+
 static bool dd_has_work(struct blk_mq_hw_ctx *hctx)
 {
 	struct deadline_data *dd = hctx->queue->elevator->elevator_data;
+	enum dd_prio prio;
+
+	for (prio = 0; prio <= DD_PRIO_MAX; prio++)
+		if (dd_has_work_for_prio(dd, prio))
+			return true;
 
-	return !list_empty_careful(&dd->dispatch) ||
-		!list_empty_careful(&dd->fifo_list[0]) ||
-		!list_empty_careful(&dd->fifo_list[1]);
+	return false;
 }
 
 /*
@@ -707,7 +801,7 @@ static struct elv_fs_entry deadline_attrs[] = {
 };
 
 #ifdef CONFIG_BLK_DEBUG_FS
-#define DEADLINE_DEBUGFS_DDIR_ATTRS(ddir, name)				\
+#define DEADLINE_DEBUGFS_DDIR_ATTRS(prio, data_dir, name)		\
 static void *deadline_##name##_fifo_start(struct seq_file *m,		\
 					  loff_t *pos)			\
 	__acquires(&dd->lock)						\
@@ -716,7 +810,7 @@ static void *deadline_##name##_fifo_start(struct seq_file *m,		\
 	struct deadline_data *dd = q->elevator->elevator_data;		\
 									\
 	spin_lock(&dd->lock);						\
-	return seq_list_start(&dd->fifo_list[ddir], *pos);		\
+	return seq_list_start(&dd->fifo_list[prio][data_dir], *pos);	\
 }									\
 									\
 static void *deadline_##name##_fifo_next(struct seq_file *m, void *v,	\
@@ -725,7 +819,7 @@ static void *deadline_##name##_fifo_next(struct seq_file *m, void *v,	\
 	struct request_queue *q = m->private;				\
 	struct deadline_data *dd = q->elevator->elevator_data;		\
 									\
-	return seq_list_next(v, &dd->fifo_list[ddir], pos);		\
+	return seq_list_next(v, &dd->fifo_list[prio][data_dir], pos);	\
 }									\
 									\
 static void deadline_##name##_fifo_stop(struct seq_file *m, void *v)	\
@@ -742,22 +836,31 @@ static const struct seq_operations deadline_##name##_fifo_seq_ops = {	\
 	.next	= deadline_##name##_fifo_next,				\
 	.stop	= deadline_##name##_fifo_stop,				\
 	.show	= blk_mq_debugfs_rq_show,				\
-};									\
-									\
+};
+
+#define DEADLINE_DEBUGFS_NEXT_RQ(data_dir, name)			\
 static int deadline_##name##_next_rq_show(void *data,			\
 					  struct seq_file *m)		\
 {									\
 	struct request_queue *q = data;					\
 	struct deadline_data *dd = q->elevator->elevator_data;		\
-	struct request *rq = dd->next_rq[ddir];				\
+	struct request *rq = dd->next_rq[data_dir];			\
 									\
 	if (rq)								\
 		__blk_mq_debugfs_rq_show(m, rq);			\
 	return 0;							\
 }
-DEADLINE_DEBUGFS_DDIR_ATTRS(DD_READ, read)
-DEADLINE_DEBUGFS_DDIR_ATTRS(DD_WRITE, write)
+
+DEADLINE_DEBUGFS_DDIR_ATTRS(DD_RT_PRIO, DD_READ, read0)
+DEADLINE_DEBUGFS_DDIR_ATTRS(DD_RT_PRIO, DD_WRITE, write0)
+DEADLINE_DEBUGFS_DDIR_ATTRS(DD_BE_PRIO, DD_READ, read1)
+DEADLINE_DEBUGFS_DDIR_ATTRS(DD_BE_PRIO, DD_WRITE, write1)
+DEADLINE_DEBUGFS_DDIR_ATTRS(DD_IDLE_PRIO, DD_READ, read2)
+DEADLINE_DEBUGFS_DDIR_ATTRS(DD_IDLE_PRIO, DD_WRITE, write2)
+DEADLINE_DEBUGFS_NEXT_RQ(DD_READ, read)
+DEADLINE_DEBUGFS_NEXT_RQ(DD_WRITE, write)
 #undef DEADLINE_DEBUGFS_DDIR_ATTRS
+#undef DEADLINE_DEBUGFS_NEXT_RQ
 
 static int deadline_batching_show(void *data, struct seq_file *m)
 {
@@ -786,50 +889,100 @@ static int dd_async_depth_show(void *data, struct seq_file *m)
 	return 0;
 }
 
-static void *deadline_dispatch_start(struct seq_file *m, loff_t *pos)
-	__acquires(&dd->lock)
+static int dd_queued_show(void *data, struct seq_file *m)
 {
-	struct request_queue *q = m->private;
+	struct request_queue *q = data;
 	struct deadline_data *dd = q->elevator->elevator_data;
 
-	spin_lock(&dd->lock);
-	return seq_list_start(&dd->dispatch, *pos);
+	seq_printf(m, "%llu %llu %llu\n", dd_queued(dd, DD_RT_PRIO),
+		   dd_queued(dd, DD_BE_PRIO),
+		   dd_queued(dd, DD_IDLE_PRIO));
+	return 0;
 }
 
-static void *deadline_dispatch_next(struct seq_file *m, void *v, loff_t *pos)
+/* Number of requests owned by the block driver for a given priority. */
+static u64 dd_owned_by_driver(struct deadline_data *dd, enum dd_prio prio)
 {
-	struct request_queue *q = m->private;
-	struct deadline_data *dd = q->elevator->elevator_data;
-
-	return seq_list_next(v, &dd->dispatch, pos);
+	return atomic_read(&dd->dispatched[prio]) +
+		atomic_read(&dd->merged[prio]) -
+		atomic_read(&dd->completed[prio]);
 }
 
-static void deadline_dispatch_stop(struct seq_file *m, void *v)
-	__releases(&dd->lock)
+static int dd_owned_by_driver_show(void *data, struct seq_file *m)
 {
-	struct request_queue *q = m->private;
+	struct request_queue *q = data;
 	struct deadline_data *dd = q->elevator->elevator_data;
 
-	spin_unlock(&dd->lock);
+	seq_printf(m, "%llu %llu %llu\n", dd_owned_by_driver(dd, DD_RT_PRIO),
+		   dd_owned_by_driver(dd, DD_BE_PRIO),
+		   dd_owned_by_driver(dd, DD_IDLE_PRIO));
+	return 0;
 }
 
-static const struct seq_operations deadline_dispatch_seq_ops = {
-	.start	= deadline_dispatch_start,
-	.next	= deadline_dispatch_next,
-	.stop	= deadline_dispatch_stop,
-	.show	= blk_mq_debugfs_rq_show,
+#define DEADLINE_DISPATCH_ATTR(prio)					\
+static void *deadline_dispatch##prio##_start(struct seq_file *m,	\
+					     loff_t *pos)		\
+	__acquires(&dd->lock)						\
+{									\
+	struct request_queue *q = m->private;				\
+	struct deadline_data *dd = q->elevator->elevator_data;		\
+									\
+	spin_lock(&dd->lock);						\
+	return seq_list_start(&dd->dispatch[prio], *pos);		\
+}									\
+									\
+static void *deadline_dispatch##prio##_next(struct seq_file *m,		\
+					    void *v, loff_t *pos)	\
+{									\
+	struct request_queue *q = m->private;				\
+	struct deadline_data *dd = q->elevator->elevator_data;		\
+									\
+	return seq_list_next(v, &dd->dispatch[prio], pos);		\
+}									\
+									\
+static void deadline_dispatch##prio##_stop(struct seq_file *m, void *v)	\
+	__releases(&dd->lock)						\
+{									\
+	struct request_queue *q = m->private;				\
+	struct deadline_data *dd = q->elevator->elevator_data;		\
+									\
+	spin_unlock(&dd->lock);						\
+}									\
+									\
+static const struct seq_operations deadline_dispatch##prio##_seq_ops = { \
+	.start	= deadline_dispatch##prio##_start,			\
+	.next	= deadline_dispatch##prio##_next,			\
+	.stop	= deadline_dispatch##prio##_stop,			\
+	.show	= blk_mq_debugfs_rq_show,				\
 };
 
-#define DEADLINE_QUEUE_DDIR_ATTRS(name)						\
-	{#name "_fifo_list", 0400, .seq_ops = &deadline_##name##_fifo_seq_ops},	\
+DEADLINE_DISPATCH_ATTR(0);
+DEADLINE_DISPATCH_ATTR(1);
+DEADLINE_DISPATCH_ATTR(2);
+#undef DEADLINE_DISPATCH_ATTR
+
+#define DEADLINE_QUEUE_DDIR_ATTRS(name)					\
+	{#name "_fifo_list", 0400,					\
+			.seq_ops = &deadline_##name##_fifo_seq_ops}
+#define DEADLINE_NEXT_RQ_ATTR(name)					\
 	{#name "_next_rq", 0400, deadline_##name##_next_rq_show}
 static const struct blk_mq_debugfs_attr deadline_queue_debugfs_attrs[] = {
-	DEADLINE_QUEUE_DDIR_ATTRS(read),
-	DEADLINE_QUEUE_DDIR_ATTRS(write),
+	DEADLINE_QUEUE_DDIR_ATTRS(read0),
+	DEADLINE_QUEUE_DDIR_ATTRS(write0),
+	DEADLINE_QUEUE_DDIR_ATTRS(read1),
+	DEADLINE_QUEUE_DDIR_ATTRS(write1),
+	DEADLINE_QUEUE_DDIR_ATTRS(read2),
+	DEADLINE_QUEUE_DDIR_ATTRS(write2),
+	DEADLINE_NEXT_RQ_ATTR(read),
+	DEADLINE_NEXT_RQ_ATTR(write),
 	{"batching", 0400, deadline_batching_show},
 	{"starved", 0400, deadline_starved_show},
 	{"async_depth", 0400, dd_async_depth_show},
-	{"dispatch", 0400, .seq_ops = &deadline_dispatch_seq_ops},
+	{"dispatch0", 0400, .seq_ops = &deadline_dispatch0_seq_ops},
+	{"dispatch1", 0400, .seq_ops = &deadline_dispatch1_seq_ops},
+	{"dispatch2", 0400, .seq_ops = &deadline_dispatch2_seq_ops},
+	{"owned_by_driver", 0400, dd_owned_by_driver_show},
+	{"queued", 0400, dd_queued_show},
 	{},
 };
 #undef DEADLINE_QUEUE_DDIR_ATTRS
@@ -879,6 +1032,6 @@ static void __exit deadline_exit(void)
 module_init(deadline_init);
 module_exit(deadline_exit);
 
-MODULE_AUTHOR("Jens Axboe");
+MODULE_AUTHOR("Jens Axboe, Damien Le Moal and Bart Van Assche");
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("MQ deadline IO scheduler");
#46 lore raw

Re: [PATCH 8/9] block/mq-deadline: Add I/O priority support

Quoted 1 line · Bart Van Assche

Maintain one FIFO list per I/O priority: RT, BE and IDLE. Only dispatch

I/O priority -> I/O priority class. Since there is the prio level too, I think it is better to clarify that this acts only on the class, not the level. It may be good to mention that piro level is ignored.

Quoted 3 lines

requests for a lower priority after all higher priority requests have finished. Maintain statistics for each priority level. Split the debugfs attributes per priority level as follows:

s/priority level/priority class

Quoted 20 lines
$ ls /sys/kernel/debug/block/.../sched/
async_depth  dispatch2        read_next_rq      write2_fifo_list
batching     read0_fifo_list  starved           write_next_rq
dispatch0    read1_fifo_list  write0_fifo_list
dispatch1    read2_fifo_list  write1_fifo_list
Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/mq-deadline.c | 293 +++++++++++++++++++++++++++++++++-----------
 1 file changed, 223 insertions(+), 70 deletions(-)
block/mq-deadline.c +0 -0
index 81f487d77e09..5a703e1228fa 100644

block/mq-deadline.c enum dd_data_dir { · line 52

Quoted 9 lines
block/mq-deadline.c +6 -0
@@ -44,16 +44,27 @@ enum dd_data_dir {
 
 enum { DD_DIR_COUNT = 2 };
 
+enum dd_prio {
+	DD_RT_PRIO	= 0,
+	DD_BE_PRIO	= 1,
+	DD_IDLE_PRIO	= 2,
+	DD_PRIO_MAX	= 2,
+} __packed;

Why __packed ?

block/mq-deadline.c enum dd_data_dir { · line 54

Quoted 2 lines
block/mq-deadline.c +2 -0
+
+enum { DD_PRIO_COUNT = 3 };

#define ?

Quoted 63 lines
block/mq-deadline.c +26 -3
+
 struct deadline_data {
 	/*
 	 * run time data
 	 */
 
 	/*
-	 * requests (deadline_rq s) are present on both sort_list and fifo_list
+	 * Requests are present on both sort_list[] and fifo_list[][]. The
+	 * first index of fifo_list[][] is the I/O priority class (DD_*_PRIO).
+	 * The second index is the data direction (rq_data_dir(rq)).
 	 */
 	struct rb_root sort_list[DD_DIR_COUNT];
-	struct list_head fifo_list[DD_DIR_COUNT];
+	struct list_head fifo_list[DD_PRIO_COUNT][DD_DIR_COUNT];
 
 	/*
 	 * next in sort order. read, write or both are NULL
@@ -62,6 +73,12 @@ struct deadline_data {
 	unsigned int batching;		/* number of sequential requests made */
 	unsigned int starved;		/* times reads have starved writes */
 
+	/* statistics */
+	atomic_t inserted[DD_PRIO_COUNT];
+	atomic_t dispatched[DD_PRIO_COUNT];
+	atomic_t merged[DD_PRIO_COUNT];
+	atomic_t completed[DD_PRIO_COUNT];
+
 	/*
 	 * settings that change how the i/o scheduler behaves
 	 */
@@ -73,7 +90,15 @@ struct deadline_data {
 
 	spinlock_t lock;
 	spinlock_t zone_lock;
-	struct list_head dispatch;
+	struct list_head dispatch[DD_PRIO_COUNT];
+};
+
+/* Maps an I/O priority class to a deadline scheduler priority. */
+static const enum dd_prio ioprio_class_to_prio[] = {
+	[IOPRIO_CLASS_NONE]	= DD_BE_PRIO,
+	[IOPRIO_CLASS_RT]	= DD_RT_PRIO,
+	[IOPRIO_CLASS_BE]	= DD_BE_PRIO,
+	[IOPRIO_CLASS_IDLE]	= DD_IDLE_PRIO,
 };
 
 static inline struct rb_root *
@@ -149,12 +174,28 @@ static void dd_request_merged(struct request_queue *q, struct request *req,
 	}
 }
 
+/* Returns the I/O class that has been assigned by dd_insert_request(). */
+static u8 dd_rq_ioclass(struct request *rq)
+{
+	return (uintptr_t)rq->elv.priv[1];
+}
+
 /*
  * Callback function that is invoked after @next has been merged into @req.
  */
 static void dd_merged_requests(struct request_queue *q, struct request *req,
 			       struct request *next)

block/mq-deadline.c static void dd_request_merged(struct request_queue *q, struct request *req, · line 197

Quoted 10 lines
block/mq-deadline.c +9 -0
 {
+	struct deadline_data *dd = q->elevator->elevator_data;
+	const u8 ioprio_class = dd_rq_ioclass(next);
+	const enum dd_prio prio = ioprio_class_to_prio[ioprio_class];
+
+	if (next->elv.priv[0]) {
+		atomic_inc(&dd->merged[prio]);
+	} else {
+		WARN_ON_ONCE(true);
+	}

I do not think you need the curly braces here.

Quoted 142 lines
block/mq-deadline.c +31 -17
+
 	/*
 	 * if next expires before rq, assign its expire time to rq
 	 * and move into next position (next will be deleted) in fifo
@@ -191,14 +232,22 @@ deadline_move_request(struct deadline_data *dd, struct request *rq)
 	deadline_remove_request(rq->q, rq);
 }
 
+/* Number of requests queued for a given priority level. */
+static u64 dd_queued(struct deadline_data *dd, enum dd_prio prio)
+{
+	return atomic_read(&dd->inserted[prio]) -
+		atomic_read(&dd->completed[prio]);
+}
+
 /*
  * deadline_check_fifo returns 0 if there are no expired requests on the fifo,
  * 1 otherwise. Requires !list_empty(&dd->fifo_list[data_dir])
  */
 static inline int deadline_check_fifo(struct deadline_data *dd,
+				      enum dd_prio prio,
 				      enum dd_data_dir data_dir)
 {
-	struct request *rq = rq_entry_fifo(dd->fifo_list[data_dir].next);
+	struct request *rq = rq_entry_fifo(dd->fifo_list[prio][data_dir].next);
 
 	/*
 	 * rq is expired!
@@ -214,15 +263,16 @@ static inline int deadline_check_fifo(struct deadline_data *dd,
  * dispatch using arrival ordered lists.
  */
 static struct request *
-deadline_fifo_request(struct deadline_data *dd, enum dd_data_dir data_dir)
+deadline_fifo_request(struct deadline_data *dd, enum dd_prio prio,
+		      enum dd_data_dir data_dir)
 {
 	struct request *rq;
 	unsigned long flags;
 
-	if (list_empty(&dd->fifo_list[data_dir]))
+	if (list_empty(&dd->fifo_list[prio][data_dir]))
 		return NULL;
 
-	rq = rq_entry_fifo(dd->fifo_list[data_dir].next);
+	rq = rq_entry_fifo(dd->fifo_list[prio][data_dir].next);
 	if (data_dir == DD_READ || !blk_queue_is_zoned(rq->q))
 		return rq;
 
@@ -231,7 +281,7 @@ deadline_fifo_request(struct deadline_data *dd, enum dd_data_dir data_dir)
 	 * an unlocked target zone.
 	 */
 	spin_lock_irqsave(&dd->zone_lock, flags);
-	list_for_each_entry(rq, &dd->fifo_list[DD_WRITE], queuelist) {
+	list_for_each_entry(rq, &dd->fifo_list[prio][DD_WRITE], queuelist) {
 		if (blk_req_can_dispatch_to_zone(rq))
 			goto out;
 	}
@@ -247,7 +297,8 @@ deadline_fifo_request(struct deadline_data *dd, enum dd_data_dir data_dir)
  * dispatch using sector position sorted lists.
  */
 static struct request *
-deadline_next_request(struct deadline_data *dd, enum dd_data_dir data_dir)
+deadline_next_request(struct deadline_data *dd, enum dd_prio prio,
+		      enum dd_data_dir data_dir)
 {
 	struct request *rq;
 	unsigned long flags;
@@ -278,15 +329,18 @@ deadline_next_request(struct deadline_data *dd, enum dd_data_dir data_dir)
  * deadline_dispatch_requests selects the best request according to
  * read/write expire, fifo_batch, etc
  */
-static struct request *__dd_dispatch_request(struct deadline_data *dd)
+static struct request *__dd_dispatch_request(struct deadline_data *dd,
+					     enum dd_prio prio)
 {
 	struct request *rq, *next_rq;
 	enum dd_data_dir data_dir;
+	u8 ioprio_class;
 
 	lockdep_assert_held(&dd->lock);
 
-	if (!list_empty(&dd->dispatch)) {
-		rq = list_first_entry(&dd->dispatch, struct request, queuelist);
+	if (!list_empty(&dd->dispatch[prio])) {
+		rq = list_first_entry(&dd->dispatch[prio], struct request,
+				      queuelist);
 		list_del_init(&rq->queuelist);
 		goto done;
 	}
@@ -294,9 +348,9 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
 	/*
 	 * batches are currently reads XOR writes
 	 */
-	rq = deadline_next_request(dd, DD_WRITE);
+	rq = deadline_next_request(dd, prio, DD_WRITE);
 	if (!rq)
-		rq = deadline_next_request(dd, DD_READ);
+		rq = deadline_next_request(dd, prio, DD_READ);
 
 	if (rq && dd->batching < dd->fifo_batch)
 		/* we have a next request are still entitled to batch */
@@ -307,10 +361,10 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
 	 * data direction (read / write)
 	 */
 
-	if (!list_empty(&dd->fifo_list[DD_READ])) {
+	if (!list_empty(&dd->fifo_list[prio][DD_READ])) {
 		BUG_ON(RB_EMPTY_ROOT(&dd->sort_list[DD_READ]));
 
-		if (deadline_fifo_request(dd, DD_WRITE) &&
+		if (deadline_fifo_request(dd, prio, DD_WRITE) &&
 		    (dd->starved++ >= dd->writes_starved))
 			goto dispatch_writes;
 
@@ -323,7 +377,7 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
 	 * there are either no reads or writes have been starved
 	 */
 
-	if (!list_empty(&dd->fifo_list[DD_WRITE])) {
+	if (!list_empty(&dd->fifo_list[prio][DD_WRITE])) {
 dispatch_writes:
 		BUG_ON(RB_EMPTY_ROOT(&dd->sort_list[DD_WRITE]));
 
@@ -340,14 +394,14 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
 	/*
 	 * we are not running a batch, find best request for selected data_dir
 	 */
-	next_rq = deadline_next_request(dd, data_dir);
-	if (deadline_check_fifo(dd, data_dir) || !next_rq) {
+	next_rq = deadline_next_request(dd, prio, data_dir);
+	if (deadline_check_fifo(dd, prio, data_dir) || !next_rq) {
 		/*
 		 * A deadline has expired, the last request was in the other
 		 * direction, or we have run out of higher-sectored requests.
 		 * Start again from the request with the earliest expiry time.
 		 */
-		rq = deadline_fifo_request(dd, data_dir);
+		rq = deadline_fifo_request(dd, prio, data_dir);
 	} else {
 		/*
 		 * The last req was the same dir and we have a next request in

block/mq-deadline.c static struct request *__dd_dispatch_request(struct deadline_data *dd) · line 435

Quoted 10 lines
block/mq-deadline.c +7 -0
@@ -372,6 +426,13 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd)
 	dd->batching++;
 	deadline_move_request(dd, rq);
 done:
+	ioprio_class = dd_rq_ioclass(rq);
+	prio = ioprio_class_to_prio[ioprio_class];
+	if (rq->elv.priv[0]) {
+		atomic_inc(&dd->dispatched[prio]);
+	} else {
+		WARN_ON_ONCE(true);
+	}

No need for the curly braces.

Quoted 7 lines
block/mq-deadline.c +0 -0
 	/*
 	 * If the request needs its target zone locked, do it.
 	 */
@@ -392,9 +453,14 @@ static struct request *dd_dispatch_request(struct blk_mq_hw_ctx *hctx)
 {
 	struct deadline_data *dd = hctx->queue->elevator->elevator_data;
 	struct request *rq;

block/mq-deadline.c static struct request *dd_dispatch_request(struct blk_mq_hw_ctx *hctx) · line 464

Quoted 10 lines
block/mq-deadline.c +6 -1
+	enum dd_prio prio;
 
 	spin_lock(&dd->lock);
-	rq = __dd_dispatch_request(dd);
+	for (prio = 0; prio <= DD_PRIO_MAX; prio++) {
+		rq = __dd_dispatch_request(dd, prio);
+		if (rq || dd_queued(dd, prio))
+			break;
+	}
 	spin_unlock(&dd->lock);

Unless I missed something, this means that the aging (fifo list expire) mechanism is per prio list but there is no aging between the prio classes. This means that an application doing lots of RT direct IOs will completely starve other prio classes and hang the applications using them.

I think we need aging between the prio classes too to avoid that. Otherwise, that.

Quoted 347 lines
block/mq-deadline.c +136 -49
 	return rq;
@@ -435,9 +501,12 @@ static int dd_init_hctx(struct blk_mq_hw_ctx *hctx, unsigned int hctx_idx)
 static void dd_exit_sched(struct elevator_queue *e)
 {
 	struct deadline_data *dd = e->elevator_data;
+	enum dd_prio prio;
 
-	BUG_ON(!list_empty(&dd->fifo_list[DD_READ]));
-	BUG_ON(!list_empty(&dd->fifo_list[DD_WRITE]));
+	for (prio = 0; prio <= DD_PRIO_MAX; prio++) {
+		WARN_ON_ONCE(!list_empty(&dd->fifo_list[prio][DD_READ]));
+		WARN_ON_ONCE(!list_empty(&dd->fifo_list[prio][DD_WRITE]));
+	}
 
 	kfree(dd);
 }
@@ -449,6 +518,7 @@ static int dd_init_sched(struct request_queue *q, struct elevator_type *e)
 {
 	struct deadline_data *dd;
 	struct elevator_queue *eq;
+	enum dd_prio prio;
 
 	eq = elevator_alloc(q, e);
 	if (!eq)
@@ -461,8 +531,11 @@ static int dd_init_sched(struct request_queue *q, struct elevator_type *e)
 	}
 	eq->elevator_data = dd;
 
-	INIT_LIST_HEAD(&dd->fifo_list[DD_READ]);
-	INIT_LIST_HEAD(&dd->fifo_list[DD_WRITE]);
+	for (prio = 0; prio <= DD_PRIO_MAX; prio++) {
+		INIT_LIST_HEAD(&dd->fifo_list[prio][DD_READ]);
+		INIT_LIST_HEAD(&dd->fifo_list[prio][DD_WRITE]);
+		INIT_LIST_HEAD(&dd->dispatch[prio]);
+	}
 	dd->sort_list[DD_READ] = RB_ROOT;
 	dd->sort_list[DD_WRITE] = RB_ROOT;
 	dd->fifo_expire[DD_READ] = blk_queue_nonrot(q) ? read_expire_nonrot :
@@ -473,7 +546,6 @@ static int dd_init_sched(struct request_queue *q, struct elevator_type *e)
 	dd->fifo_batch = fifo_batch;
 	spin_lock_init(&dd->lock);
 	spin_lock_init(&dd->zone_lock);
-	INIT_LIST_HEAD(&dd->dispatch);
 
 	q->elevator = eq;
 	return 0;
@@ -536,6 +608,9 @@ static void dd_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
 	struct request_queue *q = hctx->queue;
 	struct deadline_data *dd = q->elevator->elevator_data;
 	const enum dd_data_dir data_dir = rq_data_dir(rq);
+	u16 ioprio = req_get_ioprio(rq);
+	u8 ioprio_class = IOPRIO_PRIO_CLASS(ioprio);
+	enum dd_prio prio;
 
 	lockdep_assert_held(&dd->lock);
 
@@ -545,13 +620,19 @@ static void dd_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
 	 */
 	blk_req_zone_write_unlock(rq);
 
+	prio = ioprio_class_to_prio[ioprio_class];
+	atomic_inc(&dd->inserted[prio]);
+	WARN_ON_ONCE(rq->elv.priv[0]);
+	rq->elv.priv[0] = (void *)1ULL;
+	rq->elv.priv[1] = (void *)(uintptr_t)ioprio_class;
+
 	if (blk_mq_sched_try_insert_merge(q, rq))
 		return;
 
 	trace_block_rq_insert(rq);
 
 	if (at_head) {
-		list_add(&rq->queuelist, &dd->dispatch);
+		list_add(&rq->queuelist, &dd->dispatch[prio]);
 	} else {
 		deadline_add_rq_rb(dd, rq);
 
@@ -565,7 +646,7 @@ static void dd_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
 		 * set expire time and add to fifo list
 		 */
 		rq->fifo_time = jiffies + dd->fifo_expire[data_dir];
-		list_add_tail(&rq->queuelist, &dd->fifo_list[data_dir]);
+		list_add_tail(&rq->queuelist, &dd->fifo_list[prio][data_dir]);
 	}
 }
 
@@ -589,12 +670,10 @@ static void dd_insert_requests(struct blk_mq_hw_ctx *hctx,
 	spin_unlock(&dd->lock);
 }
 
-/*
- * Nothing to do here. This is defined only to ensure that .finish_request
- * method is called upon request completion.
- */
+/* Callback function called from inside blk_mq_rq_ctx_init(). */
 static void dd_prepare_request(struct request *rq)
 {
+	rq->elv.priv[0] = NULL;
 }
 
 /*
@@ -616,26 +695,41 @@ static void dd_prepare_request(struct request *rq)
 static void dd_finish_request(struct request *rq)
 {
 	struct request_queue *q = rq->q;
+	struct deadline_data *dd = q->elevator->elevator_data;
+	const u8 ioprio_class = dd_rq_ioclass(rq);
+	const enum dd_prio prio = ioprio_class_to_prio[ioprio_class];
+
+	if (rq->elv.priv[0])
+		atomic_inc(&dd->completed[prio]);
 
 	if (blk_queue_is_zoned(q)) {
-		struct deadline_data *dd = q->elevator->elevator_data;
 		unsigned long flags;
 
 		spin_lock_irqsave(&dd->zone_lock, flags);
 		blk_req_zone_write_unlock(rq);
-		if (!list_empty(&dd->fifo_list[DD_WRITE]))
+		if (!list_empty(&dd->fifo_list[prio][DD_WRITE]))
 			blk_mq_sched_mark_restart_hctx(rq->mq_hctx);
 		spin_unlock_irqrestore(&dd->zone_lock, flags);
 	}
 }
 
+static bool dd_has_work_for_prio(struct deadline_data *dd, enum dd_prio prio)
+{
+	return !list_empty_careful(&dd->dispatch[prio]) ||
+		!list_empty_careful(&dd->fifo_list[prio][DD_READ]) ||
+		!list_empty_careful(&dd->fifo_list[prio][DD_WRITE]);
+}
+
 static bool dd_has_work(struct blk_mq_hw_ctx *hctx)
 {
 	struct deadline_data *dd = hctx->queue->elevator->elevator_data;
+	enum dd_prio prio;
+
+	for (prio = 0; prio <= DD_PRIO_MAX; prio++)
+		if (dd_has_work_for_prio(dd, prio))
+			return true;
 
-	return !list_empty_careful(&dd->dispatch) ||
-		!list_empty_careful(&dd->fifo_list[0]) ||
-		!list_empty_careful(&dd->fifo_list[1]);
+	return false;
 }
 
 /*
@@ -707,7 +801,7 @@ static struct elv_fs_entry deadline_attrs[] = {
 };
 
 #ifdef CONFIG_BLK_DEBUG_FS
-#define DEADLINE_DEBUGFS_DDIR_ATTRS(ddir, name)				\
+#define DEADLINE_DEBUGFS_DDIR_ATTRS(prio, data_dir, name)		\
 static void *deadline_##name##_fifo_start(struct seq_file *m,		\
 					  loff_t *pos)			\
 	__acquires(&dd->lock)						\
@@ -716,7 +810,7 @@ static void *deadline_##name##_fifo_start(struct seq_file *m,		\
 	struct deadline_data *dd = q->elevator->elevator_data;		\
 									\
 	spin_lock(&dd->lock);						\
-	return seq_list_start(&dd->fifo_list[ddir], *pos);		\
+	return seq_list_start(&dd->fifo_list[prio][data_dir], *pos);	\
 }									\
 									\
 static void *deadline_##name##_fifo_next(struct seq_file *m, void *v,	\
@@ -725,7 +819,7 @@ static void *deadline_##name##_fifo_next(struct seq_file *m, void *v,	\
 	struct request_queue *q = m->private;				\
 	struct deadline_data *dd = q->elevator->elevator_data;		\
 									\
-	return seq_list_next(v, &dd->fifo_list[ddir], pos);		\
+	return seq_list_next(v, &dd->fifo_list[prio][data_dir], pos);	\
 }									\
 									\
 static void deadline_##name##_fifo_stop(struct seq_file *m, void *v)	\
@@ -742,22 +836,31 @@ static const struct seq_operations deadline_##name##_fifo_seq_ops = {	\
 	.next	= deadline_##name##_fifo_next,				\
 	.stop	= deadline_##name##_fifo_stop,				\
 	.show	= blk_mq_debugfs_rq_show,				\
-};									\
-									\
+};
+
+#define DEADLINE_DEBUGFS_NEXT_RQ(data_dir, name)			\
 static int deadline_##name##_next_rq_show(void *data,			\
 					  struct seq_file *m)		\
 {									\
 	struct request_queue *q = data;					\
 	struct deadline_data *dd = q->elevator->elevator_data;		\
-	struct request *rq = dd->next_rq[ddir];				\
+	struct request *rq = dd->next_rq[data_dir];			\
 									\
 	if (rq)								\
 		__blk_mq_debugfs_rq_show(m, rq);			\
 	return 0;							\
 }
-DEADLINE_DEBUGFS_DDIR_ATTRS(DD_READ, read)
-DEADLINE_DEBUGFS_DDIR_ATTRS(DD_WRITE, write)
+
+DEADLINE_DEBUGFS_DDIR_ATTRS(DD_RT_PRIO, DD_READ, read0)
+DEADLINE_DEBUGFS_DDIR_ATTRS(DD_RT_PRIO, DD_WRITE, write0)
+DEADLINE_DEBUGFS_DDIR_ATTRS(DD_BE_PRIO, DD_READ, read1)
+DEADLINE_DEBUGFS_DDIR_ATTRS(DD_BE_PRIO, DD_WRITE, write1)
+DEADLINE_DEBUGFS_DDIR_ATTRS(DD_IDLE_PRIO, DD_READ, read2)
+DEADLINE_DEBUGFS_DDIR_ATTRS(DD_IDLE_PRIO, DD_WRITE, write2)
+DEADLINE_DEBUGFS_NEXT_RQ(DD_READ, read)
+DEADLINE_DEBUGFS_NEXT_RQ(DD_WRITE, write)
 #undef DEADLINE_DEBUGFS_DDIR_ATTRS
+#undef DEADLINE_DEBUGFS_NEXT_RQ
 
 static int deadline_batching_show(void *data, struct seq_file *m)
 {
@@ -786,50 +889,100 @@ static int dd_async_depth_show(void *data, struct seq_file *m)
 	return 0;
 }
 
-static void *deadline_dispatch_start(struct seq_file *m, loff_t *pos)
-	__acquires(&dd->lock)
+static int dd_queued_show(void *data, struct seq_file *m)
 {
-	struct request_queue *q = m->private;
+	struct request_queue *q = data;
 	struct deadline_data *dd = q->elevator->elevator_data;
 
-	spin_lock(&dd->lock);
-	return seq_list_start(&dd->dispatch, *pos);
+	seq_printf(m, "%llu %llu %llu\n", dd_queued(dd, DD_RT_PRIO),
+		   dd_queued(dd, DD_BE_PRIO),
+		   dd_queued(dd, DD_IDLE_PRIO));
+	return 0;
 }
 
-static void *deadline_dispatch_next(struct seq_file *m, void *v, loff_t *pos)
+/* Number of requests owned by the block driver for a given priority. */
+static u64 dd_owned_by_driver(struct deadline_data *dd, enum dd_prio prio)
 {
-	struct request_queue *q = m->private;
-	struct deadline_data *dd = q->elevator->elevator_data;
-
-	return seq_list_next(v, &dd->dispatch, pos);
+	return atomic_read(&dd->dispatched[prio]) +
+		atomic_read(&dd->merged[prio]) -
+		atomic_read(&dd->completed[prio]);
 }
 
-static void deadline_dispatch_stop(struct seq_file *m, void *v)
-	__releases(&dd->lock)
+static int dd_owned_by_driver_show(void *data, struct seq_file *m)
 {
-	struct request_queue *q = m->private;
+	struct request_queue *q = data;
 	struct deadline_data *dd = q->elevator->elevator_data;
 
-	spin_unlock(&dd->lock);
+	seq_printf(m, "%llu %llu %llu\n", dd_owned_by_driver(dd, DD_RT_PRIO),
+		   dd_owned_by_driver(dd, DD_BE_PRIO),
+		   dd_owned_by_driver(dd, DD_IDLE_PRIO));
+	return 0;
 }
 
-static const struct seq_operations deadline_dispatch_seq_ops = {
-	.start	= deadline_dispatch_start,
-	.next	= deadline_dispatch_next,
-	.stop	= deadline_dispatch_stop,
-	.show	= blk_mq_debugfs_rq_show,
+#define DEADLINE_DISPATCH_ATTR(prio)					\
+static void *deadline_dispatch##prio##_start(struct seq_file *m,	\
+					     loff_t *pos)		\
+	__acquires(&dd->lock)						\
+{									\
+	struct request_queue *q = m->private;				\
+	struct deadline_data *dd = q->elevator->elevator_data;		\
+									\
+	spin_lock(&dd->lock);						\
+	return seq_list_start(&dd->dispatch[prio], *pos);		\
+}									\
+									\
+static void *deadline_dispatch##prio##_next(struct seq_file *m,		\
+					    void *v, loff_t *pos)	\
+{									\
+	struct request_queue *q = m->private;				\
+	struct deadline_data *dd = q->elevator->elevator_data;		\
+									\
+	return seq_list_next(v, &dd->dispatch[prio], pos);		\
+}									\
+									\
+static void deadline_dispatch##prio##_stop(struct seq_file *m, void *v)	\
+	__releases(&dd->lock)						\
+{									\
+	struct request_queue *q = m->private;				\
+	struct deadline_data *dd = q->elevator->elevator_data;		\
+									\
+	spin_unlock(&dd->lock);						\
+}									\
+									\
+static const struct seq_operations deadline_dispatch##prio##_seq_ops = { \
+	.start	= deadline_dispatch##prio##_start,			\
+	.next	= deadline_dispatch##prio##_next,			\
+	.stop	= deadline_dispatch##prio##_stop,			\
+	.show	= blk_mq_debugfs_rq_show,				\
 };
 
-#define DEADLINE_QUEUE_DDIR_ATTRS(name)						\
-	{#name "_fifo_list", 0400, .seq_ops = &deadline_##name##_fifo_seq_ops},	\
+DEADLINE_DISPATCH_ATTR(0);
+DEADLINE_DISPATCH_ATTR(1);
+DEADLINE_DISPATCH_ATTR(2);
+#undef DEADLINE_DISPATCH_ATTR
+
+#define DEADLINE_QUEUE_DDIR_ATTRS(name)					\
+	{#name "_fifo_list", 0400,					\
+			.seq_ops = &deadline_##name##_fifo_seq_ops}
+#define DEADLINE_NEXT_RQ_ATTR(name)					\
 	{#name "_next_rq", 0400, deadline_##name##_next_rq_show}
 static const struct blk_mq_debugfs_attr deadline_queue_debugfs_attrs[] = {
-	DEADLINE_QUEUE_DDIR_ATTRS(read),
-	DEADLINE_QUEUE_DDIR_ATTRS(write),
+	DEADLINE_QUEUE_DDIR_ATTRS(read0),
+	DEADLINE_QUEUE_DDIR_ATTRS(write0),
+	DEADLINE_QUEUE_DDIR_ATTRS(read1),
+	DEADLINE_QUEUE_DDIR_ATTRS(write1),
+	DEADLINE_QUEUE_DDIR_ATTRS(read2),
+	DEADLINE_QUEUE_DDIR_ATTRS(write2),
+	DEADLINE_NEXT_RQ_ATTR(read),
+	DEADLINE_NEXT_RQ_ATTR(write),
 	{"batching", 0400, deadline_batching_show},
 	{"starved", 0400, deadline_starved_show},
 	{"async_depth", 0400, dd_async_depth_show},
-	{"dispatch", 0400, .seq_ops = &deadline_dispatch_seq_ops},
+	{"dispatch0", 0400, .seq_ops = &deadline_dispatch0_seq_ops},
+	{"dispatch1", 0400, .seq_ops = &deadline_dispatch1_seq_ops},
+	{"dispatch2", 0400, .seq_ops = &deadline_dispatch2_seq_ops},
+	{"owned_by_driver", 0400, dd_owned_by_driver_show},
+	{"queued", 0400, dd_queued_show},
 	{},
 };
 #undef DEADLINE_QUEUE_DDIR_ATTRS
@@ -879,6 +1032,6 @@ static void __exit deadline_exit(void)
 module_init(deadline_init);
 module_exit(deadline_exit);
 
-MODULE_AUTHOR("Jens Axboe");
+MODULE_AUTHOR("Jens Axboe, Damien Le Moal and Bart Van Assche");
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("MQ deadline IO scheduler");
Signature · 2 lines
Damien Le Moal
Western Digital Research
#47 lore raw

Re: [PATCH 8/9] block/mq-deadline: Add I/O priority support

Quoted 8 lines · Damien Le Moal

block/mq-deadline.c static void dd_request_merged(struct request_queue *q, struct request *req, · line 197

Quoted 5 lines · Bart Van Assche
block/mq-deadline.c +5 -0
+	if (next->elv.priv[0]) {
+		atomic_inc(&dd->merged[prio]);
+	} else {
+		WARN_ON_ONCE(true);
+	}

I do not think you need the curly braces here.

These are present because patch 9/9 adds more code in this if-statement and to improve readability of patch 9/9.

Quoted 20 lines
Quoted 4 lines
block/mq-deadline.c +0 -0
@@ -392,9 +453,14 @@ static struct request *dd_dispatch_request(struct blk_mq_hw_ctx *hctx)
 {
 	struct deadline_data *dd = hctx->queue->elevator->elevator_data;
 	struct request *rq;

block/mq-deadline.c static struct request *dd_dispatch_request(struct blk_mq_hw_ctx *hctx) · line 464

Quoted 10 lines
block/mq-deadline.c +6 -1
+	enum dd_prio prio;
 
 	spin_lock(&dd->lock);
-	rq = __dd_dispatch_request(dd);
+	for (prio = 0; prio <= DD_PRIO_MAX; prio++) {
+		rq = __dd_dispatch_request(dd, prio);
+		if (rq || dd_queued(dd, prio))
+			break;
+	}
 	spin_unlock(&dd->lock);

Unless I missed something, this means that the aging (fifo list expire) mechanism is per prio list but there is no aging between the prio classes. This means that an application doing lots of RT direct IOs will completely starve other prio classes and hang the applications using them.

Quoted 1 line

I think we need aging between the prio classes too to avoid that.

OK, I will add an aging mechanism.

Bart.

#48 lore raw

Re: [PATCH 8/9] block/mq-deadline: Add I/O priority support

In reply to Bart Van Assche
Quoted 11 lines · Bart Van Assche

Maintain one FIFO list per I/O priority: RT, BE and IDLE. Only dispatch requests for a lower priority after all higher priority requests have finished. Maintain statistics for each priority level. Split the debugfs attributes per priority level as follows:

$ ls /sys/kernel/debug/block/.../sched/
async_depth  dispatch2        read_next_rq      write2_fifo_list
batching     read0_fifo_list  starved           write_next_rq
dispatch0    read1_fifo_list  write0_fifo_list
dispatch1    read2_fifo_list  write1_fifo_list
Quoted 8 lines
Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/mq-deadline.c | 293 +++++++++++++++++++++++++++++++++-----------
 1 file changed, 223 insertions(+), 70 deletions(-)

Interesting question, though, wrt to request merging and realtime
priority: what takes priority?
Is the realtime priority more important than request merging?

And also the ioprio document states that there are 8 levels of class data, determining how much time each class should spend on disk access. Have these been taken into consideration?

Quoted 107 lines
block/mq-deadline.c +51 -3
index 81f487d77e09..5a703e1228fa 100644
@@ -44,16 +44,27 @@ enum dd_data_dir {
 
 enum { DD_DIR_COUNT = 2 };
 
+enum dd_prio {
+	DD_RT_PRIO	= 0,
+	DD_BE_PRIO	= 1,
+	DD_IDLE_PRIO	= 2,
+	DD_PRIO_MAX	= 2,
+} __packed;
+
+enum { DD_PRIO_COUNT = 3 };
+
 struct deadline_data {
 	/*
 	 * run time data
 	 */
 
 	/*
-	 * requests (deadline_rq s) are present on both sort_list and fifo_list
+	 * Requests are present on both sort_list[] and fifo_list[][]. The
+	 * first index of fifo_list[][] is the I/O priority class (DD_*_PRIO).
+	 * The second index is the data direction (rq_data_dir(rq)).
 	 */
 	struct rb_root sort_list[DD_DIR_COUNT];
-	struct list_head fifo_list[DD_DIR_COUNT];
+	struct list_head fifo_list[DD_PRIO_COUNT][DD_DIR_COUNT];
 
 	/*
 	 * next in sort order. read, write or both are NULL
@@ -62,6 +73,12 @@ struct deadline_data {
 	unsigned int batching;		/* number of sequential requests made */
 	unsigned int starved;		/* times reads have starved writes */
 
+	/* statistics */
+	atomic_t inserted[DD_PRIO_COUNT];
+	atomic_t dispatched[DD_PRIO_COUNT];
+	atomic_t merged[DD_PRIO_COUNT];
+	atomic_t completed[DD_PRIO_COUNT];
+
 	/*
 	 * settings that change how the i/o scheduler behaves
 	 */
@@ -73,7 +90,15 @@ struct deadline_data {
 
 	spinlock_t lock;
 	spinlock_t zone_lock;
-	struct list_head dispatch;
+	struct list_head dispatch[DD_PRIO_COUNT];
+};
+
+/* Maps an I/O priority class to a deadline scheduler priority. */
+static const enum dd_prio ioprio_class_to_prio[] = {
+	[IOPRIO_CLASS_NONE]	= DD_BE_PRIO,
+	[IOPRIO_CLASS_RT]	= DD_RT_PRIO,
+	[IOPRIO_CLASS_BE]	= DD_BE_PRIO,
+	[IOPRIO_CLASS_IDLE]	= DD_IDLE_PRIO,
 };
 
 static inline struct rb_root *
@@ -149,12 +174,28 @@ static void dd_request_merged(struct request_queue *q, struct request *req,
 	}
 }
 
+/* Returns the I/O class that has been assigned by dd_insert_request(). */
+static u8 dd_rq_ioclass(struct request *rq)
+{
+	return (uintptr_t)rq->elv.priv[1];
+}
+
 /*
  * Callback function that is invoked after @next has been merged into @req.
  */
 static void dd_merged_requests(struct request_queue *q, struct request *req,
 			       struct request *next)
 {
+	struct deadline_data *dd = q->elevator->elevator_data;
+	const u8 ioprio_class = dd_rq_ioclass(next);
+	const enum dd_prio prio = ioprio_class_to_prio[ioprio_class];
+
+	if (next->elv.priv[0]) {
+		atomic_inc(&dd->merged[prio]);
+	} else {
+		WARN_ON_ONCE(true);
+	}
+
 	/*
 	 * if next expires before rq, assign its expire time to rq
 	 * and move into next position (next will be deleted) in fifo
@@ -191,14 +232,22 @@ deadline_move_request(struct deadline_data *dd, struct request *rq)
 	deadline_remove_request(rq->q, rq);
 }
 
+/* Number of requests queued for a given priority level. */
+static u64 dd_queued(struct deadline_data *dd, enum dd_prio prio)
+{
+	return atomic_read(&dd->inserted[prio]) -
+		atomic_read(&dd->completed[prio]);
+}
+
 /*
  * deadline_check_fifo returns 0 if there are no expired requests on the fifo,
  * 1 otherwise. Requires !list_empty(&dd->fifo_list[data_dir])

block/mq-deadline.c deadline_move_request(struct deadline_data *dd, struct request *rq) · line 253

Quoted 10 lines
block/mq-deadline.c +2 -1
  */
 static inline int deadline_check_fifo(struct deadline_data *dd,
+				      enum dd_prio prio,
 				      enum dd_data_dir data_dir)
 {
-	struct request *rq = rq_entry_fifo(dd->fifo_list[data_dir].next);
+	struct request *rq = rq_entry_fifo(dd->fifo_list[prio][data_dir].next);
 
 	/*
 	 * rq is expired!

I am _so_ not a fan of arrays in C.
Can't you make this an accessor and use
dd->fifo_list[prio * 2 + data_dir] ?

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke		        Kernel Storage Architect
[email protected]			               +49 911 74053 688
SUSE Software Solutions Germany GmbH, 90409 Nürnberg
GF: F. Imendörffer, HRB 36809 (AG Nürnberg)
#49 lore raw

Re: [PATCH 8/9] block/mq-deadline: Add I/O priority support

Quoted 12 lines · Hannes Reinecke
Quoted 10 lines · Bart Van Assche

Maintain one FIFO list per I/O priority: RT, BE and IDLE. Only dispatch requests for a lower priority after all higher priority requests have finished. Maintain statistics for each priority level. Split the debugfs attributes per priority level as follows:

$ ls /sys/kernel/debug/block/.../sched/
async_depth  dispatch2        read_next_rq      write2_fifo_list
batching     read0_fifo_list  starved           write_next_rq
dispatch0    read1_fifo_list  write0_fifo_list
dispatch1    read2_fifo_list  write1_fifo_list
Quoted 3 lines

Interesting question, though, wrt to request merging and realtime
priority: what takes priority?
Is the realtime priority more important than request merging?

We plan to use two I/O priorities: one for foreground applications and one for background applications. We want to lower the application startup time if background I/O is ongoing. The code that associates different cgroups with foreground and background applications is already available. We care more about foreground I/O being prioritized over background I/O than about foreground I/O being real-time.

Quoted 3 lines

And also the ioprio document states that there are 8 levels of class data, determining how much time each class should spend on disk access. Have these been taken into consideration?

My understanding is that the ioprio document was written before any I/O controllers implemented I/O priorities. I'm not sure whether I/O controllers will ever implement more than two I/O priorities. See also commit 8e061784b51e ("ata: Enabling ATA Command Priorities"). A paper about the benefits of I/O controllers supporting I/O priorities is available at
https://www.usenix.org/system/files/conference/hotstorage17/hotstorage17-paper-manzanares.pdf.

Quoted 11 lines
Quoted 11 lines

/*
* deadline_check_fifo returns 0 if there are no expired requests on the fifo,
* 1 otherwise. Requires !list_empty(&dd->fifo_list[data_dir])
*/
static inline int deadline_check_fifo(struct deadline_data *dd,

block/mq-deadline.c +2 -1
+				      enum dd_prio prio,
 				      enum dd_data_dir data_dir)
 {
-	struct request *rq = rq_entry_fifo(dd->fifo_list[data_dir].next);
+	struct request *rq = rq_entry_fifo(dd->fifo_list[prio][data_dir].next);
Quoted 6 lines

block/mq-deadline.c deadline_move_request(struct deadline_data *dd, struct request *rq) · line 253

Quoted 2 lines
block/mq-deadline.c +0 -0
 	/*
 	 * rq is expired!

I am _so_ not a fan of arrays in C.
Can't you make this an accessor and use
dd->fifo_list[prio * 2 + data_dir] ?

That's possible, but if the compiler can translate [prio][data_dir] into [prio * 2 + data_dir], should I really do this myself instead of letting the compiler generate that transformation?

Thanks,

Bart.

#50 lore raw

Re: [PATCH 8/9] block/mq-deadline: Add I/O priority support

Quoted 28 lines · Bart Van Assche
Quoted 12 lines · Hannes Reinecke
Quoted 10 lines · Bart Van Assche

Maintain one FIFO list per I/O priority: RT, BE and IDLE. Only dispatch requests for a lower priority after all higher priority requests have finished. Maintain statistics for each priority level. Split the debugfs attributes per priority level as follows:

$ ls /sys/kernel/debug/block/.../sched/
async_depth  dispatch2        read_next_rq      write2_fifo_list
batching     read0_fifo_list  starved           write_next_rq
dispatch0    read1_fifo_list  write0_fifo_list
dispatch1    read2_fifo_list  write1_fifo_list
Quoted 3 lines

Interesting question, though, wrt to request merging and realtime
priority: what takes priority?
Is the realtime priority more important than request merging?

We plan to use two I/O priorities: one for foreground applications and one for background applications. We want to lower the application startup time if background I/O is ongoing. The code that associates different cgroups with foreground and background applications is already available. We care more about foreground I/O being prioritized over background I/O than about foreground I/O being real-time.

Quoted 3 lines

And also the ioprio document states that there are 8 levels of class data, determining how much time each class should spend on disk access. Have these been taken into consideration?

Quoted 7 lines

My understanding is that the ioprio document was written before any I/O controllers implemented I/O priorities. I'm not sure whether I/O controllers will ever implement more than two I/O priorities. See also commit 8e061784b51e ("ata: Enabling ATA Command Priorities"). A paper about the benefits of I/O controllers supporting I/O priorities is available at
https://www.usenix.org/system/files/conference/hotstorage17/hotstorage17-paper-manzanares.pdf.

ATA NCQ has only 2 bits, defining 3 different priority levels, one of which is not really a priority but rather latency limitation. So yes, basically, ATA supports only high-priority and no-priority. 2 levels only with all prio levels of the RT class mapping to the device high-priority level and everything else mapping to device no-priority level.

That said, Command Duration Limits has been standardized and I was planning to introduce support for it using a new priority class IOPRIO_CLASS_DURATION with the priority level indicating the duration limit to apply to the IOs. In this case, differentiation between the different priority levels of that class may be necessary at the scheduler level. I will probably revisit this when I send command duration limit support.

Quoted 27 lines
Quoted 12 lines
Quoted 12 lines

/*
* deadline_check_fifo returns 0 if there are no expired requests on the fifo,
* 1 otherwise. Requires !list_empty(&dd->fifo_list[data_dir])
*/
static inline int deadline_check_fifo(struct deadline_data *dd,

block/mq-deadline.c +2 -1
+				      enum dd_prio prio,
 				      enum dd_data_dir data_dir)
 {
-	struct request *rq = rq_entry_fifo(dd->fifo_list[data_dir].next);
+	struct request *rq = rq_entry_fifo(dd->fifo_list[prio][data_dir].next);
Quoted 6 lines

block/mq-deadline.c deadline_move_request(struct deadline_data *dd, struct request *rq) · line 253

Quoted 2 lines
block/mq-deadline.c +0 -0
 	/*
 	 * rq is expired!

I am _so_ not a fan of arrays in C.
Can't you make this an accessor and use
dd->fifo_list[prio * 2 + data_dir] ?

That's possible, but if the compiler can translate [prio][data_dir] into [prio * 2 + data_dir], should I really do this myself instead of letting the compiler generate that transformation?

Thanks,

Bart.

Signature · 2 lines
Damien Le Moal
Western Digital Research
#51 lore raw

PATCH 9/9 block/mq-deadline: Add cgroup support

In reply to Bart Van Assche

Add support for configuring I/O priority per block cgroup. Assign the lowest of the following two priorities to a request: rq->ioprio and blkcg->ioprio. Maintain statistics per cgroup and make these available in sysfs.

This patch has been tested as follows:

SHELL 1

modprobe scsi_debug ndelay=1000000 max_queue=16 &&
while [ -z "$sd" ]; do sd=/dev/$(basename /sys/bus/pseudo/drivers/scsi_debug/adapter*/host*/target*/*/block/*); done && cd /sys/fs/cgroup/blkio/ &&
echo 2 >blkio.dd.prio &&
mkdir -p hipri &&
cd hipri &&
echo 1 >blkio.dd.prio &&
echo $$ >cgroup.procs &&
max-iops -a1 -d32 -j1 -e mq-deadline $sd

SHELL 2

sd=/dev/$(basename /sys/bus/pseudo/drivers/scsi_debug/adapter*/host*/target*/*/block/*) && max-iops -a1 -d32 -j1 -e mq-deadline $sd

Result:
* 12000 IOPS in shell 1
* 2000 IOPS in shell 2

The max-iops script is a script that runs fio with the following arguments:
--bs=4K --gtod_reduce=1 --ioengine=libaio --ioscheduler=${arg_e} --runtime=60 --norandommap --rw=read --thread --buffered=0 --numjobs=${arg_j} --iodepth=${arg_d}
--iodepth_batch_submit=${arg_a} --iodepth_batch_complete=$((arg_d / 2)) --name=${positional_argument_1} --filename=${positional_argument_1}

Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/Kconfig.iosched      |   6 ++
 block/Makefile             |   1 +
 block/mq-deadline-cgroup.c | 206 +++++++++++++++++++++++++++++++++++++
 block/mq-deadline-cgroup.h |  73 +++++++++++++
 block/mq-deadline.c        |  96 ++++++++++++++---
 5 files changed, 370 insertions(+), 12 deletions(-)
 create mode 100644 block/mq-deadline-cgroup.c
 create mode 100644 block/mq-deadline-cgroup.h
block/Kconfig.iosched +6 -0
index 2f2158e05a91..64053d67a97b 100644
@@ -9,6 +9,12 @@ config MQ_IOSCHED_DEADLINE
 	help
 	  MQ version of the deadline IO scheduler.
 
+config MQ_IOSCHED_DEADLINE_CGROUP
+       tristate
+       default y
+       depends on MQ_IOSCHED_DEADLINE
+       depends on BLK_CGROUP
+
 config MQ_IOSCHED_KYBER
 	tristate "Kyber I/O scheduler"
 	default y
block/Makefile +1 -0
index 8d841f5f986f..7d5763d5f988 100644
@@ -20,6 +20,7 @@ obj-$(CONFIG_BLK_DEV_THROTTLING)	+= blk-throttle.o
 obj-$(CONFIG_BLK_CGROUP_IOLATENCY)	+= blk-iolatency.o
 obj-$(CONFIG_BLK_CGROUP_IOCOST)	+= blk-iocost.o
 obj-$(CONFIG_MQ_IOSCHED_DEADLINE)	+= mq-deadline.o
+obj-$(CONFIG_MQ_IOSCHED_DEADLINE_CGROUP)+= mq-deadline-cgroup.o
 obj-$(CONFIG_MQ_IOSCHED_KYBER)	+= kyber-iosched.o
 bfq-y				:= bfq-iosched.o bfq-wf2q.o bfq-cgroup.o
 obj-$(CONFIG_IOSCHED_BFQ)	+= bfq.o
block/mq-deadline-cgroup.c new file +206 -0

206 lines not on this page · raw message

block/mq-deadline-cgroup.h new file +73 -0

73 lines not on this page · raw message

block/mq-deadline.c +84 -12

204 lines not on this page · raw message

#52 lore raw

Re: [PATCH 9/9] block/mq-deadline: Add cgroup support

Quoted 47 lines · Bart Van Assche

Add support for configuring I/O priority per block cgroup. Assign the lowest of the following two priorities to a request: rq->ioprio and blkcg->ioprio. Maintain statistics per cgroup and make these available in sysfs.

This patch has been tested as follows:

SHELL 1

modprobe scsi_debug ndelay=1000000 max_queue=16 &&
while [ -z "$sd" ]; do sd=/dev/$(basename /sys/bus/pseudo/drivers/scsi_debug/adapter*/host*/target*/*/block/*); done && cd /sys/fs/cgroup/blkio/ &&
echo 2 >blkio.dd.prio &&
mkdir -p hipri &&
cd hipri &&
echo 1 >blkio.dd.prio &&
echo $$ >cgroup.procs &&
max-iops -a1 -d32 -j1 -e mq-deadline $sd

SHELL 2

sd=/dev/$(basename /sys/bus/pseudo/drivers/scsi_debug/adapter*/host*/target*/*/block/*) && max-iops -a1 -d32 -j1 -e mq-deadline $sd

Result:
* 12000 IOPS in shell 1
* 2000 IOPS in shell 2

The max-iops script is a script that runs fio with the following arguments:
--bs=4K --gtod_reduce=1 --ioengine=libaio --ioscheduler=${arg_e} --runtime=60 --norandommap --rw=read --thread --buffered=0 --numjobs=${arg_j} --iodepth=${arg_d}
--iodepth_batch_submit=${arg_a} --iodepth_batch_complete=$((arg_d / 2)) --name=${positional_argument_1} --filename=${positional_argument_1}

Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/Kconfig.iosched      |   6 ++
 block/Makefile             |   1 +
 block/mq-deadline-cgroup.c | 206 +++++++++++++++++++++++++++++++++++++
 block/mq-deadline-cgroup.h |  73 +++++++++++++
 block/mq-deadline.c        |  96 ++++++++++++++---
 5 files changed, 370 insertions(+), 12 deletions(-)
 create mode 100644 block/mq-deadline-cgroup.c
 create mode 100644 block/mq-deadline-cgroup.h
Quoted 1 line

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke		        Kernel Storage Architect
[email protected]			               +49 911 74053 688
SUSE Software Solutions Germany GmbH, 90409 Nürnberg
GF: F. Imendörffer, HRB 36809 (AG Nürnberg)
#53 lore raw
In reply to Bart Van Assche
Quoted 9 lines · Bart Van Assche

Hi Jens,

A feature that is missing from the Linux kernel for storage devices that support I/O priorities is to set the I/O priority in requests involving page cache writeback. Since the identity of the process that triggers page cache writeback is not known in the writeback code, the priority set by ioprio_set() is ignored. However, an I/O cgroup is associated with writeback requests by certain filesystems. Hence this patch series that implements the following changes for the mq-deadline scheduler:

Hi Bart

How about implement this feature based on the rq-qos framework ? Maybe it is better to make mq-deadline a pure io-scheduler.

Best regards
Jianchao

Quoted 32 lines

* Make the I/O priority configurable per I/O cgroup.
* Change the I/O priority of requests to the lower of (request I/O priority, cgroup I/O priority).
* Introduce one queue per I/O priority in the mq-deadline scheduler.

Please consider this patch series for kernel v5.14.

Thanks,

Bart.

Bart Van Assche (9):
block/mq-deadline: Add several comments block/mq-deadline: Add two lockdep_assert_held() statements block/mq-deadline: Remove two local variables block/mq-deadline: Rename dd_init_queue() and dd_exit_queue() block/mq-deadline: Improve compile-time argument checking block/mq-deadline: Reduce the read expiry time for non-rotational
media
block/mq-deadline: Reserve 25% of tags for synchronous requests block/mq-deadline: Add I/O priority support block/mq-deadline: Add cgroup support

 block/Kconfig.iosched      |   6 +
 block/Makefile             |   1 +
 block/mq-deadline-cgroup.c | 206 +++++++++++++++
 block/mq-deadline-cgroup.h |  73 ++++++
 block/mq-deadline.c        | 524 +++++++++++++++++++++++++++++--------
 5 files changed, 695 insertions(+), 115 deletions(-)
 create mode 100644 block/mq-deadline-cgroup.c
 create mode 100644 block/mq-deadline-cgroup.h
#54 lore raw
Quoted 12 lines · Wang Jianchao
Quoted 9 lines · Bart Van Assche

Hi Jens,

A feature that is missing from the Linux kernel for storage devices that support I/O priorities is to set the I/O priority in requests involving page cache writeback. Since the identity of the process that triggers page cache writeback is not known in the writeback code, the priority set by ioprio_set() is ignored. However, an I/O cgroup is associated with writeback requests by certain filesystems. Hence this patch series that implements the following changes for the mq-deadline scheduler:

Quoted 4 lines

Hi Bart

How about implement this feature based on the rq-qos framework ? Maybe it is better to make mq-deadline a pure io-scheduler.

In addition, it is more flexible to combine different io-scheduler and rq-qos policy if we take io priority as a new policy ;)

Quoted 36 lines

Best regards
Jianchao

Quoted 32 lines

* Make the I/O priority configurable per I/O cgroup.
* Change the I/O priority of requests to the lower of (request I/O priority, cgroup I/O priority).
* Introduce one queue per I/O priority in the mq-deadline scheduler.

Please consider this patch series for kernel v5.14.

Thanks,

Bart.

Bart Van Assche (9):
block/mq-deadline: Add several comments block/mq-deadline: Add two lockdep_assert_held() statements block/mq-deadline: Remove two local variables block/mq-deadline: Rename dd_init_queue() and dd_exit_queue() block/mq-deadline: Improve compile-time argument checking block/mq-deadline: Reduce the read expiry time for non-rotational
media
block/mq-deadline: Reserve 25% of tags for synchronous requests block/mq-deadline: Add I/O priority support block/mq-deadline: Add cgroup support

 block/Kconfig.iosched      |   6 +
 block/Makefile             |   1 +
 block/mq-deadline-cgroup.c | 206 +++++++++++++++
 block/mq-deadline-cgroup.h |  73 ++++++
 block/mq-deadline.c        | 524 +++++++++++++++++++++++++++++--------
 5 files changed, 695 insertions(+), 115 deletions(-)
 create mode 100644 block/mq-deadline-cgroup.c
 create mode 100644 block/mq-deadline-cgroup.h
#55 lore raw
Quoted 10 lines · Wang Jianchao
Quoted 9 lines · Wang Jianchao
Quoted 7 lines · Bart Van Assche

A feature that is missing from the Linux kernel for storage devices that support I/O priorities is to set the I/O priority in requests involving page cache writeback. Since the identity of the process that triggers page cache writeback is not known in the writeback code, the priority set by ioprio_set() is ignored. However, an I/O cgroup is associated with writeback requests by certain filesystems. Hence this patch series that implements the following changes for the mq-deadline scheduler:

Quoted 5 lines
Quoted 2 lines

How about implement this feature based on the rq-qos framework ? Maybe it is better to make mq-deadline a pure io-scheduler.

In addition, it is more flexible to combine different io-scheduler and rq-qos policy if we take io priority as a new policy ;)

Hi Jianchao,

That's an interesting question. I'm in favor of flexibility. However, I'm not sure whether it would be possible to combine an rq-qos policy that submits high priority requests first with an I/O scheduler that ignores I/O priorities. Since a typical I/O scheduler reorders requests, such a combination would lead to requests being submitted in the wrong order to storage devices. In other words, when using an I/O scheduler, proper support for I/O priority in the I/O scheduler is essential. The BFQ I/O scheduler is still maturing. The purpose of the Kyber I/O scheduler is to control latency by reducing the queue depth without differentiating between requests of the same type. The mq-deadline scheduler is already being used in combination with storage devices that support I/O priorities in their controller. Hence the choice for the mq-deadline scheduler.

Thanks,

Bart.

#56 lore raw
Quoted 17 lines · Bart Van Assche
Quoted 10 lines · Wang Jianchao
Quoted 9 lines · Wang Jianchao
Quoted 7 lines · Bart Van Assche

A feature that is missing from the Linux kernel for storage devices that support I/O priorities is to set the I/O priority in requests involving page cache writeback. Since the identity of the process that triggers page cache writeback is not known in the writeback code, the priority set by ioprio_set() is ignored. However, an I/O cgroup is associated with writeback requests by certain filesystems. Hence this patch series that implements the following changes for the mq-deadline scheduler:

Quoted 5 lines
Quoted 2 lines

How about implement this feature based on the rq-qos framework ? Maybe it is better to make mq-deadline a pure io-scheduler.

In addition, it is more flexible to combine different io-scheduler and rq-qos policy if we take io priority as a new policy ;)

Quoted 8 lines

Hi Jianchao,

That's an interesting question. I'm in favor of flexibility. However,
I'm not sure whether it would be possible to combine an rq-qos policy
that submits high priority requests first with an I/O scheduler that
ignores I/O priorities. Since a typical I/O scheduler reorders requests,
such a combination would lead to requests being submitted in the wrong
order to storage devices. In other words, when using an I/O scheduler,> proper support for I/O priority in the I/O scheduler is essential. The

Hi Bart,

Does it really matter that issue IO request by the order of io priority ?

Given a device with a 32 depth queue and doesn't support io priority, even if we issue the request by the order of io priority, will the fw of device handle them by the same order ? Or in the other word, we always issue 32 io requests to device one time and then the fw of device decides how to handle them. The order of dispatching request from queue may only work when the device's queue is full and we have a deeper queue in io scheduler. And at this moment, maybe the user needs to check why their application saturates the block device.

As for the qos policy of io priority, it seems similar with wbt in which read, sync write and background write have different priority. Since we always want the io with higher priority to be served more by the device, adapting the depth of queue of different io priority may work ;)

Best regards
Jianchao

Quoted 11 lines

BFQ I/O scheduler is still maturing. The purpose of the Kyber I/O scheduler is to control latency by reducing the queue depth without differentiating between requests of the same type. The mq-deadline scheduler is already being used in combination with storage devices that support I/O priorities in their controller. Hence the choice for the mq-deadline scheduler.

Thanks,

Bart.

#57 lore raw
Quoted 45 lines

Il giorno 28 mag 2021, alle ore 04:05, Wang Jianchao <[email protected]> ha scritto:

Quoted 17 lines · Bart Van Assche
Quoted 10 lines · Wang Jianchao
Quoted 9 lines · Wang Jianchao
Quoted 7 lines · Bart Van Assche

A feature that is missing from the Linux kernel for storage devices that support I/O priorities is to set the I/O priority in requests involving page cache writeback. Since the identity of the process that triggers page cache writeback is not known in the writeback code, the priority set by ioprio_set() is ignored. However, an I/O cgroup is associated with writeback requests by certain filesystems. Hence this patch series that implements the following changes for the mq-deadline scheduler:

Quoted 5 lines
Quoted 2 lines

How about implement this feature based on the rq-qos framework ? Maybe it is better to make mq-deadline a pure io-scheduler.

In addition, it is more flexible to combine different io-scheduler and rq-qos policy if we take io priority as a new policy ;)

Quoted 8 lines

Hi Jianchao,

That's an interesting question. I'm in favor of flexibility. However,
I'm not sure whether it would be possible to combine an rq-qos policy
that submits high priority requests first with an I/O scheduler that
ignores I/O priorities. Since a typical I/O scheduler reorders requests,
such a combination would lead to requests being submitted in the wrong
order to storage devices. In other words, when using an I/O scheduler,> proper support for I/O priority in the I/O scheduler is essential. The

Hi Bart,

Does it really matter that issue IO request by the order of io priority ?

Given a device with a 32 depth queue and doesn't support io priority, even if we issue the request by the order of io priority, will the fw of device handle them by the same order ? Or in the other word, we always issue 32 io requests to device one time and then the fw of device decides how to handle them. The order of dispatching request from queue may only work when the device's queue is full and we have a deeper queue in io scheduler. And at this moment, maybe the user needs to check why their application saturates the block device.

Quoted 5 lines

As for the qos policy of io priority, it seems similar with wbt in which read, sync write and background write have different priority. Since we always want the io with higher priority to be served more by the device, adapting the depth of queue of different io priority may work ;)

That's exactly what BFQ does, as this is the only option to truly control I/O in a device with internal queueing :)

Thanks,
Paolo

Quoted 13 lines

Best regards
Jianchao

Quoted 10 lines

BFQ I/O scheduler is still maturing. The purpose of the Kyber I/O scheduler is to control latency by reducing the queue depth without differentiating between requests of the same type. The mq-deadline scheduler is already being used in combination with storage devices that support I/O priorities in their controller. Hence the choice for the mq-deadline scheduler.

Thanks,

Bart.

#58 lore raw
In reply to Wang Jianchao
Quoted 10 lines · Wang Jianchao

Does it really matter that issue IO request by the order of io priority ?

Given a device with a 32 depth queue and doesn't support io priority, even if we issue the request by the order of io priority, will the fw of device handle them by the same order ? Or in the other word, we always issue 32 io requests to device one time and then the fw of device decides how to handle them. The order of dispatching request from queue may only work when the device's queue is full and we have a deeper queue in io scheduler. And at this moment, maybe the user needs to check why their application saturates the block device.

Quoted 4 lines

As for the qos policy of io priority, it seems similar with wbt in which read, sync write and background write have different priority. Since we always want the io with higher priority to be served more by the device, adapting the depth of queue of different io priority may work ;)

Hi Jianchao,

Our conclusion from the extensive measurements we ran is that we cannot reach our latency goals for high-priority I/O without I/O priority support in the storage device. This is why we are working with device vendors on implementing I/O priority support in the storage devices that matter to us.

Thanks,

Bart.

#59 lore raw
In reply to Bart Van Assche
Quoted 18 lines · Bart Van Assche

Hi Jens,

A feature that is missing from the Linux kernel for storage devices that support I/O priorities is to set the I/O priority in requests involving page cache writeback. Since the identity of the process that triggers page cache writeback is not known in the writeback code, the priority set by ioprio_set() is ignored. However, an I/O cgroup is associated with writeback requests by certain filesystems. Hence this patch series that implements the following changes for the mq-deadline scheduler:
* Make the I/O priority configurable per I/O cgroup.
* Change the I/O priority of requests to the lower of (request I/O priority, cgroup I/O priority).
* Introduce one queue per I/O priority in the mq-deadline scheduler.

Please consider this patch series for kernel v5.14.

Thanks,

Quoted 9 lines

Bart.

Bart Van Assche (9):
block/mq-deadline: Add several comments block/mq-deadline: Add two lockdep_assert_held() statements block/mq-deadline: Remove two local variables block/mq-deadline: Rename dd_init_queue() and dd_exit_queue() block/mq-deadline: Improve compile-time argument checking

I think the above 5 patches can go in independently as cleanups.

#60 lore raw
Quoted 21 lines · Johannes Thumshirn
Quoted 20 lines · Bart Van Assche

Hi Jens,

A feature that is missing from the Linux kernel for storage devices that support I/O priorities is to set the I/O priority in requests involving page cache writeback. Since the identity of the process that triggers page cache writeback is not known in the writeback code, the priority set by ioprio_set() is ignored. However, an I/O cgroup is associated with writeback requests by certain filesystems. Hence this patch series that implements the following changes for the mq-deadline scheduler:
* Make the I/O priority configurable per I/O cgroup.
* Change the I/O priority of requests to the lower of (request I/O priority, cgroup I/O priority).
* Introduce one queue per I/O priority in the mq-deadline scheduler.

Please consider this patch series for kernel v5.14.

Thanks,

Bart.

Quoted 9 lines
Quoted 7 lines

Bart Van Assche (9):
block/mq-deadline: Add several comments block/mq-deadline: Add two lockdep_assert_held() statements block/mq-deadline: Remove two local variables block/mq-deadline: Rename dd_init_queue() and dd_exit_queue() block/mq-deadline: Improve compile-time argument checking

I think the above 5 patches can go in independently as cleanups.

Yes they seems purely cleanup from review point of view.

#61 lore raw
Quoted 9 lines · Chaitanya Kulkarni
Quoted 8 lines · Johannes Thumshirn
Quoted 7 lines · Bart Van Assche

Bart Van Assche (9):
block/mq-deadline: Add several comments block/mq-deadline: Add two lockdep_assert_held() statements block/mq-deadline: Remove two local variables block/mq-deadline: Rename dd_init_queue() and dd_exit_queue() block/mq-deadline: Improve compile-time argument checking

Quoted 3 lines
Quoted 1 line

I think the above 5 patches can go in independently as cleanups.

Yes they seems purely cleanup from review point of view.

That's right. This patch series has been organized such that the cleanup patches occur first.

I have posted all 9 patches as a series to make it easier to review and apply all these patches.

Thanks,

Bart.

#62 lore raw
In reply to Bart Van Assche
Quoted 7 lines · Bart Van Assche

Hi Jens,

A feature that is missing from the Linux kernel for storage devices that
support I/O priorities is to set the I/O priority in requests involving page
cache writeback.

Hello Bart,

When I worked in this area the goal was to control tail latencies for a prioritized app. Once the page cache is involved app control over IO is handed off suggesting that the priorities passed down to the device aren't as meaningful anymore.

Is passing the priority to the device making an impact to performance with your test case? If not, could BFQ be seen as a viable alternative.

Take care,
Adam

Quoted 42 lines

Since the identity of the process that triggers page cache writeback is not known in the writeback code, the priority set by ioprio_set()
is ignored. However, an I/O cgroup is associated with writeback requests
by certain filesystems. Hence this patch series that implements the following
changes for the mq-deadline scheduler:
* Make the I/O priority configurable per I/O cgroup.
* Change the I/O priority of requests to the lower of (request I/O priority,
  cgroup I/O priority).
* Introduce one queue per I/O priority in the mq-deadline scheduler.

Please consider this patch series for kernel v5.14.

Thanks,

Bart.

Bart Van Assche (9):
  block/mq-deadline: Add several comments block/mq-deadline: Add two lockdep_assert_held() statements block/mq-deadline: Remove two local variables block/mq-deadline: Rename dd_init_queue() and dd_exit_queue() block/mq-deadline: Improve compile-time argument checking block/mq-deadline: Reduce the read expiry time for non-rotational media
  block/mq-deadline: Reserve 25% of tags for synchronous requests block/mq-deadline: Add I/O priority support block/mq-deadline: Add cgroup support

 block/Kconfig.iosched      |   6 +
 block/Makefile             |   1 + block/mq-deadline-cgroup.c | 206 +++++++++++++++ block/mq-deadline-cgroup.h |  73 ++++++ block/mq-deadline.c        | 524 +++++++++++++++++++++++++++++------ --

 5 files changed, 695 insertions(+), 115 deletions(-)

 create mode 100644 block/mq-deadline-cgroup.c
 create mode 100644 block/mq-deadline-cgroup.h

#63 lore raw
Quoted 5 lines · Adam Manzanares
Quoted 3 lines · Bart Van Assche

A feature that is missing from the Linux kernel for storage devices that support I/O priorities is to set the I/O priority in requests involving page cache writeback.

Quoted 8 lines

When I worked in this area the goal was to control tail latencies for a prioritized app. Once the page cache is involved app control over IO is handed off suggesting that the priorities passed down to the device aren't as meaningful anymore.

Is passing the priority to the device making an impact to performance with your test case? If not, could BFQ be seen as a viable alternative.

Hi Adam,

As we all know complexity is the enemy of reliability. BFQ is complicated so I am hesitant to use BFQ in a context where reliability is important. Additionally, the BFQ scheduler uses heuristics to detect the application type. As became clear recently, there heuristics can be misled easily and fixing this is nontrivial (see also
https://lore.kernel.org/linux-block/[email protected]/).
I want the application launcher to create one cgroup for foreground applications and another cgroup for background applications. Configuring different I/O priorities per cgroup is an easy and reliable approach to communicate information about the application type and latency expectations to the block layer.

Some database applications use buffered I/O and flush that data by calling fsync(). We want to support such applications. So it seems like we have a different opinion about whether or not an I/O priority should be assigned to I/O that is the result of page cache writeback?

Thanks,

Bart.

#64 lore raw
Quoted 27 lines · Bart Van Assche
Quoted 11 lines · Adam Manzanares
Quoted 3 lines · Bart Van Assche

A feature that is missing from the Linux kernel for storage devices that support I/O priorities is to set the I/O priority in requests involving page cache writeback.

When I worked in this area the goal was to control tail latencies for
a prioritized app. Once the page cache is involved app control over IO is handed off suggesting that the priorities passed down to the device aren't as meaningful anymore.

Quoted 3 lines

Is passing the priority to the device making an impact to performance with your test case? If not, could BFQ be seen as a viable alternative.

Hi Adam,

As we all know complexity is the enemy of reliability. BFQ is complicated so I am hesitant to use BFQ in a context where reliability
is important. Additionally, the BFQ scheduler uses heuristics to detect
the application type. As became clear recently, there heuristics can be
misled easily and fixing this is nontrivial (see also
https://lore.kernel.org/linux-block/[email protected]/

Quoted 8 lines

).
I want the application launcher to create one cgroup for foreground applications and another cgroup for background applications. Configuring
different I/O priorities per cgroup is an easy and reliable approach to
communicate information about the application type and latency expectations to the block layer.

Ok, now I know why you are staying away from BFQ. Thanks for sharing this information.

Quoted 7 lines

Some database applications use buffered I/O and flush that data by calling fsync(). We want to support such applications. So it seems like
we have a different opinion about whether or not an I/O priority should
be assigned to I/O that is the result of page cache writeback?

Not necessarily, I am just a bit cautious because in my experience prioritized I/O has benefits as well as limitations. You just have to make sure that the page cache writeback does not push the hardware to a point where the I/O prioritization is no longer beneficial.

Quoted 4 lines

Thanks,

Bart.