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 /mm/sparse.c | |
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>
Diffstat (limited to 'mm/sparse.c')
-rw-r--r-- | mm/sparse.c | 17 |
1 files changed, 11 insertions, 6 deletions
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) |