mm: pass nid to reserve_bootmem_region()
PATCH 1/1 mm: pass nid to reserve_bootmem_region()
early_pfn_to_nid() is called frequently in init_reserved_page(), it is used to convert PFN to node id. These PFN may belong to the same memory region, they have the same node id. It is not necessary to call early_pfn_to_nid() for each PFN.
Pass nid to reserve_bootmem_region() and drop the call to early_pfn_to_nid() in init_reserved_page().
The following data was tested on my machine, it has 190GB RAM, and enable CONFIG_DEFERRED_STRUCT_PAGE_INIT.
before the patch:memmap_init_reserved_pages() 67ms
after the patch:memmap_init_reserved_pages() 20ms
--- include/linux/mm.h | 3 ++- mm/memblock.c | 9 ++++++--- mm/mm_init.c | 31 +++++++++++++++++++------------ 3 files changed, 27 insertions(+), 16 deletions(-)
include/linux/mm.h +2 -1
@@ -2964,7 +2964,8 @@ extern unsigned long free_reserved_area(void *start, void *end,extern void adjust_managed_page_count (struct page *page,long count); -extern void reserve_bootmem_region (phys_addr_t start,phys_addr_t end); +extern void reserve_bootmem_region (phys_addr_t start, +phys_addr_t end,int nid);/* Free the reserved page into the buddy system, so it gets managed. */ static inline void free_reserved_page (struct page *page)
mm/memblock.c +6 -3
@@ -2091,18 +2091,21 @@ static void __init memmap_init_reserved_pages(void) {struct memblock_region *region;phys_addr_t start, end; +int nid;u64 i;/* initialize struct pages for the reserved regions */ -for_each_reserved_mem_range (i, &start, &end) -reserve_bootmem_region (start, end); +__for_each_mem_range (i, &memblock.reserved,NULL ,NUMA_NO_NODE , +MEMBLOCK_NONE , &start, &end, &nid) +reserve_bootmem_region (start, end, nid);/* and also treat struct pages for the NOMAP regions as PageReserved */ for_each_mem_region (region) {if (memblock_is_nomap (region)) { start = region->base; end = start + region->size; -reserve_bootmem_region (start, end); + nid = region->nid; +reserve_bootmem_region (start, end, nid); } } }
mm/mm_init.c +19 -12
@@ -646,10 +646,8 @@ static inline void pgdat_set_deferred_range(pg_data_t *pgdat) }/* Returns true if the struct page for the pfn is initialised */ -static inline bool __meminit early_page_initialised (unsigned long pfn) +static inline bool __meminit early_page_initialised (unsigned long pfn,int nid) { -int nid =early_pfn_to_nid (pfn); -if (node_online (nid) && pfn >=NODE_DATA (nid)->first_deferred_pfn)return false;
@@ -695,15 +693,14 @@ defer_init(int nid, unsigned long pfn, unsigned long end_pfn)return false; } -static void __meminit init_reserved_page (unsigned long pfn) +static void __meminit init_reserved_page (unsigned long pfn,int nid) {pg_data_t *pgdat; -int nid, zid; +int zid; -if (early_page_initialised (pfn)) +if (early_page_initialised (pfn, nid))return ; - nid =early_pfn_to_nid (pfn); pgdat =NODE_DATA (nid);for (zid =0 ; zid <MAX_NR_ZONES ; zid++) {
@@ -717,7 +714,7 @@ static void __meminit init_reserved_page(unsigned long pfn)#else static inline void pgdat_set_deferred_range (pg_data_t *pgdat) {} -static inline bool early_page_initialised (unsigned long pfn) +static inline bool early_page_initialised (unsigned long pfn,int nid) {return true; }
@@ -727,7 +724,7 @@ static inline bool defer_init(int nid, unsigned long pfn, unsigned long end_pfn) return false; } -static inline void init_reserved_page (unsigned long pfn) +static inline void init_reserved_page (unsigned long pfn,int nid) { }#endif /* CONFIG_DEFERRED_STRUCT_PAGE_INIT */
@@ -738,16 +735,20 @@ static inline void init_reserved_page(unsigned long pfn)* marks the pages PageReserved. The remaining valid pages are later * sent to the buddy page allocator. */ -void __meminit reserve_bootmem_region (phys_addr_t start,phys_addr_t end) +void __meminit reserve_bootmem_region (phys_addr_t start, +phys_addr_t end,int nid) {unsigned long start_pfn =PFN_DOWN (start);unsigned long end_pfn =PFN_UP (end); +if (nid ==MAX_NUMNODES ) + nid = first_online_node; +for (; start_pfn < end_pfn; start_pfn++) {if (pfn_valid (start_pfn)) {struct page *page =pfn_to_page (start_pfn); -init_reserved_page (start_pfn); +init_reserved_page (start_pfn, nid);/* Avoid false-positive PageTail() */ INIT_LIST_HEAD (&page->lru);
@@ -2579,7 +2580,13 @@ void __init set_dma_reserve(unsigned long new_dma_reserve)void __init memblock_free_pages (struct page *page,unsigned long pfn,unsigned int order) { -if (!early_page_initialised (pfn)) +int nid =0 ; + +#ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT + nid =early_pfn_to_nid (pfn); +#endif + +if (!early_page_initialised (pfn, nid))return ;if (!kmsan_memblock_free_pages (page, order)) {/* KMSAN will take care of these pages. */
Signature · 1 line
2.25.1
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Yajun,
kernel test robot noticed the following build errors:
[auto build test ERROR on akpm-mm/mm-everything]
url: https://github.com/intel-lab-lkp/linux/commits/Yajun-Deng/mm-pass-nid-to-reserve_bootmem_region/20230615-190631 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/20230615110355.1694461-1-yajun.deng%40linux.dev patch subject: [PATCH] mm: pass nid to reserve_bootmem_region() config: arm-randconfig-r023-20230614 (https://download.01.org/0day-ci/archive/20230616/[email protected]/config) compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07)
reproduce (this is a W=1 build):
mkdir -p ~/bin
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install arm cross compiling tool for clang build
# apt-get install binutils-arm-linux-gnueabi
git remote add akpm-mm https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git
git fetch akpm-mm mm-everything
git checkout akpm-mm/mm-everything
b4 shazam https://lore.kernel.org/r/[email protected]
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=arm olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=arm SHELL=/bin/bash
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> mm/memblock.c:2098:18: error: no member named 'nid' in 'struct memblock_region'
nid = region->nid;
~~~~~~ ^1 error generated.
vim +2098 mm/memblock.c
2080
2081 static void __init memmap_init_reserved_pages(void)
2082 {
2083 struct memblock_region *region;
2084 phys_addr_t start, end;
2085 int nid;
2086 u64 i;
2087
2088 /* initialize struct pages for the reserved regions */
2089 __for_each_mem_range(i, &memblock.reserved, NULL, NUMA_NO_NODE,
2090 MEMBLOCK_NONE, &start, &end, &nid)
2091 reserve_bootmem_region(start, end, nid);
2092
2093 /* and also treat struct pages for the NOMAP regions as PageReserved */
2094 for_each_mem_region(region) {
2095 if (memblock_is_nomap(region)) {
2096 start = region->base;
2097 end = start + region->size;
> 2098 nid = region->nid;
2099 reserve_bootmem_region(start, end, nid);
2100 }
2101 }
2102 }
2103
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki