mm: page_alloc: default node-ordering on 64-bit NUMA, zone-ordering on 32-bit
[firefly-linux-kernel-4.4.55.git] / mm / mempolicy.c
index ad27bbc757bf04965bd8e1e777c667f83b385a50..008fb32936ebfbc99ff737ff66ff177243c8a930 100644 (file)
@@ -123,7 +123,7 @@ static struct mempolicy default_policy = {
 
 static struct mempolicy preferred_node_policy[MAX_NUMNODES];
 
-static struct mempolicy *get_task_policy(struct task_struct *p)
+struct mempolicy *get_task_policy(struct task_struct *p)
 {
        struct mempolicy *pol = p->mempolicy;
        int node;
@@ -802,7 +802,6 @@ static long do_set_mempolicy(unsigned short mode, unsigned short flags,
                             nodemask_t *nodes)
 {
        struct mempolicy *new, *old;
-       struct mm_struct *mm = current->mm;
        NODEMASK_SCRATCH(scratch);
        int ret;
 
@@ -814,20 +813,11 @@ static long do_set_mempolicy(unsigned short mode, unsigned short flags,
                ret = PTR_ERR(new);
                goto out;
        }
-       /*
-        * prevent changing our mempolicy while show_numa_maps()
-        * is using it.
-        * Note:  do_set_mempolicy() can be called at init time
-        * with no 'mm'.
-        */
-       if (mm)
-               down_write(&mm->mmap_sem);
+
        task_lock(current);
        ret = mpol_set_nodemask(new, nodes, scratch);
        if (ret) {
                task_unlock(current);
-               if (mm)
-                       up_write(&mm->mmap_sem);
                mpol_put(new);
                goto out;
        }
@@ -837,9 +827,6 @@ static long do_set_mempolicy(unsigned short mode, unsigned short flags,
            nodes_weight(new->v.nodes))
                current->il_next = first_node(new->v.nodes);
        task_unlock(current);
-       if (mm)
-               up_write(&mm->mmap_sem);
-
        mpol_put(old);
        ret = 0;
 out:
@@ -1603,23 +1590,8 @@ COMPAT_SYSCALL_DEFINE6(mbind, compat_ulong_t, start, compat_ulong_t, len,
 
 #endif
 
-/*
- * get_vma_policy(@task, @vma, @addr)
- * @task: task for fallback if vma policy == default
- * @vma: virtual memory area whose policy is sought
- * @addr: address in @vma for shared policy lookup
- *
- * Returns effective policy for a VMA at specified address.
- * Falls back to @task or system default policy, as necessary.
- * Current or other task's task mempolicy and non-shared vma policies must be
- * protected by task_lock(task) by the caller.
- * Shared policies [those marked as MPOL_F_SHARED] require an extra reference
- * count--added by the get_policy() vm_op, as appropriate--to protect against
- * freeing by another task.  It is the caller's responsibility to free the
- * extra reference for shared policies.
- */
-struct mempolicy *get_vma_policy(struct task_struct *task,
-               struct vm_area_struct *vma, unsigned long addr)
+struct mempolicy *__get_vma_policy(struct vm_area_struct *vma,
+                                               unsigned long addr)
 {
        struct mempolicy *pol = NULL;
 
@@ -1640,8 +1612,28 @@ struct mempolicy *get_vma_policy(struct task_struct *task,
                }
        }
 
+       return pol;
+}
+
+/*
+ * get_vma_policy(@vma, @addr)
+ * @vma: virtual memory area whose policy is sought
+ * @addr: address in @vma for shared policy lookup
+ *
+ * Returns effective policy for a VMA at specified address.
+ * Falls back to current->mempolicy or system default policy, as necessary.
+ * Shared policies [those marked as MPOL_F_SHARED] require an extra reference
+ * count--added by the get_policy() vm_op, as appropriate--to protect against
+ * 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 vm_area_struct *vma,
+                                               unsigned long addr)
+{
+       struct mempolicy *pol = __get_vma_policy(vma, addr);
+
        if (!pol)
-               pol = get_task_policy(task);
+               pol = get_task_policy(current);
 
        return pol;
 }
@@ -1869,7 +1861,7 @@ struct zonelist *huge_zonelist(struct vm_area_struct *vma, unsigned long addr,
 {
        struct zonelist *zl;
 
-       *mpol = get_vma_policy(current, vma, addr);
+       *mpol = get_vma_policy(vma, addr);
        *nodemask = NULL;       /* assume !MPOL_BIND */
 
        if (unlikely((*mpol)->mode == MPOL_INTERLEAVE)) {
@@ -2024,7 +2016,7 @@ alloc_pages_vma(gfp_t gfp, int order, struct vm_area_struct *vma,
        unsigned int cpuset_mems_cookie;
 
 retry_cpuset:
-       pol = get_vma_policy(current, vma, addr);
+       pol = get_vma_policy(vma, addr);
        cpuset_mems_cookie = read_mems_allowed_begin();
 
        if (unlikely(pol->mode == MPOL_INTERLEAVE)) {
@@ -2290,7 +2282,7 @@ int mpol_misplaced(struct page *page, struct vm_area_struct *vma, unsigned long
 
        BUG_ON(!vma);
 
-       pol = get_vma_policy(current, vma, addr);
+       pol = get_vma_policy(vma, addr);
        if (!(pol->flags & MPOL_F_MOF))
                goto out;