Skip to content
  • Mike Kravetz's avatar
    mm/hugetlb: fix huge page reserve accounting for private mappings · 67961f9d
    Mike Kravetz authored
    When creating a private mapping of a hugetlbfs file, it is possible to
    unmap pages via ftruncate or fallocate hole punch.  If subsequent faults
    repopulate these mappings, the reserve counts will go negative.  This is
    because the code currently assumes all faults to private mappings will
    consume reserves.  The problem can be recreated as follows:
    
     - mmap(MAP_PRIVATE) a file in hugetlbfs filesystem
     - write fault in pages in the mapping
     - fallocate(FALLOC_FL_PUNCH_HOLE) some pages in the mapping
     - write fault in pages in the hole
    
    This will result in negative huge page reserve counts and negative
    subpool usage counts for the hugetlbfs.  Note that this can also be
    recreated with ftruncate, but fallocate is more straight forward.
    
    This patch modifies the routines vma_needs_reserves and vma_has_reserves
    to examine the reserve map associated with private mappings similar to
    that for shared mappings.  However, the reserve map semantics for
    private and shared mappings are very different.  This results in subtly
    different code that is explained in the comments.
    
    Link: http://lkml.kernel.org/r/1464720957-15698-1-git-send-email-mike.kravetz@oracle.com
    
    
    Signed-off-by: default avatarMike Kravetz <mike.kravetz@oracle.com>
    Acked-by: default avatarHillf Danton <hillf.zj@alibaba-inc.com>
    Cc: Dave Hansen <dave.hansen@linux.intel.com>
    Cc: Kirill Shutemov <kirill.shutemov@linux.intel.com>
    Cc: Michal Hocko <mhocko@suse.cz>
    Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
    Cc: Aneesh Kumar <aneesh.kumar@linux.vnet.ibm.com>
    Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    67961f9d