mm/mpol: Introduce vma_dup_policy()
Subsystems (6)
Commit-ID: 9fc52f506a4ed7330bac067a76dd670760008536 Gitweb: http://git.kernel.org/tip/9fc52f506a4ed7330bac067a76dd670760008536 Author: Peter Zijlstra <[email protected]> AuthorDate: Mon, 9 Jan 2012 11:41:03 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Fri, 18 May 2012 08:16:19 +0200
mm/mpol: Introduce vma_dup_policy()
In preparation of other changes, pull some code duplication in a common function so that we can later extend its behaviour without having to touch all these sites.
Signed-off-by Peter Zijlstra <[email protected]>
Cc Suresh Siddha <[email protected]>
Cc Paul Turner <[email protected]>
Cc Dan Smith <[email protected]>
Cc Bharata B Rao <[email protected]>
Cc Lee Schermerhorn <[email protected]>
Cc Christoph Lameter <[email protected]>
Cc Rik van Riel <[email protected]>
Cc Andrea Arcangeli <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Linus Torvalds <[email protected]>
Signed-off-by Ingo Molnar <[email protected]>
--- include/linux/mempolicy.h | 3 +++ kernel/fork.c | 9 +++------ mm/mempolicy.c | 11 +++++++++++ mm/mmap.c | 17 +++++------------ 4 files changed, 22 insertions(+), 18 deletions(-)
include/linux/mempolicy.h +3 -0
@@ -169,6 +169,8 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)#define vma_policy (vma) ((vma)->vm_policy)#define vma_set_policy (vma, pol) ((vma)->vm_policy = (pol)) +extern int vma_dup_policy (struct vm_area_struct *new,struct vm_area_struct *old); +static inline void mpol_get (struct mempolicy *pol) {if (pol)
@@ -309,6 +311,7 @@ mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)#define vma_policy (vma) NULL#define vma_set_policy (vma, pol) do {} while(0) +#define vma_dup_policy (new, old) (0)static inline void numa_policy_init (void ) {
kernel/fork.c +3 -6
@@ -344,7 +344,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)struct rb_node **rb_link, *rb_parent;int retval;unsigned long charge; -struct mempolicy *pol;down_write (&oldmm->mmap_sem);flush_cache_dup_mm (oldmm);
@@ -394,11 +393,9 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) goto fail_nomem; *tmp = *mpnt;INIT_LIST_HEAD (&tmp->anon_vma_chain); - pol =mpol_dup (vma_policy (mpnt)); - retval =PTR_ERR (pol); -if (IS_ERR (pol)) + retval =vma_dup_policy (tmp, mpnt); +if (retval) goto fail_nomem_policy; -vma_set_policy (tmp, pol); tmp->vm_mm = mm;if (anon_vma_fork (tmp, mpnt)) goto fail_nomem_anon_vma_fork;
@@ -460,7 +457,7 @@ out:up_write (&oldmm->mmap_sem);return retval; fail_nomem_anon_vma_fork: -mpol_put (pol); +mpol_put (vma_policy (tmp)); fail_nomem_policy:kmem_cache_free (vm_area_cachep, tmp); fail_nomem:
mm/mempolicy.c +11 -0
@@ -1940,6 +1940,17 @@ struct mempolicy *__mpol_dup(struct mempolicy *old)return new; } +int vma_dup_policy (struct vm_area_struct *new,struct vm_area_struct *old) +{ +struct mempolicy *mpol; + + mpol =mpol_dup (vma_policy (old)); +if (IS_ERR (mpol)) +return PTR_ERR (mpol); +vma_set_policy (new, mpol); +return 0 ; +} +/* * If *frompol needs [has] an extra ref, copy *frompol to *tompol , * eliminate the * MPOL_F_* flags that require conditional ref and
mm/mmap.c +5 -12
@@ -1963,7 +1963,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 ;
@@ -1987,12 +1986,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 (new, vma); +if (err) goto out_free_vma; - } -vma_set_policy (new, pol);if (anon_vma_clone (new, vma)) goto out_free_mpol;
@@ -2026,7 +2022,7 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma, }unlink_anon_vmas (new); out_free_mpol: -mpol_put (pol); +mpol_put (new->vm_policy); out_free_vma:kmem_cache_free (vm_area_cachep, new); out_err:
@@ -2368,7 +2364,6 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,struct mm_struct *mm = vma->vm_mm;struct vm_area_struct *new_vma, *prev;struct rb_node **rb_link, *rb_parent; -struct mempolicy *pol;bool faulted_in_anon_vma = true;/*
@@ -2409,13 +2404,11 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, new_vma =kmem_cache_alloc (vm_area_cachep,GFP_KERNEL );if (new_vma) { *new_vma = *vma; - pol =mpol_dup (vma_policy (vma)); -if (IS_ERR (pol)) +if (vma_dup_policy (new_vma, vma)) goto out_free_vma;INIT_LIST_HEAD (&new_vma->anon_vma_chain);if (anon_vma_clone (new_vma, vma)) goto out_free_mempol; -vma_set_policy (new_vma, pol); new_vma->vm_start = addr; new_vma->vm_end = addr + len; new_vma->vm_pgoff = pgoff;
@@ -2432,7 +2425,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,return new_vma; out_free_mempol: -mpol_put (pol); +mpol_put (new_vma->vm_policy); out_free_vma:kmem_cache_free (vm_area_cachep, new_vma);return NULL ;