fix wrong value when user modify nr_request by sysfs
v2 cover fix wrong value when user modify nr_request by sysfs
Hi Jens,
This is v2 of fixing nr_request.
v1 -> v2:
blk-mq: fix nr_requests wrong value when modify it from sysfs this patch return -EINVAL when user write a value that's too large.
blk-sysfs: return EINVAL when user modify nr_request less than
BLKDEV_MIN_RQ
In order to keep same behavior with former patch, also return EINVAL when user write a value less than BLKDEV_MIN_RQ
weiping zhang (2):
blk-mq: fix nr_requests wrong value when modify it from sysfs
blk-sysfs: return EINVAL when user modify nr_request less than
BLKDEV_MIN_RQ
block/blk-mq.c | 8 ++++++-- block/blk-sysfs.c | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-)
Signature · 1 line
2.9.4
PATCH v2 1/2 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/ioscheduler echo 1000000 > /sys/block/nvme0n1/queue/nr_requests cat /sys/block/nvme0n1/queue/nr_requests 1000000
--- block/blk-mq.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
block/blk-mq.c +6 -2
@@ -2642,8 +2642,12 @@ 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), +if (nr > set->queue_depth) { + ret = -EINVAL ; +break ; + } + + 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
Jens Axboe
maintainerRe: [PATCH v2 1/2] blk-mq: fix nr_requests wrong value when modify it from sysfs
Quoted 24 lines · weiping zhang
if blk-mq use "none" io scheduler,
nr_requestget a wrong value when input a number >tag_set->queue_depth.blk_mq_tag_update_depthwill get the smaller onemin(nr, set->queue_depth), and thenq->nr_requestget a wrong value.Reproduce:
echo none >
/sys/block/nvme0n1/queue/ioschedulerecho 1000000 >/sys/block/nvme0n1/queue/nr_requestscat/sys/block/nvme0n1/queue/nr_requests1000000Signed-off-by weiping zhang <[email protected]>--- block/blk-mq.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)block/blk-mq.c +0
-0@@ -2642,8 +2642,12 @@ 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. */
block/blk-mq.c int blk_mq_update_nr_requests(struct request_queue *q, unsigned int nr) · line 2651
Quoted 10 lines
block/blk-mq.c +6
-2if (!hctx->sched_tags) { - ret =blk_mq_tag_update_depth (hctx, &hctx->tags, -min (nr, set->queue_depth), +if (nr > set->queue_depth) { + ret = -EINVAL ; +break ; + } + + ret =blk_mq_tag_update_depth (hctx, &hctx->tags, nr, false);
What am I missing here? 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'. Should not need the duplicated check for depth.
Signature · 1 line
Jens Axboe
Re: [PATCH v2 1/2] blk-mq: fix nr_requests wrong value when modify it from sysfs
Quoted 32 lines · Jens Axboe
Quoted 31 lines · weiping zhang
if blk-mq use "none" io scheduler,
nr_requestget a wrong value when input a number >tag_set->queue_depth.blk_mq_tag_update_depthwill get the smaller onemin(nr, set->queue_depth), and thenq->nr_requestget a wrong value.Reproduce:
echo none >
/sys/block/nvme0n1/queue/ioschedulerecho 1000000 >/sys/block/nvme0n1/queue/nr_requestscat/sys/block/nvme0n1/queue/nr_requests1000000Signed-off-by weiping zhang <[email protected]>--- block/blk-mq.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)block/blk-mq.c +4
-2@@ -2642,8 +2642,12 @@ 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), +if (nr > set->queue_depth) { + ret = -EINVAL ; +break ; + }
Quoted 9 lines
block/blk-mq.c int blk_mq_update_nr_requests(struct request_queue *q, unsigned int nr) · line 2651
Quoted 3 lines
block/blk-mq.c +2
-0+ + ret =blk_mq_tag_update_depth (hctx, &hctx->tags, nr, false);What am I missing here?
blk_mq_tag_update_depth()should already return-EINVALfor the case where we can't grow the tags. Looks like this patch should simply remove themin(nr, set->queue_depth)and just pass in 'nr'. Should not need the duplicated check for depth.
Ya, you are right, I will send V3 later.
Thanks
PATCH v2 2/2 blk-sysfs: return EINVAL when user modify nr_request less than BLKDEV_MIN_RQ
In reply to weiping zhang--- block/blk-sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/blk-sysfs.c +1 -1
@@ -75,7 +75,7 @@ queue_requests_store(struct request_queue *q, const char *page, size_t count)return ret;if (nr <BLKDEV_MIN_RQ ) - nr =BLKDEV_MIN_RQ ; +return -EINVAL ;if (q->request_fn) err =blk_update_nr_requests (q, nr);
Signature · 1 line
2.9.4
Jens Axboe
maintainerRe: [PATCH v2 2/2] blk-sysfs: return EINVAL when user modify nr_request less than BLKDEV_MIN_RQ
Quoted 10 lines · weiping zhang
Signed-off-by weiping zhang <[email protected]>--- block/blk-sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)block/blk-sysfs.c +0
-0
block/blk-sysfs.c queue_requests_store(struct request_queue *q, const char *page, size_t count) · line 78
Quoted 5 lines
block/blk-sysfs.c +1
-1@@ -75,7 +75,7 @@ queue_requests_store(struct request_queue *q, const char *page, size_t count)return ret;if (nr <BLKDEV_MIN_RQ ) - nr =BLKDEV_MIN_RQ ; +return -EINVAL ;
This is potentially breaking existing scripts.
Signature · 1 line
Jens Axboe
Re: [PATCH v2 2/2] blk-sysfs: return EINVAL when user modify nr_request less than BLKDEV_MIN_RQ
Quoted 13 lines · Jens Axboe
Quoted 12 lines · weiping zhang
Signed-off-by weiping zhang <[email protected]>--- block/blk-sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)block/blk-sysfs.c +0
-0@@ -75,7 +75,7 @@ queue_requests_store(struct request_queue *q, const char *page, size_t count)return ret;
Quoted 6 lines
block/blk-sysfs.c queue_requests_store(struct request_queue *q, const char *page, size_t count) · line 78
Quoted 3 lines
block/blk-sysfs.c +1
-1if (nr <BLKDEV_MIN_RQ ) - nr =BLKDEV_MIN_RQ ; +return -EINVAL ;This is potentially breaking existing scripts.
I just want this keep same behavior with the too larger case, If this may make other side effect, I drop this patch.
Thanks
weiping