Re: [PATCH] mm/filemap: do not allocate cache pages beyond end of file at read
From: Linus Torvalds
Date: Wed Nov 27 2019 - 12:30:08 EST
On Wed, Nov 27, 2019 at 7:42 AM Steven Whitehouse <swhiteho@xxxxxxxxxx> wrote:
>
> I'll leave the finer details to Andreas here, since it is his patch, and
> hopefully we can figure out a good path forward.
As mentioned, I don't _hate_ that patch (ok, I seem to have typoed it
and said that I don't "gate" it ;), so if that's what you guys really
want to do, I'm ok with it. But..
I do think you already get the data with the current case, from the
"short read" thing. So just changing the current generic read function
to check against the size first:
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2021,9 +2021,9 @@ static ssize_t
generic_file_buffered_read(struct kiocb *iocb,
unsigned int prev_offset;
int error = 0;
- if (unlikely(*ppos >= inode->i_sb->s_maxbytes))
+ if (unlikely(*ppos >= inode->i_size))
return 0;
- iov_iter_truncate(iter, inode->i_sb->s_maxbytes);
+ iov_iter_truncate(iter, inode->i_size);
index = *ppos >> PAGE_SHIFT;
prev_index = ra->prev_pos >> PAGE_SHIFT;
and you're done. Nice and clean.
Then in gfs2 you just notice the short read, and check at that point.
Sure, you'll also cut read-ahead to the old size boundary, but does
anybody _seriously_ believe that read-ahead matters when you hit the
"some other node write more data, we're reading past the old end"
case? I don't think that's the case.
But I _can_ live with the patch that adds the extra "cached only" bit.
It just honestly feels pointless.
Linus