]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - mm/mempolicy.c
regmap: mmio: convert some error returns to BUG()
[linux-2.6.git] / mm / mempolicy.c
index d49956d302599fc66c9bcfd1717799100ec8cb9c..cfb6c8678754fdb3baf411e2331e87ea64766fb2 100644 (file)
 #include <linux/sched.h>
 #include <linux/nodemask.h>
 #include <linux/cpuset.h>
-#include <linux/gfp.h>
 #include <linux/slab.h>
 #include <linux/string.h>
-#include <linux/module.h>
+#include <linux/export.h>
 #include <linux/nsproxy.h>
 #include <linux/interrupt.h>
 #include <linux/init.h>
 #include <linux/seq_file.h>
 #include <linux/proc_fs.h>
 #include <linux/migrate.h>
+#include <linux/ksm.h>
 #include <linux/rmap.h>
 #include <linux/security.h>
 #include <linux/syscalls.h>
 #include <linux/ctype.h>
+#include <linux/mm_inline.h>
 
 #include <asm/tlbflush.h>
 #include <asm/uaccess.h>
+#include <linux/random.h>
 
 #include "internal.h"
 
 /* Internal flags */
 #define MPOL_MF_DISCONTIG_OK (MPOL_MF_INTERNAL << 0)   /* Skip checks for continuous vmas */
 #define MPOL_MF_INVERT (MPOL_MF_INTERNAL << 1)         /* Invert check for nodemask */
-#define MPOL_MF_STATS (MPOL_MF_INTERNAL << 2)          /* Gather statistics */
 
 static struct kmem_cache *policy_cache;
 static struct kmem_cache *sn_cache;
@@ -110,7 +111,7 @@ enum zone_type policy_zone = 0;
 /*
  * run-time system-wide default policy => local allocation
  */
-struct mempolicy default_policy = {
+static struct mempolicy default_policy = {
        .refcnt = ATOMIC_INIT(1), /* never free it */
        .mode = MPOL_PREFERRED,
        .flags = MPOL_F_LOCAL,
@@ -118,7 +119,22 @@ struct mempolicy default_policy = {
 
 static const struct mempolicy_operations {
        int (*create)(struct mempolicy *pol, const nodemask_t *nodes);
-       void (*rebind)(struct mempolicy *pol, const nodemask_t *nodes);
+       /*
+        * If read-side task has no lock to protect task->mempolicy, write-side
+        * task will rebind the task->mempolicy by two step. The first step is
+        * setting all the newly nodes, and the second step is cleaning all the
+        * disallowed nodes. In this way, we can avoid finding no node to alloc
+        * page.
+        * If we have a lock to protect task->mempolicy in read-side, we do
+        * rebind directly.
+        *
+        * step:
+        *      MPOL_REBIND_ONCE - do rebind work at once
+        *      MPOL_REBIND_STEP1 - set all the newly nodes
+        *      MPOL_REBIND_STEP2 - clean all the disallowed nodes
+        */
+       void (*rebind)(struct mempolicy *pol, const nodemask_t *nodes,
+                       enum mpol_rebind_step step);
 } mpol_ops[MPOL_MAX];
 
 /* Check that the nodemask contains at least one populated zone */
@@ -126,9 +142,6 @@ static int is_valid_nodemask(const nodemask_t *nodemask)
 {
        int nd, k;
 
-       /* Check that there is something useful in this mask */
-       k = policy_zone;
-
        for_each_node_mask(nd, *nodemask) {
                struct zone *z;
 
@@ -144,7 +157,7 @@ static int is_valid_nodemask(const nodemask_t *nodemask)
 
 static inline int mpol_store_user_nodemask(const struct mempolicy *pol)
 {
-       return pol->flags & (MPOL_F_STATIC_NODES | MPOL_F_RELATIVE_NODES);
+       return pol->flags & MPOL_MODE_FLAGS;
 }
 
 static void mpol_relative_nodemask(nodemask_t *ret, const nodemask_t *orig,
@@ -276,12 +289,19 @@ void __mpol_put(struct mempolicy *p)
        kmem_cache_free(policy_cache, p);
 }
 
-static void mpol_rebind_default(struct mempolicy *pol, const nodemask_t *nodes)
+static void mpol_rebind_default(struct mempolicy *pol, const nodemask_t *nodes,
+                               enum mpol_rebind_step step)
 {
 }
 
-static void mpol_rebind_nodemask(struct mempolicy *pol,
-                                const nodemask_t *nodes)
+/*
+ * step:
+ *     MPOL_REBIND_ONCE  - do rebind work at once
+ *     MPOL_REBIND_STEP1 - set all the newly nodes
+ *     MPOL_REBIND_STEP2 - clean all the disallowed nodes
+ */
+static void mpol_rebind_nodemask(struct mempolicy *pol, const nodemask_t *nodes,
+                                enum mpol_rebind_step step)
 {
        nodemask_t tmp;
 
@@ -290,12 +310,31 @@ static void mpol_rebind_nodemask(struct mempolicy *pol,
        else if (pol->flags & MPOL_F_RELATIVE_NODES)
                mpol_relative_nodemask(&tmp, &pol->w.user_nodemask, nodes);
        else {
-               nodes_remap(tmp, pol->v.nodes, pol->w.cpuset_mems_allowed,
-                           *nodes);
-               pol->w.cpuset_mems_allowed = *nodes;
+               /*
+                * if step == 1, we use ->w.cpuset_mems_allowed to cache the
+                * result
+                */
+               if (step == MPOL_REBIND_ONCE || step == MPOL_REBIND_STEP1) {
+                       nodes_remap(tmp, pol->v.nodes,
+                                       pol->w.cpuset_mems_allowed, *nodes);
+                       pol->w.cpuset_mems_allowed = step ? tmp : *nodes;
+               } else if (step == MPOL_REBIND_STEP2) {
+                       tmp = pol->w.cpuset_mems_allowed;
+                       pol->w.cpuset_mems_allowed = *nodes;
+               } else
+                       BUG();
        }
 
-       pol->v.nodes = tmp;
+       if (nodes_empty(tmp))
+               tmp = *nodes;
+
+       if (step == MPOL_REBIND_STEP1)
+               nodes_or(pol->v.nodes, pol->v.nodes, tmp);
+       else if (step == MPOL_REBIND_ONCE || step == MPOL_REBIND_STEP2)
+               pol->v.nodes = tmp;
+       else
+               BUG();
+
        if (!node_isset(current->il_next, tmp)) {
                current->il_next = next_node(current->il_next, tmp);
                if (current->il_next >= MAX_NUMNODES)
@@ -306,7 +345,8 @@ static void mpol_rebind_nodemask(struct mempolicy *pol,
 }
 
 static void mpol_rebind_preferred(struct mempolicy *pol,
-                                 const nodemask_t *nodes)
+                                 const nodemask_t *nodes,
+                                 enum mpol_rebind_step step)
 {
        nodemask_t tmp;
 
@@ -329,16 +369,45 @@ static void mpol_rebind_preferred(struct mempolicy *pol,
        }
 }
 
-/* Migrate a policy to a different set of nodes */
-static void mpol_rebind_policy(struct mempolicy *pol,
-                              const nodemask_t *newmask)
+/*
+ * mpol_rebind_policy - Migrate a policy to a different set of nodes
+ *
+ * If read-side task has no lock to protect task->mempolicy, write-side
+ * task will rebind the task->mempolicy by two step. The first step is
+ * setting all the newly nodes, and the second step is cleaning all the
+ * disallowed nodes. In this way, we can avoid finding no node to alloc
+ * page.
+ * If we have a lock to protect task->mempolicy in read-side, we do
+ * rebind directly.
+ *
+ * step:
+ *     MPOL_REBIND_ONCE  - do rebind work at once
+ *     MPOL_REBIND_STEP1 - set all the newly nodes
+ *     MPOL_REBIND_STEP2 - clean all the disallowed nodes
+ */
+static void mpol_rebind_policy(struct mempolicy *pol, const nodemask_t *newmask,
+                               enum mpol_rebind_step step)
 {
        if (!pol)
                return;
-       if (!mpol_store_user_nodemask(pol) &&
+       if (!mpol_store_user_nodemask(pol) && step == 0 &&
            nodes_equal(pol->w.cpuset_mems_allowed, *newmask))
                return;
-       mpol_ops[pol->mode].rebind(pol, newmask);
+
+       if (step == MPOL_REBIND_STEP1 && (pol->flags & MPOL_F_REBINDING))
+               return;
+
+       if (step == MPOL_REBIND_STEP2 && !(pol->flags & MPOL_F_REBINDING))
+               BUG();
+
+       if (step == MPOL_REBIND_STEP1)
+               pol->flags |= MPOL_F_REBINDING;
+       else if (step == MPOL_REBIND_STEP2)
+               pol->flags &= ~MPOL_F_REBINDING;
+       else if (step >= MPOL_REBIND_NSTEP)
+               BUG();
+
+       mpol_ops[pol->mode].rebind(pol, newmask, step);
 }
 
 /*
@@ -348,9 +417,10 @@ static void mpol_rebind_policy(struct mempolicy *pol,
  * Called with task's alloc_lock held.
  */
 
-void mpol_rebind_task(struct task_struct *tsk, const nodemask_t *new)
+void mpol_rebind_task(struct task_struct *tsk, const nodemask_t *new,
+                       enum mpol_rebind_step step)
 {
-       mpol_rebind_policy(tsk->mempolicy, new);
+       mpol_rebind_policy(tsk->mempolicy, new, step);
 }
 
 /*
@@ -365,7 +435,7 @@ void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new)
 
        down_write(&mm->mmap_sem);
        for (vma = mm->mmap; vma; vma = vma->vm_next)
-               mpol_rebind_policy(vma->vm_policy, new);
+               mpol_rebind_policy(vma->vm_policy, new, MPOL_REBIND_ONCE);
        up_write(&mm->mmap_sem);
 }
 
@@ -387,7 +457,6 @@ static const struct mempolicy_operations mpol_ops[MPOL_MAX] = {
        },
 };
 
-static void gather_stats(struct page *, void *, int pte_dirty);
 static void migrate_page_add(struct page *page, struct list_head *pagelist,
                                unsigned long flags);
 
@@ -412,25 +481,17 @@ static int check_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
                if (!page)
                        continue;
                /*
-                * The check for PageReserved here is important to avoid
-                * handling zero pages and other pages that may have been
-                * marked special by the system.
-                *
-                * If the PageReserved would not be checked here then f.e.
-                * the location of the zero page could have an influence
-                * on MPOL_MF_STRICT, zero pages would be counted for
-                * the per node stats, and there would be useless attempts
-                * to put zero pages on the migration list.
+                * vm_normal_page() filters out zero pages, but there might
+                * still be PageReserved pages to skip, perhaps in a VDSO.
+                * And we cannot move PageKsm pages sensibly or safely yet.
                 */
-               if (PageReserved(page))
+               if (PageReserved(page) || PageKsm(page))
                        continue;
                nid = page_to_nid(page);
                if (node_isset(nid, *nodes) == !!(flags & MPOL_MF_INVERT))
                        continue;
 
-               if (flags & MPOL_MF_STATS)
-                       gather_stats(page, private, pte_dirty(*pte));
-               else if (flags & (MPOL_MF_MOVE | MPOL_MF_MOVE_ALL))
+               if (flags & (MPOL_MF_MOVE | MPOL_MF_MOVE_ALL))
                        migrate_page_add(page, private, flags);
                else
                        break;
@@ -450,7 +511,8 @@ static inline int check_pmd_range(struct vm_area_struct *vma, pud_t *pud,
        pmd = pmd_offset(pud, addr);
        do {
                next = pmd_addr_end(addr, end);
-               if (pmd_none_or_clear_bad(pmd))
+               split_huge_page_pmd(vma->vm_mm, pmd);
+               if (pmd_none_or_trans_huge_or_clear_bad(pmd))
                        continue;
                if (check_pte_range(vma, pmd, addr, next, nodes,
                                    flags, private))
@@ -567,24 +629,59 @@ static int policy_vma(struct vm_area_struct *vma, struct mempolicy *new)
 }
 
 /* Step 2: apply policy to a range and do splits. */
-static int mbind_range(struct vm_area_struct *vma, unsigned long start,
-                      unsigned long end, struct mempolicy *new)
+static int mbind_range(struct mm_struct *mm, unsigned long start,
+                      unsigned long end, struct mempolicy *new_pol)
 {
        struct vm_area_struct *next;
-       int err;
+       struct vm_area_struct *prev;
+       struct vm_area_struct *vma;
+       int err = 0;
+       pgoff_t pgoff;
+       unsigned long vmstart;
+       unsigned long vmend;
 
-       err = 0;
-       for (; vma && vma->vm_start < end; vma = next) {
+       vma = find_vma(mm, start);
+       if (!vma || vma->vm_start > start)
+               return -EFAULT;
+
+       prev = vma->vm_prev;
+       if (start > vma->vm_start)
+               prev = vma;
+
+       for (; vma && vma->vm_start < end; prev = vma, vma = next) {
                next = vma->vm_next;
-               if (vma->vm_start < start)
-                       err = split_vma(vma->vm_mm, vma, start, 1);
-               if (!err && vma->vm_end > end)
-                       err = split_vma(vma->vm_mm, vma, end, 0);
-               if (!err)
-                       err = policy_vma(vma, new);
+               vmstart = max(start, vma->vm_start);
+               vmend   = min(end, vma->vm_end);
+
+               if (mpol_equal(vma_policy(vma), new_pol))
+                       continue;
+
+               pgoff = vma->vm_pgoff +
+                       ((vmstart - vma->vm_start) >> PAGE_SHIFT);
+               prev = vma_merge(mm, prev, vmstart, vmend, vma->vm_flags,
+                                 vma->anon_vma, vma->vm_file, pgoff,
+                                 new_pol);
+               if (prev) {
+                       vma = prev;
+                       next = vma->vm_next;
+                       continue;
+               }
+               if (vma->vm_start != vmstart) {
+                       err = split_vma(vma->vm_mm, vma, vmstart, 1);
+                       if (err)
+                               goto out;
+               }
+               if (vma->vm_end != vmend) {
+                       err = split_vma(vma->vm_mm, vma, vmend, 0);
+                       if (err)
+                               goto out;
+               }
+               err = policy_vma(vma, new_pol);
                if (err)
-                       break;
+                       goto out;
        }
+
+ out:
        return err;
 }
 
@@ -784,9 +881,13 @@ static long do_get_mempolicy(int *policy, nodemask_t *nmask,
 
        err = 0;
        if (nmask) {
-               task_lock(current);
-               get_policy_nodemask(pol, nmask);
-               task_unlock(current);
+               if (mpol_store_user_nodemask(pol)) {
+                       *nmask = pol->w.user_nodemask;
+               } else {
+                       task_lock(current);
+                       get_policy_nodemask(pol, nmask);
+                       task_unlock(current);
+               }
        }
 
  out:
@@ -809,6 +910,8 @@ static void migrate_page_add(struct page *page, struct list_head *pagelist,
        if ((flags & MPOL_MF_MOVE_ALL) || page_mapcount(page) == 1) {
                if (!isolate_lru_page(page)) {
                        list_add_tail(&page->lru, pagelist);
+                       inc_zone_page_state(page, NR_ISOLATED_ANON +
+                                           page_is_file_cache(page));
                }
        }
 }
@@ -828,15 +931,22 @@ static int migrate_to_node(struct mm_struct *mm, int source, int dest,
        nodemask_t nmask;
        LIST_HEAD(pagelist);
        int err = 0;
+       struct vm_area_struct *vma;
 
        nodes_clear(nmask);
        node_set(source, nmask);
 
-       check_range(mm, mm->mmap->vm_start, TASK_SIZE, &nmask,
+       vma = check_range(mm, mm->mmap->vm_start, mm->task_size, &nmask,
                        flags | MPOL_MF_DISCONTIG_OK, &pagelist);
+       if (IS_ERR(vma))
+               return PTR_ERR(vma);
 
-       if (!list_empty(&pagelist))
-               err = migrate_pages(&pagelist, new_node_page, dest);
+       if (!list_empty(&pagelist)) {
+               err = migrate_pages(&pagelist, new_node_page, dest,
+                                                       false, MIGRATE_SYNC);
+               if (err)
+                       putback_lru_pages(&pagelist);
+       }
 
        return err;
 }
@@ -864,36 +974,36 @@ int do_migrate_pages(struct mm_struct *mm,
        if (err)
                goto out;
 
-/*
- * Find a 'source' bit set in 'tmp' whose corresponding 'dest'
- * bit in 'to' is not also set in 'tmp'.  Clear the found 'source'
- * bit in 'tmp', and return that <source, dest> pair for migration.
- * The pair of nodemasks 'to' and 'from' define the map.
- *
- * If no pair of bits is found that way, fallback to picking some
- * pair of 'source' and 'dest' bits that are not the same.  If the
- * 'source' and 'dest' bits are the same, this represents a node
- * that will be migrating to itself, so no pages need move.
- *
- * If no bits are left in 'tmp', or if all remaining bits left
- * in 'tmp' correspond to the same bit in 'to', return false
- * (nothing left to migrate).
- *
- * This lets us pick a pair of nodes to migrate between, such that
- * if possible the dest node is not already occupied by some other
- * source node, minimizing the risk of overloading the memory on a
- * node that would happen if we migrated incoming memory to a node
- * before migrating outgoing memory source that same node.
- *
- * A single scan of tmp is sufficient.  As we go, we remember the
- * most recent <s, d> pair that moved (s != d).  If we find a pair
- * that not only moved, but what's better, moved to an empty slot
- * (d is not set in tmp), then we break out then, with that pair.
* Otherwise when we finish scannng from_tmp, we at least have the
- * most recent <s, d> pair that moved.  If we get all the way through
- * the scan of tmp without finding any node that moved, much less
- * moved to an empty node, then there is nothing left worth migrating.
- */
+       /*
       * Find a 'source' bit set in 'tmp' whose corresponding 'dest'
       * bit in 'to' is not also set in 'tmp'.  Clear the found 'source'
       * bit in 'tmp', and return that <source, dest> pair for migration.
       * The pair of nodemasks 'to' and 'from' define the map.
       *
       * If no pair of bits is found that way, fallback to picking some
       * pair of 'source' and 'dest' bits that are not the same.  If the
       * 'source' and 'dest' bits are the same, this represents a node
       * that will be migrating to itself, so no pages need move.
       *
       * If no bits are left in 'tmp', or if all remaining bits left
       * in 'tmp' correspond to the same bit in 'to', return false
       * (nothing left to migrate).
       *
       * This lets us pick a pair of nodes to migrate between, such that
       * if possible the dest node is not already occupied by some other
       * source node, minimizing the risk of overloading the memory on a
       * node that would happen if we migrated incoming memory to a node
       * before migrating outgoing memory source that same node.
       *
       * A single scan of tmp is sufficient.  As we go, we remember the
       * most recent <s, d> pair that moved (s != d).  If we find a pair
       * that not only moved, but what's better, moved to an empty slot
       * (d is not set in tmp), then we break out then, with that pair.
       * Otherwise when we finish scanning from_tmp, we at least have the
       * most recent <s, d> pair that moved.  If we get all the way through
       * the scan of tmp without finding any node that moved, much less
       * moved to an empty node, then there is nothing left worth migrating.
       */
 
        tmp = *from_nodes;
        while (!nodes_empty(tmp)) {
@@ -1024,7 +1134,7 @@ static long do_mbind(unsigned long start, unsigned long len,
 
                err = migrate_prep();
                if (err)
-                       return err;
+                       goto mpol_out;
        }
        {
                NODEMASK_SCRATCH(scratch);
@@ -1039,10 +1149,9 @@ static long do_mbind(unsigned long start, unsigned long len,
                        err = -ENOMEM;
                NODEMASK_SCRATCH_FREE(scratch);
        }
-       if (err) {
-               mpol_put(new);
-               return err;
-       }
+       if (err)
+               goto mpol_out;
+
        vma = check_range(mm, start, end, nmask,
                          flags | MPOL_MF_INVERT, &pagelist);
 
@@ -1050,11 +1159,15 @@ static long do_mbind(unsigned long start, unsigned long len,
        if (!IS_ERR(vma)) {
                int nr_failed = 0;
 
-               err = mbind_range(vma, start, end, new);
+               err = mbind_range(mm, start, end, new);
 
-               if (!list_empty(&pagelist))
+               if (!list_empty(&pagelist)) {
                        nr_failed = migrate_pages(&pagelist, new_vma_page,
-                                               (unsigned long)vma);
+                                               (unsigned long)vma,
+                                               false, true);
+                       if (nr_failed)
+                               putback_lru_pages(&pagelist);
+               }
 
                if (!err && nr_failed && (flags & MPOL_MF_STRICT))
                        err = -EIO;
@@ -1062,6 +1175,7 @@ static long do_mbind(unsigned long start, unsigned long len,
                putback_lru_pages(&pagelist);
 
        up_write(&mm->mmap_sem);
+ mpol_out:
        mpol_put(new);
        return err;
 }
@@ -1179,33 +1293,39 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
                const unsigned long __user *, new_nodes)
 {
        const struct cred *cred = current_cred(), *tcred;
-       struct mm_struct *mm;
+       struct mm_struct *mm = NULL;
        struct task_struct *task;
-       nodemask_t old;
-       nodemask_t new;
        nodemask_t task_nodes;
        int err;
+       nodemask_t *old;
+       nodemask_t *new;
+       NODEMASK_SCRATCH(scratch);
+
+       if (!scratch)
+               return -ENOMEM;
 
-       err = get_nodes(&old, old_nodes, maxnode);
+       old = &scratch->mask1;
+       new = &scratch->mask2;
+
+       err = get_nodes(old, old_nodes, maxnode);
        if (err)
-               return err;
+               goto out;
 
-       err = get_nodes(&new, new_nodes, maxnode);
+       err = get_nodes(new, new_nodes, maxnode);
        if (err)
-               return err;
+               goto out;
 
        /* Find the mm_struct */
-       read_lock(&tasklist_lock);
+       rcu_read_lock();
        task = pid ? find_task_by_vpid(pid) : current;
        if (!task) {
-               read_unlock(&tasklist_lock);
-               return -ESRCH;
+               rcu_read_unlock();
+               err = -ESRCH;
+               goto out;
        }
-       mm = get_task_mm(task);
-       read_unlock(&tasklist_lock);
+       get_task_struct(task);
 
-       if (!mm)
-               return -EINVAL;
+       err = -EINVAL;
 
        /*
         * Check if this process has the right to modify the specified
@@ -1213,38 +1333,50 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
         * capabilities, superuser privileges or the same
         * userid as the target process.
         */
-       rcu_read_lock();
        tcred = __task_cred(task);
        if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
            cred->uid  != tcred->suid && cred->uid  != tcred->uid &&
            !capable(CAP_SYS_NICE)) {
                rcu_read_unlock();
                err = -EPERM;
-               goto out;
+               goto out_put;
        }
        rcu_read_unlock();
 
        task_nodes = cpuset_mems_allowed(task);
        /* Is the user allowed to access the target nodes? */
-       if (!nodes_subset(new, task_nodes) && !capable(CAP_SYS_NICE)) {
+       if (!nodes_subset(*new, task_nodes) && !capable(CAP_SYS_NICE)) {
                err = -EPERM;
-               goto out;
+               goto out_put;
        }
 
-       if (!nodes_subset(new, node_states[N_HIGH_MEMORY])) {
+       if (!nodes_subset(*new, node_states[N_HIGH_MEMORY])) {
                err = -EINVAL;
-               goto out;
+               goto out_put;
        }
 
        err = security_task_movememory(task);
        if (err)
-               goto out;
+               goto out_put;
+
+       mm = get_task_mm(task);
+       put_task_struct(task);
+       if (mm)
+               err = do_migrate_pages(mm, old, new,
+                       capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
+       else
+               err = -EINVAL;
 
-       err = do_migrate_pages(mm, &old, &new,
-               capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
-out:
        mmput(mm);
+out:
+       NODEMASK_SCRATCH_FREE(scratch);
+
        return err;
+
+out_put:
+       put_task_struct(task);
+       goto out;
+
 }
 
 
@@ -1295,7 +1427,9 @@ asmlinkage long compat_sys_get_mempolicy(int __user *policy,
        err = sys_get_mempolicy(policy, nm, nr_bits+1, addr, flags);
 
        if (!err && nmask) {
-               err = copy_from_user(bm, nm, alloc_size);
+               unsigned long copy_size;
+               copy_size = min_t(unsigned long, sizeof(bm), alloc_size);
+               err = copy_from_user(bm, nm, copy_size);
                /* ensure entire bitmap is zeroed */
                err |= clear_user(nmask, ALIGN(maxnode-1, 8) / 8);
                err |= compat_put_bitmap(nmask, bm, nr_bits);
@@ -1369,7 +1503,7 @@ asmlinkage long compat_sys_mbind(compat_ulong_t start, compat_ulong_t len,
  * freeing by another task.  It is the caller's responsibility to free the
  * extra reference for shared policies.
  */
-static struct mempolicy *get_vma_policy(struct task_struct *task,
+struct mempolicy *get_vma_policy(struct task_struct *task,
                struct vm_area_struct *vma, unsigned long addr)
 {
        struct mempolicy *pol = task->mempolicy;
@@ -1404,10 +1538,9 @@ static nodemask_t *policy_nodemask(gfp_t gfp, struct mempolicy *policy)
 }
 
 /* Return a zonelist indicated by gfp for node representing a mempolicy */
-static struct zonelist *policy_zonelist(gfp_t gfp, struct mempolicy *policy)
+static struct zonelist *policy_zonelist(gfp_t gfp, struct mempolicy *policy,
+       int nd)
 {
-       int nd = numa_node_id();
-
        switch (policy->mode) {
        case MPOL_PREFERRED:
                if (!(policy->flags & MPOL_F_LOCAL))
@@ -1417,15 +1550,13 @@ static struct zonelist *policy_zonelist(gfp_t gfp, struct mempolicy *policy)
                /*
                 * Normally, MPOL_BIND allocations are node-local within the
                 * allowed nodemask.  However, if __GFP_THISNODE is set and the
-                * current node is part of the mask, we use the zonelist for
+                * current node isn't part of the mask, we use the zonelist for
                 * the first node in the mask instead.
                 */
                if (unlikely(gfp & __GFP_THISNODE) &&
                                unlikely(!node_isset(nd, policy->v.nodes)))
                        nd = first_node(policy->v.nodes);
                break;
-       case MPOL_INTERLEAVE: /* should not happen */
-               break;
        default:
                BUG();
        }
@@ -1482,7 +1613,7 @@ unsigned slab_node(struct mempolicy *policy)
                (void)first_zones_zonelist(zonelist, highest_zoneidx,
                                                        &policy->v.nodes,
                                                        &zone);
-               return zone->node;
+               return zone ? zone->node : numa_node_id();
        }
 
        default:
@@ -1532,6 +1663,21 @@ static inline unsigned interleave_nid(struct mempolicy *pol,
                return interleave_nodes(pol);
 }
 
+/*
+ * Return the bit number of a random bit set in the nodemask.
+ * (returns -1 if nodemask is empty)
+ */
+int node_random(const nodemask_t *maskp)
+{
+       int w, bit = -1;
+
+       w = nodes_weight(*maskp);
+       if (w)
+               bit = bitmap_ord_to_pos(maskp->bits,
+                       get_random_int() % w, MAX_NUMNODES);
+       return bit;
+}
+
 #ifdef CONFIG_HUGETLBFS
 /*
  * huge_zonelist(@vma, @addr, @gfp_flags, @mpol)
@@ -1545,6 +1691,8 @@ static inline unsigned interleave_nid(struct mempolicy *pol,
  * to the struct mempolicy for conditional unref after allocation.
  * If the effective policy is 'BIND, returns a pointer to the mempolicy's
  * @nodemask for filtering the zonelist.
+ *
+ * Must be protected by get_mems_allowed()
  */
 struct zonelist *huge_zonelist(struct vm_area_struct *vma, unsigned long addr,
                                gfp_t gfp_flags, struct mempolicy **mpol,
@@ -1559,14 +1707,107 @@ struct zonelist *huge_zonelist(struct vm_area_struct *vma, unsigned long addr,
                zl = node_zonelist(interleave_nid(*mpol, vma, addr,
                                huge_page_shift(hstate_vma(vma))), gfp_flags);
        } else {
-               zl = policy_zonelist(gfp_flags, *mpol);
+               zl = policy_zonelist(gfp_flags, *mpol, numa_node_id());
                if ((*mpol)->mode == MPOL_BIND)
                        *nodemask = &(*mpol)->v.nodes;
        }
        return zl;
 }
+
+/*
+ * init_nodemask_of_mempolicy
+ *
+ * If the current task's mempolicy is "default" [NULL], return 'false'
+ * to indicate default policy.  Otherwise, extract the policy nodemask
+ * for 'bind' or 'interleave' policy into the argument nodemask, or
+ * initialize the argument nodemask to contain the single node for
+ * 'preferred' or 'local' policy and return 'true' to indicate presence
+ * of non-default mempolicy.
+ *
+ * We don't bother with reference counting the mempolicy [mpol_get/put]
+ * because the current task is examining it's own mempolicy and a task's
+ * mempolicy is only ever changed by the task itself.
+ *
+ * N.B., it is the caller's responsibility to free a returned nodemask.
+ */
+bool init_nodemask_of_mempolicy(nodemask_t *mask)
+{
+       struct mempolicy *mempolicy;
+       int nid;
+
+       if (!(mask && current->mempolicy))
+               return false;
+
+       task_lock(current);
+       mempolicy = current->mempolicy;
+       switch (mempolicy->mode) {
+       case MPOL_PREFERRED:
+               if (mempolicy->flags & MPOL_F_LOCAL)
+                       nid = numa_node_id();
+               else
+                       nid = mempolicy->v.preferred_node;
+               init_nodemask_of_node(mask, nid);
+               break;
+
+       case MPOL_BIND:
+               /* Fall through */
+       case MPOL_INTERLEAVE:
+               *mask =  mempolicy->v.nodes;
+               break;
+
+       default:
+               BUG();
+       }
+       task_unlock(current);
+
+       return true;
+}
 #endif
 
+/*
+ * mempolicy_nodemask_intersects
+ *
+ * If tsk's mempolicy is "default" [NULL], return 'true' to indicate default
+ * policy.  Otherwise, check for intersection between mask and the policy
+ * nodemask for 'bind' or 'interleave' policy.  For 'perferred' or 'local'
+ * policy, always return true since it may allocate elsewhere on fallback.
+ *
+ * Takes task_lock(tsk) to prevent freeing of its mempolicy.
+ */
+bool mempolicy_nodemask_intersects(struct task_struct *tsk,
+                                       const nodemask_t *mask)
+{
+       struct mempolicy *mempolicy;
+       bool ret = true;
+
+       if (!mask)
+               return ret;
+       task_lock(tsk);
+       mempolicy = tsk->mempolicy;
+       if (!mempolicy)
+               goto out;
+
+       switch (mempolicy->mode) {
+       case MPOL_PREFERRED:
+               /*
+                * MPOL_PREFERRED and MPOL_F_LOCAL are only preferred nodes to
+                * allocate from, they may fallback to other nodes when oom.
+                * Thus, it's possible for tsk to have allocated memory from
+                * nodes in mask.
+                */
+               break;
+       case MPOL_BIND:
+       case MPOL_INTERLEAVE:
+               ret = nodes_intersects(mempolicy->v.nodes, *mask);
+               break;
+       default:
+               BUG();
+       }
+out:
+       task_unlock(tsk);
+       return ret;
+}
+
 /* Allocate a page in interleaved policy.
    Own path because it needs to do special accounting. */
 static struct page *alloc_page_interleave(gfp_t gfp, unsigned order,
@@ -1583,7 +1824,7 @@ static struct page *alloc_page_interleave(gfp_t gfp, unsigned order,
 }
 
 /**
- *     alloc_page_vma  - Allocate a page for a VMA.
+ *     alloc_pages_vma - Allocate a page for a VMA.
  *
  *     @gfp:
  *      %GFP_USER    user allocation.
@@ -1592,6 +1833,7 @@ static struct page *alloc_page_interleave(gfp_t gfp, unsigned order,
  *      %GFP_FS      allocation should not call back into a file system.
  *      %GFP_ATOMIC  don't sleep.
  *
+ *     @order:Order of the GFP allocation.
  *     @vma:  Pointer to VMA or NULL if not available.
  *     @addr: Virtual Address of the allocation. Must be inside the VMA.
  *
@@ -1605,32 +1847,49 @@ static struct page *alloc_page_interleave(gfp_t gfp, unsigned order,
  *     Should be called with the mm_sem of the vma hold.
  */
 struct page *
-alloc_page_vma(gfp_t gfp, struct vm_area_struct *vma, unsigned long addr)
+alloc_pages_vma(gfp_t gfp, int order, struct vm_area_struct *vma,
+               unsigned long addr, int node)
 {
-       struct mempolicy *pol = get_vma_policy(current, vma, addr);
+       struct mempolicy *pol;
        struct zonelist *zl;
+       struct page *page;
+       unsigned int cpuset_mems_cookie;
+
+retry_cpuset:
+       pol = get_vma_policy(current, vma, addr);
+       cpuset_mems_cookie = get_mems_allowed();
 
        if (unlikely(pol->mode == MPOL_INTERLEAVE)) {
                unsigned nid;
 
-               nid = interleave_nid(pol, vma, addr, PAGE_SHIFT);
+               nid = interleave_nid(pol, vma, addr, PAGE_SHIFT + order);
                mpol_cond_put(pol);
-               return alloc_page_interleave(gfp, 0, nid);
+               page = alloc_page_interleave(gfp, order, nid);
+               if (unlikely(!put_mems_allowed(cpuset_mems_cookie) && !page))
+                       goto retry_cpuset;
+
+               return page;
        }
-       zl = policy_zonelist(gfp, pol);
+       zl = policy_zonelist(gfp, pol, node);
        if (unlikely(mpol_needs_cond_ref(pol))) {
                /*
                 * slow path: ref counted shared policy
                 */
-               struct page *page =  __alloc_pages_nodemask(gfp, 0,
+               struct page *page =  __alloc_pages_nodemask(gfp, order,
                                                zl, policy_nodemask(gfp, pol));
                __mpol_put(pol);
+               if (unlikely(!put_mems_allowed(cpuset_mems_cookie) && !page))
+                       goto retry_cpuset;
                return page;
        }
        /*
         * fast path:  default or task policy
         */
-       return __alloc_pages_nodemask(gfp, 0, zl, policy_nodemask(gfp, pol));
+       page = __alloc_pages_nodemask(gfp, order, zl,
+                                     policy_nodemask(gfp, pol));
+       if (unlikely(!put_mems_allowed(cpuset_mems_cookie) && !page))
+               goto retry_cpuset;
+       return page;
 }
 
 /**
@@ -1655,18 +1914,30 @@ alloc_page_vma(gfp_t gfp, struct vm_area_struct *vma, unsigned long addr)
 struct page *alloc_pages_current(gfp_t gfp, unsigned order)
 {
        struct mempolicy *pol = current->mempolicy;
+       struct page *page;
+       unsigned int cpuset_mems_cookie;
 
        if (!pol || in_interrupt() || (gfp & __GFP_THISNODE))
                pol = &default_policy;
 
+retry_cpuset:
+       cpuset_mems_cookie = get_mems_allowed();
+
        /*
         * No reference counting needed for current->mempolicy
         * nor system default_policy
         */
        if (pol->mode == MPOL_INTERLEAVE)
-               return alloc_page_interleave(gfp, order, interleave_nodes(pol));
-       return __alloc_pages_nodemask(gfp, order,
-                       policy_zonelist(gfp, pol), policy_nodemask(gfp, pol));
+               page = alloc_page_interleave(gfp, order, interleave_nodes(pol));
+       else
+               page = __alloc_pages_nodemask(gfp, order,
+                               policy_zonelist(gfp, pol, numa_node_id()),
+                               policy_nodemask(gfp, pol));
+
+       if (unlikely(!put_mems_allowed(cpuset_mems_cookie) && !page))
+               goto retry_cpuset;
+
+       return page;
 }
 EXPORT_SYMBOL(alloc_pages_current);
 
@@ -1676,6 +1947,9 @@ EXPORT_SYMBOL(alloc_pages_current);
  * with the mems_allowed returned by cpuset_mems_allowed().  This
  * keeps mempolicies cpuset relative after its cpuset moves.  See
  * further kernel/cpuset.c update_nodemask().
+ *
+ * current's mempolicy may be rebinded by the other task(the task that changes
+ * cpuset's mems), so we needn't do rebind work for current task.
  */
 
 /* Slow path of a mempolicy duplicate */
@@ -1685,11 +1959,24 @@ struct mempolicy *__mpol_dup(struct mempolicy *old)
 
        if (!new)
                return ERR_PTR(-ENOMEM);
+
+       /* task's mempolicy is protected by alloc_lock */
+       if (old == current->mempolicy) {
+               task_lock(current);
+               *new = *old;
+               task_unlock(current);
+       } else
+               *new = *old;
+
+       rcu_read_lock();
        if (current_cpuset_is_being_rebound()) {
                nodemask_t mems = cpuset_mems_allowed(current);
-               mpol_rebind_policy(old, &mems);
+               if (new->flags & MPOL_F_REBINDING)
+                       mpol_rebind_policy(new, &mems, MPOL_REBIND_STEP2);
+               else
+                       mpol_rebind_policy(new, &mems, MPOL_REBIND_ONCE);
        }
-       *new = *old;
+       rcu_read_unlock();
        atomic_set(&new->refcnt, 1);
        return new;
 }
@@ -1716,36 +2003,29 @@ struct mempolicy *__mpol_cond_copy(struct mempolicy *tompol,
        return tompol;
 }
 
-static int mpol_match_intent(const struct mempolicy *a,
-                            const struct mempolicy *b)
-{
-       if (a->flags != b->flags)
-               return 0;
-       if (!mpol_store_user_nodemask(a))
-               return 1;
-       return nodes_equal(a->w.user_nodemask, b->w.user_nodemask);
-}
-
 /* Slow path of a mempolicy comparison */
-int __mpol_equal(struct mempolicy *a, struct mempolicy *b)
+bool __mpol_equal(struct mempolicy *a, struct mempolicy *b)
 {
        if (!a || !b)
-               return 0;
+               return false;
        if (a->mode != b->mode)
-               return 0;
-       if (a->mode != MPOL_DEFAULT && !mpol_match_intent(a, b))
-               return 0;
+               return false;
+       if (a->flags != b->flags)
+               return false;
+       if (mpol_store_user_nodemask(a))
+               if (!nodes_equal(a->w.user_nodemask, b->w.user_nodemask))
+                       return false;
+
        switch (a->mode) {
        case MPOL_BIND:
                /* Fall through */
        case MPOL_INTERLEAVE:
-               return nodes_equal(a->v.nodes, b->v.nodes);
+               return !!nodes_equal(a->v.nodes, b->v.nodes);
        case MPOL_PREFERRED:
-               return a->v.preferred_node == b->v.preferred_node &&
-                       a->flags == b->flags;
+               return a->v.preferred_node == b->v.preferred_node;
        default:
                BUG();
-               return 0;
+               return false;
        }
 }
 
@@ -1927,31 +2207,29 @@ void mpol_shared_policy_init(struct shared_policy *sp, struct mempolicy *mpol)
                NODEMASK_SCRATCH(scratch);
 
                if (!scratch)
-                       return;
+                       goto put_mpol;
                /* contextualize the tmpfs mount point mempolicy */
                new = mpol_new(mpol->mode, mpol->flags, &mpol->w.user_nodemask);
-               if (IS_ERR(new)) {
-                       mpol_put(mpol); /* drop our ref on sb mpol */
-                       NODEMASK_SCRATCH_FREE(scratch);
-                       return;         /* no valid nodemask intersection */
-               }
+               if (IS_ERR(new))
+                       goto free_scratch; /* no valid nodemask intersection */
 
                task_lock(current);
                ret = mpol_set_nodemask(new, &mpol->w.user_nodemask, scratch);
                task_unlock(current);
-               mpol_put(mpol); /* drop our ref on sb mpol */
-               if (ret) {
-                       NODEMASK_SCRATCH_FREE(scratch);
-                       mpol_put(new);
-                       return;
-               }
+               if (ret)
+                       goto put_new;
 
                /* Create pseudo-vma that contains just the policy */
                memset(&pvma, 0, sizeof(struct vm_area_struct));
                pvma.vm_end = TASK_SIZE;        /* policy covers entire file */
                mpol_set_shared_policy(sp, &pvma, new); /* adds ref */
+
+put_new:
                mpol_put(new);                  /* drop initial ref */
+free_scratch:
                NODEMASK_SCRATCH_FREE(scratch);
+put_mpol:
+               mpol_put(mpol); /* drop our incoming ref on sb mpol */
        }
 }
 
@@ -2056,9 +2334,15 @@ void numa_default_policy(void)
  * "local" is pseudo-policy:  MPOL_PREFERRED with MPOL_F_LOCAL flag
  * Used only for mpol_parse_str() and mpol_to_str()
  */
-#define MPOL_LOCAL (MPOL_INTERLEAVE + 1)
-static const char * const policy_types[] =
-       { "default", "prefer", "bind", "interleave", "local" };
+#define MPOL_LOCAL MPOL_MAX
+static const char * const policy_modes[] =
+{
+       [MPOL_DEFAULT]    = "default",
+       [MPOL_PREFERRED]  = "prefer",
+       [MPOL_BIND]       = "bind",
+       [MPOL_INTERLEAVE] = "interleave",
+       [MPOL_LOCAL]      = "local"
+};
 
 
 #ifdef CONFIG_TMPFS
@@ -2083,12 +2367,11 @@ static const char * const policy_types[] =
 int mpol_parse_str(char *str, struct mempolicy **mpol, int no_context)
 {
        struct mempolicy *new = NULL;
-       unsigned short uninitialized_var(mode);
+       unsigned short mode;
        unsigned short uninitialized_var(mode_flags);
        nodemask_t nodes;
        char *nodelist = strchr(str, ':');
        char *flags = strchr(str, '=');
-       int i;
        int err = 1;
 
        if (nodelist) {
@@ -2104,13 +2387,12 @@ int mpol_parse_str(char *str, struct mempolicy **mpol, int no_context)
        if (flags)
                *flags++ = '\0';        /* terminate mode string */
 
-       for (i = 0; i <= MPOL_LOCAL; i++) {
-               if (!strcmp(str, policy_types[i])) {
-                       mode = i;
+       for (mode = 0; mode <= MPOL_LOCAL; mode++) {
+               if (!strcmp(str, policy_modes[mode])) {
                        break;
                }
        }
-       if (i > MPOL_LOCAL)
+       if (mode > MPOL_LOCAL)
                goto out;
 
        switch (mode) {
@@ -2122,8 +2404,8 @@ int mpol_parse_str(char *str, struct mempolicy **mpol, int no_context)
                        char *rest = nodelist;
                        while (isdigit(*rest))
                                rest++;
-                       if (!*rest)
-                               err = 0;
+                       if (*rest)
+                               goto out;
                }
                break;
        case MPOL_INTERLEAVE:
@@ -2132,7 +2414,6 @@ int mpol_parse_str(char *str, struct mempolicy **mpol, int no_context)
                 */
                if (!nodelist)
                        nodes = node_states[N_HIGH_MEMORY];
-               err = 0;
                break;
        case MPOL_LOCAL:
                /*
@@ -2142,11 +2423,19 @@ int mpol_parse_str(char *str, struct mempolicy **mpol, int no_context)
                        goto out;
                mode = MPOL_PREFERRED;
                break;
-
-       /*
-        * case MPOL_BIND:    mpol_new() enforces non-empty nodemask.
-        * case MPOL_DEFAULT: mpol_new() enforces empty nodemask, ignores flags.
-        */
+       case MPOL_DEFAULT:
+               /*
+                * Insist on a empty nodelist
+                */
+               if (!nodelist)
+                       err = 0;
+               goto out;
+       case MPOL_BIND:
+               /*
+                * Insist on a nodelist
+                */
+               if (!nodelist)
+                       goto out;
        }
 
        mode_flags = 0;
@@ -2160,13 +2449,17 @@ int mpol_parse_str(char *str, struct mempolicy **mpol, int no_context)
                else if (!strcmp(flags, "relative"))
                        mode_flags |= MPOL_F_RELATIVE_NODES;
                else
-                       err = 1;
+                       goto out;
        }
 
        new = mpol_new(mode, mode_flags, &nodes);
        if (IS_ERR(new))
-               err = 1;
-       else {
+               goto out;
+
+       if (no_context) {
+               /* save for contextualization */
+               new->w.user_nodemask = nodes;
+       } else {
                int ret;
                NODEMASK_SCRATCH(scratch);
                if (scratch) {
@@ -2177,13 +2470,11 @@ int mpol_parse_str(char *str, struct mempolicy **mpol, int no_context)
                        ret = -ENOMEM;
                NODEMASK_SCRATCH_FREE(scratch);
                if (ret) {
-                       err = 1;
                        mpol_put(new);
-               } else if (no_context) {
-                       /* save for contextualization */
-                       new->w.user_nodemask = nodes;
+                       goto out;
                }
        }
+       err = 0;
 
 out:
        /* Restore string for error message */
@@ -2252,11 +2543,11 @@ int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol, int no_context)
                BUG();
        }
 
-       l = strlen(policy_types[mode]);
+       l = strlen(policy_modes[mode]);
        if (buffer + maxlen < p + l + 1)
                return -ENOSPC;
 
-       strcpy(p, policy_types[mode]);
+       strcpy(p, policy_modes[mode]);
        p += l;
 
        if (flags & MPOL_MODE_FLAGS) {
@@ -2281,159 +2572,3 @@ int mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol, int no_context)
        }
        return p - buffer;
 }
-
-struct numa_maps {
-       unsigned long pages;
-       unsigned long anon;
-       unsigned long active;
-       unsigned long writeback;
-       unsigned long mapcount_max;
-       unsigned long dirty;
-       unsigned long swapcache;
-       unsigned long node[MAX_NUMNODES];
-};
-
-static void gather_stats(struct page *page, void *private, int pte_dirty)
-{
-       struct numa_maps *md = private;
-       int count = page_mapcount(page);
-
-       md->pages++;
-       if (pte_dirty || PageDirty(page))
-               md->dirty++;
-
-       if (PageSwapCache(page))
-               md->swapcache++;
-
-       if (PageActive(page) || PageUnevictable(page))
-               md->active++;
-
-       if (PageWriteback(page))
-               md->writeback++;
-
-       if (PageAnon(page))
-               md->anon++;
-
-       if (count > md->mapcount_max)
-               md->mapcount_max = count;
-
-       md->node[page_to_nid(page)]++;
-}
-
-#ifdef CONFIG_HUGETLB_PAGE
-static void check_huge_range(struct vm_area_struct *vma,
-               unsigned long start, unsigned long end,
-               struct numa_maps *md)
-{
-       unsigned long addr;
-       struct page *page;
-       struct hstate *h = hstate_vma(vma);
-       unsigned long sz = huge_page_size(h);
-
-       for (addr = start; addr < end; addr += sz) {
-               pte_t *ptep = huge_pte_offset(vma->vm_mm,
-                                               addr & huge_page_mask(h));
-               pte_t pte;
-
-               if (!ptep)
-                       continue;
-
-               pte = *ptep;
-               if (pte_none(pte))
-                       continue;
-
-               page = pte_page(pte);
-               if (!page)
-                       continue;
-
-               gather_stats(page, md, pte_dirty(*ptep));
-       }
-}
-#else
-static inline void check_huge_range(struct vm_area_struct *vma,
-               unsigned long start, unsigned long end,
-               struct numa_maps *md)
-{
-}
-#endif
-
-/*
- * Display pages allocated per node and memory policy via /proc.
- */
-int show_numa_map(struct seq_file *m, void *v)
-{
-       struct proc_maps_private *priv = m->private;
-       struct vm_area_struct *vma = v;
-       struct numa_maps *md;
-       struct file *file = vma->vm_file;
-       struct mm_struct *mm = vma->vm_mm;
-       struct mempolicy *pol;
-       int n;
-       char buffer[50];
-
-       if (!mm)
-               return 0;
-
-       md = kzalloc(sizeof(struct numa_maps), GFP_KERNEL);
-       if (!md)
-               return 0;
-
-       pol = get_vma_policy(priv->task, vma, vma->vm_start);
-       mpol_to_str(buffer, sizeof(buffer), pol, 0);
-       mpol_cond_put(pol);
-
-       seq_printf(m, "%08lx %s", vma->vm_start, buffer);
-
-       if (file) {
-               seq_printf(m, " file=");
-               seq_path(m, &file->f_path, "\n\t= ");
-       } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
-               seq_printf(m, " heap");
-       } else if (vma->vm_start <= mm->start_stack &&
-                       vma->vm_end >= mm->start_stack) {
-               seq_printf(m, " stack");
-       }
-
-       if (is_vm_hugetlb_page(vma)) {
-               check_huge_range(vma, vma->vm_start, vma->vm_end, md);
-               seq_printf(m, " huge");
-       } else {
-               check_pgd_range(vma, vma->vm_start, vma->vm_end,
-                       &node_states[N_HIGH_MEMORY], MPOL_MF_STATS, md);
-       }
-
-       if (!md->pages)
-               goto out;
-
-       if (md->anon)
-               seq_printf(m," anon=%lu",md->anon);
-
-       if (md->dirty)
-               seq_printf(m," dirty=%lu",md->dirty);
-
-       if (md->pages != md->anon && md->pages != md->dirty)
-               seq_printf(m, " mapped=%lu", md->pages);
-
-       if (md->mapcount_max > 1)
-               seq_printf(m, " mapmax=%lu", md->mapcount_max);
-
-       if (md->swapcache)
-               seq_printf(m," swapcache=%lu", md->swapcache);
-
-       if (md->active < md->pages && !is_vm_hugetlb_page(vma))
-               seq_printf(m," active=%lu", md->active);
-
-       if (md->writeback)
-               seq_printf(m," writeback=%lu", md->writeback);
-
-       for_each_node_state(n, N_HIGH_MEMORY)
-               if (md->node[n])
-                       seq_printf(m, " N%d=%lu", n, md->node[n]);
-out:
-       seq_putc(m, '\n');
-       kfree(md);
-
-       if (m->count < m->size)
-               m->version = (vma != priv->tail_vma) ? vma->vm_start : 0;
-       return 0;
-}