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: hugetlb: convert to use more alloc_fresh_hugetlb_folio()

Patch series "mm: hugetlb: cleanup hugetlb folio allocation", v3.

Some cleanups for hugetlb folio allocation.


This patch (of 3):

Simplify alloc_fresh_hugetlb_folio() and convert more functions to use it,
which help us to remove prep_new_hugetlb_folio() and
__prep_new_hugetlb_folio().

Link: https://lkml.kernel.org/r/20250910133958.301467-1-wangkefeng.wang@huawei.com
Link: https://lkml.kernel.org/r/20250910133958.301467-2-wangkefeng.wang@huawei.com
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Acked-by: Oscar Salvador <osalvador@suse.de>
Reviewed-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Cc: Brendan Jackman <jackmanb@google.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Jane Chu <jane.chu@oracle.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Kefeng Wang and committed by
Andrew Morton
902020f0 0c83e7fa

+14 -32
+14 -32
mm/hugetlb.c
··· 1906 1906 set_hugetlb_cgroup_rsvd(folio, NULL); 1907 1907 } 1908 1908 1909 - static void __prep_new_hugetlb_folio(struct hstate *h, struct folio *folio) 1910 - { 1911 - init_new_hugetlb_folio(h, folio); 1912 - hugetlb_vmemmap_optimize_folio(h, folio); 1913 - } 1914 - 1915 - static void prep_new_hugetlb_folio(struct hstate *h, struct folio *folio, int nid) 1916 - { 1917 - __prep_new_hugetlb_folio(h, folio); 1918 - spin_lock_irq(&hugetlb_lock); 1919 - __prep_account_new_huge_page(h, nid); 1920 - spin_unlock_irq(&hugetlb_lock); 1921 - } 1922 - 1923 1909 /* 1924 1910 * Find and lock address space (mapping) in write mode. 1925 1911 * ··· 1991 2005 } 1992 2006 1993 2007 /* 1994 - * Common helper to allocate a fresh hugetlb page. All specific allocators 1995 - * should use this function to get new hugetlb pages 2008 + * Common helper to allocate a fresh hugetlb folio. All specific allocators 2009 + * should use this function to get new hugetlb folio 1996 2010 * 1997 - * Note that returned page is 'frozen': ref count of head page and all tail 1998 - * pages is zero. 2011 + * Note that returned folio is 'frozen': ref count of head page and all tail 2012 + * pages is zero, and the accounting must be done in the caller. 1999 2013 */ 2000 2014 static struct folio *alloc_fresh_hugetlb_folio(struct hstate *h, 2001 2015 gfp_t gfp_mask, int nid, nodemask_t *nmask) 2002 2016 { 2003 2017 struct folio *folio; 2004 2018 2005 - if (hstate_is_gigantic(h)) 2006 - folio = alloc_gigantic_folio(h, gfp_mask, nid, nmask); 2007 - else 2008 - folio = alloc_buddy_hugetlb_folio(h, gfp_mask, nid, nmask, NULL); 2009 - if (!folio) 2010 - return NULL; 2011 - 2012 - prep_new_hugetlb_folio(h, folio, folio_nid(folio)); 2019 + folio = only_alloc_fresh_hugetlb_folio(h, gfp_mask, nid, nmask, NULL); 2020 + if (folio) 2021 + hugetlb_vmemmap_optimize_folio(h, folio); 2013 2022 return folio; 2014 2023 } 2015 2024 ··· 2222 2241 goto out_unlock; 2223 2242 spin_unlock_irq(&hugetlb_lock); 2224 2243 2225 - folio = only_alloc_fresh_hugetlb_folio(h, gfp_mask, nid, nmask, NULL); 2244 + folio = alloc_fresh_hugetlb_folio(h, gfp_mask, nid, nmask); 2226 2245 if (!folio) 2227 2246 return NULL; 2228 - 2229 - hugetlb_vmemmap_optimize_folio(h, folio); 2230 2247 2231 2248 spin_lock_irq(&hugetlb_lock); 2232 2249 /* ··· 2268 2289 folio = alloc_fresh_hugetlb_folio(h, gfp_mask, nid, nmask); 2269 2290 if (!folio) 2270 2291 return NULL; 2292 + 2293 + spin_lock_irq(&hugetlb_lock); 2294 + __prep_account_new_huge_page(h, folio_nid(folio)); 2295 + spin_unlock_irq(&hugetlb_lock); 2271 2296 2272 2297 /* fresh huge pages are frozen */ 2273 2298 folio_ref_unfreeze(folio, 1); ··· 2819 2836 if (!new_folio) { 2820 2837 spin_unlock_irq(&hugetlb_lock); 2821 2838 gfp_mask = htlb_alloc_mask(h) | __GFP_THISNODE; 2822 - new_folio = alloc_buddy_hugetlb_folio(h, gfp_mask, nid, 2823 - NULL, NULL); 2839 + new_folio = alloc_fresh_hugetlb_folio(h, gfp_mask, 2840 + nid, NULL); 2824 2841 if (!new_folio) 2825 2842 return -ENOMEM; 2826 - __prep_new_hugetlb_folio(h, new_folio); 2827 2843 goto retry; 2828 2844 } 2829 2845