Re: [PATCH v3] mm/slub: deduplicate NUMA policy calculation in allocation paths

From: Harry Yoo

Date: Thu Jun 25 2026 - 00:36:10 EST




On 6/24/26 7:00 PM, Hao Li wrote:
> Currently, alloc_from_pcs() and __slab_alloc_node() both calculate the
> NUMA policy independently. Since they are called consecutively in paths
> like __kmalloc_nolock_noprof() and slab_alloc_node(), this leads to
> redundant code snippets.
>
> Introduce a helper function to resolve the NUMA policy once, eliminating
> the duplicated code and reducing execution overhead.
>
> Also remove __slab_alloc_node() function because it is almost empty.
> The callers of __slab_alloc_node now call ___slab_alloc() directly.
>
> Additional notes:
>
> Previously, when slab_strict_numa was enabled, alloc_from_pcs() and
> __slab_alloc_node() could each resolve the task mempolicy, so
> MPOL_INTERLEAVE or MPOL_WEIGHTED_INTERLEAVE could advance the
> interleave state twice for a single object allocation attempt.
> And each retry will also advance the interleave state.
>
> With this change, the strict NUMA node is resolved once and reused by
> both alloc_from_pcs() and ___slab_alloc() in each retry.
>
> This is a behavior change, but it better matches the intent of
> selecting one policy node for one allocation attempt.
>
> Signed-off-by: Hao Li <hao.li@xxxxxxxxx>
> ---
> Changes in v3:
> * Move apply_strict_numa_policy before retry label to simplify code (Thanks
> Harry)
>
> Changes in v2:
> * Use a better function name apply_strict_numa_policy() (Thanks Harry)
> * Remove almost empty function __slab_alloc_node.
> * Add a local variable, strict_node, so the retry path in
> __kmalloc_nolock_noprof() computes the strict NUMA node from the original
> node parameter instead of a previously resolved node value.
> ---

Looks good to me,
Reviewed-by: Harry Yoo (Oracle) <harry@xxxxxxxxxx>

Thanks!

--
Cheers,
Harry / Hyeonggon

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature