[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <b8cd66bd0c6341b5f9fb8c885013bbb7a8abd3f2.camel@redhat.com>
Date: Tue, 19 Oct 2021 13:13:04 -0400
From: Jeff Layton <jlayton@...hat.com>
To: David Howells <dhowells@...hat.com>, linux-cachefs@...hat.com
Cc: Kent Overstreet <kent.overstreet@...il.com>,
"Matthew Wilcox (Oracle)" <willy@...radead.org>,
linux-mm@...ck.org, linux-fsdevel@...r.kernel.org,
Trond Myklebust <trondmy@...merspace.com>,
Anna Schumaker <anna.schumaker@...app.com>,
Steve French <sfrench@...ba.org>,
Dominique Martinet <asmadeus@...ewreck.org>,
Alexander Viro <viro@...iv.linux.org.uk>,
Omar Sandoval <osandov@...ndov.com>,
Linus Torvalds <torvalds@...ux-foundation.org>,
linux-afs@...ts.infradead.org, linux-nfs@...r.kernel.org,
linux-cifs@...r.kernel.org, ceph-devel@...r.kernel.org,
v9fs-developer@...ts.sourceforge.net, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 01/67] mm: Stop filemap_read() from grabbing a
superfluous page
On Mon, 2021-10-18 at 15:50 +0100, David Howells wrote:
> 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.
>
> Signed-off-by: David Howells <dhowells@...hat.com>
> Acked-by: Kent Overstreet <kent.overstreet@...il.com>
> cc: Matthew Wilcox (Oracle) <willy@...radead.org>
> 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/
> ---
>
> mm/filemap.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/mm/filemap.c b/mm/filemap.c
> index dae481293b5d..c0cdc44c844e 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -2625,6 +2625,10 @@ ssize_t filemap_read(struct kiocb *iocb, struct iov_iter *iter,
> if ((iocb->ki_flags & IOCB_WAITQ) && already_read)
> iocb->ki_flags |= IOCB_NOWAIT;
>
> + isize = i_size_read(inode);
> + if (unlikely(iocb->ki_pos >= isize))
> + goto put_pages;
> +
> error = filemap_get_pages(iocb, iter, &pvec);
> if (error < 0)
> break;
>
>
I would wager that it's worth checking for this. I imagine read calls
beyond EOF are common enough that it's probably helpful to optimize that
case:
Acked-by: Jeff Layton <jlayton@...hat.com>
Powered by blists - more mailing lists