]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - mm/mempolicy.c
mempolicy: remove the "task" arg of vma_policy_mof() and simplify it
[karo-tx-linux.git] / mm / mempolicy.c
index 8f5330d74f47bded6c1119b49fe34c2ba2573029..ad27bbc757bf04965bd8e1e777c667f83b385a50 100644 (file)
@@ -126,22 +126,20 @@ static struct mempolicy preferred_node_policy[MAX_NUMNODES];
 static struct mempolicy *get_task_policy(struct task_struct *p)
 {
        struct mempolicy *pol = p->mempolicy;
+       int node;
 
-       if (!pol) {
-               int node = numa_node_id();
+       if (pol)
+               return pol;
 
-               if (node != NUMA_NO_NODE) {
-                       pol = &preferred_node_policy[node];
-                       /*
-                        * preferred_node_policy is not initialised early in
-                        * boot
-                        */
-                       if (!pol->mode)
-                               pol = NULL;
-               }
+       node = numa_node_id();
+       if (node != NUMA_NO_NODE) {
+               pol = &preferred_node_policy[node];
+               /* preferred_node_policy is not initialised early in boot */
+               if (pol->mode)
+                       return pol;
        }
 
-       return pol;
+       return &default_policy;
 }
 
 static const struct mempolicy_operations {
@@ -1623,14 +1621,11 @@ COMPAT_SYSCALL_DEFINE6(mbind, compat_ulong_t, start, compat_ulong_t, len,
 struct mempolicy *get_vma_policy(struct task_struct *task,
                struct vm_area_struct *vma, unsigned long addr)
 {
-       struct mempolicy *pol = get_task_policy(task);
+       struct mempolicy *pol = NULL;
 
        if (vma) {
                if (vma->vm_ops && vma->vm_ops->get_policy) {
-                       struct mempolicy *vpol = vma->vm_ops->get_policy(vma,
-                                                                       addr);
-                       if (vpol)
-                               pol = vpol;
+                       pol = vma->vm_ops->get_policy(vma, addr);
                } else if (vma->vm_policy) {
                        pol = vma->vm_policy;
 
@@ -1644,31 +1639,31 @@ struct mempolicy *get_vma_policy(struct task_struct *task,
                                mpol_get(pol);
                }
        }
+
        if (!pol)
-               pol = &default_policy;
+               pol = get_task_policy(task);
+
        return pol;
 }
 
-bool vma_policy_mof(struct task_struct *task, struct vm_area_struct *vma)
+bool vma_policy_mof(struct vm_area_struct *vma)
 {
-       struct mempolicy *pol = get_task_policy(task);
-       if (vma) {
-               if (vma->vm_ops && vma->vm_ops->get_policy) {
-                       bool ret = false;
+       struct mempolicy *pol;
 
-                       pol = vma->vm_ops->get_policy(vma, vma->vm_start);
-                       if (pol && (pol->flags & MPOL_F_MOF))
-                               ret = true;
-                       mpol_cond_put(pol);
+       if (vma->vm_ops && vma->vm_ops->get_policy) {
+               bool ret = false;
 
-                       return ret;
-               } else if (vma->vm_policy) {
-                       pol = vma->vm_policy;
-               }
+               pol = vma->vm_ops->get_policy(vma, vma->vm_start);
+               if (pol && (pol->flags & MPOL_F_MOF))
+                       ret = true;
+               mpol_cond_put(pol);
+
+               return ret;
        }
 
+       pol = vma->vm_policy;
        if (!pol)
-               return default_policy.flags & MPOL_F_MOF;
+               pol = get_task_policy(current);
 
        return pol->flags & MPOL_F_MOF;
 }
@@ -2046,8 +2041,7 @@ retry_cpuset:
        page = __alloc_pages_nodemask(gfp, order,
                                      policy_zonelist(gfp, pol, node),
                                      policy_nodemask(gfp, pol));
-       if (unlikely(mpol_needs_cond_ref(pol)))
-               __mpol_put(pol);
+       mpol_cond_put(pol);
        if (unlikely(!page && read_mems_allowed_retry(cpuset_mems_cookie)))
                goto retry_cpuset;
        return page;
@@ -2074,12 +2068,12 @@ retry_cpuset:
  */
 struct page *alloc_pages_current(gfp_t gfp, unsigned order)
 {
-       struct mempolicy *pol = get_task_policy(current);
+       struct mempolicy *pol = &default_policy;
        struct page *page;
        unsigned int cpuset_mems_cookie;
 
-       if (!pol || in_interrupt() || (gfp & __GFP_THISNODE))
-               pol = &default_policy;
+       if (!in_interrupt() && !(gfp & __GFP_THISNODE))
+               pol = get_task_policy(current);
 
 retry_cpuset:
        cpuset_mems_cookie = read_mems_allowed_begin();