Skip to contentSkip to conversation

blk-mq: fix nr_requests wrong value when modify it from sysfs

PATCH In review weiping zhang 2 participants 5 messages Sep 22, 2017 – Nov 3, 2017 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 blk-mq: fix nr_requests wrong value when modify it from sysfs

if blk-mq use "none" io scheduler, nr_request get a wrong value when input a number > tag_set->queue_depth. blk_mq_tag_update_depth will get the smaller one min(nr, set->queue_depth), and then q->nr_request get a wrong value.

Reproduce:

echo none > /sys/block/nvme0n1/queue/scheduler echo 1000000 > /sys/block/nvme0n1/queue/nr_requests cat /sys/block/nvme0n1/queue/nr_requests 1000000

---

Changes since v4:
* fix typo in commit message(queue/ioscheduler => queue/scheduler)

Changes since v3:
* remove compare nr with tags->qdepth, pass nr to blk_mq_tag_update_depth
directly

* remove return EINVAL when user modify nr_request less than BLKDEV_MIN_RQ

Changes since v2:
* add return EINVAL when user modify nr_request less than BLKDEV_MIN_RQ
* remove pr_warn, and return EINVAL, if input number is too large

 block/blk-mq.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
block/blk-mq.c +1 -2
index 98a1860..491e336 100644
@@ -2642,8 +2642,7 @@ int blk_mq_update_nr_requests(struct request_queue *q, unsigned int nr)
 		 * queue depth. This is similar to what the old code would do.
 		 */
 		if (!hctx->sched_tags) {
-			ret = blk_mq_tag_update_depth(hctx, &hctx->tags,
-							min(nr, set->queue_depth),
+			ret = blk_mq_tag_update_depth(hctx, &hctx->tags, nr,
 							false);
 		} else {
 			ret = blk_mq_tag_update_depth(hctx, &hctx->sched_tags,
Signature · 1 line
2.9.4
#1 lore raw
Quoted 48 lines · weiping zhang

if blk-mq use "none" io scheduler, nr_request get a wrong value when input a number > tag_set->queue_depth. blk_mq_tag_update_depth will get the smaller one min(nr, set->queue_depth), and then q->nr_request get a wrong value.

Reproduce:

echo none > /sys/block/nvme0n1/queue/scheduler echo 1000000 > /sys/block/nvme0n1/queue/nr_requests cat /sys/block/nvme0n1/queue/nr_requests 1000000

---

Changes since v4:
* fix typo in commit message(queue/ioscheduler => queue/scheduler)

Changes since v3:
* remove compare nr with tags->qdepth, pass nr to blk_mq_tag_update_depth
directly

* remove return EINVAL when user modify nr_request less than BLKDEV_MIN_RQ

Changes since v2:
* add return EINVAL when user modify nr_request less than BLKDEV_MIN_RQ
* remove pr_warn, and return EINVAL, if input number is too large

 block/blk-mq.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
block/blk-mq.c +1 -2
index 98a1860..491e336 100644
@@ -2642,8 +2642,7 @@ int blk_mq_update_nr_requests(struct request_queue *q, unsigned int nr)
 		 * queue depth. This is similar to what the old code would do.
 		 */
 		if (!hctx->sched_tags) {
-			ret = blk_mq_tag_update_depth(hctx, &hctx->tags,
-							min(nr, set->queue_depth),
+			ret = blk_mq_tag_update_depth(hctx, &hctx->tags, nr,
 							false);
 		} else {
 			ret = blk_mq_tag_update_depth(hctx, &hctx->sched_tags,
Signature · 1 line
2.9.4

Hi Jens,

As you say before:

Quoted 3 lines

blk_mq_tag_update_depth() should already return
-EINVAL for the case where we can't grow the tags. Looks like this patch should simply remove the min(nr, set->queue_depth) and just pass in 'nr'.

I also find that hctx->tags->nr_tags equal to tag_set->queue_depth no matter use hctx->sched_tags or not. So I think it's safe to verify 'nr' by hctx->tags->nr_tags.

Thanks
weiping

#2 lore raw
Quoted 52 lines · weiping zhang
Quoted 48 lines · weiping zhang

if blk-mq use "none" io scheduler, nr_request get a wrong value when input a number > tag_set->queue_depth. blk_mq_tag_update_depth will get the smaller one min(nr, set->queue_depth), and then q->nr_request get a wrong value.

Reproduce:

echo none > /sys/block/nvme0n1/queue/scheduler echo 1000000 > /sys/block/nvme0n1/queue/nr_requests cat /sys/block/nvme0n1/queue/nr_requests 1000000

---

Changes since v4:
* fix typo in commit message(queue/ioscheduler => queue/scheduler)

Changes since v3:
* remove compare nr with tags->qdepth, pass nr to blk_mq_tag_update_depth
directly

* remove return EINVAL when user modify nr_request less than BLKDEV_MIN_RQ

Changes since v2:
* add return EINVAL when user modify nr_request less than BLKDEV_MIN_RQ
* remove pr_warn, and return EINVAL, if input number is too large

 block/blk-mq.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
block/blk-mq.c +1 -2
index 98a1860..491e336 100644
@@ -2642,8 +2642,7 @@ int blk_mq_update_nr_requests(struct request_queue *q, unsigned int nr)
 		 * queue depth. This is similar to what the old code would do.
 		 */
 		if (!hctx->sched_tags) {
-			ret = blk_mq_tag_update_depth(hctx, &hctx->tags,
-							min(nr, set->queue_depth),
+			ret = blk_mq_tag_update_depth(hctx, &hctx->tags, nr,
 							false);
 		} else {
 			ret = blk_mq_tag_update_depth(hctx, &hctx->sched_tags,
Signature · 1 line
2.9.4

Hi Jens,

Quoted 8 lines

As you say before:

Quoted 3 lines

blk_mq_tag_update_depth() should already return
-EINVAL for the case where we can't grow the tags. Looks like this patch should simply remove the min(nr, set->queue_depth) and just pass in 'nr'.

I also find that hctx->tags->nr_tags equal to tag_set->queue_depth no matter use hctx->sched_tags or not. So I think it's safe to verify 'nr' by hctx->tags->nr_tags.

Hello Jens,

ping

#3 lore raw
In reply to weiping zhang
Quoted 48 lines · weiping zhang

if blk-mq use "none" io scheduler, nr_request get a wrong value when input a number > tag_set->queue_depth. blk_mq_tag_update_depth will get the smaller one min(nr, set->queue_depth), and then q->nr_request get a wrong value.

Reproduce:

echo none > /sys/block/nvme0n1/queue/scheduler echo 1000000 > /sys/block/nvme0n1/queue/nr_requests cat /sys/block/nvme0n1/queue/nr_requests 1000000

---

Changes since v4:
* fix typo in commit message(queue/ioscheduler => queue/scheduler)

Changes since v3:
* remove compare nr with tags->qdepth, pass nr to blk_mq_tag_update_depth
directly

* remove return EINVAL when user modify nr_request less than BLKDEV_MIN_RQ

Changes since v2:
* add return EINVAL when user modify nr_request less than BLKDEV_MIN_RQ
* remove pr_warn, and return EINVAL, if input number is too large

 block/blk-mq.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
block/blk-mq.c +1 -2
index 98a1860..491e336 100644
@@ -2642,8 +2642,7 @@ int blk_mq_update_nr_requests(struct request_queue *q, unsigned int nr)
 		 * queue depth. This is similar to what the old code would do.
 		 */
 		if (!hctx->sched_tags) {
-			ret = blk_mq_tag_update_depth(hctx, &hctx->tags,
-							min(nr, set->queue_depth),
+			ret = blk_mq_tag_update_depth(hctx, &hctx->tags, nr,
 							false);
 		} else {
 			ret = blk_mq_tag_update_depth(hctx, &hctx->sched_tags,
Signature · 1 line
2.9.4

Hello Jens,

ping

maintainer
#4 lore raw
In reply to weiping zhang
Quoted 11 lines · weiping zhang

if blk-mq use "none" io scheduler, nr_request get a wrong value when input a number > tag_set->queue_depth. blk_mq_tag_update_depth will get the smaller one min(nr, set->queue_depth), and then q->nr_request get a wrong value.

Reproduce:

echo none > /sys/block/nvme0n1/queue/scheduler echo 1000000 > /sys/block/nvme0n1/queue/nr_requests cat /sys/block/nvme0n1/queue/nr_requests 1000000

Sorry for the delay - looks good to me, and also tested that it does fix the issue. Thanks, applied for 4.15.

Signature · 1 line
Jens Axboe