[PATCH 2/3] do_wp_page: clarify dirty_page handling

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Michel Lespinasse
Date: Wednesday, November 17, 2010 - 5:23 am

Reorganize the code so that dirty pages are handled closer to the place
that makes them dirty (handling write fault into shared, writable VMAs).
No behavior changes.

Signed-off-by: Michel Lespinasse <walken@google.com>
---
 mm/memory.c |   72 +++++++++++++++++++++++++++++++---------------------------
 1 files changed, 38 insertions(+), 34 deletions(-)

diff --git a/mm/memory.c b/mm/memory.c
index 810a75f..d4c0c2e 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -2227,8 +2227,45 @@ reuse:
 		entry = maybe_mkwrite(pte_mkdirty(entry), vma);
 		if (ptep_set_access_flags(vma, address, page_table, entry,1))
 			update_mmu_cache(vma, address, page_table);
+		pte_unmap_unlock(page_table, ptl);
 		ret |= VM_FAULT_WRITE;
-		goto unlock;
+
+		if (!dirty_page)
+			return ret;
+
+		/*
+		 * Yes, Virginia, this is actually required to prevent a race
+		 * with clear_page_dirty_for_io() from clearing the page dirty
+		 * bit after it clear all dirty ptes, but before a racing
+		 * do_wp_page installs a dirty pte.
+		 *
+		 * do_no_page is protected similarly.
+		 */
+		if (!page_mkwrite) {
+			wait_on_page_locked(dirty_page);
+			set_page_dirty_balance(dirty_page, page_mkwrite);
+		}
+		put_page(dirty_page);
+		if (page_mkwrite) {
+			struct address_space *mapping = dirty_page->mapping;
+
+			set_page_dirty(dirty_page);
+			unlock_page(dirty_page);
+			page_cache_release(dirty_page);
+			if (mapping)	{
+				/*
+				 * Some device drivers do not set page.mapping
+				 * but still dirty their pages
+				 */
+				balance_dirty_pages_ratelimited(mapping);
+			}
+		}
+
+		/* file_update_time outside page_lock */
+		if (vma->vm_file)
+			file_update_time(vma->vm_file);
+
+		return ret;
 	}
 
 	/*
@@ -2334,39 +2371,6 @@ gotten:
 		page_cache_release(old_page);
 unlock:
 	pte_unmap_unlock(page_table, ptl);
-	if (dirty_page) {
-		/*
-		 * Yes, Virginia, this is actually required to prevent a race
-		 * with clear_page_dirty_for_io() from clearing the page dirty
-		 * bit after it clear all dirty ptes, but before a racing
-		 * do_wp_page installs a dirty pte.
-		 *
-		 * do_no_page is protected similarly.
-		 */
-		if (!page_mkwrite) {
-			wait_on_page_locked(dirty_page);
-			set_page_dirty_balance(dirty_page, page_mkwrite);
-		}
-		put_page(dirty_page);
-		if (page_mkwrite) {
-			struct address_space *mapping = dirty_page->mapping;
-
-			set_page_dirty(dirty_page);
-			unlock_page(dirty_page);
-			page_cache_release(dirty_page);
-			if (mapping)	{
-				/*
-				 * Some device drivers do not set page.mapping
-				 * but still dirty their pages
-				 */
-				balance_dirty_pages_ratelimited(mapping);
-			}
-		}
-
-		/* file_update_time outside page_lock */
-		if (vma->vm_file)
-			file_update_time(vma->vm_file);
-	}
 	return ret;
 oom_free_new:
 	page_cache_release(new_page);
-- 
1.7.3.1

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0/3] Avoid dirtying pages during mlock, Michel Lespinasse, (Wed Nov 17, 5:23 am)
[PATCH 1/3] do_wp_page: remove the 'reuse' flag, Michel Lespinasse, (Wed Nov 17, 5:23 am)
[PATCH 2/3] do_wp_page: clarify dirty_page handling, Michel Lespinasse, (Wed Nov 17, 5:23 am)
[PATCH 3/3] mlock: avoid dirtying pages and triggering wri ..., Michel Lespinasse, (Wed Nov 17, 5:23 am)
Re: [PATCH 3/3] mlock: avoid dirtying pages and triggering ..., Michel Lespinasse, (Wed Nov 17, 3:05 pm)
Re: [PATCH 3/3] mlock: avoid dirtying pages and triggering ..., Michel Lespinasse, (Wed Nov 17, 4:31 pm)
Re: [PATCH 3/3] mlock: avoid dirtying pages and triggering ..., Michel Lespinasse, (Thu Nov 18, 4:03 am)
Re: [PATCH 3/3] mlock: avoid dirtying pages and triggering ..., Christoph Hellwig, (Thu Nov 18, 6:37 am)
Re: [PATCH 3/3] mlock: avoid dirtying pages and triggering ..., Christoph Hellwig, (Thu Nov 18, 6:39 am)
Re: [PATCH 3/3] mlock: avoid dirtying pages and triggering ..., Michel Lespinasse, (Fri Nov 19, 12:23 am)
Re: [PATCH 3/3] mlock: avoid dirtying pages and triggering ..., Christoph Hellwig, (Fri Nov 19, 8:06 am)
Re: [PATCH 3/3] mlock: avoid dirtying pages and triggering ..., Michel Lespinasse, (Fri Nov 19, 4:31 pm)