Skip to content

Commit

Permalink
mm: write_cache_pages terminate quickly
Browse files Browse the repository at this point in the history
Terminate the write_cache_pages loop upon encountering the first page past
end, without locking the page.  Pages cannot have their index change when
we have a reference on them (truncate, eg truncate_inode_pages_range
performs the same check without the page lock).

Signed-off-by: Nick Piggin <npiggin@suse.de>
Cc: Chris Mason <chris.mason@oracle.com>
Cc: Dave Chinner <david@fromorbit.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Nick Piggin authored and torvalds committed Jan 6, 2009
1 parent 515f4a0 commit d5482cd
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions mm/page-writeback.c
Original file line number Diff line number Diff line change
Expand Up @@ -911,15 +911,24 @@ int write_cache_pages(struct address_space *mapping,
for (i = 0; i < nr_pages; i++) {
struct page *page = pvec.pages[i];

done_index = page->index + 1;

/*
* At this point we hold neither mapping->tree_lock nor
* lock on the page itself: the page may be truncated or
* invalidated (changing page->mapping to NULL), or even
* swizzled back from swapper_space to tmpfs file
* mapping
* At this point, the page may be truncated or
* invalidated (changing page->mapping to NULL), or
* even swizzled back from swapper_space to tmpfs file
* mapping. However, page->index will not change
* because we have a reference on the page.
*/
if (page->index > end) {
/*
* can't be range_cyclic (1st pass) because
* end == -1 in that case.
*/
done = 1;
break;
}

done_index = page->index + 1;

lock_page(page);

/*
Expand All @@ -936,15 +945,6 @@ int write_cache_pages(struct address_space *mapping,
continue;
}

if (page->index > end) {
/*
* can't be range_cyclic (1st pass) because
* end == -1 in that case.
*/
done = 1;
goto continue_unlock;
}

if (!PageDirty(page)) {
/* someone wrote it for us */
goto continue_unlock;
Expand Down

0 comments on commit d5482cd

Please sign in to comment.