diff mbox series

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

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

Commit Message

Jens Axboe Feb. 8, 2021, 10:18 p.m. UTC
For the generic page cache read/write helpers, use the better variant
of checking for the need to call filemap_write_and_wait_range() when
doing O_DIRECT reads or writes. 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 | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/mm/filemap.c b/mm/filemap.c
index 1ed7acac8a1b..3bc76f99ddc3 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2646,8 +2646,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,
@@ -3326,7 +3326,7 @@  generic_file_direct_write(struct kiocb *iocb, struct iov_iter *from)
 
 	if (iocb->ki_flags & IOCB_NOWAIT) {
 		/* If there are pages to writeback, return */
-		if (filemap_range_has_page(file->f_mapping, pos,
+		if (filemap_range_needs_writeback(file->f_mapping, pos,
 					   pos + write_len - 1))
 			return -EAGAIN;
 	} else {