[PATCH] Re: [PATCH] VFS readahead bug in 2.6.8-rc[1-3]
From: Ram Pai
Date: Mon Aug 16 2004 - 02:58:10 EST
On Fri, 6 Aug 2004, Andrew Morton wrote:
> Phillip Lougher <phillip@xxxxxxxxxxxxxxxxxxx> wrote:
> >
> > Nick Piggin wrote:
> >
> > > No, I suggest you start to code assuming this interface does
> > > what it does. I didn't say there is no bug here, but nobody
> > > else's filesystem breaks.
> > >
> >
> > To stop this silly argument from escalating, I will patch my code.
> >
>
> Well I don't think it's silly.
>
> We are deterministically asking the fs to read a page which lies outside
> EOF, and we shouldn't. If for no other reason than that the ever-popular
> "read a million 4k files" workload will consume extra CPU and twice the
> pagecache.
Andrew,
Enclosed a patch developed with Nick Piggin. It takes care of the
bug.
Thanks,
RP
--- ram/linux-2.6.8.1/mm/filemap.c 2004-08-14 03:56:25.000000000 -0700
+++ linux-2.6.8.1/mm/filemap.c 2004-08-16 07:56:31.912038720 -0700
@@ -665,14 +665,18 @@ void do_generic_mapping_read(struct addr
offset = *ppos & ~PAGE_CACHE_MASK;
isize = i_size_read(inode);
- end_index = isize >> PAGE_CACHE_SHIFT;
- if (index > end_index)
+ if (!isize)
goto out;
+
+ end_index = isize >> PAGE_CACHE_SHIFT;
for (;;) {
struct page *page;
unsigned long nr, ret;
+ if (index > end_index)
+ goto out;
+
cond_resched();
page_cache_readahead(mapping, &ra, filp, index);