mm: make mem_map allocation continuous

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <git-commits-head@...>
Date: Saturday, April 26, 2008 - 6:01 pm

Gitweb:     http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=e123dd...
Commit:     e123dd3f0ec1664576456ea1ea045591a0a95f0c
Parent:     539a5fe22620a1665cce504167953a71a43232ad
Author:     Yinghai Lu <yhlu.kernel@gmail.com>
AuthorDate: Sun Apr 13 11:51:06 2008 -0700
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Sat Apr 26 22:51:07 2008 +0200

    mm: make mem_map allocation continuous
    
    vmemmap allocation currently has this layout:
    
     [ffffe20000000000-ffffe200001fffff] PMD ->ffff810001400000 on node 0
     [ffffe20000200000-ffffe200003fffff] PMD ->ffff810001800000 on node 0
     [ffffe20000400000-ffffe200005fffff] PMD ->ffff810001c00000 on node 0
     [ffffe20000600000-ffffe200007fffff] PMD ->ffff810002000000 on node 0
     [ffffe20000800000-ffffe200009fffff] PMD ->ffff810002400000 on node 0
    ...
    
    note that there is a 2M hole between them - not optimal.
    
    the root cause is that usemap (24 bytes) will be allocated after every 2M
    mem_map, and it will push next vmemmap (2M) to the next (2M) alignment.
    
    solution: try to allocate the mem_map continously.
    
    after the patch, we get:
    
     [ffffe20000000000-ffffe200001fffff] PMD ->ffff810001400000 on node 0
     [ffffe20000200000-ffffe200003fffff] PMD ->ffff810001600000 on node 0
     [ffffe20000400000-ffffe200005fffff] PMD ->ffff810001800000 on node 0
     [ffffe20000600000-ffffe200007fffff] PMD ->ffff810001a00000 on node 0
     [ffffe20000800000-ffffe200009fffff] PMD ->ffff810001c00000 on node 0
    ...
    
    which is the ideal layout.
    
    and usemap will share a page because of they are allocated continuously too:
    
    sparse_early_usemap_alloc: usemap = ffff810024e00000 size = 24
    sparse_early_usemap_alloc: usemap = ffff810024e00080 size = 24
    sparse_early_usemap_alloc: usemap = ffff810024e00100 size = 24
    sparse_early_usemap_alloc: usemap = ffff810024e00180 size = 24
    ...
    
    so we make the bootmem allocation more compact and use less memory
    for usemap => mission accomplished ;-)
    
    Signed-off-by: Yinghai Lu <yhlu.kernel@gmail.com>
    Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 mm/sparse.c |   32 +++++++++++++++++++++++++++++---
 1 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/mm/sparse.c b/mm/sparse.c
index 98d6b39..458109b 100644
--- a/mm/sparse.c
+++ b/mm/sparse.c
@@ -304,22 +304,48 @@ void __init sparse_init(void)
 	unsigned long pnum;
 	struct page *map;
 	unsigned long *usemap;
+	unsigned long **usemap_map;
+	int size;
+
+	/*
+	 * map is using big page (aka 2M in x86 64 bit)
+	 * usemap is less one page (aka 24 bytes)
+	 * so alloc 2M (with 2M align) and 24 bytes in turn will
+	 * make next 2M slip to one more 2M later.
+	 * then in big system, the memory will have a lot of holes...
+	 * here try to allocate 2M pages continously.
+	 *
+	 * powerpc need to call sparse_init_one_section right after each
+	 * sparse_early_mem_map_alloc, so allocate usemap_map at first.
+	 */
+	size = sizeof(unsigned long *) * NR_MEM_SECTIONS;
+	usemap_map = alloc_bootmem(size);
+	if (!usemap_map)
+		panic("can not allocate usemap_map\n");
 
 	for (pnum = 0; pnum < NR_MEM_SECTIONS; pnum++) {
 		if (!present_section_nr(pnum))
 			continue;
+		usemap_map[pnum] = sparse_early_usemap_alloc(pnum);
+	}
 
-		map = sparse_early_mem_map_alloc(pnum);
-		if (!map)
+	for (pnum = 0; pnum < NR_MEM_SECTIONS; pnum++) {
+		if (!present_section_nr(pnum))
 			continue;
 
-		usemap = sparse_early_usemap_alloc(pnum);
+		usemap = usemap_map[pnum];
 		if (!usemap)
 			continue;
 
+		map = sparse_early_mem_map_alloc(pnum);
+		if (!map)
+			continue;
+
 		sparse_init_one_section(__nr_to_section(pnum), pnum, map,
 								usemap);
 	}
+
+	free_bootmem(__pa(usemap_map), size);
 }
 
 #ifdef CONFIG_MEMORY_HOTPLUG
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
mm: make mem_map allocation continuous, Linux Kernel Mailing List..., (Sat Apr 26, 6:01 pm)