[PATCH 4/4] correct locking functions of hugepage migration routine

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Naoya Horiguchi
Date: Thursday, August 12, 2010 - 1:00 am

For the migration of PAGE_SIZE pages, we can choose to continue to do
migration with "force" switch even if the old page has page lock held.
But for hugepage, I/O of subpages are not necessarily completed
in ascending order, which can cause race.
So we make migration fail then for safety.

Signed-off-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
---
 mm/migrate.c |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/mm/migrate.c b/mm/migrate.c
index 7f9a37c..43347e1 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -820,11 +820,14 @@ static int unmap_and_move_huge_page(new_page_t get_new_page,
 
 	rc = -EAGAIN;
 
-	if (!trylock_page(hpage)) {
-		if (!force)
-			goto out;
-		lock_page(hpage);
-	}
+	/*
+	 * If some subpages are locked, it can cause race condition.
+	 * So then we return from migration and try again.
+	 */
+	if (!trylock_huge_page(hpage))
+		goto out;
+
+	wait_on_huge_page_writeback(hpage);
 
 	if (PageAnon(hpage)) {
 		rcu_read_lock();
@@ -855,7 +858,7 @@ static int unmap_and_move_huge_page(new_page_t get_new_page,
 	if (rcu_locked)
 		rcu_read_unlock();
 out:
-	unlock_page(hpage);
+	unlock_huge_page(hpage);
 
 	if (rc != -EAGAIN)
 		put_page(hpage);
-- 
1.7.2.1

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

Messages in current thread:
[PATCH 0/9] Hugepage migration (v2), Naoya Horiguchi, (Tue Aug 10, 2:27 am)
[PATCH 1/9] HWPOISON, hugetlb: move PG_HWPoison bit check, Naoya Horiguchi, (Tue Aug 10, 2:27 am)
[PATCH 3/9] hugetlb: rename hugepage allocation functions, Naoya Horiguchi, (Tue Aug 10, 2:27 am)
[PATCH 4/9] hugetlb: redefine hugepage copy functions, Naoya Horiguchi, (Tue Aug 10, 2:27 am)
[PATCH 6/9] HWPOISON, hugetlb: soft offlining for hugepage, Naoya Horiguchi, (Tue Aug 10, 2:27 am)
[PATCH 7/9] HWPOISON, hugetlb: fix unpoison for hugepage, Naoya Horiguchi, (Tue Aug 10, 2:27 am)
[PATCH 8/9] page-types.c: fix name of unpoison interface, Naoya Horiguchi, (Tue Aug 10, 2:27 am)
[PATCH 9/9] hugetlb: add corrupted hugepage counter, Naoya Horiguchi, (Tue Aug 10, 2:27 am)
Re: [PATCH 0/9] Hugepage migration (v2), Christoph Lameter, (Wed Aug 11, 6:09 am)
Re: [PATCH 0/9] Hugepage migration (v2), Naoya Horiguchi, (Thu Aug 12, 12:53 am)
[RFC] [PATCH 2/4] dio: add page locking for direct I/O, Naoya Horiguchi, (Thu Aug 12, 12:59 am)
[PATCH 4/4] correct locking functions of hugepage migratio ..., Naoya Horiguchi, (Thu Aug 12, 1:00 am)
Re: [PATCH 0/9] Hugepage migration (v2), Christoph Lameter, (Fri Aug 13, 5:47 am)
Re: [RFC] [PATCH 2/4] dio: add page locking for direct I/O, Naoya Horiguchi, (Sun Aug 15, 7:07 pm)
Re: [PATCH 0/9] Hugepage migration (v2), Naoya Horiguchi, (Mon Aug 16, 2:19 am)
Re: [PATCH 0/9] Hugepage migration (v2), Christoph Lameter, (Mon Aug 16, 5:19 am)
Re: [PATCH 0/9] Hugepage migration (v2), Naoya Horiguchi, (Mon Aug 16, 7:37 pm)
Re: [RFC] [PATCH 2/4] dio: add page locking for direct I/O, Naoya Horiguchi, (Tue Aug 17, 1:17 am)
Re: [PATCH 0/9] Hugepage migration (v2), Naoya Horiguchi, (Tue Aug 17, 1:18 am)
Re: [PATCH 0/9] Hugepage migration (v2), Andi Kleen, (Tue Aug 17, 2:40 am)
Re: [RFC] [PATCH 2/4] dio: add page locking for direct I/O, Christoph Lameter, (Tue Aug 17, 9:41 am)
Re: [PATCH 0/9] Hugepage migration (v2), Naoya Horiguchi, (Wed Aug 18, 12:32 am)
Re: [PATCH 0/9] Hugepage migration (v2), Andi Kleen, (Wed Aug 18, 12:46 am)
Re: [PATCH 9/9] hugetlb: add corrupted hugepage counter, Wu Fengguang, (Wed Aug 18, 6:57 pm)
Re: [PATCH 1/9] HWPOISON, hugetlb: move PG_HWPoison bit check, Naoya Horiguchi, (Thu Aug 19, 12:55 am)
Re: [PATCH 9/9] hugetlb: add corrupted hugepage counter, Naoya Horiguchi, (Mon Aug 23, 8:01 pm)
Re: [PATCH 9/9] hugetlb: add corrupted hugepage counter, Wu Fengguang, (Mon Aug 23, 8:08 pm)