mm/rmap: fix munlocking Anon THP with mlocked ptes

Many thanks to Kirill for reminding that PageDoubleMap cannot be relied on
to warn of pte mappings in the Anon THP case; and a scan of subpages does
not seem appropriate here.  Note how follow_trans_huge_pmd() does not even
mark an Anon THP as mlocked when compound_mapcount != 1: multiple mlocking
of Anon THP is avoided, so simply return from page_mlock() in this case.

Fixes: d9770fcc1c0c ("mm/rmap: fix old bug: munlocking THP missed other mlocks")
Reported-by: Kirill A. Shutemov <>
Signed-off-by: Hugh Dickins <>
Acked-by: Kirill A. Shutemov <>
Cc: Andrew Morton <>
Cc: Alistair Popple <>
Cc: Jason Gunthorpe <>
Cc: Ralph Campbell <>
Cc: Christoph Hellwig <>
Cc: Yang Shi <>
Cc: Shakeel Butt <>
Signed-off-by: Linus Torvalds <>
1 file changed