]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
mm, hugetlb: move the error handle logic out of normal code path
authorJianyu Zhan <nasa4836@gmail.com>
Thu, 22 May 2014 00:43:24 +0000 (10:43 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Thu, 22 May 2014 00:43:24 +0000 (10:43 +1000)
alloc_huge_page() now mixes normal code path with error handle logic.
This patches move out the error handle logic, to make normal code path
more clean and redue code duplicate.

Signed-off-by: Jianyu Zhan <nasa4836@gmail.com>
Acked-by: Davidlohr Bueso <davidlohr@hp.com>
Reviewed-by: Michal Hocko <mhocko@suse.cz>
Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/hugetlb.c

index e73f7bccd10c9bce26b87d81cc1e628cd368b2af..9519cde969619e08faff5e1d1cb6598faf6d6078 100644 (file)
@@ -1387,24 +1387,17 @@ static struct page *alloc_huge_page(struct vm_area_struct *vma,
                        return ERR_PTR(-ENOSPC);
 
        ret = hugetlb_cgroup_charge_cgroup(idx, pages_per_huge_page(h), &h_cg);
-       if (ret) {
-               if (chg || avoid_reserve)
-                       hugepage_subpool_put_pages(spool, 1);
-               return ERR_PTR(-ENOSPC);
-       }
+       if (ret)
+               goto out_subpool_put;
+
        spin_lock(&hugetlb_lock);
        page = dequeue_huge_page_vma(h, vma, addr, avoid_reserve, chg);
        if (!page) {
                spin_unlock(&hugetlb_lock);
                page = alloc_buddy_huge_page(h, NUMA_NO_NODE);
-               if (!page) {
-                       hugetlb_cgroup_uncharge_cgroup(idx,
-                                                      pages_per_huge_page(h),
-                                                      h_cg);
-                       if (chg || avoid_reserve)
-                               hugepage_subpool_put_pages(spool, 1);
-                       return ERR_PTR(-ENOSPC);
-               }
+               if (!page)
+                       goto out_uncharge_cgroup;
+
                spin_lock(&hugetlb_lock);
                list_move(&page->lru, &h->hugepage_activelist);
                /* Fall through */
@@ -1416,6 +1409,13 @@ static struct page *alloc_huge_page(struct vm_area_struct *vma,
 
        vma_commit_reservation(h, vma, addr);
        return page;
+
+out_uncharge_cgroup:
+       hugetlb_cgroup_uncharge_cgroup(idx, pages_per_huge_page(h), h_cg);
+out_subpool_put:
+       if (chg || avoid_reserve)
+               hugepage_subpool_put_pages(spool, 1);
+       return ERR_PTR(-ENOSPC);
 }
 
 /*