mm: use filemap_range_needs_writeback() for O_DIRECT reads

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).

Link: https://lkml.kernel.org/r/20210224164455.1096727-3-axboe@kernel.dk
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Jens Axboe 2021-04-29 22:55:21 -07:00 committed by Linus Torvalds
parent 63135aa386
commit 7a60d6d7b3
1 changed files with 2 additions and 2 deletions

View File

@ -2681,8 +2681,8 @@ generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
size = i_size_read(inode); size = i_size_read(inode);
if (iocb->ki_flags & IOCB_NOWAIT) { if (iocb->ki_flags & IOCB_NOWAIT) {
if (filemap_range_has_page(mapping, iocb->ki_pos, if (filemap_range_needs_writeback(mapping, iocb->ki_pos,
iocb->ki_pos + count - 1)) iocb->ki_pos + count - 1))
return -EAGAIN; return -EAGAIN;
} else { } else {
retval = filemap_write_and_wait_range(mapping, retval = filemap_write_and_wait_range(mapping,