Skip to content

Commit d9770fc

Browse files
Hugh Dickinstorvalds
authored andcommitted
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: 9a73f61 ("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>
1 parent 64b586d commit d9770fc

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

mm/rmap.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,8 +1442,9 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
14421442
*/
14431443
if (!(flags & TTU_IGNORE_MLOCK)) {
14441444
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))) {
14471448
/*
14481449
* Holding pte lock, we do *not* need
14491450
* mmap_lock here
@@ -1984,9 +1985,11 @@ static bool page_mlock_one(struct page *page, struct vm_area_struct *vma,
19841985
* munlock_vma_pages_range().
19851986
*/
19861987
if (vma->vm_flags & VM_LOCKED) {
1987-
/* PTE-mapped THP are never mlocked */
1988-
if (!PageTransCompound(page))
1989-
mlock_vma_page(page);
1988+
/*
1989+
* PTE-mapped THP are never marked as mlocked, but
1990+
* this function is never called when PageDoubleMap().
1991+
*/
1992+
mlock_vma_page(page);
19901993
page_vma_mapped_walk_done(&pvmw);
19911994
}
19921995

0 commit comments

Comments
 (0)