From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail172.messagelabs.com (mail172.messagelabs.com [216.82.254.3]) by kanga.kvack.org (Postfix) with SMTP id AC0756B007D for ; Fri, 26 Feb 2010 15:09:06 -0500 (EST) Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o1QK95sR001277 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 26 Feb 2010 15:09:05 -0500 Message-Id: <20100226200903.710125544@redhat.com> Date: Fri, 26 Feb 2010 21:05:03 +0100 From: aarcange@redhat.com Subject: [patch 30/35] madvise(MADV_HUGEPAGE) References: <20100226200433.516502198@redhat.com> Content-Disposition: inline; filename=madv_hugepage Sender: owner-linux-mm@kvack.org To: linux-mm@kvack.org Cc: Andrea Arcangeli , Rik van Riel List-ID: From: Andrea Arcangeli Add madvise MADV_HUGEPAGE to mark regions that are important to be hugepage backed. Return -EINVAL if the vma is not of an anonymous type, or the feature isn't built into the kernel. Never silently return success. Signed-off-by: Andrea Arcangeli Acked-by: Rik van Riel --- include/linux/huge_mm.h | 6 ++++++ mm/huge_memory.c | 16 ++++++++++++++++ mm/madvise.c | 8 ++++++++ 3 files changed, 30 insertions(+) --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -107,6 +107,7 @@ extern int split_huge_page(struct page * #endif extern unsigned long vma_address(struct page *page, struct vm_area_struct *vma); +extern int hugepage_madvise(unsigned long *vm_flags); static inline int PageTransHuge(struct page *page) { VM_BUG_ON(PageTail(page)); @@ -131,6 +132,11 @@ static inline int split_huge_page(struct #define wait_split_huge_page(__anon_vma, __pmd) \ do { } while (0) #define PageTransHuge(page) 0 +static inline int hugepage_madvise(unsigned long *vm_flags) +{ + BUG_ON(0); + return 0; +} #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ #endif /* _LINUX_HUGE_MM_H */ --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -856,3 +856,19 @@ out_unlock: out: return ret; } + +int hugepage_madvise(unsigned long *vm_flags) +{ + /* + * Be somewhat over-protective like KSM for now! + */ + if (*vm_flags & (VM_HUGEPAGE | VM_SHARED | VM_MAYSHARE | + VM_PFNMAP | VM_IO | VM_DONTEXPAND | + VM_RESERVED | VM_HUGETLB | VM_INSERTPAGE | + VM_MIXEDMAP | VM_SAO)) + return -EINVAL; + + *vm_flags |= VM_HUGEPAGE; + + return 0; +} --- a/mm/madvise.c +++ b/mm/madvise.c @@ -71,6 +71,11 @@ static long madvise_behavior(struct vm_a if (error) goto out; break; + case MADV_HUGEPAGE: + error = hugepage_madvise(&new_flags); + if (error) + goto out; + break; } if (new_flags == vma->vm_flags) { @@ -283,6 +288,9 @@ madvise_behavior_valid(int behavior) case MADV_MERGEABLE: case MADV_UNMERGEABLE: #endif +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + case MADV_HUGEPAGE: +#endif return 1; default: -- 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/ . Don't email: email@kvack.org