Commit ef694222 authored by Bob Liu's avatar Bob Liu Committed by Linus Torvalds

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: default avatarBob Liu <lliubbo@gmail.com>
Acked-by: default avatarHugh Dickins <hughd@google.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent cc9a6c87
...@@ -374,6 +374,20 @@ static int break_ksm(struct vm_area_struct *vma, unsigned long addr) ...@@ -374,6 +374,20 @@ static int break_ksm(struct vm_area_struct *vma, unsigned long addr)
return (ret & VM_FAULT_OOM) ? -ENOMEM : 0; return (ret & VM_FAULT_OOM) ? -ENOMEM : 0;
} }
static struct vm_area_struct *find_mergeable_vma(struct mm_struct *mm,
unsigned long addr)
{
struct vm_area_struct *vma;
if (ksm_test_exit(mm))
return NULL;
vma = find_vma(mm, addr);
if (!vma || vma->vm_start > addr)
return NULL;
if (!(vma->vm_flags & VM_MERGEABLE) || !vma->anon_vma)
return NULL;
return vma;
}
static void break_cow(struct rmap_item *rmap_item) static void break_cow(struct rmap_item *rmap_item)
{ {
struct mm_struct *mm = rmap_item->mm; struct mm_struct *mm = rmap_item->mm;
...@@ -387,15 +401,9 @@ static void break_cow(struct rmap_item *rmap_item) ...@@ -387,15 +401,9 @@ static void break_cow(struct rmap_item *rmap_item)
put_anon_vma(rmap_item->anon_vma); put_anon_vma(rmap_item->anon_vma);
down_read(&mm->mmap_sem); down_read(&mm->mmap_sem);
if (ksm_test_exit(mm)) vma = find_mergeable_vma(mm, addr);
goto out; if (vma)
vma = find_vma(mm, addr); break_ksm(vma, addr);
if (!vma || vma->vm_start > addr)
goto out;
if (!(vma->vm_flags & VM_MERGEABLE) || !vma->anon_vma)
goto out;
break_ksm(vma, addr);
out:
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
} }
...@@ -421,12 +429,8 @@ static struct page *get_mergeable_page(struct rmap_item *rmap_item) ...@@ -421,12 +429,8 @@ static struct page *get_mergeable_page(struct rmap_item *rmap_item)
struct page *page; struct page *page;
down_read(&mm->mmap_sem); down_read(&mm->mmap_sem);
if (ksm_test_exit(mm)) vma = find_mergeable_vma(mm, addr);
goto out; if (!vma)
vma = find_vma(mm, addr);
if (!vma || vma->vm_start > addr)
goto out;
if (!(vma->vm_flags & VM_MERGEABLE) || !vma->anon_vma)
goto out; goto out;
page = follow_page(vma, addr, FOLL_GET); page = follow_page(vma, addr, FOLL_GET);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment