]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
mm/page_alloc: Fix try_alloc_pages
authorAlexei Starovoitov <ast@kernel.org>
Tue, 1 Apr 2025 03:23:36 +0000 (20:23 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 2 Apr 2025 16:34:31 +0000 (09:34 -0700)
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 <ast@kernel.org>
Reviewed-by: Shakeel Butt <shakeel.butt@linux.dev>
Acked-by: Michal Hocko <mhocko@suse.com>
Acked-by: Vlastimil BAbka <vbabka@suse.cz>
Reviewed-by: Harry Yoo <harry.yoo@oracle.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/page_alloc.c

index f51aa6051a99867d2d7d8c70aa7c30e523629951..5b173c2da64179b9f6b21e2489c70d9b68bd2b17 100644 (file)
@@ -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);