diff mbox series

[10/13] mm: open code readahead in filemap_new_page

Message ID 20201031090004.452516-11-hch@lst.de (mailing list archive)
State New
Headers show
Series [01/13] mm: simplify generic_file_buffered_read_readpage | expand

Commit Message

Christoph Hellwig Oct. 31, 2020, 9 a.m. UTC
Calling filemap_make_page_uptodate right after filemap_readpage in
filemap_new_page is rather counterintuitive.  The call is in fact
only needed to issue async readahead, and is guaranteed to return
just after that because the page is uptodate.  Just open code the
readahead related parts of filemap_make_page_uptodate instead.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 mm/filemap.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Comments

Matthew Wilcox Nov. 1, 2020, 11:20 a.m. UTC | #1
On Sat, Oct 31, 2020 at 10:00:01AM +0100, Christoph Hellwig wrote:
> Calling filemap_make_page_uptodate right after filemap_readpage in
> filemap_new_page is rather counterintuitive.  The call is in fact
> only needed to issue async readahead, and is guaranteed to return
> just after that because the page is uptodate.  Just open code the
> readahead related parts of filemap_make_page_uptodate instead.

Oh, you got rid of it again ;-)

It's still not possible for this page to have Readahead set on it --
it was only just created, and can't possibly have been created by
an earlier readahead call.
diff mbox series

Patch

diff --git a/mm/filemap.c b/mm/filemap.c
index 5f4937715689e7..000f75cd359d1c 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2309,9 +2309,14 @@  static int filemap_new_page(struct kiocb *iocb, struct iov_iter *iter,
 	error = filemap_readpage(iocb, *page);
 	if (error)
 		goto put_page;
-	error = filemap_make_page_uptodate(iocb, iter, *page, index, true);
-	if (error)
-		goto put_page;
+	if (PageReadahead(*page)) {
+		error = -EAGAIN;
+		if (iocb->ki_flags & IOCB_NOIO)
+			goto put_page;
+		page_cache_async_readahead(mapping, &iocb->ki_filp->f_ra,
+				iocb->ki_filp, *page, index,
+				(iter->count + PAGE_SIZE - 1) >> PAGE_SHIFT);
+	}
 	return 0;
 put_page:
 	put_page(*page);