[PATCH 2/5] [hugetlb] Account for hugepages as locked_vm

Adam Litke
2007-07-13T15:16:46Z

Hugepages allocated for a process are pinned and may not be reclaimed. This
patch accounts for hugepages under locked_vm.

TODO:
Explore replacing this patch with a hugetlb pool high watermark
instead.

Signed-off-by: Adam Litke <agl@us.ibm.com>
Signed-off-by: Mel Gorman <mel@csn.ul.ie>
---

mm/hugetlb.c | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 61a52b0..d1ca501 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -402,6 +402,7 @@ void __unmap_hugepage_range(struct vm_area_struct *vma, unsigned long start,
continue;

page = pte_page(pte);
+ mm->locked_vm -= BASE_PAGES_PER_HPAGE;
if (pte_dirty(pte))
set_page_dirty(page);
list_add(&page->lru, &page_list);
@@ -535,6 +536,14 @@ retry:
&& (vma->vm_flags & VM_SHARED)));
set_huge_pte_at(mm, address, ptep, new_pte);

+ /*
+ * Account for huge pages as locked. Note that lock limits are not
+ * enforced here because it is not expected that limits are enforced
+ * at fault time. It also would not be right to enforce the limits
+ * at mmap() time because the pages are not pinned at that point
+ */
+ mm->locked_vm += BASE_PAGES_PER_HPAGE;
+
if (write_access && !(vma->vm_flags & VM_SHARED)) {
/* Optimization, do the COW without a second fault */
ret = hugetlb_cow(mm, vma, address, ptep, new_pte);