* [PATCH v2] ksm: cleanup: introduce find_mergeable_vma()
@ 2012-03-07 11:09 Bob Liu
2012-03-08 19:38 ` Hugh Dickins
0 siblings, 1 reply; 2+ messages in thread
From: Bob Liu @ 2012-03-07 11:09 UTC (permalink / raw)
To: akpm
Cc: hughd, rientjes, kamezawa.hiroyu, minchan.kim, linux-mm,
aarcange, Bob Liu
There are multi place do the same check, using find_mergeable_vma() to
replace.
Signed-off-by: Bob Liu <lliubbo@gmail.com>
---
mm/ksm.c | 34 +++++++++++++++++++---------------
1 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/mm/ksm.c b/mm/ksm.c
index 1925ffb..3a00767 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -375,6 +375,20 @@ static int break_ksm(struct vm_area_struct *vma, unsigned long addr)
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)
{
struct mm_struct *mm = rmap_item->mm;
@@ -388,15 +402,9 @@ static void break_cow(struct rmap_item *rmap_item)
put_anon_vma(rmap_item->anon_vma);
down_read(&mm->mmap_sem);
- if (ksm_test_exit(mm))
- goto out;
- vma = find_vma(mm, 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:
+ vma = find_mergeable_vma(mm, addr);
+ if (vma)
+ break_ksm(vma, addr);
up_read(&mm->mmap_sem);
}
@@ -422,12 +430,8 @@ static struct page *get_mergeable_page(struct rmap_item *rmap_item)
struct page *page;
down_read(&mm->mmap_sem);
- if (ksm_test_exit(mm))
- goto out;
- vma = find_vma(mm, addr);
- if (!vma || vma->vm_start > addr)
- goto out;
- if (!(vma->vm_flags & VM_MERGEABLE) || !vma->anon_vma)
+ vma = find_mergeable_vma(mm, addr);
+ if (!vma)
goto out;
page = follow_page(vma, addr, FOLL_GET);
--
1.7.0.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v2] ksm: cleanup: introduce find_mergeable_vma()
2012-03-07 11:09 [PATCH v2] ksm: cleanup: introduce find_mergeable_vma() Bob Liu
@ 2012-03-08 19:38 ` Hugh Dickins
0 siblings, 0 replies; 2+ messages in thread
From: Hugh Dickins @ 2012-03-08 19:38 UTC (permalink / raw)
To: Bob Liu; +Cc: akpm, rientjes, kamezawa.hiroyu, minchan.kim, linux-mm, aarcange
On Wed, 7 Mar 2012, Bob Liu wrote:
> There are multi place do the same check, using find_mergeable_vma() to
> replace.
>
> Signed-off-by: Bob Liu <lliubbo@gmail.com>
Acked-by: Hugh Dickins <hughd@google.com>
> ---
> mm/ksm.c | 34 +++++++++++++++++++---------------
> 1 files changed, 19 insertions(+), 15 deletions(-)
>
> diff --git a/mm/ksm.c b/mm/ksm.c
> index 1925ffb..3a00767 100644
> --- a/mm/ksm.c
> +++ b/mm/ksm.c
> @@ -375,6 +375,20 @@ static int break_ksm(struct vm_area_struct *vma, unsigned long addr)
> 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)
> {
> struct mm_struct *mm = rmap_item->mm;
> @@ -388,15 +402,9 @@ static void break_cow(struct rmap_item *rmap_item)
> put_anon_vma(rmap_item->anon_vma);
>
> down_read(&mm->mmap_sem);
> - if (ksm_test_exit(mm))
> - goto out;
> - vma = find_vma(mm, 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:
> + vma = find_mergeable_vma(mm, addr);
> + if (vma)
> + break_ksm(vma, addr);
> up_read(&mm->mmap_sem);
> }
>
> @@ -422,12 +430,8 @@ static struct page *get_mergeable_page(struct rmap_item *rmap_item)
> struct page *page;
>
> down_read(&mm->mmap_sem);
> - if (ksm_test_exit(mm))
> - goto out;
> - vma = find_vma(mm, addr);
> - if (!vma || vma->vm_start > addr)
> - goto out;
> - if (!(vma->vm_flags & VM_MERGEABLE) || !vma->anon_vma)
> + vma = find_mergeable_vma(mm, addr);
> + if (!vma)
> goto out;
>
> page = follow_page(vma, addr, FOLL_GET);
> --
> 1.7.0.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-03-08 19:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-07 11:09 [PATCH v2] ksm: cleanup: introduce find_mergeable_vma() Bob Liu
2012-03-08 19:38 ` Hugh Dickins
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox