[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <163472463105.3126792.7056099385135786492.stgit@warthog.procyon.org.uk>
Date: Wed, 20 Oct 2021 11:10:31 +0100
From: David Howells <dhowells@...hat.com>
To: kent.overstreet@...il.com, willy@...radead.org
Cc: Andrew Morton <akpm@...ux-foundation.org>,
Jeff Layton <jlayton@...hat.com>, linux-mm@...ck.org,
linux-fsdevel@...r.kernel.org, dhowells@...hat.com,
linux-kernel@...r.kernel.org
Subject: [PATCH v2] mm: Stop filemap_read() from grabbing a superfluous page
Under some circumstances, filemap_read() will allocate sufficient pages to
read to the end of the file, call readahead/readpages on them and copy the
data over - and then it will allocate another page at the EOF and call
readpage on that and then ignore it. This is unnecessary and a waste of
time and resources.
filemap_read() *does* check for this, but only after it has already done
the allocation and I/O. Fix this by checking before calling
filemap_get_pages() also.
Changes:
v2) Break out of the loop immediately rather than going to put_pages (the
pvec is unoccupied). Setting isize is then unnecessary.
Signed-off-by: David Howells <dhowells@...hat.com>
cc: Kent Overstreet <kent.overstreet@...il.com>
cc: Matthew Wilcox (Oracle) <willy@...radead.org>
cc: Andrew Morton <akpm@...ux-foundation.org>
cc: Jeff Layton <jlayton@...hat.com>
cc: linux-mm@...ck.org
cc: linux-fsdevel@...r.kernel.org
Link: https://lore.kernel.org/r/160588481358.3465195.16552616179674485179.stgit@warthog.procyon.org.uk/
Link: https://lore.kernel.org/r/163456863216.2614702.6384850026368833133.stgit@warthog.procyon.org.uk/
---
mm/filemap.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/mm/filemap.c b/mm/filemap.c
index dae481293b5d..e50be519f6a4 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2625,6 +2625,9 @@ ssize_t filemap_read(struct kiocb *iocb, struct iov_iter *iter,
if ((iocb->ki_flags & IOCB_WAITQ) && already_read)
iocb->ki_flags |= IOCB_NOWAIT;
+ if (unlikely(iocb->ki_pos >= i_size_read(inode)))
+ break;
+
error = filemap_get_pages(iocb, iter, &pvec);
if (error < 0)
break;
Powered by blists - more mailing lists