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

mm/hugetlb: move huge_boot_pages list init to hugetlb_bootmem_alloc

Instead of initializing the per-node hugetlb bootmem pages list from the
alloc function, we can now do it in a somewhat cleaner way, since there is
an explicit hugetlb_bootmem_alloc function. Initialize the lists there.

Link: https://lkml.kernel.org/r/20250228182928.2645936-17-fvdl@google.com
Signed-off-by: Frank van der Linden <fvdl@google.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Joao Martins <joao.m.martins@oracle.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Roman Gushchin (Cruise) <roman.gushchin@linux.dev>
Cc: Usama Arif <usamaarif642@gmail.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Yu Zhao <yuzhao@google.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Frank van der Linden and committed by
Andrew Morton
91ec7187 d58b2498

+7 -12
+7 -12
mm/hugetlb.c
··· 3586 3586 static void __init hugetlb_hstate_alloc_pages(struct hstate *h) 3587 3587 { 3588 3588 unsigned long allocated; 3589 - static bool initialized __initdata; 3590 3589 3591 3590 /* skip gigantic hugepages allocation if hugetlb_cma enabled */ 3592 3591 if (hstate_is_gigantic(h) && hugetlb_cma_size) { 3593 3592 pr_warn_once("HugeTLB: hugetlb_cma is enabled, skip boot time allocation\n"); 3594 3593 return; 3595 - } 3596 - 3597 - /* hugetlb_hstate_alloc_pages will be called many times, initialize huge_boot_pages once */ 3598 - if (!initialized) { 3599 - int i = 0; 3600 - 3601 - for (i = 0; i < MAX_NUMNODES; i++) 3602 - INIT_LIST_HEAD(&huge_boot_pages[i]); 3603 - h->next_nid_to_alloc = first_online_node; 3604 - h->next_nid_to_free = first_online_node; 3605 - initialized = true; 3606 3594 } 3607 3595 3608 3596 /* do node specific alloc */ ··· 4916 4928 void __init hugetlb_bootmem_alloc(void) 4917 4929 { 4918 4930 struct hstate *h; 4931 + int i; 4919 4932 4920 4933 if (__hugetlb_bootmem_allocated) 4921 4934 return; 4922 4935 4936 + for (i = 0; i < MAX_NUMNODES; i++) 4937 + INIT_LIST_HEAD(&huge_boot_pages[i]); 4938 + 4923 4939 hugetlb_parse_params(); 4924 4940 4925 4941 for_each_hstate(h) { 4942 + h->next_nid_to_alloc = first_online_node; 4943 + h->next_nid_to_free = first_online_node; 4944 + 4926 4945 if (hstate_is_gigantic(h)) 4927 4946 hugetlb_hstate_alloc_pages(h); 4928 4947 }