From: npiggin@suse.de Subject: [patch 7/7] mm: write_cache_pages terminate quickly Date: Tue, 21 Oct 2008 19:09:54 +1100 Message-ID: <20081021081139.411091000@nick.local0.net> References: <20081021080947.032757000@suse.de> Cc: linux-fsdevel@vger.kernel.org To: akpm@linux-foundation.org Return-path: Received: from cantor2.suse.de ([195.135.220.15]:47867 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751461AbYJUIP1 (ORCPT ); Tue, 21 Oct 2008 04:15:27 -0400 Content-Disposition: inline; filename=mm-wcp-terminate-quickly.patch Sender: linux-fsdevel-owner@vger.kernel.org List-ID: 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 --- Index: linux-2.6/mm/page-writeback.c =================================================================== --- linux-2.6.orig/mm/page-writeback.c +++ linux-2.6/mm/page-writeback.c @@ -910,12 +910,18 @@ retry: struct page *page = pvec.pages[i]; /* - * 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: end == -1 there */ + done = 1; + break; + } + lock_page(page); /* @@ -932,12 +938,6 @@ continue_unlock: continue; } - if (page->index > end) { - /* Can't be range_cyclic: end == -1 there */ - done = 1; - goto continue_unlock; - } - if (!PageDirty(page)) { /* someone wrote it for us */ goto continue_unlock; --