All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: Pavel Begunkov <asml.silence@gmail.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-kernel@vger.kernel.org
Cc: io-uring@vger.kernel.org
Subject: Re: [PATCH] /dev/mem: nowait zero/null ops
Date: Wed, 8 Sep 2021 07:53:58 -0600	[thread overview]
Message-ID: <e1142f64-906e-a75e-dd89-501102093761@kernel.dk> (raw)
In-Reply-To: <654d5c75-72fa-bfab-dc14-fa923a2a815a@gmail.com>

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 <asml.silence@gmail.com>
>>> ---
>>>  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


      reply	other threads:[~2021-09-08 13:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e1142f64-906e-a75e-dd89-501102093761@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=arnd@arndb.de \
    --cc=asml.silence@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=io-uring@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.