• Andrea Arcangeli's avatar
    mm: hugetlb: initialize PG_reserved for tail pages of gigantic compound pages · ef5a22be
    Andrea Arcangeli authored
    Commit 11feeb49 ("kvm: optimize away THP checks in
    kvm_is_mmio_pfn()") introduced a memory leak when KVM is run on gigantic
    compound pages.
    
    That commit depends on the assumption that PG_reserved is identical for
    all head and tail pages of a compound page.  So that if get_user_pages
    returns a tail page, we don't need to check the head page in order to
    know if we deal with a reserved page that requires different
    refcounting.
    
    The assumption that PG_reserved is the same for head and tail pages is
    certainly correct for THP and regular hugepages, but gigantic hugepages
    allocated through bootmem don't clear the PG_reserved on the tail pages
    (the clearing of PG_reserved is done later only if the gigantic hugepage
    is freed).
    
    This patch corrects the gigantic compound page initialization so that we
    can retain the optimization in 11feeb49.  The cacheline was already
    modified in order to set PG_tail so this won't affect the boot time of
    large memory systems.
    
    [akpm@linux-foundation.org: tweak comment layout and grammar]
    Signed-off-by: default avatarAndrea Arcangeli <aarcange@redhat.com>
    Reported-by: default avatarandy123 <ajs124.ajs124@gmail.com>
    Acked-by: default avatarRik van Riel <riel@redhat.com>
    Cc: Gleb Natapov <gleb@redhat.com>
    Cc: Mel Gorman <mgorman@suse.de>
    Cc: Hugh Dickins <hughd@google.com>
    Acked-by: default avatarRafael Aquini <aquini@redhat.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    ef5a22be
hugetlb.c 92.3 KB