Replace user_alloc_needs_zeroing() with the direct aliasing checks (cpu_dcache_is_aliasing() || cpu_icache_is_aliasing()) in the post_alloc_hook aliasing guard.
user_alloc_needs_zeroing() includes a !init_on_alloc term that means "allocator didn't zero this page." But in this guard's context (!zeroed && !init && __GFP_ZERO), we already know the page is zero; init incorporates init_on_alloc via want_init_on_alloc(). The only question left is whether the cache architecture needs the data re-zeroed through a congruent mapping, which is purely cpu_dcache_is_aliasing() || cpu_icache_is_aliasing(). On non-aliasing architectures with init_on_free=true and init_on_alloc=false, this avoids a redundant re-zero of an already-zero page. Signed-off-by: Michael S. Tsirkin <[email protected]> Assisted-by: Claude:claude-opus-4-6 --- mm/page_alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 5158f7e23d18..4cb7e779a6c5 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1883,7 +1883,7 @@ inline void post_alloc_hook(struct page *page, unsigned int order, */ if (!zeroed && !init && (gfp_flags & __GFP_ZERO) && user_addr != USER_ADDR_NONE && - user_alloc_needs_zeroing()) + (cpu_dcache_is_aliasing() || cpu_icache_is_aliasing())) init = true; /* * If memory is still not initialized, initialize it now. -- MST

