[tip:sched/numa] mm/mpol: Simplify do_mbind()

From: tip-bot for Peter Zijlstra
Date: Fri May 18 2012 - 06:28:37 EST


Commit-ID: 6494a5f2cb894b1bcc4431d0b87d14901b05b3ba
Gitweb: http://git.kernel.org/tip/6494a5f2cb894b1bcc4431d0b87d14901b05b3ba
Author: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
AuthorDate: Mon, 30 Jan 2012 15:51:05 +0100
Committer: Ingo Molnar <mingo@xxxxxxxxxx>
CommitDate: Fri, 18 May 2012 08:16:18 +0200

mm/mpol: Simplify do_mbind()

Code flow got a little convoluted, try and straighten it some.

Signed-off-by: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
Cc: Suresh Siddha <suresh.b.siddha@xxxxxxxxx>
Cc: Paul Turner <pjt@xxxxxxxxxx>
Cc: Dan Smith <danms@xxxxxxxxxx>
Cc: Bharata B Rao <bharata.rao@xxxxxxxxx>
Cc: Lee Schermerhorn <Lee.Schermerhorn@xxxxxx>
Cc: Christoph Lameter <cl@xxxxxxxxx>
Cc: Rik van Riel <riel@xxxxxxxxxx>
Cc: Andrea Arcangeli <aarcange@xxxxxxxxxx>
Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Cc: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
Link: http://lkml.kernel.org/n/tip-olds8r1atae6j44rso80c2ad@xxxxxxxxxxxxxx
Signed-off-by: Ingo Molnar <mingo@xxxxxxxxxx>
---
mm/mempolicy.c | 73 +++++++++++++++++++++++++++++--------------------------
1 files changed, 38 insertions(+), 35 deletions(-)

diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index b60c991..113b091 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -1062,9 +1062,9 @@ static long do_mbind(unsigned long start, unsigned long len,
{
struct vm_area_struct *vma;
struct mm_struct *mm = current->mm;
- struct mempolicy *new;
+ struct mempolicy *new = NULL;
unsigned long end;
- int err;
+ int err, nr_failed = 0;
LIST_HEAD(pagelist);

if (flags & ~(unsigned long)MPOL_MF_VALID)
@@ -1086,13 +1086,15 @@ static long do_mbind(unsigned long start, unsigned long len,
if (end == start)
return 0;

- new = mpol_new(mode, mode_flags, nmask);
- if (IS_ERR(new))
- return PTR_ERR(new);
+ if (mode != MPOL_NOOP) {
+ new = mpol_new(mode, mode_flags, nmask);
+ if (IS_ERR(new))
+ return PTR_ERR(new);

- if (flags & MPOL_MF_LAZY)
- new->flags |= MPOL_F_MOF;
+ if (flags & MPOL_MF_LAZY)
+ new->flags |= MPOL_F_MOF;

+ }
/*
* If we are using the default policy then operation
* on discontinuous address spaces is okay after all
@@ -1105,56 +1107,57 @@ static long do_mbind(unsigned long start, unsigned long len,
nmask ? nodes_addr(*nmask)[0] : -1);

if (flags & (MPOL_MF_MOVE | MPOL_MF_MOVE_ALL)) {
-
err = migrate_prep();
if (err)
goto mpol_out;
}
- {
+
+ down_write(&mm->mmap_sem);
+
+ if (mode != MPOL_NOOP) {
NODEMASK_SCRATCH(scratch);
+ err = -ENOMEM;
if (scratch) {
- down_write(&mm->mmap_sem);
task_lock(current);
err = mpol_set_nodemask(new, nmask, scratch);
task_unlock(current);
- if (err)
- up_write(&mm->mmap_sem);
- } else
- err = -ENOMEM;
+ }
NODEMASK_SCRATCH_FREE(scratch);
+ if (err)
+ goto mpol_out_unlock;
}
- if (err)
- goto mpol_out;

vma = check_range(mm, start, end, nmask,
flags | MPOL_MF_INVERT, &pagelist);

err = PTR_ERR(vma); /* maybe ... */
- if (!IS_ERR(vma) && mode != MPOL_NOOP)
+ if (IS_ERR(vma))
+ goto mpol_out_unlock;
+
+ if (mode != MPOL_NOOP) {
err = mbind_range(mm, start, end, new);
+ if (err)
+ goto mpol_out_unlock;
+ }

- if (!err) {
- int nr_failed = 0;
-
- if (!list_empty(&pagelist)) {
- if (flags & MPOL_MF_LAZY)
- nr_failed = migrate_pages_unmap_only(&pagelist);
- else {
- nr_failed = migrate_pages(&pagelist, new_vma_page,
- (unsigned long)vma,
- false, true);
- }
- if (nr_failed)
- putback_lru_pages(&pagelist);
+ if (!list_empty(&pagelist)) {
+ if (flags & MPOL_MF_LAZY)
+ nr_failed = migrate_pages_unmap_only(&pagelist);
+ else {
+ nr_failed = migrate_pages(&pagelist, new_vma_page,
+ (unsigned long)vma,
+ false, true);
}
+ }

- if (nr_failed && (flags & MPOL_MF_STRICT))
- err = -EIO;
- } else
- putback_lru_pages(&pagelist);
+ if (nr_failed && (flags & MPOL_MF_STRICT))
+ err = -EIO;
+
+ putback_lru_pages(&pagelist);

+mpol_out_unlock:
up_write(&mm->mmap_sem);
- mpol_out:
+mpol_out:
mpol_put(new);
return err;
}
--
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/