From: Adam Litke <agl@us.ibm.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, Ken Chen <kenchen@google.com>,
Andy Whitcroft <apw@shadowen.org>
Subject: [PATCH 1/3] [FIX] hugetlb: Fix broken fs quota management
Date: Wed, 24 Oct 2007 06:23:45 -0700 [thread overview]
Message-ID: <20071024132345.13013.36192.stgit@kernel> (raw)
In-Reply-To: <20071024132335.13013.76227.stgit@kernel>
The hugetlbfs quota management system was never taught to handle
MAP_PRIVATE mappings when that support was added. Currently, quota is
debited at page instantiation and credited at file truncation. This
approach works correctly for shared pages but is incomplete for private
pages. In addition to hugetlb_no_page(), private pages can be instantiated
by hugetlb_cow(); but this function does not respect quotas.
Private huge pages are treated very much like normal, anonymous pages.
They are not "backed" by the hugetlbfs file and are not stored in the
mapping's radix tree. This means that private pages are invisible to
truncate_hugepages() so that function will not credit the quota.
This patch teaches the unmap path how to release fs quota analogous to
truncate_hugepages(). If __unmap_hugepage_range() clears the last page
reference it will credit the corresponding fs quota before calling the page
dtor. This will catch pages that were mapped MAP_PRIVATE only as the file
will always hold the last reference on a MAP_SHARED page.
hugetlb_cow() is also updated to charge against quota before allocating the
new page.
Signed-off-by: Adam Litke <agl@us.ibm.com>
Signed-off-by: Andy Whitcroft <apw@shadowen.org>
---
mm/hugetlb.c | 14 +++++++++++++-
1 files changed, 13 insertions(+), 1 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index ae2959b..0d645ca 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -685,7 +685,17 @@ void __unmap_hugepage_range(struct vm_area_struct *vma, unsigned long start,
flush_tlb_range(vma, start, end);
list_for_each_entry_safe(page, tmp, &page_list, lru) {
list_del(&page->lru);
- put_page(page);
+ if (put_page_testzero(page)) {
+ /*
+ * When releasing the last reference to a page we must
+ * credit the quota. For MAP_PRIVATE pages this occurs
+ * when the last PTE is cleared, for MAP_SHARED pages
+ * this occurs when the file is truncated.
+ */
+ VM_BUG_ON(PageMapping(page));
+ hugetlb_put_quota(vma->vm_file->f_mapping);
+ free_huge_page(page);
+ }
}
}
@@ -722,6 +732,8 @@ static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma,
set_huge_ptep_writable(vma, address, ptep);
return 0;
}
+ if (hugetlb_get_quota(vma->vm_file->f_mapping))
+ return VM_FAULT_SIGBUS;
page_cache_get(old_page);
new_page = alloc_huge_page(vma, address);
--
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: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2007-10-24 13:23 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-24 13:23 [PATCH 0/3] hugetlb: Fix up filesystem quota accounting Adam Litke
2007-10-24 13:23 ` Adam Litke [this message]
2007-10-24 18:43 ` [PATCH 1/3] [FIX] hugetlb: Fix broken fs quota management Dave Hansen
2007-10-24 19:03 ` Adam Litke
2007-10-24 19:18 ` Dave Hansen
2007-10-24 19:21 ` Ken Chen
2007-10-24 20:02 ` Adam Litke
2007-10-24 22:12 ` Dave Hansen
2007-10-25 5:20 ` Ken Chen
2007-10-25 14:54 ` Adam Litke
2007-10-24 13:23 ` [PATCH 2/3] hugetlb: Allow bulk updating in hugetlb_*_quota() Adam Litke
2007-10-24 13:24 ` [PATCH 3/3] [PATCH] hugetlb: Enforce quotas during reservation for shared mappings Adam Litke
2007-10-24 19:07 ` Dave Hansen
2007-10-24 19:52 ` Adam Litke
2007-10-24 20:00 ` Dave Hansen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20071024132345.13013.36192.stgit@kernel \
--to=agl@us.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=apw@shadowen.org \
--cc=kenchen@google.com \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).