All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] blk-mq: fix nr_requests wrong value when modify it from sysfs
@ 2017-09-03 13:46 weiping zhang
  2017-09-04 10:02 ` Ming Lei
  2017-09-05 15:42 ` Bart Van Assche
  0 siblings, 2 replies; 9+ messages in thread
From: weiping zhang @ 2017-09-03 13:46 UTC (permalink / raw)
  To: axboe; +Cc: linux-block

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

Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
---
 block/blk-mq.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index f84d145..8303e5e 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2622,8 +2622,11 @@ 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) {
+				nr = set->queue_depth;
+				pr_warn("reduce nr_request to %u\n", nr);
+			}
+			ret = blk_mq_tag_update_depth(hctx, &hctx->tags, nr,
 							false);
 		} else {
 			ret = blk_mq_tag_update_depth(hctx, &hctx->sched_tags,
-- 
2.9.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] blk-mq: fix nr_requests wrong value when modify it from sysfs
  2017-09-03 13:46 [PATCH] blk-mq: fix nr_requests wrong value when modify it from sysfs weiping zhang
@ 2017-09-04 10:02 ` Ming Lei
  2017-09-05 15:42 ` Bart Van Assche
  1 sibling, 0 replies; 9+ messages in thread
From: Ming Lei @ 2017-09-04 10:02 UTC (permalink / raw)
  To: Jens Axboe, linux-block

On Sun, Sep 3, 2017 at 9:46 PM, weiping zhang
<zhangweiping@didichuxing.com> wrote:
> 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
>
> Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
> ---
>  block/blk-mq.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/block/blk-mq.c b/block/blk-mq.c
> index f84d145..8303e5e 100644
> --- a/block/blk-mq.c
> +++ b/block/blk-mq.c
> @@ -2622,8 +2622,11 @@ 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) {
> +                               nr = set->queue_depth;
> +                               pr_warn("reduce nr_request to %u\n", nr);
> +                       }
> +                       ret = blk_mq_tag_update_depth(hctx, &hctx->tags, nr,
>                                                         false);
>                 } else {
>                         ret = blk_mq_tag_update_depth(hctx, &hctx->sched_tags,

Not sure if the pr_warn() is useful, but the idea is correct:

          Reviewed-by: Ming Lei <ming.lei@redhat.com>

-- 
Ming Lei

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] blk-mq: fix nr_requests wrong value when modify it from sysfs
  2017-09-03 13:46 [PATCH] blk-mq: fix nr_requests wrong value when modify it from sysfs weiping zhang
  2017-09-04 10:02 ` Ming Lei
@ 2017-09-05 15:42 ` Bart Van Assche
  2017-09-06  7:34   ` weiping zhang
  1 sibling, 1 reply; 9+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V1ZSBkZXB0aC4NCg0KVGhhbmtzLA0KDQpCYXJ0Lg==

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] blk-mq: fix nr_requests wrong value when modify it from sysfs
  2017-09-05 15:42 ` Bart Van Assche
@ 2017-09-06  7:34   ` weiping zhang
  2017-09-06 13:00     ` Bart Van Assche
  0 siblings, 1 reply; 9+ messages in thread
From: weiping zhang @ 2017-09-06  7:34 UTC (permalink / raw)
  To: Bart Van Assche; +Cc: axboe, linux-block

On Tue, Sep 05, 2017 at 03:42:45PM +0000, Bart Van Assche wrote:
> On Sun, 2017-09-03 at 21:46 +0800, weiping zhang wrote:
> > 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
> > 
> > Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
> > ---
> >  block/blk-mq.c | 7 +++++--
> >  1 file changed, 5 insertions(+), 2 deletions(-)
> > 
> > diff --git a/block/blk-mq.c b/block/blk-mq.c
> > index f84d145..8303e5e 100644
> > --- a/block/blk-mq.c
> > +++ b/block/blk-mq.c
> > @@ -2622,8 +2622,11 @@ 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) {
> > +				nr = set->queue_depth;
> > +				pr_warn("reduce nr_request to %u\n", nr);
> > +			}
> > +			ret = blk_mq_tag_update_depth(hctx, &hctx->tags, nr,
> >  							false);
> >  		} else {
> >  			ret = blk_mq_tag_update_depth(hctx, &hctx->sched_tags,
> 
> Shouldn't this code return -EINVAL or -ERANGE if 'nr' is too large? That will help to
> keep user space code simple that updates the queue depth.

Hi Bart,

The reason why not return -EINVAL is keeping alin with minimum checking in queue_requests_store,
if you insist return -EINVAL/-ERANGE, minimum checking should also keep
same behavior. Both return error meesage and quietly changing are okey
for me. Which way do you prefer ?

static ssize_t
queue_requests_store(struct request_queue *q, const char *page, size_t count)
{
	unsigned long nr;
	int ret, err;

	if (!q->request_fn && !q->mq_ops)
		return -EINVAL;

	ret = queue_var_store(&nr, page, count);
	if (ret < 0)
		return ret;

	if (nr < BLKDEV_MIN_RQ)
		nr = BLKDEV_MIN_RQ;

Thanks

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] blk-mq: fix nr_requests wrong value when modify it from sysfs
  2017-09-06  7:34   ` weiping zhang
@ 2017-09-06 13:00     ` Bart Van Assche
  2017-09-12 13:57       ` weiping zhang
  0 siblings, 1 reply; 9+ messages in thread
From: Bart Van Assche @ 2017-09-06 13:00 UTC (permalink / raw)
  To: zhangweiping; +Cc: linux-block, axboe

T24gV2VkLCAyMDE3LTA5LTA2IGF0IDE1OjM0ICswODAwLCB3ZWlwaW5nIHpoYW5nIHdyb3RlOg0K
PiBPbiBUdWUsIFNlcCAwNSwgMjAxNyBhdCAwMzo0Mjo0NVBNICswMDAwLCBCYXJ0IFZhbiBBc3Nj
aGUgd3JvdGU6DQo+ID4gT24gU3VuLCAyMDE3LTA5LTAzIGF0IDIxOjQ2ICswODAwLCB3ZWlwaW5n
IHpoYW5nIHdyb3RlOg0KPiA+ID4gaWYgYmxrLW1xIHVzZSAibm9uZSIgaW8gc2NoZWR1bGVyLCBu
cl9yZXF1ZXN0IGdldCBhIHdyb25nIHZhbHVlIHdoZW4NCj4gPiA+IGlucHV0IGEgbnVtYmVyID4g
dGFnX3NldC0+cXVldWVfZGVwdGguIGJsa19tcV90YWdfdXBkYXRlX2RlcHRoIHdpbGwgZ2V0DQo+
ID4gPiB0aGU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W5zaXN0IHJldHVybiAtRUlOVkFMLy1FUkFO
R0UsIG1pbmltdW0gY2hlY2tpbmcgc2hvdWxkIGFsc28ga2VlcA0KPiBzYW1lIGJlaGF2aW9yLiBC
b3RoIHJldHVybiBlcnJvciBtZWVzYWdlIGFuZCBxdWlldGx5IGNoYW5naW5nIGFyZSBva2V5DQo+
IGZvciBtZS4gV2hpY2ggd2F5IGRvIHlvdSBwcmVmZXIgPw0KPiANCj4gc3RhdGljIHNzaXplX3QN
Cj4gcXVldWVfcmVxdWVzdHNfc3RvcmUoc3RydWN0IHJlcXVlc3RfcXVldWUgKnEsIGNvbnN0IGNo
YXIgKnBhZ2UsIHNpemVfdCBjb3VudCkNCj4gew0KPiAJdW5zaWduZWQgbG9uZyBucjsNCj4gCWlu
dCByZXQsIGVycjsNCj4gDQo+IAlpZiAoIXEtPnJlcXVlc3RfZm4gJiYgIXEtPm1xX29wcykNCj4g
CQlyZXR1cm4gLUVJTlZBTDsNCj4gDQo+IAlyZXQgPSBxdWV1ZV92YXJfc3RvcmUoJm5yLCBwYWdl
LCBjb3VudCk7DQo+IAlpZiAocmV0IDwgMCkNCj4gCQlyZXR1cm4gcmV0Ow0KPiANCj4gCWlmIChu
ciA8IEJMS0RFVl9NSU5fUlEpDQo+IAkJbnIgPSBCTEtERVZfTUlOX1JROw0KDQpIZWxsbyBKZW5z
LA0KDQpEbyB5b3UgcGVyaGFwcyBoYXZlIGEgcHJlZmVyZW5jZSBmb3Igb25lIG9mIHRoZSBhcHBy
b2FjaGVzIHRoYXQgaGF2ZSBiZWVuIGRpc2N1c3NlZA0KaW4gdGhpcyBlLW1haWwgdGhyZWFkPw0K
DQpUaGFua3MsDQoNCkJhcnQu

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] blk-mq: fix nr_requests wrong value when modify it from sysfs
  2017-09-06 13:00     ` Bart Van Assche
@ 2017-09-12 13:57       ` weiping zhang
  2017-09-21 13:03         ` weiping zhang
  0 siblings, 1 reply; 9+ messages in thread
From: weiping zhang @ 2017-09-12 13:57 UTC (permalink / raw)
  To: axboe, Bart Van Assche; +Cc: linux-block, axboe

On Wed, Sep 06, 2017 at 01:00:44PM +0000, Bart Van Assche wrote:
> On Wed, 2017-09-06 at 15:34 +0800, weiping zhang wrote:
> > On Tue, Sep 05, 2017 at 03:42:45PM +0000, Bart Van Assche wrote:
> > > On Sun, 2017-09-03 at 21:46 +0800, weiping zhang wrote:
> > > > 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
> > > > 
> > > > Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
> > > > ---
> > > >  block/blk-mq.c | 7 +++++--
> > > >  1 file changed, 5 insertions(+), 2 deletions(-)
> > > > 
> > > > diff --git a/block/blk-mq.c b/block/blk-mq.c
> > > > index f84d145..8303e5e 100644
> > > > --- a/block/blk-mq.c
> > > > +++ b/block/blk-mq.c
> > > > @@ -2622,8 +2622,11 @@ 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) {
> > > > +				nr = set->queue_depth;
> > > > +				pr_warn("reduce nr_request to %u\n", nr);
> > > > +			}
> > > > +			ret = blk_mq_tag_update_depth(hctx, &hctx->tags, nr,
> > > >  							false);
> > > >  		} else {
> > > >  			ret = blk_mq_tag_update_depth(hctx, &hctx->sched_tags,
> > > 
> > > Shouldn't this code return -EINVAL or -ERANGE if 'nr' is too large? That will help to
> > > keep user space code simple that updates the queue depth.
> > 
> > Hi Bart,
> > 
> > The reason why not return -EINVAL is keeping alin with minimum checking in queue_requests_store,
> > if you insist return -EINVAL/-ERANGE, minimum checking should also keep
> > same behavior. Both return error meesage and quietly changing are okey
> > for me. Which way do you prefer ?
> > 
> > static ssize_t
> > queue_requests_store(struct request_queue *q, const char *page, size_t count)
> > {
> > 	unsigned long nr;
> > 	int ret, err;
> > 
> > 	if (!q->request_fn && !q->mq_ops)
> > 		return -EINVAL;
> > 
> > 	ret = queue_var_store(&nr, page, count);
> > 	if (ret < 0)
> > 		return ret;
> > 
> > 	if (nr < BLKDEV_MIN_RQ)
> > 		nr = BLKDEV_MIN_RQ;
> 
> Hello Jens,
> 
> Do you perhaps have a preference for one of the approaches that have been discussed
> in this e-mail thread?
> 
> Thanks,
> 
> Bart.

Hello Jens,

Would you please give some comments about this patch,

Thanks
Weiping.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] blk-mq: fix nr_requests wrong value when modify it from sysfs
  2017-09-12 13:57       ` weiping zhang
@ 2017-09-21 13:03         ` weiping zhang
  2017-09-21 14:09           ` Jens Axboe
  0 siblings, 1 reply; 9+ messages in thread
From: weiping zhang @ 2017-09-21 13:03 UTC (permalink / raw)
  To: axboe, Bart Van Assche; +Cc: linux-block

On Tue, Sep 12, 2017 at 09:57:32PM +0800, weiping zhang wrote:
> On Wed, Sep 06, 2017 at 01:00:44PM +0000, Bart Van Assche wrote:
> > On Wed, 2017-09-06 at 15:34 +0800, weiping zhang wrote:
> > > On Tue, Sep 05, 2017 at 03:42:45PM +0000, Bart Van Assche wrote:
> > > > On Sun, 2017-09-03 at 21:46 +0800, weiping zhang wrote:
> > > > > 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
> > > > > 
> > > > > Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
> > > > > ---
> > > > >  block/blk-mq.c | 7 +++++--
> > > > >  1 file changed, 5 insertions(+), 2 deletions(-)
> > > > > 
> > > > > diff --git a/block/blk-mq.c b/block/blk-mq.c
> > > > > index f84d145..8303e5e 100644
> > > > > --- a/block/blk-mq.c
> > > > > +++ b/block/blk-mq.c
> > > > > @@ -2622,8 +2622,11 @@ 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) {
> > > > > +				nr = set->queue_depth;
> > > > > +				pr_warn("reduce nr_request to %u\n", nr);
> > > > > +			}
> > > > > +			ret = blk_mq_tag_update_depth(hctx, &hctx->tags, nr,
> > > > >  							false);
> > > > >  		} else {
> > > > >  			ret = blk_mq_tag_update_depth(hctx, &hctx->sched_tags,
> > > > 
> > > > Shouldn't this code return -EINVAL or -ERANGE if 'nr' is too large? That will help to
> > > > keep user space code simple that updates the queue depth.
> > > 
> > > Hi Bart,
> > > 
> > > The reason why not return -EINVAL is keeping alin with minimum checking in queue_requests_store,
> > > if you insist return -EINVAL/-ERANGE, minimum checking should also keep
> > > same behavior. Both return error meesage and quietly changing are okey
> > > for me. Which way do you prefer ?
> > > 
> > > static ssize_t
> > > queue_requests_store(struct request_queue *q, const char *page, size_t count)
> > > {
> > > 	unsigned long nr;
> > > 	int ret, err;
> > > 
> > > 	if (!q->request_fn && !q->mq_ops)
> > > 		return -EINVAL;
> > > 
> > > 	ret = queue_var_store(&nr, page, count);
> > > 	if (ret < 0)
> > > 		return ret;
> > > 
> > > 	if (nr < BLKDEV_MIN_RQ)
> > > 		nr = BLKDEV_MIN_RQ;
> > 
> > Hello Jens,
> > 
> > Do you perhaps have a preference for one of the approaches that have been discussed
> > in this e-mail thread?
> > 
> > Thanks,
> > 
> > Bart.
> 
Hello Jens,

Would you please give some comments about this patch,

Thanks
Weiping.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] blk-mq: fix nr_requests wrong value when modify it from sysfs
  2017-09-21 13:03         ` weiping zhang
@ 2017-09-21 14:09           ` Jens Axboe
  2017-09-21 15:14             ` weiping zhang
  0 siblings, 1 reply; 9+ messages in thread
From: Jens Axboe @ 2017-09-21 14:09 UTC (permalink / raw)
  To: Bart Van Assche, linux-block

On 09/21/2017 07:03 AM, weiping zhang wrote:
> On Tue, Sep 12, 2017 at 09:57:32PM +0800, weiping zhang wrote:
>> On Wed, Sep 06, 2017 at 01:00:44PM +0000, Bart Van Assche wrote:
>>> On Wed, 2017-09-06 at 15:34 +0800, weiping zhang wrote:
>>>> On Tue, Sep 05, 2017 at 03:42:45PM +0000, Bart Van Assche wrote:
>>>>> On Sun, 2017-09-03 at 21:46 +0800, weiping zhang wrote:
>>>>>> 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
>>>>>>
>>>>>> Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
>>>>>> ---
>>>>>>  block/blk-mq.c | 7 +++++--
>>>>>>  1 file changed, 5 insertions(+), 2 deletions(-)
>>>>>>
>>>>>> diff --git a/block/blk-mq.c b/block/blk-mq.c
>>>>>> index f84d145..8303e5e 100644
>>>>>> --- a/block/blk-mq.c
>>>>>> +++ b/block/blk-mq.c
>>>>>> @@ -2622,8 +2622,11 @@ 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) {
>>>>>> +				nr = set->queue_depth;
>>>>>> +				pr_warn("reduce nr_request to %u\n", nr);
>>>>>> +			}
>>>>>> +			ret = blk_mq_tag_update_depth(hctx, &hctx->tags, nr,
>>>>>>  							false);
>>>>>>  		} else {
>>>>>>  			ret = blk_mq_tag_update_depth(hctx, &hctx->sched_tags,
>>>>>
>>>>> Shouldn't this code return -EINVAL or -ERANGE if 'nr' is too large? That will help to
>>>>> keep user space code simple that updates the queue depth.
>>>>
>>>> Hi Bart,
>>>>
>>>> The reason why not return -EINVAL is keeping alin with minimum checking in queue_requests_store,
>>>> if you insist return -EINVAL/-ERANGE, minimum checking should also keep
>>>> same behavior. Both return error meesage and quietly changing are okey
>>>> for me. Which way do you prefer ?
>>>>
>>>> static ssize_t
>>>> queue_requests_store(struct request_queue *q, const char *page, size_t count)
>>>> {
>>>> 	unsigned long nr;
>>>> 	int ret, err;
>>>>
>>>> 	if (!q->request_fn && !q->mq_ops)
>>>> 		return -EINVAL;
>>>>
>>>> 	ret = queue_var_store(&nr, page, count);
>>>> 	if (ret < 0)
>>>> 		return ret;
>>>>
>>>> 	if (nr < BLKDEV_MIN_RQ)
>>>> 		nr = BLKDEV_MIN_RQ;
>>>
>>> Hello Jens,
>>>
>>> Do you perhaps have a preference for one of the approaches that have been discussed
>>> in this e-mail thread?
>>>
>>> Thanks,
>>>
>>> Bart.
>>
> Hello Jens,
> 
> Would you please give some comments about this patch,

If someone writes a value that's too large, return -EINVAL and
don't set it. Don't add weird debug printks.


-- 
Jens Axboe

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] blk-mq: fix nr_requests wrong value when modify it from sysfs
  2017-09-21 14:09           ` Jens Axboe
@ 2017-09-21 15:14             ` weiping zhang
  0 siblings, 0 replies; 9+ messages in thread
From: weiping zhang @ 2017-09-21 15:14 UTC (permalink / raw)
  To: Jens Axboe; +Cc: Bart Van Assche, linux-block

On Thu, Sep 21, 2017 at 08:09:47AM -0600, Jens Axboe wrote:
> On 09/21/2017 07:03 AM, weiping zhang wrote:
> > On Tue, Sep 12, 2017 at 09:57:32PM +0800, weiping zhang wrote:
> >> On Wed, Sep 06, 2017 at 01:00:44PM +0000, Bart Van Assche wrote:
> >>> On Wed, 2017-09-06 at 15:34 +0800, weiping zhang wrote:
> >>>> On Tue, Sep 05, 2017 at 03:42:45PM +0000, Bart Van Assche wrote:
> >>>>> On Sun, 2017-09-03 at 21:46 +0800, weiping zhang wrote:
> >>>>>> 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
> >>>>>>
> >>>>>> Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
> >>>>>> ---
> >>>>>>  block/blk-mq.c | 7 +++++--
> >>>>>>  1 file changed, 5 insertions(+), 2 deletions(-)
> >>>>>>
> >>>>>> diff --git a/block/blk-mq.c b/block/blk-mq.c
> >>>>>> index f84d145..8303e5e 100644
> >>>>>> --- a/block/blk-mq.c
> >>>>>> +++ b/block/blk-mq.c
> >>>>>> @@ -2622,8 +2622,11 @@ 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) {
> >>>>>> +				nr = set->queue_depth;
> >>>>>> +				pr_warn("reduce nr_request to %u\n", nr);
> >>>>>> +			}
> >>>>>> +			ret = blk_mq_tag_update_depth(hctx, &hctx->tags, nr,
> >>>>>>  							false);
> >>>>>>  		} else {
> >>>>>>  			ret = blk_mq_tag_update_depth(hctx, &hctx->sched_tags,
> >>>>>
> >>>>> Shouldn't this code return -EINVAL or -ERANGE if 'nr' is too large? That will help to
> >>>>> keep user space code simple that updates the queue depth.
> >>>>
> >>>> Hi Bart,
> >>>>
> >>>> The reason why not return -EINVAL is keeping alin with minimum checking in queue_requests_store,
> >>>> if you insist return -EINVAL/-ERANGE, minimum checking should also keep
> >>>> same behavior. Both return error meesage and quietly changing are okey
> >>>> for me. Which way do you prefer ?
> >>>>
> >>>> static ssize_t
> >>>> queue_requests_store(struct request_queue *q, const char *page, size_t count)
> >>>> {
> >>>> 	unsigned long nr;
> >>>> 	int ret, err;
> >>>>
> >>>> 	if (!q->request_fn && !q->mq_ops)
> >>>> 		return -EINVAL;
> >>>>
> >>>> 	ret = queue_var_store(&nr, page, count);
> >>>> 	if (ret < 0)
> >>>> 		return ret;
> >>>>
> >>>> 	if (nr < BLKDEV_MIN_RQ)
> >>>> 		nr = BLKDEV_MIN_RQ;
> >>>
> >>> Hello Jens,
> >>>
> >>> Do you perhaps have a preference for one of the approaches that have been discussed
> >>> in this e-mail thread?
> >>>
> >>> Thanks,
> >>>
> >>> Bart.
> >>
> > Hello Jens,
> > 
> > Would you please give some comments about this patch,
> 
> If someone writes a value that's too large, return -EINVAL and
> don't set it. Don't add weird debug printks.
> 
> 
OK, I send patch V2 soon.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-09-21 15:14 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-03 13:46 [PATCH] blk-mq: fix nr_requests wrong value when modify it from sysfs weiping zhang
2017-09-04 10:02 ` Ming Lei
2017-09-05 15:42 ` Bart Van Assche
2017-09-06  7:34   ` weiping zhang
2017-09-06 13:00     ` Bart Van Assche
2017-09-12 13:57       ` weiping zhang
2017-09-21 13:03         ` weiping zhang
2017-09-21 14:09           ` Jens Axboe
2017-09-21 15:14             ` weiping zhang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.