mirror of
https://github.com/torvalds/linux.git
synced 2024-09-20 23:13:00 +00:00
mm/hugetlb: add available_huge_pages() func
In hugetlb.c there are several places which compare the values of 'h->free_huge_pages' and 'h->resv_huge_pages', it looks a bit messy, so add a new available_huge_pages() function to do these. Link: https://lkml.kernel.org/r/20220922021929.98961-1-xhao@linux.alibaba.com Signed-off-by: Xin Hao <xhao@linux.alibaba.com> Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com> Reviewed-by: Muchun Song <songmuchun@bytedance.com> Reviewed-by: David Hildenbrand <david@redhat.com> Reviewed-by: Oscar Salvador <osalvador@suse.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
6b91e5dfb3
commit
8346d69d8b
14
mm/hugetlb.c
14
mm/hugetlb.c
|
@ -1191,6 +1191,11 @@ retry_cpuset:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static unsigned long available_huge_pages(struct hstate *h)
|
||||||
|
{
|
||||||
|
return h->free_huge_pages - h->resv_huge_pages;
|
||||||
|
}
|
||||||
|
|
||||||
static struct page *dequeue_huge_page_vma(struct hstate *h,
|
static struct page *dequeue_huge_page_vma(struct hstate *h,
|
||||||
struct vm_area_struct *vma,
|
struct vm_area_struct *vma,
|
||||||
unsigned long address, int avoid_reserve,
|
unsigned long address, int avoid_reserve,
|
||||||
|
@ -1207,12 +1212,11 @@ static struct page *dequeue_huge_page_vma(struct hstate *h,
|
||||||
* have no page reserves. This check ensures that reservations are
|
* have no page reserves. This check ensures that reservations are
|
||||||
* not "stolen". The child may still get SIGKILLed
|
* not "stolen". The child may still get SIGKILLed
|
||||||
*/
|
*/
|
||||||
if (!vma_has_reserves(vma, chg) &&
|
if (!vma_has_reserves(vma, chg) && !available_huge_pages(h))
|
||||||
h->free_huge_pages - h->resv_huge_pages == 0)
|
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
/* If reserves cannot be used, ensure enough pages are in the pool */
|
/* If reserves cannot be used, ensure enough pages are in the pool */
|
||||||
if (avoid_reserve && h->free_huge_pages - h->resv_huge_pages == 0)
|
if (avoid_reserve && !available_huge_pages(h))
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
gfp_mask = htlb_alloc_mask(h);
|
gfp_mask = htlb_alloc_mask(h);
|
||||||
|
@ -2124,7 +2128,7 @@ retry:
|
||||||
if (!page_count(page)) {
|
if (!page_count(page)) {
|
||||||
struct page *head = compound_head(page);
|
struct page *head = compound_head(page);
|
||||||
struct hstate *h = page_hstate(head);
|
struct hstate *h = page_hstate(head);
|
||||||
if (h->free_huge_pages - h->resv_huge_pages == 0)
|
if (!available_huge_pages(h))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -2311,7 +2315,7 @@ struct page *alloc_huge_page_nodemask(struct hstate *h, int preferred_nid,
|
||||||
nodemask_t *nmask, gfp_t gfp_mask)
|
nodemask_t *nmask, gfp_t gfp_mask)
|
||||||
{
|
{
|
||||||
spin_lock_irq(&hugetlb_lock);
|
spin_lock_irq(&hugetlb_lock);
|
||||||
if (h->free_huge_pages - h->resv_huge_pages > 0) {
|
if (available_huge_pages(h)) {
|
||||||
struct page *page;
|
struct page *page;
|
||||||
|
|
||||||
page = dequeue_huge_page_nodemask(h, gfp_mask, preferred_nid, nmask);
|
page = dequeue_huge_page_nodemask(h, gfp_mask, preferred_nid, nmask);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user