Commit 8f34af6f authored by Jianyu Zhan's avatar Jianyu Zhan Committed by Linus Torvalds

mm, hugetlb: move the error handle logic out of normal code path

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: default avatarJianyu Zhan <nasa4836@gmail.com>
Acked-by: default avatarDavidlohr Bueso <davidlohr@hp.com>
Reviewed-by: default avatarMichal Hocko <mhocko@suse.cz>
Reviewed-by: default avatarAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 6edd6cc6
...@@ -1386,24 +1386,17 @@ static struct page *alloc_huge_page(struct vm_area_struct *vma, ...@@ -1386,24 +1386,17 @@ static struct page *alloc_huge_page(struct vm_area_struct *vma,
return ERR_PTR(-ENOSPC); return ERR_PTR(-ENOSPC);
ret = hugetlb_cgroup_charge_cgroup(idx, pages_per_huge_page(h), &h_cg); ret = hugetlb_cgroup_charge_cgroup(idx, pages_per_huge_page(h), &h_cg);
if (ret) { if (ret)
if (chg || avoid_reserve) goto out_subpool_put;
hugepage_subpool_put_pages(spool, 1);
return ERR_PTR(-ENOSPC);
}
spin_lock(&hugetlb_lock); spin_lock(&hugetlb_lock);
page = dequeue_huge_page_vma(h, vma, addr, avoid_reserve, chg); page = dequeue_huge_page_vma(h, vma, addr, avoid_reserve, chg);
if (!page) { if (!page) {
spin_unlock(&hugetlb_lock); spin_unlock(&hugetlb_lock);
page = alloc_buddy_huge_page(h, NUMA_NO_NODE); page = alloc_buddy_huge_page(h, NUMA_NO_NODE);
if (!page) { if (!page)
hugetlb_cgroup_uncharge_cgroup(idx, goto out_uncharge_cgroup;
pages_per_huge_page(h),
h_cg);
if (chg || avoid_reserve)
hugepage_subpool_put_pages(spool, 1);
return ERR_PTR(-ENOSPC);
}
spin_lock(&hugetlb_lock); spin_lock(&hugetlb_lock);
list_move(&page->lru, &h->hugepage_activelist); list_move(&page->lru, &h->hugepage_activelist);
/* Fall through */ /* Fall through */
...@@ -1415,6 +1408,13 @@ static struct page *alloc_huge_page(struct vm_area_struct *vma, ...@@ -1415,6 +1408,13 @@ static struct page *alloc_huge_page(struct vm_area_struct *vma,
vma_commit_reservation(h, vma, addr); vma_commit_reservation(h, vma, addr);
return page; 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);
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment