mm: write_cache_pages optimise page cleaning
authorNick Piggin <npiggin@suse.de>
Tue, 6 Jan 2009 22:39:10 +0000 (14:39 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 6 Jan 2009 23:58:59 +0000 (15:58 -0800)
In write_cache_pages, if we get stuck behind another process that is
cleaning pages, we will be forced to wait for them to finish, then perform
our own writeout (if it was redirtied during the long wait), then wait for
that.

If a page under writeout is still clean, we can skip waiting for it (if
we're part of a data integrity sync, we'll be waiting for all writeout
pages afterwards, so we'll still be waiting for the other guy's write
that's cleaned the page).

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>
mm/page-writeback.c

index c3fb38b1ea4340dd917e4a4fe81e9baa1c3ff6e2..2e8c2b01d5d5e6130edc94c51fe77a4548dd6799 100644 (file)
@@ -945,11 +945,20 @@ continue_unlock:
                                goto continue_unlock;
                        }
 
-                       if (wbc->sync_mode != WB_SYNC_NONE)
-                               wait_on_page_writeback(page);
+                       if (!PageDirty(page)) {
+                               /* someone wrote it for us */
+                               goto continue_unlock;
+                       }
+
+                       if (PageWriteback(page)) {
+                               if (wbc->sync_mode != WB_SYNC_NONE)
+                                       wait_on_page_writeback(page);
+                               else
+                                       goto continue_unlock;
+                       }
 
-                       if (PageWriteback(page) ||
-                           !clear_page_dirty_for_io(page))
+                       BUG_ON(PageWriteback(page));
+                       if (!clear_page_dirty_for_io(page))
                                goto continue_unlock;
 
                        ret = (*writepage)(page, wbc, data);