diff options
author | Bob Liu <lliubbo@gmail.com> | 2012-03-21 19:34:11 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-03-21 20:54:59 -0400 |
commit | ef6942224a185c9e434f6cfe69fe434e732f5b38 (patch) | |
tree | e26664dbfd6077129d75f555757d36b5fbec43c2 /mm/ksm.c | |
parent | cc9a6c8776615f9c194ccf0b63a0aa5628235545 (diff) |
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>
Diffstat (limited to 'mm/ksm.c')
-rw-r--r-- | mm/ksm.c | 34 |
1 files changed, 19 insertions, 15 deletions
@@ -374,6 +374,20 @@ static int break_ksm(struct vm_area_struct *vma, unsigned long addr) | |||
374 | return (ret & VM_FAULT_OOM) ? -ENOMEM : 0; | 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 | static void break_cow(struct rmap_item *rmap_item) | 391 | static void break_cow(struct rmap_item *rmap_item) |
378 | { | 392 | { |
379 | struct mm_struct *mm = rmap_item->mm; | 393 | struct mm_struct *mm = rmap_item->mm; |
@@ -387,15 +401,9 @@ static void break_cow(struct rmap_item *rmap_item) | |||
387 | put_anon_vma(rmap_item->anon_vma); | 401 | put_anon_vma(rmap_item->anon_vma); |
388 | 402 | ||
389 | down_read(&mm->mmap_sem); | 403 | down_read(&mm->mmap_sem); |
390 | if (ksm_test_exit(mm)) | 404 | vma = find_mergeable_vma(mm, addr); |
391 | goto out; | 405 | if (vma) |
392 | vma = find_vma(mm, addr); | 406 | break_ksm(vma, 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: | ||
399 | up_read(&mm->mmap_sem); | 407 | up_read(&mm->mmap_sem); |
400 | } | 408 | } |
401 | 409 | ||
@@ -421,12 +429,8 @@ static struct page *get_mergeable_page(struct rmap_item *rmap_item) | |||
421 | struct page *page; | 429 | struct page *page; |
422 | 430 | ||
423 | down_read(&mm->mmap_sem); | 431 | down_read(&mm->mmap_sem); |
424 | if (ksm_test_exit(mm)) | 432 | vma = find_mergeable_vma(mm, addr); |
425 | goto out; | 433 | if (!vma) |
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) | ||
430 | goto out; | 434 | goto out; |
431 | 435 | ||
432 | page = follow_page(vma, addr, FOLL_GET); | 436 | page = follow_page(vma, addr, FOLL_GET); |