Re: [PATCH] mm: mempolicy: turn vma_set_policy() intovma_dup_policy()

From: David Rientjes
Date: Thu Jul 11 2013 - 18:13:34 EST


On Wed, 10 Jul 2013, Oleg Nesterov wrote:

> Simple cleanup. Every user of vma_set_policy() does the same work,
> this looks a bit annoying imho. And the new trivial helper which
> does mpol_dup() + vma_set_policy() to simplify the callers.
>

Good idea, just a few simple issues to fix.

> diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> index 4baf12e..6b1d426 100644
> --- a/mm/mempolicy.c
> +++ b/mm/mempolicy.c
> @@ -2065,6 +2065,16 @@ retry_cpuset:
> }
> EXPORT_SYMBOL(alloc_pages_current);
>
> +int vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
> +{
> + struct mempolicy *pol = mpol_dup(vma_policy(src));
> +
> + if (IS_ERR(pol))
> + return PTR_ERR(pol);

PTR_ERR() returns long, so vma_dup_policy() needs to return long.

> + dst->vm_policy = pol;
> + return 0;
> +}
> +
> /*
> * If mpol_dup() sees current->cpuset == cpuset_being_rebound, then it
> * rebinds the mempolicy its copying by calling mpol_rebind_policy()
> diff --git a/mm/mmap.c b/mm/mmap.c
> index 7a1ba76..d8a310b 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -2481,7 +2481,6 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
> static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
> unsigned long addr, int new_below)
> {
> - struct mempolicy *pol;
> struct vm_area_struct *new;
> int err = -ENOMEM;
>
> @@ -2505,12 +2504,9 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
> new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
> }
>
> - pol = mpol_dup(vma_policy(vma));
> - if (IS_ERR(pol)) {
> - err = PTR_ERR(pol);
> + err = vma_dup_policy(vma, new);
> + if (err)
> goto out_free_vma;
> - }
> - vma_set_policy(new, pol);
>
> if (anon_vma_clone(new, vma))
> goto out_free_mpol;

This isn't the first occurrence in mm/mmap.c, what about vma_adjust()?
Probably need to patch 3.10 or later.

Otherwise looks good.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/