• David Rientjes's avatar
    mm, thp: fix collapsing of hugepages on madvise · 37e867c1
    David Rientjes authored
    commit 6d50e60c upstream.
    
    If an anonymous mapping is not allowed to fault thp memory and then
    madvise(MADV_HUGEPAGE) is used after fault, khugepaged will never
    collapse this memory into thp memory.
    
    This occurs because the madvise(2) handler for thp, hugepage_madvise(),
    clears VM_NOHUGEPAGE on the stack and it isn't stored in vma->vm_flags
    until the final action of madvise_behavior().  This causes the
    khugepaged_enter_vma_merge() to be a no-op in hugepage_madvise() when
    the vma had previously had VM_NOHUGEPAGE set.
    
    Fix this by passing the correct vma flags to the khugepaged mm slot
    handler.  There's no chance khugepaged can run on this vma until after
    madvise_behavior() returns since we hold mm->mmap_sem.
    
    It would be possible to clear VM_NOHUGEPAGE directly from vma->vm_flags
    in hugepage_advise(), but I didn't want to introduce special case
    behavior into madvise_behavior().  I think it's best to just let it
    always set vma->vm_flags itself.
    Signed-off-by: default avatarDavid Rientjes <rientjes@google.com>
    Reported-by: default avatarSuleiman Souhlal <suleiman@google.com>
    Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
    Cc: Andrea Arcangeli <aarcange@redhat.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    [bwh: Backported to 3.2: adjust context, indentation]
    Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
    37e867c1
mmap.c 69.6 KB