diff mbox series

[2/3] mm: use filemap_range_needs_writeback() for O_DIRECT reads

Message ID 20210209023008.76263-3-axboe@kernel.dk (mailing list archive)
State New
Headers show
Series Improve IOCB_NOWAIT O_DIRECT reads | expand

Commit Message

Jens Axboe Feb. 9, 2021, 2:30 a.m. UTC
For the generic page cache read helper, use the better variant of checking
for the need to call filemap_write_and_wait_range() when doing O_DIRECT
reads. This avoids falling back to the slow path for IOCB_NOWAIT, if there
are no pages to wait for (or write out).

Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 mm/filemap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Christoph Hellwig Feb. 9, 2021, 7:48 a.m. UTC | #1
On Mon, Feb 08, 2021 at 07:30:07PM -0700, Jens Axboe wrote:
> For the generic page cache read helper, use the better variant of checking
> for the need to call filemap_write_and_wait_range() when doing O_DIRECT
> reads. This avoids falling back to the slow path for IOCB_NOWAIT, if there
> are no pages to wait for (or write out).
> 
> Signed-off-by: Jens Axboe <axboe@kernel.dk>
> ---
>  mm/filemap.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/filemap.c b/mm/filemap.c
> index 6a58d50fbd31..c80acb80e8f7 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -2643,8 +2643,8 @@ generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
>  
>  		size = i_size_read(inode);
>  		if (iocb->ki_flags & IOCB_NOWAIT) {
> -			if (filemap_range_has_page(mapping, iocb->ki_pos,
> -						   iocb->ki_pos + count - 1))
> +			if (filemap_range_needs_writeback(mapping, iocb->ki_pos,
> +							  iocb->ki_pos + count - 1))

Please avoid the overy long line, which is trivial to do by using the
normal two tab indent for the continuation.
Jens Axboe Feb. 9, 2021, 2:27 p.m. UTC | #2
On 2/9/21 12:48 AM, Christoph Hellwig wrote:
> On Mon, Feb 08, 2021 at 07:30:07PM -0700, Jens Axboe wrote:
>> For the generic page cache read helper, use the better variant of checking
>> for the need to call filemap_write_and_wait_range() when doing O_DIRECT
>> reads. This avoids falling back to the slow path for IOCB_NOWAIT, if there
>> are no pages to wait for (or write out).
>>
>> Signed-off-by: Jens Axboe <axboe@kernel.dk>
>> ---
>>  mm/filemap.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/mm/filemap.c b/mm/filemap.c
>> index 6a58d50fbd31..c80acb80e8f7 100644
>> --- a/mm/filemap.c
>> +++ b/mm/filemap.c
>> @@ -2643,8 +2643,8 @@ generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
>>  
>>  		size = i_size_read(inode);
>>  		if (iocb->ki_flags & IOCB_NOWAIT) {
>> -			if (filemap_range_has_page(mapping, iocb->ki_pos,
>> -						   iocb->ki_pos + count - 1))
>> +			if (filemap_range_needs_writeback(mapping, iocb->ki_pos,
>> +							  iocb->ki_pos + count - 1))
> 
> Please avoid the overy long line, which is trivial to do by using the
> normal two tab indent for the continuation.

Sure, fixed.
diff mbox series

Patch

diff --git a/mm/filemap.c b/mm/filemap.c
index 6a58d50fbd31..c80acb80e8f7 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2643,8 +2643,8 @@  generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
 
 		size = i_size_read(inode);
 		if (iocb->ki_flags & IOCB_NOWAIT) {
-			if (filemap_range_has_page(mapping, iocb->ki_pos,
-						   iocb->ki_pos + count - 1))
+			if (filemap_range_needs_writeback(mapping, iocb->ki_pos,
+							  iocb->ki_pos + count - 1))
 				return -EAGAIN;
 		} else {
 			retval = filemap_write_and_wait_range(mapping,