mm: munlock: fix deadlock in __munlock_pagevec()
mm: munlock: fix deadlock in __munlock_pagevec()

Commit 7225522bb429 ("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: Vlastimil Babka <db766431e3f0373ca1ec8fa855cfd5f84b2f2eb6@suse.cz>
Reported-by: Sasha Levin <e642b69ed2fc111e09ffdc37feb733a52253340d@oracle.com>
Cc: Michel Lespinasse <6a4cf9207bb95b1a4cf1be22c2e93f8b38036f65@google.com>
Cc: Andrea Arcangeli <6cb163d975a8c4c46420677e0054b55c39bdb339@redhat.com>
Cc: Rik van Riel <a21938f5d463ddf41aa718934c205ca2cce8ebbc@redhat.com>
Cc: Mel Gorman <39ea6a09710987173e32e37c86918024a0f441c1@suse.de>
Cc: Hugh Dickins <d3abdf3e2800e6cb849f11b81e6eb50b34d96431@google.com>
Cc: <4fbacc2fa0ffdbb11bf1ad6925b886ebd08dd15f@vger.kernel.org>
Signed-off-by: Andrew Morton <5c1e68b099950c134891f0b6e179498a8ebe9cf9@linux-foundation.org>
Signed-off-by: Linus Torvalds <69652caca27c8b940640ad396ab71f93cacec34f@linux-foundation.org>

KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs