Re: [PATCH v3 05/14] mm/hugetlb: use direct assignment instead of folio_change_private()
From: Zi Yan
Date: Tue Sep 08 2026 - 11:39:42 EST
On Tue Sep 8, 2026 at 11:26 AM EDT, David Hildenbrand (Arm) wrote:
> On 9/8/26 04:56, Zi Yan wrote:
>> folio_change_private() should be used along with folio_attach_private() and
>> folio_detach_private(), where adding and remove ->private content requires
>> folio refcount change. add_hugetlb_folio() simply sets folio->private to
>> NULL without refcount manipulation. Change it to direct assignment to avoid
>> semantic confusion.
>>
>> It prepares for a future commit that remove PG_private.
>>
>> No functional change intended.
>>
>> Assisted-by: Claude:claude-opus-4-8
>> Assisted-by: Codex:gpt-5
>> To: Muchun Song <muchun.song@xxxxxxxxx>
>> To: Oscar Salvador <osalvador@xxxxxxx>
>> To: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
>> Cc: David Hildenbrand <david@xxxxxxxxxx>
>> Cc: linux-mm@xxxxxxxxx
>> Cc: linux-kernel@xxxxxxxxxxxxxxx
>> Acked-by: Usama Arif <usama.arif@xxxxxxxxx>
>> Reviewed-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
>> Signed-off-by: Zi Yan <ziy@xxxxxxxxxx>
>> ---
>> mm/hugetlb.c | 6 +++---
>> 1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
>> index a69bd463b1aef..08a538739d785 100644
>> --- a/mm/hugetlb.c
>> +++ b/mm/hugetlb.c
>> @@ -1445,10 +1445,10 @@ void add_hugetlb_folio(struct hstate *h, struct folio *folio,
>> }
>>
>> __folio_set_hugetlb(folio);
>> - folio_change_private(folio, NULL);
>> + folio->private = NULL;
>> /*
>> - * We have to set hugetlb_vmemmap_optimized again as above
>> - * folio_change_private(folio, NULL) cleared it.
>> + * The hugetlb flags live in folio->private and are cleared by the above
>> + * assignment. Restore the hugetlb_vmemmap_optimized flag.
>
> "are cleared by the above assignment" ... isn't "folio->private = NULL;" as
> self-documenting as it gets? :)
>
> "Clear all folio->private flags except hugetlb_vmemmap_optimized."
It looks better. Will change it.
> folio->private = NULL;
> folio_set_hugetlb_vmemmap_optimized(folio);
>
> Acked-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
Thanks.
>
> It's also pretty odd that we use an atomic here, when just erasing all flags ...
> but that's something for another day.
--
Best Regards,
Yan, Zi