Commit:     c5c99429fa57dcf6e05203ebe3676db1ec646793
Parent:     c2f3dabefa73fe3307578553f456e93f0a1bca08
Author:     Larry Woodman <[EMAIL PROTECTED]>
AuthorDate: Thu Jan 24 05:49:25 2008 -0800
Committer:  Linus Torvalds <[EMAIL PROTECTED]>
CommitDate: Thu Jan 24 08:07:27 2008 -0800

    fix hugepages leak due to pagetable page sharing
    The shared page table code for hugetlb memory on x86 and x86_64
    is causing a leak.  When a user of hugepages exits using this code
    the system leaks some of the hugepages.
    Part of /proc/meminfo just before database startup:
    HugePages_Total:  5500
    HugePages_Free:   5500
    HugePages_Rsvd:      0
    Hugepagesize:     2048 kB
    Just before shutdown:
    HugePages_Total:  5500
    HugePages_Free:   4475
    HugePages_Rsvd:      0
    Hugepagesize:     2048 kB
    After shutdown:
    HugePages_Total:  5500
    HugePages_Free:   4988
    0 Hugepagesize:     2048 kB
    The problem occurs durring a fork, in copy_hugetlb_page_range().  It
    locates the dst_pte using huge_pte_alloc().  Since huge_pte_alloc() calls
    huge_pmd_share() it will share the pmd page if can, yet the main loop in
    copy_hugetlb_page_range() does a get_page() on every hugepage.  This is a
    violation of the shared hugepmd pagetable protocol and creates additional
    referenced to the hugepages causing a leak when the unmap of the VMA
    occurs.  We can skip the entire replication of the ptes when the hugepage
    pagetables are shared.  The attached patch skips copying the ptes and the
    get_page() calls if the hugetlbpage pagetable is shared.
    [EMAIL PROTECTED]: coding-style cleanups]
    Signed-off-by: Larry Woodman <[EMAIL PROTECTED]>
    Signed-off-by: Adam Litke <[EMAIL PROTECTED]>
    Cc: Badari Pulavarty <[EMAIL PROTECTED]>
    Cc: Ken Chen <[EMAIL PROTECTED]>
    Cc: David Gibson <[EMAIL PROTECTED]>
    Cc: William Lee Irwin III <[EMAIL PROTECTED]>
    Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
    Signed-off-by: Linus Torvalds <[EMAIL PROTECTED]>
 mm/hugetlb.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index e0fda15..db861d8 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -699,6 +699,11 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct 
mm_struct *src,
                dst_pte = huge_pte_alloc(dst, addr);
                if (!dst_pte)
                        goto nomem;
+               /* If the pagetables are shared don't copy or take references */
+               if (dst_pte == src_pte)
+                       continue;
                if (!pte_none(*src_pte)) {
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at

Reply via email to