
Signed-off-by: Dave Hansen <haveblue@us.ibm.com>
---

 memhotplug-dave/mm/mmigrate.c |   44 ++++++++++++++++++++++++++++++------------
 1 files changed, 32 insertions(+), 12 deletions(-)

diff -puN mm/mmigrate.c~P12.3-need_writeback-cleanup mm/mmigrate.c
--- memhotplug/mm/mmigrate.c~P12.3-need_writeback-cleanup	2004-12-10 13:53:11.000000000 -0800
+++ memhotplug-dave/mm/mmigrate.c	2004-12-10 13:53:11.000000000 -0800
@@ -395,6 +395,37 @@ need_writeback(struct page *page)
 }
 
 /*
+ * Start writeback I/O if it's a dirty page with buffers
+ */
+static inline void page_start_writeback(struct page *page)
+{
+	struct address_space *mapping;
+	int ret;
+
+	if (!need_writeback(page))
+		return;
+	if (TestSetPageLocked(page))
+		return;
+
+	mapping = page_mapping(page);
+
+	if (!mapping)
+		goto out_unlock;
+	if (mapping->a_ops->migrate_page)
+		goto out_unlock;
+	if (!need_writeback(page))
+		goto out_unlock;
+
+	ret = pageout(page, mapping);
+
+	if (ret == PAGE_SUCCESS)
+		return;
+
+out_unlock:
+	unlock_page(page);
+}
+
+/*
  * This is the main entry point to migrate pages in a specific region.
  * If a page is inactive, the page may be just released instead of
  * migration.
@@ -402,7 +433,6 @@ need_writeback(struct page *page)
 int try_to_migrate_pages(struct list_head *page_list)
 {
 	struct page *page, *page2, *newpage;
-	struct address_space* mapping;
 	LIST_HEAD(pass1_list);
 	LIST_HEAD(pass2_list);
 	int nr_busy = 0;
@@ -410,17 +440,7 @@ int try_to_migrate_pages(struct list_hea
 
 	current->flags |= PF_KSWAPD;    /*  It's fake */
 	list_for_each_entry_safe(page, page2, page_list, lru) {
-		/*
-		 * Start writeback I/O if it's a dirty page with buffers
-		 */
-		if (need_writeback(page) && !TestSetPageLocked(page)) {
-			mapping = page_mapping(page);
-			if (!mapping || mapping->a_ops->migrate_page ||
-			    !need_writeback(page) ||
-			    pageout(page, mapping) != PAGE_SUCCESS) {
-				unlock_page(page);
-			}
-		}
+		page_start_writeback(page);
 		list_del(&page->lru);
 		list_add(&page->lru, &pass1_list);
 	}
_
