Commit ef6942224a185c9e434f6cfe69fe434e732f5b38

Authored by Bob Liu
Committed by Linus Torvalds
1 parent cc9a6c8776

ksm: cleanup: introduce find_mergeable_vma()

There are multiple places which perform the same check.  Add a new
find_mergeable_vma() to handle this.

Signed-off-by: Bob Liu <lliubbo@gmail.com>
Acked-by: Hugh Dickins <hughd@google.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 19 additions and 15 deletions Side-by-side Diff

... ... @@ -374,6 +374,20 @@
374 374 return (ret & VM_FAULT_OOM) ? -ENOMEM : 0;
375 375 }
376 376  
  377 +static struct vm_area_struct *find_mergeable_vma(struct mm_struct *mm,
  378 + unsigned long addr)
  379 +{
  380 + struct vm_area_struct *vma;
  381 + if (ksm_test_exit(mm))
  382 + return NULL;
  383 + vma = find_vma(mm, addr);
  384 + if (!vma || vma->vm_start > addr)
  385 + return NULL;
  386 + if (!(vma->vm_flags & VM_MERGEABLE) || !vma->anon_vma)
  387 + return NULL;
  388 + return vma;
  389 +}
  390 +
377 391 static void break_cow(struct rmap_item *rmap_item)
378 392 {
379 393 struct mm_struct *mm = rmap_item->mm;
... ... @@ -387,15 +401,9 @@
387 401 put_anon_vma(rmap_item->anon_vma);
388 402  
389 403 down_read(&mm->mmap_sem);
390   - if (ksm_test_exit(mm))
391   - goto out;
392   - vma = find_vma(mm, addr);
393   - if (!vma || vma->vm_start > addr)
394   - goto out;
395   - if (!(vma->vm_flags & VM_MERGEABLE) || !vma->anon_vma)
396   - goto out;
397   - break_ksm(vma, addr);
398   -out:
  404 + vma = find_mergeable_vma(mm, addr);
  405 + if (vma)
  406 + break_ksm(vma, addr);
399 407 up_read(&mm->mmap_sem);
400 408 }
401 409  
... ... @@ -421,12 +429,8 @@
421 429 struct page *page;
422 430  
423 431 down_read(&mm->mmap_sem);
424   - if (ksm_test_exit(mm))
425   - goto out;
426   - vma = find_vma(mm, addr);
427   - if (!vma || vma->vm_start > addr)
428   - goto out;
429   - if (!(vma->vm_flags & VM_MERGEABLE) || !vma->anon_vma)
  432 + vma = find_mergeable_vma(mm, addr);
  433 + if (!vma)
430 434 goto out;
431 435  
432 436 page = follow_page(vma, addr, FOLL_GET);