Re: [PATCH v4] mm: page_alloc: add missing hooks to bulk allocation path
From: Vlastimil Babka (SUSE)
Date: Tue Sep 08 2026 - 08:23:15 EST
On 9/8/26 12:23, Qiqi Liu wrote:
> The bulk allocation path in alloc_pages_bulk_noprof() currently misses
> trace_mm_page_alloc() and kmsan_alloc_page() calls, leaving bulk-allocated
> pages invisible to ftrace/BPF/perf and leaving KMSAN shadow memory stale.
>
> Add both calls in the bulk loop to match the standard allocation path,
> placing them before set_page_refcounted() for consistency. The gfp mask
> passed to kmsan_alloc_page() is stripped of __GFP_RECLAIM because the
> bulk loop runs under the PCP spinlock, and KMSAN's stack depot allocation
> must not sleep.
>
> Both are no-ops when their respective features are disabled, so there
> is no overhead in production kernels.
>
> Suggested-by: Gregory Price <gourry@xxxxxxxxxx>
> Signed-off-by: Qiqi Liu <liuqiqi@xxxxxxxxxx>
Reviewed-by: Vlastimil Babka (SUSE) <vbabka@xxxxxxxxxx>
> ---
> mm/page_alloc.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 12fac9084c48..eac419eef697 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -5279,6 +5279,8 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int preferred_nid,
> nr_account++;
>
> prep_new_page(page, 0, gfp, ALLOC_DEFAULT);
> + trace_mm_page_alloc(page, 0, gfp, ac.migratetype);
> + kmsan_alloc_page(page, 0, gfp & ~__GFP_RECLAIM);
> set_page_refcounted(page);
> page_array[nr_populated++] = page;
> }