Re: [PATCH 11/12] vmscan: Write out dirty pages in batch

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Mel Gorman
Date: Tuesday, June 15, 2010 - 8:44 am

On Tue, Jun 15, 2010 at 12:43:42PM +0100, Mel Gorman wrote:

The patch to sort the list being cleaned by reclaim looks like this.
It's not actually tested

vmscan: Sort pages being queued for IO before submitting to the filesystem

While page reclaim submits dirty pages in batch, it doesn't change the
order in which the IO is issued - it is still issued in LRU order. Given
that they are issued in a short period of time now, rather than across a
longer scan period, it is likely that it will not be any faster as:

        a) IO will not be started as soon, and
        b) the IO scheduler still only has a small re-ordering
           window and will choke just as much on random IO patterns.

This patch uses list_sort() function to sort
the list; sorting the list of pages by mapping and page->index
within the mapping would result in all the pages on each mapping
being sent down in ascending offset order at once - exactly how the
filesystems want IO to be sent to it.

Credit mostly goes to Dave Chinner for this idea and the changelog text.

----

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 68b3d22..02ab246 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -32,6 +32,7 @@
 #include <linux/topology.h>
 #include <linux/cpu.h>
 #include <linux/cpuset.h>
+#include <linux/list_sort.h>
 #include <linux/notifier.h>
 #include <linux/rwsem.h>
 #include <linux/delay.h>
@@ -651,6 +652,34 @@ static noinline_for_stack void free_page_list(struct list_head *free_pages)
 		__pagevec_free(&freed_pvec);
 }
 
+/* Sort based on mapping then index */
+static int page_writeback_cmp(void *data, struct list_head *a, struct list_head *b)
+{
+	struct page *ap = list_entry(a, struct page, lru);
+	struct page *bp = list_entry(b, struct page, lru);
+	pgoff_t diff;
+
+	/*
+	 * Page not locked but it's not critical, the mapping is just for sorting
+	 * If the mapping is no longer valid, it's of little consequence
+	 */
+	if (ap->mapping != bp->mapping) {
+		if (ap->mapping < bp->mapping)
+			return -1;
+		if (ap->mapping > bp->mapping)
+			return 1;
+		return 0;
+	}
+	
+	/* Then index */
+	diff = ap->index - bp->index;
+	if (diff < 0)
+		return -1;
+	if (diff > 0)
+		return 1;
+	return 0;
+}
+
 static noinline_for_stack void clean_page_list(struct list_head *page_list,
 				struct scan_control *sc)
 {
@@ -660,6 +689,8 @@ static noinline_for_stack void clean_page_list(struct list_head *page_list,
 	if (!sc->may_writepage)
 		return;
 
+	list_sort(NULL, page_list, page_writeback_cmp);
+
 	/* Write the pages out to disk in ranges where possible */
 	while (!list_empty(page_list)) {
 		struct address_space *mapping;
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 05/12] vmscan: kill prev_priority completely, Mel Gorman, (Mon Jun 14, 4:17 am)
[PATCH 11/12] vmscan: Write out dirty pages in batch, Mel Gorman, (Mon Jun 14, 4:17 am)
Re: [PATCH 0/12] Avoid overflowing of stack during page re ..., Christoph Hellwig, (Mon Jun 14, 8:10 am)
Re: [PATCH 05/12] vmscan: kill prev_priority completely, Rik van Riel, (Mon Jun 14, 11:04 am)
Re: [PATCH 06/12] vmscan: simplify shrink_inactive_list(), Rik van Riel, (Mon Jun 14, 11:06 am)
Re: [PATCH 11/12] vmscan: Write out dirty pages in batch, Andrew Morton, (Mon Jun 14, 4:21 pm)
Re: [PATCH 0/12] Avoid overflowing of stack during page re ..., KAMEZAWA Hiroyuki, (Mon Jun 14, 5:08 pm)
Re: [PATCH 11/12] vmscan: Write out dirty pages in batch, Andrew Morton, (Mon Jun 14, 6:39 pm)
Re: [PATCH 11/12] vmscan: Write out dirty pages in batch, Andrew Morton, (Mon Jun 14, 6:45 pm)
Re: [PATCH 11/12] vmscan: Write out dirty pages in batch, Andrew Morton, (Mon Jun 14, 9:15 pm)
Re: [PATCH 11/12] vmscan: Write out dirty pages in batch, Andrew Morton, (Mon Jun 14, 9:37 pm)
[patch] mm: vmscan fix mapping use after free, Nick Piggin, (Mon Jun 14, 10:43 pm)
Re: [PATCH 11/12] vmscan: Write out dirty pages in batch, Dave Chinner, (Mon Jun 14, 11:36 pm)
Re: [PATCH 08/12] vmscan: Setup pagevec as late as possibl ..., Christoph Hellwig, (Tue Jun 15, 3:47 am)
Re: [PATCH 11/12] vmscan: Write out dirty pages in batch, Christoph Hellwig, (Tue Jun 15, 3:53 am)
Re: [PATCH 11/12] vmscan: Write out dirty pages in batch, Christoph Hellwig, (Tue Jun 15, 3:57 am)
Re: [PATCH 11/12] vmscan: Write out dirty pages in batch, Christoph Hellwig, (Tue Jun 15, 4:01 am)
Re: [PATCH 11/12] vmscan: Write out dirty pages in batch, Christoph Hellwig, (Tue Jun 15, 4:08 am)
Re: [PATCH 11/12] vmscan: Write out dirty pages in batch, Christoph Hellwig, (Tue Jun 15, 4:10 am)
Re: [patch] mm: vmscan fix mapping use after free, Mel Gorman, (Tue Jun 15, 6:23 am)
Re: [PATCH 11/12] vmscan: Write out dirty pages in batch, Mel Gorman, (Tue Jun 15, 8:44 am)
Re: [PATCH 05/12] vmscan: kill prev_priority completely, Andrew Morton, (Wed Jun 16, 4:37 pm)
Re: [PATCH 05/12] vmscan: kill prev_priority completely, Rik van Riel, (Wed Jun 16, 4:45 pm)
Re: [PATCH 05/12] vmscan: kill prev_priority completely, Andrew Morton, (Wed Jun 16, 5:18 pm)
Re: [PATCH 05/12] vmscan: kill prev_priority completely, Rik van Riel, (Wed Jun 16, 5:34 pm)
Re: [PATCH 05/12] vmscan: kill prev_priority completely, KOSAKI Motohiro, (Fri Jun 25, 1:29 am)