mm/page_alloc: move set_page_refcounted() to callers of __alloc_pages_slowpath()

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>
This commit is contained in:
Matthew Wilcox (Oracle) 2024-11-25 21:01:43 +00:00 committed by Andrew Morton
parent 30fdb6df4c
commit a88de400e3

View File

@ -4284,10 +4284,8 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
* 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 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
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 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
/* 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 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
/* 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 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
/* 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 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
* 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 &&