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

From: Oscar Salvador
Date: Tue Sep 09 2025 - 04:00:54 EST


On Tue, Sep 09, 2025 at 03:48:11PM +0800, 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);

Sure nothing might happen, but I find a bit weird that folio_nr_pages()
returns a 'long' and we store it in an 'int' type.
And then sure we handle that to mm_account_reclaimed_pages() which gets
'unsigned long', but that's another story.



--
Oscar Salvador
SUSE Labs