mm/hugetlb: add is_resv_equal_free() func
Subsystems (2)
PATCH v2 1/1 mm/hugetlb: add is_resv_equal_free() func
In hugetlb.c file, there are several places to compare the values of 'h->free_huge_pages' and 'h->resv_huge_pages', it looks a bit messy, so there add a new is_resv_equal_free() func to do these.
--- mm/hugetlb.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
mm/hugetlb.c +9 -5
@@ -1191,6 +1191,11 @@ static struct page *dequeue_huge_page_nodemask(struct hstate *h, gfp_t gfp_mask,return NULL ; } +static inline bool is_resv_equal_free (struct hstate *h) +{ +return (h->free_huge_pages - h->resv_huge_pages ==0 ) ? true : false; +} + static struct page *dequeue_huge_page_vma(struct hstate *h, struct vm_area_struct *vma, 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 * not "stolen". The child may still get SIGKILLed */ -if (!vma_has_reserves (vma, chg) && - h->free_huge_pages - h->resv_huge_pages ==0 ) +if (!vma_has_reserves (vma, chg) &&is_resv_equal_free (h)) goto err;/* 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 &&is_resv_equal_free (h)) goto err; gfp_mask =htlb_alloc_mask (h);
@@ -2105,7 +2109,7 @@ int dissolve_free_huge_page(struct page *page)if (!page_count (page)) {struct page *head =compound_head (page);struct hstate *h =page_hstate (head); -if (h->free_huge_pages - h->resv_huge_pages ==0 ) +if (is_resv_equal_free (h)) goto out;/*
@@ -2315,7 +2319,7 @@ struct page *alloc_huge_page_nodemask(struct hstate *h, int preferred_nid, nodemask_t *nmask, gfp_t gfp_mask) {spin_lock_irq (&hugetlb_lock); -if (h->free_huge_pages - h->resv_huge_pages >0 ) { +if (!is_resv_equal_free (h)) {struct page *page; page =dequeue_huge_page_nodemask (h, gfp_mask, preferred_nid, nmask);
--
2.31.0
Andrew Morton
maintainermm/hugetlb.c static struct page *dequeue_huge_page_nodemask(struct hstate *h, gfp_t gfp_mask, · line 1194
Quoted 13 lines · On Fri, 16 Sep 2022 14:41:27 +0800 Xin Hao <[email protected]> wrote:
In
hugetlb.cfile, there are several places to compare the values of 'h->free_huge_pages' and 'h->resv_huge_pages', it looks a bit messy, so there add a newis_resv_equal_free()func to do these....
mm/hugetlb.c +1
-0@@ -1191,6 +1191,11 @@ static struct page *dequeue_huge_page_nodemask(struct hstate *h, gfp_t gfp_mask,return NULL ; } +static inline bool is_resv_equal_free (struct hstate *h)
I'm not sure that's a well chosen name. A better name would reflect the *meaning* of free_huge_pages being equal to resv_huge_pages. Maybe something like reserves_exhausted()?
This would all be clearer if we'd bothered to document the fields of struct hstate :(
mm/hugetlb.c static struct page *dequeue_huge_page_nodemask(struct hstate *h, gfp_t gfp_mask, · line 1196
Quoted 2 lines
mm/hugetlb.c +2
-0+{ +return (h->free_huge_pages - h->resv_huge_pages ==0 ) ? true : false;
return h->free_huge_pages == h->resv_huge_pages;
Quoted 1 line
mm/hugetlb.c +1
-0+}
Quoted 14 lines · Andrew Morton
Quoted 12 lines · On Fri, 16 Sep 2022 14:41:27 +0800 Xin Hao <[email protected]> wrote:
In
hugetlb.cfile, there are several places to compare the values of 'h->free_huge_pages' and 'h->resv_huge_pages', it looks a bit messy, so there add a newis_resv_equal_free()func to do these....
mm/hugetlb.c +0
-0@@ -1191,6 +1191,11 @@ static struct page *dequeue_huge_page_nodemask(struct hstate *h, gfp_t gfp_mask,return NULL ; }
Quoted 5 lines
mm/hugetlb.c static struct page *dequeue_huge_page_nodemask(struct hstate *h, gfp_t gfp_mask, · line 1194
Quoted 1 line
mm/hugetlb.c +1
-0+static inline bool is_resv_equal_free (struct hstate *h)I'm not sure that's a well chosen name. A better name would reflect the *meaning* of
free_huge_pagesbeing equal toresv_huge_pages. Maybe something likereserves_exhausted()?
How about calling it free_non_reserved_huge_pages() and returning the actual value (h->free_huge_pages - h->resv_huge_pages)?
Perhaps available_huge_pages()?
It could then be used in at least one other place
- if (h->free_huge_pages - h->resv_huge_pages > 0)
Quoted 2 lines
This would all be clearer if we'd bothered to document the fields of struct hstate :(
Agree, and discussed elsewhwere some may even be able to be eliminated. I can add that to my todo list.
Signature · 1 line
Mike Kravetz
Quoted 9 lines
mm/hugetlb.c static struct page *dequeue_huge_page_nodemask(struct hstate *h, gfp_t gfp_mask, · line 1196
Quoted 4 lines
mm/hugetlb.c +2
-0+{ +return (h->free_huge_pages - h->resv_huge_pages ==0 ) ? true : false;return h->free_huge_pages == h->resv_huge_pages;Quoted 1 line
mm/hugetlb.c +1
-0+}
Quoted 15 lines · Mike Kravetz
Quoted 14 lines · Andrew Morton
Quoted 12 lines · On Fri, 16 Sep 2022 14:41:27 +0800 Xin Hao <[email protected]> wrote:
In
hugetlb.cfile, there are several places to compare the values of 'h->free_huge_pages' and 'h->resv_huge_pages', it looks a bit messy, so there add a newis_resv_equal_free()func to do these....
mm/hugetlb.c +0
-0@@ -1191,6 +1191,11 @@ static struct page *dequeue_huge_page_nodemask(struct hstate *h, gfp_t gfp_mask,return NULL ; }
Quoted 8 lines
Quoted 4 lines
mm/hugetlb.c static struct page *dequeue_huge_page_nodemask(struct hstate *h, gfp_t gfp_mask, · line 1194
Quoted 1 line
mm/hugetlb.c +1
-0+static inline bool is_resv_equal_free (struct hstate *h)I'm not sure that's a well chosen name. A better name would reflect the *meaning* of
free_huge_pagesbeing equal toresv_huge_pages. Maybe something likereserves_exhausted()?How about calling it
free_non_reserved_huge_pages()and returning the actual value (h->free_huge_pages-h->resv_huge_pages)?Perhaps
available_huge_pages()?
Ok, I am going to use available_huge_pages() in the patch v3, thanks.
Quoted 7 lines
It could then be used in at least one other place
- if (h->free_huge_pages-h->resv_huge_pages> 0)Quoted 2 lines
This would all be clearer if we'd bothered to document the fields of struct hstate :(
Agree, and discussed elsewhwere some may even be able to be eliminated. I can add that to my todo list.