Skip to content

Commit caed0f4

Browse files
kosakitorvalds
authored andcommitted
mm: simplify try_to_unmap_one()
SWAP_MLOCK mean "We marked the page as PG_MLOCK, please move it to unevictable-lru". So, following code is easy confusable. if (vma->vm_flags & VM_LOCKED) { ret = SWAP_MLOCK; goto out_unmap; } Plus, if the VMA doesn't have VM_LOCKED, We don't need to check the needed of calling mlock_vma_page(). Also, add some commentary to try_to_unmap_one(). Acked-by: Hugh Dickins <hugh.dickins@tiscali.co.uk> Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 23ce932 commit caed0f4

1 file changed

Lines changed: 22 additions & 13 deletions

File tree

‎mm/rmap.c‎

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -789,10 +789,9 @@ int try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
789789
* skipped over this mm) then we should reactivate it.
790790
*/
791791
if (!(flags & TTU_IGNORE_MLOCK)) {
792-
if (vma->vm_flags & VM_LOCKED) {
793-
ret = SWAP_MLOCK;
794-
goto out_unmap;
795-
}
792+
if (vma->vm_flags & VM_LOCKED)
793+
goto out_mlock;
794+
796795
if (TTU_ACTION(flags) == TTU_MUNLOCK)
797796
goto out_unmap;
798797
}
@@ -865,18 +864,28 @@ int try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
865864

866865
out_unmap:
867866
pte_unmap_unlock(pte, ptl);
867+
out:
868+
return ret;
868869

869-
if (ret == SWAP_MLOCK) {
870-
ret = SWAP_AGAIN;
871-
if (down_read_trylock(&vma->vm_mm->mmap_sem)) {
872-
if (vma->vm_flags & VM_LOCKED) {
873-
mlock_vma_page(page);
874-
ret = SWAP_MLOCK;
875-
}
876-
up_read(&vma->vm_mm->mmap_sem);
870+
out_mlock:
871+
pte_unmap_unlock(pte, ptl);
872+
873+
874+
/*
875+
* We need mmap_sem locking, Otherwise VM_LOCKED check makes
876+
* unstable result and race. Plus, We can't wait here because
877+
* we now hold anon_vma->lock or mapping->i_mmap_lock.
878+
* if trylock failed, the page remain in evictable lru and later
879+
* vmscan could retry to move the page to unevictable lru if the
880+
* page is actually mlocked.
881+
*/
882+
if (down_read_trylock(&vma->vm_mm->mmap_sem)) {
883+
if (vma->vm_flags & VM_LOCKED) {
884+
mlock_vma_page(page);
885+
ret = SWAP_MLOCK;
877886
}
887+
up_read(&vma->vm_mm->mmap_sem);
878888
}
879-
out:
880889
return ret;
881890
}
882891

0 commit comments

Comments
 (0)