diff mbox series

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

Message ID 20210208221829.17247-4-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>
---
 fs/iomap/direct-io.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
index 933f234d5bec..2561e50c763a 100644
--- a/fs/iomap/direct-io.c
+++ b/fs/iomap/direct-io.c
@@ -479,17 +479,17 @@  __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
 	}
 
 	if (iocb->ki_flags & IOCB_NOWAIT) {
-		if (filemap_range_has_page(mapping, pos, end)) {
+		if (filemap_range_needs_writeback(mapping, pos, end)) {
 			ret = -EAGAIN;
 			goto out_free_dio;
 		}
 		flags |= IOMAP_NOWAIT;
+	} else {
+		ret = filemap_write_and_wait_range(mapping, pos, end);
+		if (ret)
+			goto out_free_dio;
 	}
 
-	ret = filemap_write_and_wait_range(mapping, pos, end);
-	if (ret)
-		goto out_free_dio;
-
 	if (iov_iter_rw(iter) == WRITE) {
 		/*
 		 * Try to invalidate cache pages for the range we are writing.