diff options
author | Kirill A. Shutemov <kirill.shutemov@linux.intel.com> | 2017-09-29 10:08:16 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2017-10-20 07:07:09 -0400 |
commit | 83e3c48729d9ebb7af5a31a504f3fd6aff0348c4 (patch) | |
tree | 9e42ac40f3bb837359325e0b247ec8e16c1c0b52 | |
parent | 967535223f9a8d95c187a8728480b569164cd4f4 (diff) |
mm/sparsemem: Allocate mem_section at runtime for CONFIG_SPARSEMEM_EXTREME=y
Size of the mem_section[] array depends on the size of the physical address space.
In preparation for boot-time switching between paging modes on x86-64
we need to make the allocation of mem_section[] dynamic, because otherwise
we waste a lot of RAM: with CONFIG_NODE_SHIFT=10, mem_section[] size is 32kB
for 4-level paging and 2MB for 5-level paging mode.
The patch allocates the array on the first call to sparse_memory_present_with_active_regions().
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@suse.de>
Cc: Cyrill Gorcunov <gorcunov@openvz.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-mm@kvack.org
Link: http://lkml.kernel.org/r/20170929140821.37654-2-kirill.shutemov@linux.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r-- | include/linux/mmzone.h | 6 | ||||
-rw-r--r-- | mm/page_alloc.c | 10 | ||||
-rw-r--r-- | mm/sparse.c | 17 |
3 files changed, 26 insertions, 7 deletions
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index c8f89417740b..e796edf1296f 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h | |||
@@ -1150,13 +1150,17 @@ struct mem_section { | |||
1150 | #define SECTION_ROOT_MASK (SECTIONS_PER_ROOT - 1) | 1150 | #define SECTION_ROOT_MASK (SECTIONS_PER_ROOT - 1) |
1151 | 1151 | ||
1152 | #ifdef CONFIG_SPARSEMEM_EXTREME | 1152 | #ifdef CONFIG_SPARSEMEM_EXTREME |
1153 | extern struct mem_section *mem_section[NR_SECTION_ROOTS]; | 1153 | extern struct mem_section **mem_section; |
1154 | #else | 1154 | #else |
1155 | extern struct mem_section mem_section[NR_SECTION_ROOTS][SECTIONS_PER_ROOT]; | 1155 | extern struct mem_section mem_section[NR_SECTION_ROOTS][SECTIONS_PER_ROOT]; |
1156 | #endif | 1156 | #endif |
1157 | 1157 | ||
1158 | static inline struct mem_section *__nr_to_section(unsigned long nr) | 1158 | static inline struct mem_section *__nr_to_section(unsigned long nr) |
1159 | { | 1159 | { |
1160 | #ifdef CONFIG_SPARSEMEM_EXTREME | ||
1161 | if (!mem_section) | ||
1162 | return NULL; | ||
1163 | #endif | ||
1160 | if (!mem_section[SECTION_NR_TO_ROOT(nr)]) | 1164 | if (!mem_section[SECTION_NR_TO_ROOT(nr)]) |
1161 | return NULL; | 1165 | return NULL; |
1162 | return &mem_section[SECTION_NR_TO_ROOT(nr)][nr & SECTION_ROOT_MASK]; | 1166 | return &mem_section[SECTION_NR_TO_ROOT(nr)][nr & SECTION_ROOT_MASK]; |
diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 77e4d3c5c57b..8dfd13f724d9 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c | |||
@@ -5646,6 +5646,16 @@ void __init sparse_memory_present_with_active_regions(int nid) | |||
5646 | unsigned long start_pfn, end_pfn; | 5646 | unsigned long start_pfn, end_pfn; |
5647 | int i, this_nid; | 5647 | int i, this_nid; |
5648 | 5648 | ||
5649 | #ifdef CONFIG_SPARSEMEM_EXTREME | ||
5650 | if (!mem_section) { | ||
5651 | unsigned long size, align; | ||
5652 | |||
5653 | size = sizeof(struct mem_section) * NR_SECTION_ROOTS; | ||
5654 | align = 1 << (INTERNODE_CACHE_SHIFT); | ||
5655 | mem_section = memblock_virt_alloc(size, align); | ||
5656 | } | ||
5657 | #endif | ||
5658 | |||
5649 | for_each_mem_pfn_range(i, nid, &start_pfn, &end_pfn, &this_nid) | 5659 | for_each_mem_pfn_range(i, nid, &start_pfn, &end_pfn, &this_nid) |
5650 | memory_present(this_nid, start_pfn, end_pfn); | 5660 | memory_present(this_nid, start_pfn, end_pfn); |
5651 | } | 5661 | } |
diff --git a/mm/sparse.c b/mm/sparse.c index 83b3bf6461af..b00a97398795 100644 --- a/mm/sparse.c +++ b/mm/sparse.c | |||
@@ -22,8 +22,7 @@ | |||
22 | * 1) mem_section - memory sections, mem_map's for valid memory | 22 | * 1) mem_section - memory sections, mem_map's for valid memory |
23 | */ | 23 | */ |
24 | #ifdef CONFIG_SPARSEMEM_EXTREME | 24 | #ifdef CONFIG_SPARSEMEM_EXTREME |
25 | struct mem_section *mem_section[NR_SECTION_ROOTS] | 25 | struct mem_section **mem_section; |
26 | ____cacheline_internodealigned_in_smp; | ||
27 | #else | 26 | #else |
28 | struct mem_section mem_section[NR_SECTION_ROOTS][SECTIONS_PER_ROOT] | 27 | struct mem_section mem_section[NR_SECTION_ROOTS][SECTIONS_PER_ROOT] |
29 | ____cacheline_internodealigned_in_smp; | 28 | ____cacheline_internodealigned_in_smp; |
@@ -100,7 +99,7 @@ static inline int sparse_index_init(unsigned long section_nr, int nid) | |||
100 | int __section_nr(struct mem_section* ms) | 99 | int __section_nr(struct mem_section* ms) |
101 | { | 100 | { |
102 | unsigned long root_nr; | 101 | unsigned long root_nr; |
103 | struct mem_section* root; | 102 | struct mem_section *root = NULL; |
104 | 103 | ||
105 | for (root_nr = 0; root_nr < NR_SECTION_ROOTS; root_nr++) { | 104 | for (root_nr = 0; root_nr < NR_SECTION_ROOTS; root_nr++) { |
106 | root = __nr_to_section(root_nr * SECTIONS_PER_ROOT); | 105 | root = __nr_to_section(root_nr * SECTIONS_PER_ROOT); |
@@ -111,7 +110,7 @@ int __section_nr(struct mem_section* ms) | |||
111 | break; | 110 | break; |
112 | } | 111 | } |
113 | 112 | ||
114 | VM_BUG_ON(root_nr == NR_SECTION_ROOTS); | 113 | VM_BUG_ON(!root); |
115 | 114 | ||
116 | return (root_nr * SECTIONS_PER_ROOT) + (ms - root); | 115 | return (root_nr * SECTIONS_PER_ROOT) + (ms - root); |
117 | } | 116 | } |
@@ -329,11 +328,17 @@ again: | |||
329 | static void __init check_usemap_section_nr(int nid, unsigned long *usemap) | 328 | static void __init check_usemap_section_nr(int nid, unsigned long *usemap) |
330 | { | 329 | { |
331 | unsigned long usemap_snr, pgdat_snr; | 330 | unsigned long usemap_snr, pgdat_snr; |
332 | static unsigned long old_usemap_snr = NR_MEM_SECTIONS; | 331 | static unsigned long old_usemap_snr; |
333 | static unsigned long old_pgdat_snr = NR_MEM_SECTIONS; | 332 | static unsigned long old_pgdat_snr; |
334 | struct pglist_data *pgdat = NODE_DATA(nid); | 333 | struct pglist_data *pgdat = NODE_DATA(nid); |
335 | int usemap_nid; | 334 | int usemap_nid; |
336 | 335 | ||
336 | /* First call */ | ||
337 | if (!old_usemap_snr) { | ||
338 | old_usemap_snr = NR_MEM_SECTIONS; | ||
339 | old_pgdat_snr = NR_MEM_SECTIONS; | ||
340 | } | ||
341 | |||
337 | usemap_snr = pfn_to_section_nr(__pa(usemap) >> PAGE_SHIFT); | 342 | usemap_snr = pfn_to_section_nr(__pa(usemap) >> PAGE_SHIFT); |
338 | pgdat_snr = pfn_to_section_nr(__pa(pgdat) >> PAGE_SHIFT); | 343 | pgdat_snr = pfn_to_section_nr(__pa(pgdat) >> PAGE_SHIFT); |
339 | if (usemap_snr == pgdat_snr) | 344 | if (usemap_snr == pgdat_snr) |