Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1768792Ab2KOTZ6 (ORCPT ); Thu, 15 Nov 2012 14:25:58 -0500 Received: from mga03.intel.com ([143.182.124.21]:7641 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423636Ab2KOTZ5 (ORCPT ); Thu, 15 Nov 2012 14:25:57 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.83,259,1352102400"; d="scan'208";a="218336603" From: "Kirill A. Shutemov" To: Andrew Morton , Andrea Arcangeli , linux-mm@kvack.org Cc: Andi Kleen , "H. Peter Anvin" , linux-kernel@vger.kernel.org, "Kirill A. Shutemov" , David Rientjes , "Kirill A. Shutemov" Subject: [PATCH v6 01/12] thp: huge zero page: basic preparation Date: Thu, 15 Nov 2012 21:26:51 +0200 Message-Id: <1353007622-18393-2-git-send-email-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1353007622-18393-1-git-send-email-kirill.shutemov@linux.intel.com> References: <1353007622-18393-1-git-send-email-kirill.shutemov@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2528 Lines: 90 From: "Kirill A. Shutemov" Huge zero page (hzp) is a non-movable huge page (2M on x86-64) filled with zeros. For now let's allocate the page on hugepage_init(). We'll switch to lazy allocation later. We are not going to map the huge zero page until we can handle it properly on all code paths. is_huge_zero_{pfn,pmd}() functions will be used by following patches to check whether the pfn/pmd is huge zero page. Signed-off-by: Kirill A. Shutemov Acked-by: David Rientjes --- mm/huge_memory.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 40f17c3..8d7a54b 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -47,6 +47,7 @@ static unsigned int khugepaged_scan_sleep_millisecs __read_mostly = 10000; /* during fragmentation poll the hugepage allocator once every minute */ static unsigned int khugepaged_alloc_sleep_millisecs __read_mostly = 60000; static struct task_struct *khugepaged_thread __read_mostly; +static unsigned long huge_zero_pfn __read_mostly; static DEFINE_MUTEX(khugepaged_mutex); static DEFINE_SPINLOCK(khugepaged_mm_lock); static DECLARE_WAIT_QUEUE_HEAD(khugepaged_wait); @@ -159,6 +160,29 @@ static int start_khugepaged(void) return err; } +static int __init init_huge_zero_page(void) +{ + struct page *hpage; + + hpage = alloc_pages((GFP_TRANSHUGE | __GFP_ZERO) & ~__GFP_MOVABLE, + HPAGE_PMD_ORDER); + if (!hpage) + return -ENOMEM; + + huge_zero_pfn = page_to_pfn(hpage); + return 0; +} + +static inline bool is_huge_zero_pfn(unsigned long pfn) +{ + return pfn == huge_zero_pfn; +} + +static inline bool is_huge_zero_pmd(pmd_t pmd) +{ + return is_huge_zero_pfn(pmd_pfn(pmd)); +} + #ifdef CONFIG_SYSFS static ssize_t double_flag_show(struct kobject *kobj, @@ -540,6 +564,10 @@ static int __init hugepage_init(void) if (err) return err; + err = init_huge_zero_page(); + if (err) + goto out; + err = khugepaged_slab_init(); if (err) goto out; @@ -562,6 +590,8 @@ static int __init hugepage_init(void) return 0; out: + if (huge_zero_pfn) + __free_page(pfn_to_page(huge_zero_pfn)); hugepage_exit_sysfs(hugepage_kobj); return err; } -- 1.7.11.7 -- 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/