* [PATCH V3] mm/hugetlb: add available_huge_pages() func
@ 2022-09-17 1:15 Xin Hao
2022-09-19 23:58 ` Mike Kravetz
2022-09-20 3:28 ` Oscar Salvador
0 siblings, 2 replies; 4+ messages in thread
From: Xin Hao @ 2022-09-17 1:15 UTC (permalink / raw)
To: mike.kravetz; +Cc: songmuchun, akpm, linux-mm, linux-kernel, xhao
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 available_huge_pages() func to do these.
Signed-off-by: Xin Hao <xhao@linux.alibaba.com>
Changes from v2
https://lore.kernel.org/linux-mm/20220916064127.1904-1-xhao@linux.alibaba.com/
- Convert is_resv_equal_free() to available_huge_pages()
---
mm/hugetlb.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 5ea0b1b0d1ab..21d7f2361696 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1191,6 +1191,11 @@ static struct page *dequeue_huge_page_nodemask(struct hstate *h, gfp_t gfp_mask,
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,
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) && !available_huge_pages(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 && !available_huge_pages(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 (!available_huge_pages(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 (available_huge_pages(h)) {
struct page *page;
page = dequeue_huge_page_nodemask(h, gfp_mask, preferred_nid, nmask);
--
2.31.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH V3] mm/hugetlb: add available_huge_pages() func
2022-09-17 1:15 [PATCH V3] mm/hugetlb: add available_huge_pages() func Xin Hao
@ 2022-09-19 23:58 ` Mike Kravetz
2022-09-20 1:46 ` haoxin
2022-09-20 3:28 ` Oscar Salvador
1 sibling, 1 reply; 4+ messages in thread
From: Mike Kravetz @ 2022-09-19 23:58 UTC (permalink / raw)
To: Xin Hao; +Cc: songmuchun, akpm, linux-mm, linux-kernel
On 09/17/22 09:15, Xin Hao wrote:
> 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 available_huge_pages() func to do these.
Thanks, I think the code looks a little better with this change.
>
> Signed-off-by: Xin Hao <xhao@linux.alibaba.com>
> Changes from v2
> https://lore.kernel.org/linux-mm/20220916064127.1904-1-xhao@linux.alibaba.com/
> - Convert is_resv_equal_free() to available_huge_pages()
I believe the above 'Changes from v2' information should be below the marker
'---' as it will not be included in the changelog.
> ---
> mm/hugetlb.c | 14 +++++++++-----
> 1 file changed, 9 insertions(+), 5 deletions(-)
The changes look fine,
Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com>
--
Mike Kravetz
>
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 5ea0b1b0d1ab..21d7f2361696 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -1191,6 +1191,11 @@ static struct page *dequeue_huge_page_nodemask(struct hstate *h, gfp_t gfp_mask,
> 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,
> 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) && !available_huge_pages(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 && !available_huge_pages(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 (!available_huge_pages(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 (available_huge_pages(h)) {
> struct page *page;
>
> page = dequeue_huge_page_nodemask(h, gfp_mask, preferred_nid, nmask);
> --
> 2.31.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH V3] mm/hugetlb: add available_huge_pages() func
2022-09-19 23:58 ` Mike Kravetz
@ 2022-09-20 1:46 ` haoxin
0 siblings, 0 replies; 4+ messages in thread
From: haoxin @ 2022-09-20 1:46 UTC (permalink / raw)
To: Mike Kravetz; +Cc: songmuchun, akpm, linux-mm, linux-kernel
在 2022/9/20 上午7:58, Mike Kravetz 写道:
> On 09/17/22 09:15, Xin Hao wrote:
>> 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 available_huge_pages() func to do these.
> Thanks, I think the code looks a little better with this change.
>
>> Signed-off-by: Xin Hao <xhao@linux.alibaba.com>
>> Changes from v2
>> https://lore.kernel.org/linux-mm/20220916064127.1904-1-xhao@linux.alibaba.com/
>> - Convert is_resv_equal_free() to available_huge_pages()
> I believe the above 'Changes from v2' information should be below the marker
> '---' as it will not be included in the changelog.
Ok, i will remove the changelog in the next patch.
>
>> ---
>> mm/hugetlb.c | 14 +++++++++-----
>> 1 file changed, 9 insertions(+), 5 deletions(-)
> The changes look fine,
>
> Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH V3] mm/hugetlb: add available_huge_pages() func
2022-09-17 1:15 [PATCH V3] mm/hugetlb: add available_huge_pages() func Xin Hao
2022-09-19 23:58 ` Mike Kravetz
@ 2022-09-20 3:28 ` Oscar Salvador
1 sibling, 0 replies; 4+ messages in thread
From: Oscar Salvador @ 2022-09-20 3:28 UTC (permalink / raw)
To: Xin Hao; +Cc: mike.kravetz, songmuchun, akpm, linux-mm, linux-kernel
On Sat, Sep 17, 2022 at 09:15:28AM +0800, Xin Hao wrote:
> 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 available_huge_pages() func to do these.
>
> Signed-off-by: Xin Hao <xhao@linux.alibaba.com>
Reviewed-by: Oscar Salvador <osalvador@suse.de>
--
Oscar Salvador
SUSE Labs
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-09-20 3:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-17 1:15 [PATCH V3] mm/hugetlb: add available_huge_pages() func Xin Hao
2022-09-19 23:58 ` Mike Kravetz
2022-09-20 1:46 ` haoxin
2022-09-20 3:28 ` Oscar Salvador
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.