linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/hugetlb: Release pages in the error path of COW
@ 2011-10-29 13:09 Hillf Danton
  0 siblings, 0 replies; only message in thread
From: Hillf Danton @ 2011-10-29 13:09 UTC (permalink / raw)
  To: linux-mm; +Cc: Hugh Dickins, Andrew Morton, Andrea Arcangeli

If anon_vma is prepared unsuccessfully, new_page and old_page should be freed.

And due to that page_table_lock is re-acquired, race in updating page table
should also be check. If race does happen, our job is done.

All comments and ideas welcome.

Thanks

Signed-off-by: Hillf Danton <dhillf@gmail.com>
---

--- a/mm/hugetlb.c	Sat Aug 13 11:45:14 2011
+++ b/mm/hugetlb.c	Sat Oct 29 20:44:09 2011
@@ -2406,8 +2406,7 @@ retry_avoidcopy:
 			if (unmap_ref_private(mm, vma, old_page, address)) {
 				BUG_ON(page_count(old_page) != 1);
 				BUG_ON(huge_pte_none(pte));
-				spin_lock(&mm->page_table_lock);
-				goto retry_avoidcopy;
+				goto lock_and_check;
 			}
 			WARN_ON_ONCE(1);
 		}
@@ -2422,6 +2421,8 @@ retry_avoidcopy:
 	 * anon_vma prepared.
 	 */
 	if (unlikely(anon_vma_prepare(vma))) {
+		page_cache_release(new_page);
+		page_cache_release(old_page);
 		/* Caller expects lock to be held */
 		spin_lock(&mm->page_table_lock);
 		return VM_FAULT_OOM;
@@ -2455,6 +2456,14 @@ retry_avoidcopy:
 	}
 	page_cache_release(new_page);
 	page_cache_release(old_page);
+	return 0;
+
+lock_and_check:
+	spin_lock(&mm->page_table_lock);
+	ptep = huge_pte_offset(mm, address & huge_page_mask(h));
+	if (likely(pte_same(huge_ptep_get(ptep), pte)))
+		goto retry_avoidcopy;
+	/* else changes occured while taking page_table_lock, our job done */
 	return 0;
 }

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-10-29 13:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-29 13:09 [PATCH] mm/hugetlb: Release pages in the error path of COW Hillf Danton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox