summaryrefslogtreecommitdiffstats
path: root/mm/sparse-vmemmap.c
diff options
context:
space:
mode:
authorBaoquan He <bhe@redhat.com>2018-08-17 18:48:49 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-08-17 19:20:31 -0400
commitc98aff649349d9147915a19d378c9c3c1bd85de0 (patch)
tree5af2720e65d8360b66d6b736b3f89a5a58f83589 /mm/sparse-vmemmap.c
parent9258631b33374f20d856032c3542b76ad7f5a312 (diff)
mm/sparse: optimize memmap allocation during sparse_init()
In sparse_init(), two temporary pointer arrays, usemap_map and map_map are allocated with the size of NR_MEM_SECTIONS. They are used to store each memory section's usemap and mem map if marked as present. With the help of these two arrays, continuous memory chunk is allocated for usemap and memmap for memory sections on one node. This avoids too many memory fragmentations. Like below diagram, '1' indicates the present memory section, '0' means absent one. The number 'n' could be much smaller than NR_MEM_SECTIONS on most of systems. |1|1|1|1|0|0|0|0|1|1|0|0|...|1|0||1|0|...|1||0|1|...|0| ------------------------------------------------------- 0 1 2 3 4 5 i i+1 n-1 n If we fail to populate the page tables to map one section's memmap, its ->section_mem_map will be cleared finally to indicate that it's not present. After use, these two arrays will be released at the end of sparse_init(). In 4-level paging mode, each array costs 4M which can be ignorable. While in 5-level paging, they costs 256M each, 512M altogether. Kdump kernel Usually only reserves very few memory, e.g 256M. So, even thouth they are temporarily allocated, still not acceptable. In fact, there's no need to allocate them with the size of NR_MEM_SECTIONS. Since the ->section_mem_map clearing has been deferred to the last, the number of present memory sections are kept the same during sparse_init() until we finally clear out the memory section's ->section_mem_map if its usemap or memmap is not correctly handled. Thus in the middle whenever for_each_present_section_nr() loop is taken, the i-th present memory section is always the same one. Here only allocate usemap_map and map_map with the size of 'nr_present_sections'. For the i-th present memory section, install its usemap and memmap to usemap_map[i] and mam_map[i] during allocation. Then in the last for_each_present_section_nr() loop which clears the failed memory section's ->section_mem_map, fetch usemap and memmap from usemap_map[] and map_map[] array and set them into mem_section[] accordingly. [akpm@linux-foundation.org: coding-style fixes] Link: http://lkml.kernel.org/r/20180628062857.29658-5-bhe@redhat.com Signed-off-by: Baoquan He <bhe@redhat.com> Reviewed-by: Pavel Tatashin <pasha.tatashin@oracle.com> Cc: Pasha Tatashin <Pavel.Tatashin@microsoft.com> Cc: Dave Hansen <dave.hansen@intel.com> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Oscar Salvador <osalvador@techadventures.net> Cc: Pankaj Gupta <pagupta@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/sparse-vmemmap.c')
-rw-r--r--mm/sparse-vmemmap.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
index 68bb65b2d34d..95e2c7638a5c 100644
--- a/mm/sparse-vmemmap.c
+++ b/mm/sparse-vmemmap.c
@@ -281,6 +281,7 @@ void __init sparse_mem_maps_populate_node(struct page **map_map,
281 unsigned long pnum; 281 unsigned long pnum;
282 unsigned long size = sizeof(struct page) * PAGES_PER_SECTION; 282 unsigned long size = sizeof(struct page) * PAGES_PER_SECTION;
283 void *vmemmap_buf_start; 283 void *vmemmap_buf_start;
284 int nr_consumed_maps = 0;
284 285
285 size = ALIGN(size, PMD_SIZE); 286 size = ALIGN(size, PMD_SIZE);
286 vmemmap_buf_start = __earlyonly_bootmem_alloc(nodeid, size * map_count, 287 vmemmap_buf_start = __earlyonly_bootmem_alloc(nodeid, size * map_count,
@@ -295,8 +296,9 @@ void __init sparse_mem_maps_populate_node(struct page **map_map,
295 if (!present_section_nr(pnum)) 296 if (!present_section_nr(pnum))
296 continue; 297 continue;
297 298
298 map_map[pnum] = sparse_mem_map_populate(pnum, nodeid, NULL); 299 map_map[nr_consumed_maps] =
299 if (map_map[pnum]) 300 sparse_mem_map_populate(pnum, nodeid, NULL);
301 if (map_map[nr_consumed_maps++])
300 continue; 302 continue;
301 pr_err("%s: sparsemem memory map backing failed some memory will not be available\n", 303 pr_err("%s: sparsemem memory map backing failed some memory will not be available\n",
302 __func__); 304 __func__);