public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH] /dev/mem: nowait zero/null ops
@ 2021-09-08 10:06 Pavel Begunkov
  2021-09-08 10:25 ` Greg Kroah-Hartman
  2021-09-08 12:57 ` Jens Axboe
  0 siblings, 2 replies; 6+ messages in thread
From: Pavel Begunkov @ 2021-09-08 10:06 UTC (permalink / raw)
  To: Arnd Bergmann, Greg Kroah-Hartman, linux-kernel; +Cc: Jens Axboe, io-uring

Make read_iter_zero() to honor IOCB_NOWAIT, so /dev/zero can be
advertised as FMODE_NOWAIT. This helps subsystems like io_uring to use
it more effectively. Set FMODE_NOWAIT for /dev/null as well, it never
waits and therefore trivially meets the criteria.

Signed-off-by: Pavel Begunkov <[email protected]>
---
 drivers/char/mem.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 1c596b5cdb27..531f144d7132 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -495,6 +495,8 @@ static ssize_t read_iter_zero(struct kiocb *iocb, struct iov_iter *iter)
 		written += n;
 		if (signal_pending(current))
 			return written ? written : -ERESTARTSYS;
+		if (iocb->ki_flags & IOCB_NOWAIT)
+			return written ? written : -EAGAIN;
 		cond_resched();
 	}
 	return written;
@@ -696,11 +698,11 @@ static const struct memdev {
 #ifdef CONFIG_DEVMEM
 	 [DEVMEM_MINOR] = { "mem", 0, &mem_fops, FMODE_UNSIGNED_OFFSET },
 #endif
-	 [3] = { "null", 0666, &null_fops, 0 },
+	 [3] = { "null", 0666, &null_fops, FMODE_NOWAIT },
 #ifdef CONFIG_DEVPORT
 	 [4] = { "port", 0, &port_fops, 0 },
 #endif
-	 [5] = { "zero", 0666, &zero_fops, 0 },
+	 [5] = { "zero", 0666, &zero_fops, FMODE_NOWAIT },
 	 [7] = { "full", 0666, &full_fops, 0 },
 	 [8] = { "random", 0666, &random_fops, 0 },
 	 [9] = { "urandom", 0666, &urandom_fops, 0 },
-- 
2.33.0


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

* Re: [PATCH] /dev/mem: nowait zero/null ops
  2021-09-08 10:06 [PATCH] /dev/mem: nowait zero/null ops Pavel Begunkov
@ 2021-09-08 10:25 ` Greg Kroah-Hartman
  2021-09-08 10:54   ` Pavel Begunkov
  2021-09-08 12:57 ` Jens Axboe
  1 sibling, 1 reply; 6+ messages in thread
From: Greg Kroah-Hartman @ 2021-09-08 10:25 UTC (permalink / raw)
  To: Pavel Begunkov; +Cc: Arnd Bergmann, linux-kernel, Jens Axboe, io-uring

On Wed, Sep 08, 2021 at 11:06:51AM +0100, Pavel Begunkov wrote:
> Make read_iter_zero() to honor IOCB_NOWAIT, so /dev/zero can be
> advertised as FMODE_NOWAIT. This helps subsystems like io_uring to use
> it more effectively. Set FMODE_NOWAIT for /dev/null as well, it never
> waits and therefore trivially meets the criteria.

I do not understand, why would io_uring need to use /dev/zero and how is
this going to help anything?

What workload does this help with?

thanks,

greg k-h

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

* Re: [PATCH] /dev/mem: nowait zero/null ops
  2021-09-08 10:25 ` Greg Kroah-Hartman
@ 2021-09-08 10:54   ` Pavel Begunkov
  0 siblings, 0 replies; 6+ messages in thread
From: Pavel Begunkov @ 2021-09-08 10:54 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Arnd Bergmann, linux-kernel, Jens Axboe, io-uring

On 9/8/21 11:25 AM, Greg Kroah-Hartman wrote:
> On Wed, Sep 08, 2021 at 11:06:51AM +0100, Pavel Begunkov wrote:
>> Make read_iter_zero() to honor IOCB_NOWAIT, so /dev/zero can be
>> advertised as FMODE_NOWAIT. This helps subsystems like io_uring to use
>> it more effectively. Set FMODE_NOWAIT for /dev/null as well, it never
>> waits and therefore trivially meets the criteria.
> 
> I do not understand, why would io_uring need to use /dev/zero

Not directly, users can issue I/O against it via io_uring.
 
> and how is this going to help anything?

For files not supporting nowait io_uring goes through a quite slow path.

> What workload does this help with?

Personally for me it's dumping output and benchmarking (not benchmarking
/dev/zero, of course). But I'd also expect any tool that may be using
it but rewritten with io_uring being able to normally use it without a
performance hit.

-- 
Pavel Begunkov

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

* Re: [PATCH] /dev/mem: nowait zero/null ops
  2021-09-08 10:06 [PATCH] /dev/mem: nowait zero/null ops Pavel Begunkov
  2021-09-08 10:25 ` Greg Kroah-Hartman
@ 2021-09-08 12:57 ` Jens Axboe
  2021-09-08 13:07   ` Pavel Begunkov
  1 sibling, 1 reply; 6+ messages in thread
From: Jens Axboe @ 2021-09-08 12:57 UTC (permalink / raw)
  To: Pavel Begunkov, Arnd Bergmann, Greg Kroah-Hartman, linux-kernel; +Cc: io-uring

On 9/8/21 4:06 AM, Pavel Begunkov wrote:
> Make read_iter_zero() to honor IOCB_NOWAIT, so /dev/zero can be
> advertised as FMODE_NOWAIT. This helps subsystems like io_uring to use
> it more effectively. Set FMODE_NOWAIT for /dev/null as well, it never
> waits and therefore trivially meets the criteria.
> 
> Signed-off-by: Pavel Begunkov <[email protected]>
> ---
>  drivers/char/mem.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/char/mem.c b/drivers/char/mem.c
> index 1c596b5cdb27..531f144d7132 100644
> --- a/drivers/char/mem.c
> +++ b/drivers/char/mem.c
> @@ -495,6 +495,8 @@ static ssize_t read_iter_zero(struct kiocb *iocb, struct iov_iter *iter)
>  		written += n;
>  		if (signal_pending(current))
>  			return written ? written : -ERESTARTSYS;
> +		if (iocb->ki_flags & IOCB_NOWAIT)
> +			return written ? written : -EAGAIN;
>  		cond_resched();
>  	}

I don't think this part is needed.

>  	return written;
> @@ -696,11 +698,11 @@ static const struct memdev {
>  #ifdef CONFIG_DEVMEM
>  	 [DEVMEM_MINOR] = { "mem", 0, &mem_fops, FMODE_UNSIGNED_OFFSET },
>  #endif
> -	 [3] = { "null", 0666, &null_fops, 0 },
> +	 [3] = { "null", 0666, &null_fops, FMODE_NOWAIT },
>  #ifdef CONFIG_DEVPORT
>  	 [4] = { "port", 0, &port_fops, 0 },
>  #endif
> -	 [5] = { "zero", 0666, &zero_fops, 0 },
> +	 [5] = { "zero", 0666, &zero_fops, FMODE_NOWAIT },
>  	 [7] = { "full", 0666, &full_fops, 0 },
>  	 [8] = { "random", 0666, &random_fops, 0 },
>  	 [9] = { "urandom", 0666, &urandom_fops, 0 },
> 

This looks fine.

-- 
Jens Axboe


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

* Re: [PATCH] /dev/mem: nowait zero/null ops
  2021-09-08 12:57 ` Jens Axboe
@ 2021-09-08 13:07   ` Pavel Begunkov
  2021-09-08 13:53     ` Jens Axboe
  0 siblings, 1 reply; 6+ messages in thread
From: Pavel Begunkov @ 2021-09-08 13:07 UTC (permalink / raw)
  To: Jens Axboe, Arnd Bergmann, Greg Kroah-Hartman, linux-kernel; +Cc: io-uring

On 9/8/21 1:57 PM, Jens Axboe wrote:
> On 9/8/21 4:06 AM, Pavel Begunkov wrote:
>> Make read_iter_zero() to honor IOCB_NOWAIT, so /dev/zero can be
>> advertised as FMODE_NOWAIT. This helps subsystems like io_uring to use
>> it more effectively. Set FMODE_NOWAIT for /dev/null as well, it never
>> waits and therefore trivially meets the criteria.
>>
>> Signed-off-by: Pavel Begunkov <[email protected]>
>> ---
>>  drivers/char/mem.c | 6 ++++--
>>  1 file changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/char/mem.c b/drivers/char/mem.c
>> index 1c596b5cdb27..531f144d7132 100644
>> --- a/drivers/char/mem.c
>> +++ b/drivers/char/mem.c
>> @@ -495,6 +495,8 @@ static ssize_t read_iter_zero(struct kiocb *iocb, struct iov_iter *iter)
>>  		written += n;
>>  		if (signal_pending(current))
>>  			return written ? written : -ERESTARTSYS;
>> +		if (iocb->ki_flags & IOCB_NOWAIT)
>> +			return written ? written : -EAGAIN;
>>  		cond_resched();
>>  	}
> 
> I don't think this part is needed.

It can be clearing gigabytes in one go. Won't it be too much of a
delay when nowait is expected?
 
>>  	return written;
>> @@ -696,11 +698,11 @@ static const struct memdev {
>>  #ifdef CONFIG_DEVMEM
>>  	 [DEVMEM_MINOR] = { "mem", 0, &mem_fops, FMODE_UNSIGNED_OFFSET },
>>  #endif
>> -	 [3] = { "null", 0666, &null_fops, 0 },
>> +	 [3] = { "null", 0666, &null_fops, FMODE_NOWAIT },
>>  #ifdef CONFIG_DEVPORT
>>  	 [4] = { "port", 0, &port_fops, 0 },
>>  #endif
>> -	 [5] = { "zero", 0666, &zero_fops, 0 },
>> +	 [5] = { "zero", 0666, &zero_fops, FMODE_NOWAIT },
>>  	 [7] = { "full", 0666, &full_fops, 0 },
>>  	 [8] = { "random", 0666, &random_fops, 0 },
>>  	 [9] = { "urandom", 0666, &urandom_fops, 0 },
>>
> 
> This looks fine.
> 

-- 
Pavel Begunkov

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

* Re: [PATCH] /dev/mem: nowait zero/null ops
  2021-09-08 13:07   ` Pavel Begunkov
@ 2021-09-08 13:53     ` Jens Axboe
  0 siblings, 0 replies; 6+ messages in thread
From: Jens Axboe @ 2021-09-08 13:53 UTC (permalink / raw)
  To: Pavel Begunkov, Arnd Bergmann, Greg Kroah-Hartman, linux-kernel; +Cc: io-uring

On 9/8/21 7:07 AM, Pavel Begunkov wrote:
> On 9/8/21 1:57 PM, Jens Axboe wrote:
>> On 9/8/21 4:06 AM, Pavel Begunkov wrote:
>>> Make read_iter_zero() to honor IOCB_NOWAIT, so /dev/zero can be
>>> advertised as FMODE_NOWAIT. This helps subsystems like io_uring to use
>>> it more effectively. Set FMODE_NOWAIT for /dev/null as well, it never
>>> waits and therefore trivially meets the criteria.
>>>
>>> Signed-off-by: Pavel Begunkov <[email protected]>
>>> ---
>>>  drivers/char/mem.c | 6 ++++--
>>>  1 file changed, 4 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/char/mem.c b/drivers/char/mem.c
>>> index 1c596b5cdb27..531f144d7132 100644
>>> --- a/drivers/char/mem.c
>>> +++ b/drivers/char/mem.c
>>> @@ -495,6 +495,8 @@ static ssize_t read_iter_zero(struct kiocb *iocb, struct iov_iter *iter)
>>>  		written += n;
>>>  		if (signal_pending(current))
>>>  			return written ? written : -ERESTARTSYS;
>>> +		if (iocb->ki_flags & IOCB_NOWAIT)
>>> +			return written ? written : -EAGAIN;
>>>  		cond_resched();
>>>  	}
>>
>> I don't think this part is needed.
> 
> It can be clearing gigabytes in one go. Won't it be too much of a
> delay when nowait is expected?

I guess it can't hurt, but then it should be changed to:

if (!need_resched())
	continue;
if (iocb->ki_flags & IOCB_NOWAIT)
	return written ? written : -EAGAIN;
cond_resched();

to avoid doing -EAGAIN just because there's more than one segment in the
buffer. Even that may be excessive though, but definitely a lot better.

-- 
Jens Axboe


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

end of thread, other threads:[~2021-09-08 13:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-08 10:06 [PATCH] /dev/mem: nowait zero/null ops Pavel Begunkov
2021-09-08 10:25 ` Greg Kroah-Hartman
2021-09-08 10:54   ` Pavel Begunkov
2021-09-08 12:57 ` Jens Axboe
2021-09-08 13:07   ` Pavel Begunkov
2021-09-08 13:53     ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox