Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933170Ab0HLICd (ORCPT ); Thu, 12 Aug 2010 04:02:33 -0400 Received: from TYO202.gate.nec.co.jp ([202.32.8.206]:42216 "EHLO tyo202.gate.nec.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933131Ab0HLIC2 (ORCPT ); Thu, 12 Aug 2010 04:02:28 -0400 Date: Thu, 12 Aug 2010 17:00:48 +0900 From: Naoya Horiguchi To: Christoph Lameter Cc: Andi Kleen , Andrew Morton , Mel Gorman , Wu Fengguang , "Jun'ichi Nomura" , linux-mm , LKML Subject: [PATCH 4/4] correct locking functions of hugepage migration routine Message-ID: <20100812080048.GF6112@spritzera.linux.bs1.fc.nec.co.jp> References: <1281432464-14833-1-git-send-email-n-horiguchi@ah.jp.nec.com> <20100812075323.GA6112@spritzera.linux.bs1.fc.nec.co.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-2022-jp Content-Disposition: inline In-Reply-To: <20100812075323.GA6112@spritzera.linux.bs1.fc.nec.co.jp> User-Agent: Mutt/1.5.20 (2009-12-10) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1475 Lines: 52 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 --- 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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/