Skip to contentSkip to conversation

Fix the mq-deadline async_depth implementation

PATCH Applied Bart Van Assche 6 participants 17 messages May 9, 2024 – Dec 10, 2024 1 message not in the archive Block layer

lore
Share & tools
lore
#0 lore raw

v2 cover Fix the mq-deadline async_depth implementation

Hi Jens,

The mq-deadline 'async_depth' sysfs attribute doesn't behave as intended. This patch series fixes the implementation of that attribute.

Please consider this patch series for the next merge window.

Thanks,

Bart.

Changes compared to v1: replaced patch 1/2 with a patch from Christoph.

Bart Van Assche (2):
block: Call .limit_depth() after .hctx has been set block/mq-deadline: Fix the tag reservation code

 block/blk-mq.c      | 12 ++++++------
 block/mq-deadline.c | 20 +++++++++++++++++---
 2 files changed, 23 insertions(+), 9 deletions(-)
#1 lore raw

PATCH v2 1/2 block: Call .limit_depth() after .hctx has been set

Call .limit_depth() after data->hctx has been set such that data->hctx can be used in .limit_depth() implementations.

Cc Christoph Hellwig <[email protected]>
Cc Damien Le Moal <[email protected]>
Cc Zhiguo Niu <[email protected]>
Fixes 07757588e507 ("block/mq-deadline: Reserve 25% of scheduler tags for synchronous requests")
---
 block/blk-mq.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
block/blk-mq.c +6 -6
index 9f677ea85a52..a6310a550b78 100644
@@ -448,6 +448,10 @@ static struct request *__blk_mq_alloc_requests(struct blk_mq_alloc_data *data)
 	if (data->cmd_flags & REQ_NOWAIT)
 		data->flags |= BLK_MQ_REQ_NOWAIT;
 
+retry:
+	data->ctx = blk_mq_get_ctx(q);
+	data->hctx = blk_mq_map_queue(q, data->cmd_flags, data->ctx);
+
 	if (q->elevator) {
 		/*
 		 * All requests use scheduler tags when an I/O scheduler is
@@ -469,13 +473,9 @@ static struct request *__blk_mq_alloc_requests(struct blk_mq_alloc_data *data)
 			if (ops->limit_depth)
 				ops->limit_depth(data->cmd_flags, data);
 		}
-	}
-
-retry:
-	data->ctx = blk_mq_get_ctx(q);
-	data->hctx = blk_mq_map_queue(q, data->cmd_flags, data->ctx);
-	if (!(data->rq_flags & RQF_SCHED_TAGS))
+	} else {
 		blk_mq_tag_busy(data->hctx);
+	}
 
 	if (data->flags & BLK_MQ_REQ_RESERVED)
 		data->rq_flags |= RQF_RESV;
Tested-by on v2 1/2
#2 lore raw

答复: [PATCH v2 1/2] block: Call .limit_depth() after .hctx has been set

-----邮件原件-----
发件人: Bart Van Assche <[email protected]>
发送时间: 2024年5月10日 1:02
收件人: Jens Axboe <[email protected]>
抄送: [email protected]; Christoph Hellwig <[email protected]>; Bart Van Assche <[email protected]>; Damien Le Moal <[email protected]>; 牛志国 (Zhiguo Niu) <[email protected]> 主题: [PATCH v2 1/2] block: Call .limit_depth() after .hctx has been set

注意: 这封邮件来自于外部。除非你确定邮件内容安全,否则不要点击任何链接和附件。
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

Call .limit_depth() after data->hctx has been set such that data->hctx can be used in .limit_depth() implementations.

Cc Christoph Hellwig <[email protected]>
Cc Damien Le Moal <[email protected]>
Cc Zhiguo Niu <[email protected]>
Fixes 07757588e507 ("block/mq-deadline: Reserve 25% of scheduler tags for synchronous requests")
---
 block/blk-mq.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
block/blk-mq.c +4 -0
@@ -448,6 +448,10 @@ static struct request *__blk_mq_alloc_requests(struct blk_mq_alloc_data *data)
        if (data->cmd_flags & REQ_NOWAIT)
                data->flags |= BLK_MQ_REQ_NOWAIT;
 
+retry:
+       data->ctx = blk_mq_get_ctx(q);
+       data->hctx = blk_mq_map_queue(q, data->cmd_flags, data->ctx);
+

Hi Bart,
I tested basic function about these serial patches and results is pass, and no warning report after setting async_depth value by sysfs, But there is a little question here, if do "retry", the following if case will be re-run also, so Is there something wrong with this or can it be improved? Otherwise

Thanks!

        if (q->elevator) {
                /*
                 * All requests use scheduler tags when an I/O scheduler is @@ -469,13 +473,9 @@ static struct request *__blk_mq_alloc_requests(struct blk_mq_alloc_data *data)
                        if (ops->limit_depth)
                                ops->limit_depth(data->cmd_flags, data);
                }
-       }
-
-retry:
-       data->ctx = blk_mq_get_ctx(q);
-       data->hctx = blk_mq_map_queue(q, data->cmd_flags, data->ctx);
-       if (!(data->rq_flags & RQF_SCHED_TAGS))
+       } else {
                blk_mq_tag_busy(data->hctx);

+ }

        if (data->flags & BLK_MQ_REQ_RESERVED)
                data->rq_flags |= RQF_RESV;
#4 lore raw

PATCH v2 2/2 block/mq-deadline: Fix the tag reservation code

In reply to Bart Van Assche

The current tag reservation code is based on a misunderstanding of the meaning of data->shallow_depth. Fix the tag reservation code as follows:
* By default, do not reserve any tags for synchronous requests because for certain use cases reserving tags reduces performance. See also Harshit Mogalapalli, [bug-report] Performance regression with fio sequential-write on a multipath setup, 2024-03-07
(https://lore.kernel.org/linux-block/[email protected]/)
* Reduce min_shallow_depth to one because min_shallow_depth must be less than or equal any shallow_depth value.
* Scale dd->async_depth from the range [1, nr_requests] to [1, bits_per_sbitmap_word].

Cc Christoph Hellwig <[email protected]>
Cc Damien Le Moal <[email protected]>
Cc Zhiguo Niu <[email protected]>
Fixes 07757588e507 ("block/mq-deadline: Reserve 25% of scheduler tags for synchronous requests")
---
 block/mq-deadline.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
block/mq-deadline.c +17 -3
index 94eede4fb9eb..acdc28756d9d 100644
@@ -487,6 +487,20 @@ static struct request *dd_dispatch_request(struct blk_mq_hw_ctx *hctx)
 	return rq;
 }
 
+/*
+ * 'depth' is a number in the range 1..INT_MAX representing a number of
+ * requests. Scale it with a factor (1 << bt->sb.shift) / q->nr_requests since
+ * 1..(1 << bt->sb.shift) is the range expected by sbitmap_get_shallow().
+ * Values larger than q->nr_requests have the same effect as q->nr_requests.
+ */
+static int dd_to_word_depth(struct blk_mq_hw_ctx *hctx, unsigned int qdepth)
+{
+	struct sbitmap_queue *bt = &hctx->sched_tags->bitmap_tags;
+	const unsigned int nrr = hctx->queue->nr_requests;
+
+	return ((qdepth << bt->sb.shift) + nrr - 1) / nrr;
+}
+
 /*
  * Called by __blk_mq_alloc_request(). The shallow_depth value set by this
  * function is used by __blk_mq_get_tag().
@@ -503,7 +517,7 @@ static void dd_limit_depth(blk_opf_t opf, struct blk_mq_alloc_data *data)
 	 * Throttle asynchronous requests and writes such that these requests
 	 * do not block the allocation of synchronous requests.
 	 */
-	data->shallow_depth = dd->async_depth;
+	data->shallow_depth = dd_to_word_depth(data->hctx, dd->async_depth);
 }
 
 /* Called by blk_mq_update_nr_requests(). */
@@ -513,9 +527,9 @@ static void dd_depth_updated(struct blk_mq_hw_ctx *hctx)
 	struct deadline_data *dd = q->elevator->elevator_data;
 	struct blk_mq_tags *tags = hctx->sched_tags;
 
-	dd->async_depth = max(1UL, 3 * q->nr_requests / 4);
+	dd->async_depth = q->nr_requests;
 
-	sbitmap_queue_min_shallow_depth(&tags->bitmap_tags, dd->async_depth);
+	sbitmap_queue_min_shallow_depth(&tags->bitmap_tags, 1);
 }
 
 /* Called by blk_mq_init_hctx() and blk_mq_init_sched(). */
#5 lore raw

Re: [PATCH v2 2/2] block/mq-deadline: Fix the tag reservation code

Quoted 56 lines · Bart Van Assche

The current tag reservation code is based on a misunderstanding of the meaning of data->shallow_depth. Fix the tag reservation code as follows:
* By default, do not reserve any tags for synchronous requests because for certain use cases reserving tags reduces performance. See also Harshit Mogalapalli, [bug-report] Performance regression with fio sequential-write on a multipath setup, 2024-03-07
(https://lore.kernel.org/linux-block/[email protected]/)
* Reduce min_shallow_depth to one because min_shallow_depth must be less than or equal any shallow_depth value.
* Scale dd->async_depth from the range [1, nr_requests] to [1, bits_per_sbitmap_word].

Cc Christoph Hellwig <[email protected]>
Cc Damien Le Moal <[email protected]>
Cc Zhiguo Niu <[email protected]>
Fixes 07757588e507 ("block/mq-deadline: Reserve 25% of scheduler tags for synchronous requests")
---
  block/mq-deadline.c | 20 +++++++++++++++++---
  1 file changed, 17 insertions(+), 3 deletions(-)
block/mq-deadline.c +15 -1
index 94eede4fb9eb..acdc28756d9d 100644
@@ -487,6 +487,20 @@ static struct request *dd_dispatch_request(struct blk_mq_hw_ctx *hctx)
  	return rq;
  }
 
+/*
+ * 'depth' is a number in the range 1..INT_MAX representing a number of
+ * requests. Scale it with a factor (1 << bt->sb.shift) / q->nr_requests since
+ * 1..(1 << bt->sb.shift) is the range expected by sbitmap_get_shallow().
+ * Values larger than q->nr_requests have the same effect as q->nr_requests.
+ */
+static int dd_to_word_depth(struct blk_mq_hw_ctx *hctx, unsigned int qdepth)
+{
+	struct sbitmap_queue *bt = &hctx->sched_tags->bitmap_tags;
+	const unsigned int nrr = hctx->queue->nr_requests;
+
+	return ((qdepth << bt->sb.shift) + nrr - 1) / nrr;
+}
+
  /*
   * Called by __blk_mq_alloc_request(). The shallow_depth value set by this
   * function is used by __blk_mq_get_tag().
@@ -503,7 +517,7 @@ static void dd_limit_depth(blk_opf_t opf, struct blk_mq_alloc_data *data)
  	 * Throttle asynchronous requests and writes such that these requests
  	 * do not block the allocation of synchronous requests.
  	 */
-	data->shallow_depth = dd->async_depth;
+	data->shallow_depth = dd_to_word_depth(data->hctx, dd->async_depth);
  }
 
  /* Called by blk_mq_update_nr_requests(). */

block/mq-deadline.c static void dd_depth_updated(struct blk_mq_hw_ctx *hctx) · line 532

Quoted 8 lines
block/mq-deadline.c +2 -2
@@ -513,9 +527,9 @@ static void dd_depth_updated(struct blk_mq_hw_ctx *hctx)
  	struct deadline_data *dd = q->elevator->elevator_data;
  	struct blk_mq_tags *tags = hctx->sched_tags;
 
-	dd->async_depth = max(1UL, 3 * q->nr_requests / 4);
+	dd->async_depth = q->nr_requests;
 
-	sbitmap_queue_min_shallow_depth(&tags->bitmap_tags, dd->async_depth);
+	sbitmap_queue_min_shallow_depth(&tags->bitmap_tags, 1);

If sbq->min_shallow_depth is set to 1, sbq->wake_batch will also be set to 1. I guess this may result in batch wakeup not working as expected.

Quoted 4 lines
block/mq-deadline.c +0 -0
  }
 
  /* Called by blk_mq_init_hctx() and blk_mq_init_sched(). */
#6 lore raw

Re: [PATCH v2 2/2] block/mq-deadline: Fix the tag reservation code

Quoted 4 lines · YangYang
Quoted 4 lines
block/mq-deadline.c +0 -0
@@ -513,9 +527,9 @@ static void dd_depth_updated(struct blk_mq_hw_ctx 
 *hctx)
       struct deadline_data *dd = q->elevator->elevator_data;
       struct blk_mq_tags *tags = hctx->sched_tags;
Quoted 8 lines

block/mq-deadline.c static void dd_depth_updated(struct blk_mq_hw_ctx *hctx) · line 532

Quoted 5 lines
block/mq-deadline.c +2 -2
-    dd->async_depth = max(1UL, 3 * q->nr_requests / 4);
+    dd->async_depth = q->nr_requests;
-    sbitmap_queue_min_shallow_depth(&tags->bitmap_tags, 
 dd->async_depth);
+    sbitmap_queue_min_shallow_depth(&tags->bitmap_tags, 1);

If sbq->min_shallow_depth is set to 1, sbq->wake_batch will also be set to 1. I guess this may result in batch wakeup not working as expected.

The value of the sbq->min_shallow_depth parameter may affect performance but does not affect correctness. See also the comment above the sbitmap_queue_min_shallow_depth() declaration. Is this sufficient to address your concern?

Thanks,

Bart.

#7 lore raw

答复: [PATCH v2 2/2] block/mq-deadline: Fix the tag reservation code

Hi Bart Van Assche and Jens Axboe

Sorry to disturb you.
Would you have a plan When will these patch sets be merged into the mainline? Thanks!

-----邮件原件-----
发件人: Bart Van Assche <[email protected]>
发送时间: 2024年5月17日 5:28
收件人: YangYang <[email protected]>
抄送: [email protected]; Christoph Hellwig <[email protected]>; Damien Le Moal <[email protected]>; 牛志国 (Zhiguo Niu) <[email protected]>; Jens Axboe <[email protected]> 主题: Re: [PATCH v2 2/2] block/mq-deadline: Fix the tag reservation code

注意: 这封邮件来自于外部。除非你确定邮件内容安全,否则不要点击任何链接和附件。
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

Quoted 4 lines · YangYang
Quoted 4 lines
block/mq-deadline.c +0 -0
@@ -513,9 +527,9 @@ static void dd_depth_updated(struct blk_mq_hw_ctx
 *hctx)
      struct deadline_data *dd = q->elevator->elevator_data;
      struct blk_mq_tags *tags = hctx->sched_tags;
Quoted 8 lines

block/mq-deadline.c static void dd_depth_updated(struct blk_mq_hw_ctx *hctx) · line 532

Quoted 5 lines
block/mq-deadline.c +2 -2
-    dd->async_depth = max(1UL, 3 * q->nr_requests / 4);
+    dd->async_depth = q->nr_requests;
-    sbitmap_queue_min_shallow_depth(&tags->bitmap_tags,
 dd->async_depth);
+    sbitmap_queue_min_shallow_depth(&tags->bitmap_tags, 1);

If sbq->min_shallow_depth is set to 1, sbq->wake_batch will also be set to 1. I guess this may result in batch wakeup not working as expected.

The value of the sbq->min_shallow_depth parameter may affect performance but does not affect correctness. See also the comment above the sbitmap_queue_min_shallow_depth() declaration. Is this sufficient to address your concern?

Thanks,

Bart.

#8 lore raw

Re: 答复: [PATCH v2 2/2] block/mq-deadline: Fix the tag reservation code

Quoted 1 line · 牛志国 (Zhiguo Niu)

Would you have a plan When will these patch sets be merged into the mainline?

These patches still apply without any changes to Jens' block/for-next branch. I think the next step is that someone helps by posting Reviewed-by or Tested-by tags for these patches.

Thanks,

Bart.

#9 lore raw

答复: 答复: [PATCH v2 2/2] block/mq-deadline: Fix the tag reservation code

Hi block developers,

Can you help review this serials patch from Bart Van Assche?
https://lore.kernel.org/all/[email protected]/
[PATCH v2 1/2] block: Call .limit_depth() after .hctx has been set [PATCH v2 2/2] block/mq-deadline: Fix the tag reservation code

These patch will fix the issue "there may warning happen if we set dd async_depth from user", For more information about warnings, please refer to commit msg:
https://lore.kernel.org/all/CAHJ8P3KEOC_DXQmZK3u7PHgZFmWpMVzPa6pgkOgpyoH7wgT5nw@mail.gmail.com/

If you need any tests, you can ask me. I can help if my experimental environment can be implemented.
Thanks!
-----邮件原件-----
发件人: Bart Van Assche <[email protected]>
发送时间: 2024年6月4日 19:49
收件人: 牛志国 (Zhiguo Niu) <[email protected]>; Jens Axboe <[email protected]>
抄送: [email protected]; Christoph Hellwig <[email protected]>; Damien Le Moal <[email protected]>; 王皓 (Hao_hao Wang) <[email protected]> 主题: Re: 答复: [PATCH v2 2/2] block/mq-deadline: Fix the tag reservation code

注意: 这封邮件来自于外部。除非你确定邮件内容安全,否则不要点击任何链接和附件。
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

Quoted 1 line · 牛志国 (Zhiguo Niu)

Would you have a plan When will these patch sets be merged into the mainline?

These patches still apply without any changes to Jens' block/for-next branch. I think the next step is that someone helps by posting Reviewed-by or Tested-by tags for these patches.

Thanks,

Bart.

#10 lore raw

Re: 答复: 答复: [PATCH v2 2/2] block/mq-deadline: Fix the tag reservation code

Quoted 8 lines · 牛志国 (Zhiguo Niu)

Can you help review this serials patch from Bart Van Assche?
https://lore.kernel.org/all/[email protected]/
[PATCH v2 1/2] block: Call .limit_depth() after .hctx has been set [PATCH v2 2/2] block/mq-deadline: Fix the tag reservation code

These patch will fix the issue "there may warning happen if we set dd async_depth from user", For more information about warnings, please refer to commit msg:
https://lore.kernel.org/all/CAHJ8P3KEOC_DXQmZK3u7PHgZFmWpMVzPa6pgkOgpyoH7wgT5nw@mail.gmail.com/

Hi Zhiguo,

If these patches pass your tests then you can reply to these patches with your own Tested-by.

Thanks,

Bart.

#12 lore raw

Re: [PATCH v2 2/2] block/mq-deadline: Fix the tag reservation code

In reply to Bart Van Assche

Hi, Bart

Quoted 56 lines · Bart Van Assche

The current tag reservation code is based on a misunderstanding of the meaning of data->shallow_depth. Fix the tag reservation code as follows:
* By default, do not reserve any tags for synchronous requests because for certain use cases reserving tags reduces performance. See also Harshit Mogalapalli, [bug-report] Performance regression with fio sequential-write on a multipath setup, 2024-03-07
(https://lore.kernel.org/linux-block/[email protected]/)
* Reduce min_shallow_depth to one because min_shallow_depth must be less than or equal any shallow_depth value.
* Scale dd->async_depth from the range [1, nr_requests] to [1, bits_per_sbitmap_word].

Cc Christoph Hellwig <[email protected]>
Cc Damien Le Moal <[email protected]>
Cc Zhiguo Niu <[email protected]>
Fixes 07757588e507 ("block/mq-deadline: Reserve 25% of scheduler tags for synchronous requests")
---
  block/mq-deadline.c | 20 +++++++++++++++++---
  1 file changed, 17 insertions(+), 3 deletions(-)
block/mq-deadline.c +15 -1
index 94eede4fb9eb..acdc28756d9d 100644
@@ -487,6 +487,20 @@ static struct request *dd_dispatch_request(struct blk_mq_hw_ctx *hctx)
  	return rq;
  }
 
+/*
+ * 'depth' is a number in the range 1..INT_MAX representing a number of
+ * requests. Scale it with a factor (1 << bt->sb.shift) / q->nr_requests since
+ * 1..(1 << bt->sb.shift) is the range expected by sbitmap_get_shallow().
+ * Values larger than q->nr_requests have the same effect as q->nr_requests.
+ */
+static int dd_to_word_depth(struct blk_mq_hw_ctx *hctx, unsigned int qdepth)
+{
+	struct sbitmap_queue *bt = &hctx->sched_tags->bitmap_tags;
+	const unsigned int nrr = hctx->queue->nr_requests;
+
+	return ((qdepth << bt->sb.shift) + nrr - 1) / nrr;
+}
+
  /*
   * Called by __blk_mq_alloc_request(). The shallow_depth value set by this
   * function is used by __blk_mq_get_tag().
@@ -503,7 +517,7 @@ static void dd_limit_depth(blk_opf_t opf, struct blk_mq_alloc_data *data)
  	 * Throttle asynchronous requests and writes such that these requests
  	 * do not block the allocation of synchronous requests.
  	 */
-	data->shallow_depth = dd->async_depth;
+	data->shallow_depth = dd_to_word_depth(data->hctx, dd->async_depth);
  }
 
  /* Called by blk_mq_update_nr_requests(). */

block/mq-deadline.c static void dd_depth_updated(struct blk_mq_hw_ctx *hctx) · line 530

Quoted 5 lines
block/mq-deadline.c +1 -1
@@ -513,9 +527,9 @@ static void dd_depth_updated(struct blk_mq_hw_ctx *hctx)
  	struct deadline_data *dd = q->elevator->elevator_data;
  	struct blk_mq_tags *tags = hctx->sched_tags;
 
-	dd->async_depth = max(1UL, 3 * q->nr_requests / 4);
+	dd->async_depth = q->nr_requests;

We're comparing v6.6 and v5.10 performance in downstream kernel, we met a regression and bisect to this patch. And during review, I don't understand the above change.

For example, dd->async_depth is nr_requests, then dd_to_word_depth() will just return 1 << bt->sb.shift. Then nothing will be throttled.

The regression is a corner test case that unlikely to happen in real world, I can share more if you're interested.

Thanks,
Kuai

Quoted 9 lines
block/mq-deadline.c +1 -1
-	sbitmap_queue_min_shallow_depth(&tags->bitmap_tags, dd->async_depth);
+	sbitmap_queue_min_shallow_depth(&tags->bitmap_tags, 1);
  }
 
  /* Called by blk_mq_init_hctx() and blk_mq_init_sched(). */
 

.

#13 lore raw

Re: [PATCH v2 2/2] block/mq-deadline: Fix the tag reservation code

Quoted 6 lines · Yu Kuai

We're comparing v6.6 and v5.10 performance in downstream kernel, we met a regression and bisect to this patch. And during review, I don't understand the above change.

For example, dd->async_depth is nr_requests, then dd_to_word_depth() will just return 1 << bt->sb.shift. Then nothing will be throttled.

(just back from traveling)

As explained in the description of commit 39823b47bbd4 ("block/mq-
deadline: Fix the tag reservation code"), the default value of async_depth has been changed from 3 * q->nr_requests / 4 into q->nr_requests to fix a performance regression. The value of dd->async_depth can be changed through sysfs.

Thanks,

Bart.

#14 lore raw

Re: [PATCH v2 2/2] block/mq-deadline: Fix the tag reservation code

Hi,

Quoted 8 lines · Bart Van Assche
Quoted 6 lines · Yu Kuai

We're comparing v6.6 and v5.10 performance in downstream kernel, we met a regression and bisect to this patch. And during review, I don't understand the above change.

For example, dd->async_depth is nr_requests, then dd_to_word_depth() will just return 1 << bt->sb.shift. Then nothing will be throttled.

Quoted 7 lines

(just back from traveling)

As explained in the description of commit 39823b47bbd4 ("block/mq-
deadline: Fix the tag reservation code"), the default value of async_depth has been changed from 3 * q->nr_requests / 4 into q->nr_requests to fix a performance regression. The value of dd->async_depth can be changed through sysfs.

Then I think what we should do next is to fix the sysfs api as well, it's not correct for the default value for now.

Thanks,
Kuai

Quoted 6 lines

Thanks,

Bart.
.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#16 lore raw

答复: [PATCH v2 2/2] block/mq-deadline: Fix the tag reservation code

-----邮件原件-----
发件人: Bart Van Assche <[email protected]>
发送时间: 2024年5月10日 1:02
收件人: Jens Axboe <[email protected]>
抄送: [email protected]; Christoph Hellwig <[email protected]>; Bart Van Assche <[email protected]>; Damien Le Moal <[email protected]>; 牛志国 (Zhiguo Niu) <[email protected]> 主题: [PATCH v2 2/2] block/mq-deadline: Fix the tag reservation code

注意: 这封邮件来自于外部。除非你确定邮件内容安全,否则不要点击任何链接和附件。
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

The current tag reservation code is based on a misunderstanding of the meaning of data->shallow_depth. Fix the tag reservation code as follows:
* By default, do not reserve any tags for synchronous requests because
for certain use cases reserving tags reduces performance. See also
Harshit Mogalapalli, [bug-report] Performance regression with fio
sequential-write on a multipath setup, 2024-03-07
(https://lore.kernel.org/linux-block/[email protected]/)
* Reduce min_shallow_depth to one because min_shallow_depth must be less
than or equal any shallow_depth value.
* Scale dd->async_depth from the range [1, nr_requests] to [1,
bits_per_sbitmap_word].

Cc Christoph Hellwig <[email protected]>
Cc Damien Le Moal <[email protected]>
Cc Zhiguo Niu <[email protected]>
Fixes 07757588e507 ("block/mq-deadline: Reserve 25% of scheduler tags for synchronous requests")
---
 block/mq-deadline.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
block/mq-deadline.c +16 -1
@@ -487,6 +487,20 @@ static struct request *dd_dispatch_request(struct blk_mq_hw_ctx *hctx)
        return rq;
 }
 
+/*
+ * 'depth' is a number in the range 1..INT_MAX representing a number of
+ * requests. Scale it with a factor (1 << bt->sb.shift) / 
+q->nr_requests since
+ * 1..(1 << bt->sb.shift) is the range expected by sbitmap_get_shallow().
+ * Values larger than q->nr_requests have the same effect as q->nr_requests.
+ */
+static int dd_to_word_depth(struct blk_mq_hw_ctx *hctx, unsigned int 
+qdepth) {
+       struct sbitmap_queue *bt = &hctx->sched_tags->bitmap_tags;
+       const unsigned int nrr = hctx->queue->nr_requests;
+
+       return ((qdepth << bt->sb.shift) + nrr - 1) / nrr; }
+
 /*
  * Called by __blk_mq_alloc_request(). The shallow_depth value set by this
  * function is used by __blk_mq_get_tag().
@@ -503,7 +517,7 @@ static void dd_limit_depth(blk_opf_t opf, struct blk_mq_alloc_data *data)
         * Throttle asynchronous requests and writes such that these requests
         * do not block the allocation of synchronous requests.
         */
-       data->shallow_depth = dd->async_depth;
+       data->shallow_depth = dd_to_word_depth(data->hctx, 
+ dd->async_depth);
 }
 

/* Called by blk_mq_update_nr_requests(). */ @@ -513,9 +527,9 @@ static void dd_depth_updated(struct blk_mq_hw_ctx *hctx)

        struct deadline_data *dd = q->elevator->elevator_data;
        struct blk_mq_tags *tags = hctx->sched_tags;

- dd->async_depth = max(1UL, 3 * q->nr_requests / 4);
+ dd->async_depth = q->nr_requests;

- sbitmap_queue_min_shallow_depth(&tags->bitmap_tags, dd->async_depth);
+ sbitmap_queue_min_shallow_depth(&tags->bitmap_tags, 1);
}
Hi Bart,
I tested basic function about these serial patches and results is pass, and no warning report after setting async_depth value by sysfs, so

Thanks!

/* Called by blk_mq_init_hctx() and blk_mq_init_sched(). */

maintainer Applied
#17 lore raw
In reply to Bart Van Assche
Quoted 8 lines · Bart Van Assche

The mq-deadline 'async_depth' sysfs attribute doesn't behave as intended. This patch series fixes the implementation of that attribute.

Please consider this patch series for the next merge window.

Thanks,

[...]

Applied, thanks!

[1/2] block: Call .limit_depth() after .hctx has been set

      commit: 6259151c04d4e0085e00d2dcb471ebdd1778e72e
[2/2] block/mq-deadline: Fix the tag reservation code
      commit: 39823b47bbd40502632ffba90ebb34fff7c8b5e8

Best regards,

Signature · 1 line
Jens Axboe