NUMA:Improve the efficiency of calculating pages loss
Subsystems (6)
PATCH v3 1/1 NUMA:Improve the efficiency of calculating pages loss
The number of pages in memblock that doesn't have the node assigned,which also means that these pages are not in numa_info. So these pages can represent the number of lose pages.
V2:https://lore.kernel.org/all/[email protected]/ V1:https://lore.kernel.org/all/[email protected]/
Signed-off-by Liam Ni <[email protected]>
--- arch/loongarch/kernel/numa.c | 23 ++++++++--------------- arch/x86/mm/numa.c | 26 +++++++------------------- include/linux/mm.h | 1 + mm/mm_init.c | 20 ++++++++++++++++++++ 4 files changed, 36 insertions(+), 34 deletions(-)
arch/loongarch/kernel/numa.c +8 -15
@@ -262,25 +262,18 @@ static void __init node_mem_init(unsigned int node)* Sanity check to catch more bad NUMA configurations (they are amazingly * common). Make sure the nodes cover all memory. */ -static bool __init numa_meminfo_cover_memory (const struct numa_meminfo *mi) +static bool __init memblock_validate_numa_coverage (const u64 limit) { -int i; -u64 numaram, biosram; +u64 lo_pg; - numaram =0 ; -for (i =0 ; i < mi->nr_blks; i++) { -u64 s = mi->blk[i].start >>PAGE_SHIFT ; -u64 e = mi->blk[i].end >>PAGE_SHIFT ; + lo_pg = max_pfn -calculate_without_node_pages_in_range (); - numaram += e - s; - numaram -=__absent_pages_in_range (mi->blk[i].nid, s, e); -if ((s64 )numaram <0 ) - numaram =0 ; +/* We seem to lose 3 pages somewhere. Allow 1M of slack. */ +if (lo_pg >= limit) { +pr_err ("NUMA: We lost 1m size page.\n" ); +return false; } - max_pfn = max_low_pfn; - biosram = max_pfn -absent_pages_in_range (0 , max_pfn); -BUG_ON ((s64)(biosram - numaram) >= (1 << (20 -PAGE_SHIFT )));return true; }
@@ -428,7 +421,7 @@ int __init init_numa_memory(void)return -EINVAL ;init_node_memblock (); -if (numa_meminfo_cover_memory (&numa_meminfo) == false) +if (memblock_validate_numa_coverage (SZ_1M ) == false)return -EINVAL ;for_each_node_mask (node, node_possible_map) {
arch/x86/mm/numa.c +7 -19
@@ -451,30 +451,18 @@ EXPORT_SYMBOL(__node_distance);* Sanity check to catch more bad NUMA configurations (they are amazingly * common). Make sure the nodes cover all memory. */ -static bool __init numa_meminfo_cover_memory (const struct numa_meminfo *mi) +static bool __init memblock_validate_numa_coverage (const u64 limit) { -u64 numaram, e820ram; -int i; +u64 lo_pg; - numaram =0 ; -for (i =0 ; i < mi->nr_blks; i++) { -u64 s = mi->blk[i].start >>PAGE_SHIFT ; -u64 e = mi->blk[i].end >>PAGE_SHIFT ; - numaram += e - s; - numaram -=__absent_pages_in_range (mi->blk[i].nid, s, e); -if ((s64 )numaram <0 ) - numaram =0 ; - } - - e820ram = max_pfn -absent_pages_in_range (0 , max_pfn); + lo_pg = max_pfn -calculate_without_node_pages_in_range ();/* We seem to lose 3 pages somewhere. Allow 1M of slack. */ -if ((s64)(e820ram - numaram) >= (1 << (20 -PAGE_SHIFT ))) { -printk (KERN_ERR "NUMA: nodes only cover %LuMB of your %LuMB e820 RAM. Not used.\n" , - (numaram <<PAGE_SHIFT ) >>20 , - (e820ram <<PAGE_SHIFT ) >>20 ); +if (lo_pg >= limit) { +pr_err ("NUMA: We lost 1m size page.\n" );return false; } +return true; }
@@ -583,7 +571,7 @@ static int __init numa_register_memblks(struct numa_meminfo *mi)return -EINVAL ; } } -if (!numa_meminfo_cover_memory (mi)) +if (!memblock_validate_numa_coverage (SZ_1M ))return -EINVAL ;/* Finally register nodes. */
include/linux/mm.h +1 -0
@@ -3043,6 +3043,7 @@ unsigned long __absent_pages_in_range(int nid, unsigned long start_pfn, unsigned long end_pfn);extern unsigned long absent_pages_in_range (unsigned long start_pfn,unsigned long end_pfn); +extern unsigned long calculate_without_node_pages_in_range (void );extern void get_pfn_range_for_nid (unsigned int nid,unsigned long *start_pfn,unsigned long *end_pfn);
mm/mm_init.c +20 -0
@@ -1132,6 +1132,26 @@ static void __init adjust_zone_range_for_zone_movable(int nid, } } +/** +* @start_pfn: The start PFN to start searching for holes +* @end_pfn: The end PFN to stop searching for holes +* +* Return: Return the number of page frames without node assigned within a range. +*/ +unsigned long __init calculate_without_node_pages_in_range (void ) +{ +unsigned long num_pages; +unsigned long start_pfn, end_pfn; +int nid, i; + +for_each_mem_pfn_range (i,MAX_NUMNODES , &start_pfn, &end_pfn, &nid) { +if (nid ==NUMA_NO_NODE ) + num_pages += end_pfn - start_pfn; + } + +return num_pages; +} +/* * Return the number of holes in a range on a node. If nid is MAX_NUMNODES, * then all holes in the requested range will be accounted for.
Signature · 1 line
2.25.1
Friendly ping
Quoted 158 lines · Liam Ni
The number of pages in memblock that doesn't have the node assigned,which also means that these pages are not in
numa_info. So these pages can represent the number of lose pages.V2:https://lore.kernel.org/all/[email protected]/ V1:https://lore.kernel.org/all/[email protected]/
Signed-off-by Liam Ni <[email protected]>--- arch/loongarch/kernel/numa.c | 23 ++++++++--------------- arch/x86/mm/numa.c | 26 +++++++------------------- include/linux/mm.h | 1 + mm/mm_init.c | 20 ++++++++++++++++++++ 4 files changed, 36 insertions(+), 34 deletions(-)arch/loongarch/kernel/numa.c +8
-15@@ -262,25 +262,18 @@ static void __init node_mem_init(unsigned int node)* Sanity check to catch more bad NUMA configurations (they are amazingly * common). Make sure the nodes cover all memory. */ -static bool __init numa_meminfo_cover_memory (const struct numa_meminfo *mi) +static bool __init memblock_validate_numa_coverage (const u64 limit) { -int i; -u64 numaram, biosram; +u64 lo_pg; - numaram =0 ; -for (i =0 ; i < mi->nr_blks; i++) { -u64 s = mi->blk[i].start >>PAGE_SHIFT ; -u64 e = mi->blk[i].end >>PAGE_SHIFT ; + lo_pg = max_pfn -calculate_without_node_pages_in_range (); - numaram += e - s; - numaram -=__absent_pages_in_range (mi->blk[i].nid, s, e); -if ((s64 )numaram <0 ) - numaram =0 ; +/* We seem to lose 3 pages somewhere. Allow 1M of slack. */ +if (lo_pg >= limit) { +pr_err ("NUMA: We lost 1m size page.\n" ); +return false; } - max_pfn = max_low_pfn; - biosram = max_pfn -absent_pages_in_range (0 , max_pfn); -BUG_ON ((s64)(biosram - numaram) >= (1 << (20 -PAGE_SHIFT )));return true; }@@ -428,7 +421,7 @@ int __init init_numa_memory(void)return -EINVAL ;init_node_memblock (); -if (numa_meminfo_cover_memory (&numa_meminfo) == false) +if (memblock_validate_numa_coverage (SZ_1M ) == false)return -EINVAL ;for_each_node_mask (node, node_possible_map) {arch/x86/mm/numa.c +7
-19@@ -451,30 +451,18 @@ EXPORT_SYMBOL(__node_distance);* Sanity check to catch more bad NUMA configurations (they are amazingly * common). Make sure the nodes cover all memory. */ -static bool __init numa_meminfo_cover_memory (const struct numa_meminfo *mi) +static bool __init memblock_validate_numa_coverage (const u64 limit) { -u64 numaram, e820ram; -int i; +u64 lo_pg; - numaram =0 ; -for (i =0 ; i < mi->nr_blks; i++) { -u64 s = mi->blk[i].start >>PAGE_SHIFT ; -u64 e = mi->blk[i].end >>PAGE_SHIFT ; - numaram += e - s; - numaram -=__absent_pages_in_range (mi->blk[i].nid, s, e); -if ((s64 )numaram <0 ) - numaram =0 ; - } - - e820ram = max_pfn -absent_pages_in_range (0 , max_pfn); + lo_pg = max_pfn -calculate_without_node_pages_in_range ();/* We seem to lose 3 pages somewhere. Allow 1M of slack. */ -if ((s64)(e820ram - numaram) >= (1 << (20 -PAGE_SHIFT ))) { -printk (KERN_ERR "NUMA: nodes only cover %LuMB of your %LuMB e820 RAM. Not used.\n" , - (numaram <<PAGE_SHIFT ) >>20 , - (e820ram <<PAGE_SHIFT ) >>20 ); +if (lo_pg >= limit) { +pr_err ("NUMA: We lost 1m size page.\n" );return false; } +return true; }@@ -583,7 +571,7 @@ static int __init numa_register_memblks(struct numa_meminfo *mi)return -EINVAL ; } } -if (!numa_meminfo_cover_memory (mi)) +if (!memblock_validate_numa_coverage (SZ_1M ))return -EINVAL ;/* Finally register nodes. */ include/linux/mm.h +1
-0@@ -3043,6 +3043,7 @@ unsigned long __absent_pages_in_range(int nid, unsigned long start_pfn, unsigned long end_pfn);extern unsigned long absent_pages_in_range (unsigned long start_pfn,unsigned long end_pfn); +extern unsigned long calculate_without_node_pages_in_range (void );extern void get_pfn_range_for_nid (unsigned int nid,unsigned long *start_pfn,unsigned long *end_pfn);mm/mm_init.c +20
-1@@ -1132,6 +1132,26 @@ static void __init adjust_zone_range_for_zone_movable(int nid, } } +/** +* @start_pfn: The start PFN to start searching for holes +* @end_pfn: The end PFN to stop searching for holes +* +* Return: Return the number of page frames without node assigned within a range. +*/ +unsigned long __init calculate_without_node_pages_in_range (void ) +{ +unsigned long num_pages; +unsigned long start_pfn, end_pfn; +int nid, i; + +for_each_mem_pfn_range (i,MAX_NUMNODES , &start_pfn, &end_pfn, &nid) { +if (nid ==NUMA_NO_NODE ) + num_pages += end_pfn - start_pfn; + } + +return num_pages; +} +/* * Return the number of holes in a range on a node. If nid is MAX_NUMNODES, * then all holes in the requested range will be accounted for. -- 2.25.1