Skip to content
  • Vlastimil Babka's avatar
    mm: munlock: fix deadlock in __munlock_pagevec() · 3b25df93
    Vlastimil Babka authored
    Commit 7225522b
    
     ("mm: munlock: batch non-THP page isolation and
    munlock+putback using pagevec" introduced __munlock_pagevec() to speed
    up munlock by holding lru_lock over multiple isolated pages.  Pages that
    fail to be isolated are put_page()d immediately, also within the lock.
    
    This can lead to deadlock when __munlock_pagevec() becomes the holder of
    the last page pin and put_page() leads to __page_cache_release() which
    also locks lru_lock.  The deadlock has been observed by Sasha Levin
    using trinity.
    
    This patch avoids the deadlock by deferring put_page() operations until
    lru_lock is released.  Another pagevec (which is also used by later
    phases of the function is reused to gather the pages for put_page()
    operation.
    
    Signed-off-by: default avatarVlastimil Babka <vbabka@suse.cz>
    Reported-by: default avatarSasha Levin <sasha.levin@oracle.com>
    Cc: Michel Lespinasse <walken@google.com>
    Cc: Andrea Arcangeli <aarcange@redhat.com>
    Cc: Rik van Riel <riel@redhat.com>
    Cc: Mel Gorman <mgorman@suse.de>
    Cc: Hugh Dickins <hughd@google.com>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    3b25df93