diff options
author | Andrea Arcangeli <aarcange@redhat.com> | 2011-01-13 18:46:55 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-01-13 20:32:42 -0500 |
commit | 0af4e98b6b095c74588af04872f83d333c958c32 (patch) | |
tree | 56b1965482470219a8cf11b7e7c875ae91bff46e | |
parent | f66055ab6fb9731dbfce320c5202ef4441b5d77f (diff) |
thp: madvise(MADV_HUGEPAGE)
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 <aarcange@redhat.com>
Acked-by: Rik van Riel <riel@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | include/linux/huge_mm.h | 6 | ||||
-rw-r--r-- | mm/huge_memory.c | 16 | ||||
-rw-r--r-- | mm/madvise.c | 8 |
3 files changed, 30 insertions, 0 deletions
diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 9301824c7491..d9ab70d776e2 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h | |||
@@ -97,6 +97,7 @@ extern void __split_huge_page_pmd(struct mm_struct *mm, pmd_t *pmd); | |||
97 | #if HPAGE_PMD_ORDER > MAX_ORDER | 97 | #if HPAGE_PMD_ORDER > MAX_ORDER |
98 | #error "hugepages can't be allocated by the buddy allocator" | 98 | #error "hugepages can't be allocated by the buddy allocator" |
99 | #endif | 99 | #endif |
100 | extern int hugepage_madvise(unsigned long *vm_flags); | ||
100 | #else /* CONFIG_TRANSPARENT_HUGEPAGE */ | 101 | #else /* CONFIG_TRANSPARENT_HUGEPAGE */ |
101 | #define HPAGE_PMD_SHIFT ({ BUG(); 0; }) | 102 | #define HPAGE_PMD_SHIFT ({ BUG(); 0; }) |
102 | #define HPAGE_PMD_MASK ({ BUG(); 0; }) | 103 | #define HPAGE_PMD_MASK ({ BUG(); 0; }) |
@@ -113,6 +114,11 @@ static inline int split_huge_page(struct page *page) | |||
113 | do { } while (0) | 114 | do { } while (0) |
114 | #define wait_split_huge_page(__anon_vma, __pmd) \ | 115 | #define wait_split_huge_page(__anon_vma, __pmd) \ |
115 | do { } while (0) | 116 | do { } while (0) |
117 | static inline int hugepage_madvise(unsigned long *vm_flags) | ||
118 | { | ||
119 | BUG(); | ||
120 | return 0; | ||
121 | } | ||
116 | #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ | 122 | #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ |
117 | 123 | ||
118 | #endif /* _LINUX_HUGE_MM_H */ | 124 | #endif /* _LINUX_HUGE_MM_H */ |
diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 763507932898..620891f4e54f 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c | |||
@@ -896,6 +896,22 @@ out: | |||
896 | return ret; | 896 | return ret; |
897 | } | 897 | } |
898 | 898 | ||
899 | int hugepage_madvise(unsigned long *vm_flags) | ||
900 | { | ||
901 | /* | ||
902 | * Be somewhat over-protective like KSM for now! | ||
903 | */ | ||
904 | if (*vm_flags & (VM_HUGEPAGE | VM_SHARED | VM_MAYSHARE | | ||
905 | VM_PFNMAP | VM_IO | VM_DONTEXPAND | | ||
906 | VM_RESERVED | VM_HUGETLB | VM_INSERTPAGE | | ||
907 | VM_MIXEDMAP | VM_SAO)) | ||
908 | return -EINVAL; | ||
909 | |||
910 | *vm_flags |= VM_HUGEPAGE; | ||
911 | |||
912 | return 0; | ||
913 | } | ||
914 | |||
899 | void __split_huge_page_pmd(struct mm_struct *mm, pmd_t *pmd) | 915 | void __split_huge_page_pmd(struct mm_struct *mm, pmd_t *pmd) |
900 | { | 916 | { |
901 | struct page *page; | 917 | struct page *page; |
diff --git a/mm/madvise.c b/mm/madvise.c index 319528b8db74..ecde40a401c1 100644 --- a/mm/madvise.c +++ b/mm/madvise.c | |||
@@ -71,6 +71,11 @@ static long madvise_behavior(struct vm_area_struct * vma, | |||
71 | if (error) | 71 | if (error) |
72 | goto out; | 72 | goto out; |
73 | break; | 73 | break; |
74 | case MADV_HUGEPAGE: | ||
75 | error = hugepage_madvise(&new_flags); | ||
76 | if (error) | ||
77 | goto out; | ||
78 | break; | ||
74 | } | 79 | } |
75 | 80 | ||
76 | if (new_flags == vma->vm_flags) { | 81 | if (new_flags == vma->vm_flags) { |
@@ -283,6 +288,9 @@ madvise_behavior_valid(int behavior) | |||
283 | case MADV_MERGEABLE: | 288 | case MADV_MERGEABLE: |
284 | case MADV_UNMERGEABLE: | 289 | case MADV_UNMERGEABLE: |
285 | #endif | 290 | #endif |
291 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE | ||
292 | case MADV_HUGEPAGE: | ||
293 | #endif | ||
286 | return 1; | 294 | return 1; |
287 | 295 | ||
288 | default: | 296 | default: |