[<prev] [next>] [day] [month] [year] [list]
Message-ID: <tip-gjd2uz5arf4sl7j9764sae91@git.kernel.org>
Date: Fri, 18 May 2012 03:28:57 -0700
From: tip-bot for Peter Zijlstra <a.p.zijlstra@...llo.nl>
To: linux-tip-commits@...r.kernel.org
Cc: linux-kernel@...r.kernel.org, hpa@...or.com, mingo@...nel.org,
torvalds@...ux-foundation.org, a.p.zijlstra@...llo.nl,
pjt@...gle.com, cl@...ux.com, riel@...hat.com,
akpm@...ux-foundation.org, bharata.rao@...il.com,
aarcange@...hat.com, Lee.Schermerhorn@...com,
suresh.b.siddha@...el.com, danms@...ibm.com, tglx@...utronix.de
Subject: [tip:sched/numa] mm/mpol: Introduce vma_dup_policy()
Commit-ID: 9fc52f506a4ed7330bac067a76dd670760008536
Gitweb: http://git.kernel.org/tip/9fc52f506a4ed7330bac067a76dd670760008536
Author: Peter Zijlstra <a.p.zijlstra@...llo.nl>
AuthorDate: Mon, 9 Jan 2012 11:41:03 +0100
Committer: Ingo Molnar <mingo@...nel.org>
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 <a.p.zijlstra@...llo.nl>
Cc: Suresh Siddha <suresh.b.siddha@...el.com>
Cc: Paul Turner <pjt@...gle.com>
Cc: Dan Smith <danms@...ibm.com>
Cc: Bharata B Rao <bharata.rao@...il.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@...com>
Cc: Christoph Lameter <cl@...ux.com>
Cc: Rik van Riel <riel@...hat.com>
Cc: Andrea Arcangeli <aarcange@...hat.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>
Link: http://lkml.kernel.org/n/tip-gjd2uz5arf4sl7j9764sae91@git.kernel.org
Signed-off-by: Ingo Molnar <mingo@...nel.org>
---
include/linux/mempolicy.h | 3 +++
kernel/fork.c | 9 +++------
mm/mempolicy.c | 11 +++++++++++
mm/mmap.c | 17 +++++------------
4 files changed, 22 insertions(+), 18 deletions(-)
diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
index c970840..c8525db 100644
--- a/include/linux/mempolicy.h
+++ b/include/linux/mempolicy.h
@@ -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)
{
diff --git a/kernel/fork.c b/kernel/fork.c
index a1793e4..f01be7f 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -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:
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 113b091..e9c658d 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -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
diff --git a/mm/mmap.c b/mm/mmap.c
index 848ef52..8c72aed 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -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;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists