Re: [PATCH 2/2] ksm: cleanup: introduce ksm_check_mm()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 1 Mar 2012, Bob Liu wrote:

> There are multi place do the same check.
> 
> Signed-off-by: Bob Liu <lliubbo@xxxxxxxxx>

Combining two sets of alike changes into one function, fair enough.

But am I imagining it, or is vma going to be NULL in the callers forever
after, and KSM badly broken?  And for what is vma passed to the function?

I think you want to redo this with

static struct vm_area_struct *find_mergeable_vma(struct mm_struct *mm,
                                                 unsigned long addr);

The anon_vma aspect that Andrew latched on to: that's rather a red
herring.  It's not so much looking for an anon_vma, it just knows that
if an anon_vma has not (yet) been instantiated there, then it's a
waste of time to look for an Anon or KSM page in that area.

Hugh

> ---
>  mm/ksm.c |   35 ++++++++++++++++++-----------------
>  1 files changed, 18 insertions(+), 17 deletions(-)
> 
> diff --git a/mm/ksm.c b/mm/ksm.c
> index 8e10786..33175af 100644
> --- a/mm/ksm.c
> +++ b/mm/ksm.c
> @@ -375,11 +375,24 @@ static int break_ksm(struct vm_area_struct *vma, unsigned long addr)
>  	return (ret & VM_FAULT_OOM) ? -ENOMEM : 0;
>  }
>  
> +static int ksm_check_mm(struct mm_struct *mm, struct vm_area_struct *vma,
> +		unsigned long addr)
> +{
> +	if (ksm_test_exit(mm))
> +		return 0;
> +	vma = find_vma(mm, addr);
> +	if (!vma || vma->vm_start > addr)
> +		return 0;
> +	if (!(vma->vm_flags & VM_MERGEABLE) || !vma->anon_vma)
> +		return 0;
> +	return 1;
> +}
> +
>  static void break_cow(struct rmap_item *rmap_item)
>  {
>  	struct mm_struct *mm = rmap_item->mm;
>  	unsigned long addr = rmap_item->address;
> -	struct vm_area_struct *vma;
> +	struct vm_area_struct *vma = NULL;
>  
>  	/*
>  	 * It is not an accident that whenever we want to break COW
> @@ -388,15 +401,8 @@ 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:
> +	if (ksm_check_mm(mm, vma, addr))
> +		break_ksm(vma, addr);
>  	up_read(&mm->mmap_sem);
>  }
>  
> @@ -418,16 +424,11 @@ static struct page *get_mergeable_page(struct rmap_item *rmap_item)
>  {
>  	struct mm_struct *mm = rmap_item->mm;
>  	unsigned long addr = rmap_item->address;
> -	struct vm_area_struct *vma;
> +	struct vm_area_struct *vma = NULL;
>  	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)
> +	if (!ksm_check_mm(mm, vma, addr))
>  		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@xxxxxxxxx.  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@xxxxxxxxx";> email@xxxxxxxxx </a>


[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]