Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/page_alloc: move set_page_refcounted() to end of __alloc_pages()

Remove some code duplication by calling set_page_refcounted() at the end
of __alloc_pages() instead of after each call that can allocate a page.
That means that we free a frozen page if we've exceeded the allowed memcg
memory.

Link: https://lkml.kernel.org/r/20241125210149.2976098-13-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>

authored by

Matthew Wilcox (Oracle) and committed by
Andrew Morton
c972106d a88de400

+4 -6
+4 -6
mm/page_alloc.c
··· 4750 4750 4751 4751 /* First allocation attempt */ 4752 4752 page = get_page_from_freelist(alloc_gfp, order, alloc_flags, &ac); 4753 - if (likely(page)) { 4754 - set_page_refcounted(page); 4753 + if (likely(page)) 4755 4754 goto out; 4756 - } 4757 4755 4758 4756 alloc_gfp = gfp; 4759 4757 ac.spread_dirty_pages = false; ··· 4763 4765 ac.nodemask = nodemask; 4764 4766 4765 4767 page = __alloc_pages_slowpath(alloc_gfp, order, &ac); 4766 - if (page) 4767 - set_page_refcounted(page); 4768 4768 4769 4769 out: 4770 4770 if (memcg_kmem_online() && (gfp & __GFP_ACCOUNT) && page && 4771 4771 unlikely(__memcg_kmem_charge_page(page, gfp, order) != 0)) { 4772 - __free_pages(page, order); 4772 + free_frozen_pages(page, order); 4773 4773 page = NULL; 4774 4774 } 4775 + if (page) 4776 + set_page_refcounted(page); 4775 4777 4776 4778 trace_mm_page_alloc(page, order, alloc_gfp, ac.migratetype); 4777 4779 kmsan_alloc_page(page, order, alloc_gfp);