Re: [Patch] invalidate range of pages after direct IO write

From: Andrew Morton
Date: Thu Feb 03 2005 - 21:39:35 EST


Zach Brown <zach.brown@xxxxxxxxxx> wrote:
>
> > I'll make that change and plop the patch into -mm, but we need to think
> > about the infinite-loop problem..
>
> I can try hacking together that macro and auditing pagevec_lookup()
> callers..

I'd be inclined to hold off on the macro until we actually get the
open-coded stuff right.. Sometimes the page lookup loops take an end+1
argument and sometimes they take an inclusive `end'. I think. That might
make it a bit messy.

How's this look?



- Don't look up more pages than we're going to use

- Don't test page->index until we've locked the page

- Check for the cursor wrapping at the end of the mapping.

--- 25/mm/truncate.c~invalidate-range-of-pages-after-direct-io-write-fix 2005-02-03 18:20:22.000000000 -0800
+++ 25-akpm/mm/truncate.c 2005-02-03 18:28:24.627796400 -0800
@@ -264,18 +264,14 @@ int invalidate_inode_pages2_range(struct
pagevec_init(&pvec, 0);
next = start;
while (next <= end &&
- !ret && pagevec_lookup(&pvec, mapping, next, PAGEVEC_SIZE)) {
+ !ret && pagevec_lookup(&pvec, mapping, next,
+ min(end - next, (pgoff_t)PAGEVEC_SIZE - 1) + 1)) {
for (i = 0; !ret && i < pagevec_count(&pvec); i++) {
struct page *page = pvec.pages[i];
int was_dirty;

- if (page->index > end) {
- next = page->index;
- break;
- }
-
lock_page(page);
- if (page->mapping != mapping) { /* truncate race? */
+ if (page->mapping != mapping || page->index > end) {
unlock_page(page);
continue;
}
@@ -311,6 +307,8 @@ int invalidate_inode_pages2_range(struct
}
pagevec_release(&pvec);
cond_resched();
+ if (next == 0)
+ break; /* The pgoff_t wrapped */
}
return ret;
}
_

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/