Re: [PATCH 02/15] mm/hugetlb: compare against persistent count when freeing lowmem folios

From: David Hildenbrand (Arm)

Date: Mon Nov 02 2026 - 07:54:51 EST


On 10/29/26 04:39, Muchun Song wrote:
>
>
>> On Oct 29, 2026, at 04:13, David Hildenbrand (Arm) <david@xxxxxxxxxx> wrote:
>>
>> try_to_free_low() gets a target number of persistent folios, but
>> compares it with "nr_huge_pages", which includes surplus folios. As a
>> result, it can free lowmem folios below that target.
>>
>> For example, with two persistent folios and one surplus folio, a target
>> of two can still end up freeing one persistent folio.
>>
>> Compare against persistent_huge_pages() instead. Convert the macro to a
>> helper function and place it before try_to_free_low().
>>
>> Fixes: 7893d1d505d5 ("hugetlb: Try to grow hugetlb pool for MAP_PRIVATE mappings")
>> Cc: stable@xxxxxxxxxx
>> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
>
> Acked-by: Muchun Song <muchun.song@xxxxxxxxx>
>
> One nit bellow.
>
>> ---
>> mm/hugetlb.c | 8 ++++++--
>> 1 file changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
>> index da5d04edf7c1..3a94ea1c9457 100644
>> --- a/mm/hugetlb.c
>> +++ b/mm/hugetlb.c
>> @@ -1335,6 +1335,11 @@ static unsigned long available_huge_pages(struct hstate *h)
>> return h->free_huge_pages - h->resv_huge_pages;
>> }
>>
>> +static unsigned long persistent_huge_pages(struct hstate *h)
>
> Better to make *h const?

Agreed, thanks!

--
Cheers,

David