Re: [PATCH] mm: page_alloc: add trace_mm_page_alloc to bulk allocation path

From: Gregory Price

Date: Mon Sep 07 2026 - 10:55:24 EST


On Mon, Sep 07, 2026 at 08:09:49PM +0800, liuqiqi@xxxxxxxxxx wrote:
> From: Qiqi Liu <liuqiqi@xxxxxxxxxx>
>
> The bulk allocation path in alloc_pages_bulk_noprof() does not fire
> trace_mm_page_alloc for each allocated page, leaving bulk-allocated
> pages invisible to ftrace, BPF, and perf. Only the fallback path via
> __alloc_frozen_pages_noprof() is traced.
>
> Add trace_mm_page_alloc() after set_page_refcounted() in the bulk loop
> to match the standard allocation path. The tracepoint is gated by
> static key, so there is no overhead when tracing is disabled.
>
> Signed-off-by: Qiqi Liu <liuqiqi@xxxxxxxxxx>
> ---
> mm/page_alloc.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 12fac9084c48..d17c21775cb2 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -5280,6 +5280,7 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int preferred_nid,
>
> prep_new_page(page, 0, gfp, ALLOC_DEFAULT);
> set_page_refcounted(page);
> + trace_mm_page_alloc(page, 0, gfp, ac.migratetype);

Sashiko asked whether we're also missing kmsan hook here as well:

kmsan_alloc_page(page, 0, gfp);

Might be worth a quick look and just adding both in one go.

~Gregory