mm/page_alloc: move set_page_refcounted() to callers of __alloc_pages_slowpath()
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Mon, 25 Nov 2024 21:01:43 +0000 (21:01 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 14 Jan 2025 06:40:33 +0000 (22:40 -0800)
In preparation for allocating frozen pages, stop initialising the page
refcount in __alloc_pages_slowpath().

Link: https://lkml.kernel.org/r/20241125210149.2976098-12-willy@infradead.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: Vlastimil Babka <vbabka@suse.cz>
Cc: David Hildenbrand <david@redhat.com>
Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Miaohe Lin <linmiaohe@huawei.com>
Cc: Muchun Song <songmuchun@bytedance.com>
Cc: William Kucharski <william.kucharski@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/page_alloc.c

index 835b1491610d2f0ec9ad0f3b04ca61a1db377f49..e2e5cd899abd109536efab7a827cafb5e3aefea4 100644 (file)
@@ -4284,10 +4284,8 @@ restart:
         * that first
         */
        page = get_page_from_freelist(gfp_mask, order, alloc_flags, ac);
-       if (page) {
-               set_page_refcounted(page);
+       if (page)
                goto got_pg;
-       }
 
        /*
         * For costly allocations, try direct compaction first, as it's likely
@@ -4306,10 +4304,8 @@ restart:
                                                alloc_flags, ac,
                                                INIT_COMPACT_PRIORITY,
                                                &compact_result);
-               if (page) {
-                       set_page_refcounted(page);
+               if (page)
                        goto got_pg;
-               }
 
                /*
                 * Checks for costly allocations with __GFP_NORETRY, which
@@ -4369,10 +4365,8 @@ retry:
 
        /* Attempt with potentially adjusted zonelist and alloc_flags */
        page = get_page_from_freelist(gfp_mask, order, alloc_flags, ac);
-       if (page) {
-               set_page_refcounted(page);
+       if (page)
                goto got_pg;
-       }
 
        /* Caller is not willing to reclaim, we can't balance anything */
        if (!can_direct_reclaim)
@@ -4385,18 +4379,14 @@ retry:
        /* Try direct reclaim and then allocating */
        page = __alloc_pages_direct_reclaim(gfp_mask, order, alloc_flags, ac,
                                                        &did_some_progress);
-       if (page) {
-               set_page_refcounted(page);
+       if (page)
                goto got_pg;
-       }
 
        /* Try direct compaction and then allocating */
        page = __alloc_pages_direct_compact(gfp_mask, order, alloc_flags, ac,
                                        compact_priority, &compact_result);
-       if (page) {
-               set_page_refcounted(page);
+       if (page)
                goto got_pg;
-       }
 
        /* Do not loop if specifically requested */
        if (gfp_mask & __GFP_NORETRY)
@@ -4437,10 +4427,8 @@ retry:
 
        /* Reclaim has failed us, start killing things */
        page = __alloc_pages_may_oom(gfp_mask, order, ac, &did_some_progress);
-       if (page) {
-               set_page_refcounted(page);
+       if (page)
                goto got_pg;
-       }
 
        /* Avoid allocations with no watermarks from looping endlessly */
        if (tsk_is_oom_victim(current) &&
@@ -4484,10 +4472,8 @@ nopage:
                 * the situation worse.
                 */
                page = __alloc_pages_cpuset_fallback(gfp_mask, order, ALLOC_MIN_RESERVE, ac);
-               if (page) {
-                       set_page_refcounted(page);
+               if (page)
                        goto got_pg;
-               }
 
                cond_resched();
                goto retry;
@@ -4779,6 +4765,8 @@ struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order,
        ac.nodemask = nodemask;
 
        page = __alloc_pages_slowpath(alloc_gfp, order, &ac);
+       if (page)
+               set_page_refcounted(page);
 
 out:
        if (memcg_kmem_online() && (gfp & __GFP_ACCOUNT) && page &&