Re: [PATCH] /dev/mem: nowait zero/null ops

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
>>> ---
>>>  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




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux