Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/rmap: fix old bug: munlocking THP missed other mlocks

The kernel recovers in due course from missing Mlocked pages: but there
was no point in calling page_mlock() (formerly known as
try_to_munlock()) on a THP, because nothing got done even when it was
found to be mapped in another VM_LOCKED vma.

It's true that we need to be careful: Mlocked accounting of pte-mapped
THPs is too difficult (so consistently avoided); but Mlocked accounting
of only-pmd-mapped THPs is supposed to work, even when multiple mappings
are mlocked and munlocked or munmapped. Refine the tests.

There is already a VM_BUG_ON_PAGE(PageDoubleMap) in page_mlock(), so
page_mlock_one() does not even have to worry about that complication.

(I said the kernel recovers: but would page reclaim be likely to split
THP before rediscovering that it's VM_LOCKED? I've not followed that up)

Fixes: 9a73f61bdb8a ("thp, mlock: do not mlock PTE-mapped file huge pages")
Signed-off-by: Hugh Dickins <hughd@google.com>
Reviewed-by: Shakeel Butt <shakeelb@google.com>
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Link: https://lore.kernel.org/lkml/cfa154c-d595-406-eb7d-eb9df730f944@google.com/
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Jason Gunthorpe <jgg@nvidia.com>
Cc: Ralph Campbell <rcampbell@nvidia.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Yang Shi <shy828301@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Hugh Dickins and committed by
Linus Torvalds
d9770fcc 64b586d1

+8 -5
+8 -5
mm/rmap.c
··· 1442 1442 */ 1443 1443 if (!(flags & TTU_IGNORE_MLOCK)) { 1444 1444 if (vma->vm_flags & VM_LOCKED) { 1445 - /* PTE-mapped THP are never mlocked */ 1446 - if (!PageTransCompound(page)) { 1445 + /* PTE-mapped THP are never marked as mlocked */ 1446 + if (!PageTransCompound(page) || 1447 + (PageHead(page) && !PageDoubleMap(page))) { 1447 1448 /* 1448 1449 * Holding pte lock, we do *not* need 1449 1450 * mmap_lock here ··· 1985 1984 * munlock_vma_pages_range(). 1986 1985 */ 1987 1986 if (vma->vm_flags & VM_LOCKED) { 1988 - /* PTE-mapped THP are never mlocked */ 1989 - if (!PageTransCompound(page)) 1990 - mlock_vma_page(page); 1987 + /* 1988 + * PTE-mapped THP are never marked as mlocked, but 1989 + * this function is never called when PageDoubleMap(). 1990 + */ 1991 + mlock_vma_page(page); 1991 1992 page_vma_mapped_walk_done(&pvmw); 1992 1993 } 1993 1994