From 2985dae1e521ee1464130902415f5863ea05dc34 Mon Sep 17 00:00:00 2001 From: Alexei Starovoitov Date: Mon, 31 Mar 2025 20:23:36 -0700 Subject: [PATCH] mm/page_alloc: Fix try_alloc_pages Fix an obvious bug. try_alloc_pages() should set_page_refcounted. [ Not so obvious: it was probably correct at the time it was written but was at some point then rebased on top of v6.14-rc1. And at that point there was a semantic conflict with commit efabfe1420f5 ("mm/page_alloc: move set_page_refcounted() to callers of get_page_from_freelist()") and became buggy. - Linus ] Fixes: 97769a53f117 ("mm, bpf: Introduce try_alloc_pages() for opportunistic page allocation") Signed-off-by: Alexei Starovoitov Reviewed-by: Shakeel Butt Acked-by: Michal Hocko Acked-by: Vlastimil BAbka Reviewed-by: Harry Yoo Signed-off-by: Linus Torvalds --- mm/page_alloc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index f51aa6051a99..5b173c2da641 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -7385,6 +7385,9 @@ struct page *try_alloc_pages_noprof(int nid, unsigned int order) /* Unlike regular alloc_pages() there is no __alloc_pages_slowpath(). */ + if (page) + set_page_refcounted(page); + if (memcg_kmem_online() && page && unlikely(__memcg_kmem_charge_page(page, alloc_gfp, order) != 0)) { free_pages_nolock(page, order);