Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 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>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Jianyu Zhan and committed by
Linus Torvalds
8f34af6f 6edd6cc6

+13 -13
+13 -13
mm/hugetlb.c
··· 1386 1386 return ERR_PTR(-ENOSPC); 1387 1387 1388 1388 ret = hugetlb_cgroup_charge_cgroup(idx, pages_per_huge_page(h), &h_cg); 1389 - if (ret) { 1390 - if (chg || avoid_reserve) 1391 - hugepage_subpool_put_pages(spool, 1); 1392 - return ERR_PTR(-ENOSPC); 1393 - } 1389 + if (ret) 1390 + goto out_subpool_put; 1391 + 1394 1392 spin_lock(&hugetlb_lock); 1395 1393 page = dequeue_huge_page_vma(h, vma, addr, avoid_reserve, chg); 1396 1394 if (!page) { 1397 1395 spin_unlock(&hugetlb_lock); 1398 1396 page = alloc_buddy_huge_page(h, NUMA_NO_NODE); 1399 - if (!page) { 1400 - hugetlb_cgroup_uncharge_cgroup(idx, 1401 - pages_per_huge_page(h), 1402 - h_cg); 1403 - if (chg || avoid_reserve) 1404 - hugepage_subpool_put_pages(spool, 1); 1405 - return ERR_PTR(-ENOSPC); 1406 - } 1397 + if (!page) 1398 + goto out_uncharge_cgroup; 1399 + 1407 1400 spin_lock(&hugetlb_lock); 1408 1401 list_move(&page->lru, &h->hugepage_activelist); 1409 1402 /* Fall through */ ··· 1408 1415 1409 1416 vma_commit_reservation(h, vma, addr); 1410 1417 return page; 1418 + 1419 + out_uncharge_cgroup: 1420 + hugetlb_cgroup_uncharge_cgroup(idx, pages_per_huge_page(h), h_cg); 1421 + out_subpool_put: 1422 + if (chg || avoid_reserve) 1423 + hugepage_subpool_put_pages(spool, 1); 1424 + return ERR_PTR(-ENOSPC); 1411 1425 } 1412 1426 1413 1427 /*