Commit caed0f486e582eeeb6e3546417fd758230fe4ad9

Authored by KOSAKI Motohiro
Committed by Linus Torvalds
1 parent 23ce932a5e

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>

Showing 1 changed file with 22 additions and 13 deletions Side-by-side Diff

... ... @@ -789,10 +789,9 @@
789 789 * skipped over this mm) then we should reactivate it.
790 790 */
791 791 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 +
796 795 if (TTU_ACTION(flags) == TTU_MUNLOCK)
797 796 goto out_unmap;
798 797 }
799 798  
800 799  
801 800  
... ... @@ -865,18 +864,28 @@
865 864  
866 865 out_unmap:
867 866 pte_unmap_unlock(pte, ptl);
  867 +out:
  868 + return ret;
868 869  
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;
877 886 }
  887 + up_read(&vma->vm_mm->mmap_sem);
878 888 }
879   -out:
880 889 return ret;
881 890 }
882 891