Re: [PATCH] mm/slub: Use folio_nr_pages() in __free_slab()

From: Ye Liu
Date: Tue Sep 09 2025 - 05:01:28 EST



在 2025/9/9 16:46, Dev Jain 写道:
>
> On 09/09/25 1:18 pm, Hu Song wrote:
>> Use folio_nr_pages() helper instead of manual calculation (1 << order)
>> for better code readability and maintainability.
>>
>> Signed-off-by: Hu Song <husong@xxxxxxxxxx>
>> ---
>>   mm/slub.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/mm/slub.c b/mm/slub.c
>> index d257141896c9..eba25461641a 100644
>> --- a/mm/slub.c
>> +++ b/mm/slub.c
>> @@ -2719,7 +2719,7 @@ static void __free_slab(struct kmem_cache *s, struct slab *slab)
>>   {
>>       struct folio *folio = slab_folio(slab);
>>       int order = folio_order(folio);
>> -    int pages = 1 << order;
>> +    int pages = folio_nr_pages(folio);
>>         __slab_clear_pfmemalloc(slab);
>>       folio->mapping = NULL;
>
> I don't know, the current version is more readable to me. We literally
> compute the order before, so we do a simple 1 << order. I'll leave it
> to the rest.
>
>
Is the reason for calculating 'order' first because it's needed later.
I suggest using folio_nr_pages to replace the calculation of pages,
unifying the retrieval of pages in the folio and also highlighting
the significance of folio_nr_pages.                                   

--
Thanks,
Ye Liu