Skip to contentSkip to conversation

use lmb with x86

PATCH In review Yinghai Lu 5 participants 20 messages Mar 23, 2010 – Mar 24, 2010

Subsystems (9)
lore
Share & tools
lore

Yinghai Lu

author
#0 lore raw

cover use lmb with x86

extend lmb to have find_lmb_area()

Thanks

Yinghai

author
#1 lore raw

PATCH 1/4 x86: do not free zero sized per cpu areas

From: Ian Campbell <[email protected]>

This avoids an infinite loop in free_early_partial().

Add a warning to free_early_partial to catch future problems.

-v5: put back start > end back into WARN_ONCE() -v6: use one line for if according to linus

---
 kernel/early_res.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
kernel/early_res.c +6 -0
index 3cb2c66..69bed5b 100644
@@ -333,6 +333,12 @@ void __init free_early_partial(u64 start, u64 end)
 	struct early_res *r;
 	int i;
 
+	if (start == end)
+		return;
+
+	if (WARN_ONCE(start > end, "free_early_partial: wrong range [%#llx, %#llx]\n", start, end))
+		return;
+
 try_next:
 	i = find_overlapped_early(start, end);
 	if (i >= max_early_res)
Signature · 1 line
1.6.4.2
author
#2 lore raw

PATCH 2/4 x86: add find_e820_area_node

In reply to Yinghai Lu

David Miller pointed out that early_res have problem to find node data on correct node when we have
node0: [0, 2g), [4g, 6g), [10g, 14g)
node1: [6g, 10g), [14g, 18g)
the cross node case

the problem is there for x86 bits even before we are using early_res for bootmem replacement. after early_res for bootmem replacement, alloc_bootmem_node still can get range on correct node

this patch is fixing problem before bootmem or early_res replacement for bootmem.

now only user is for x86 64bit numa to find node data.

the point is use early_node_map with find_e820_area_node()

---
 arch/x86/include/asm/e820.h |    1 +
 arch/x86/kernel/e820.c      |   15 +++++++++++++++
 arch/x86/mm/numa_64.c       |    4 ++--
 include/linux/mm.h          |    2 ++
 mm/page_alloc.c             |   37 +++++++++++++++++++++++--------------
 5 files changed, 43 insertions(+), 16 deletions(-)
arch/x86/include/asm/e820.h +1 -0
index ec8a52d..41553af 100644
@@ -116,6 +116,7 @@ extern unsigned long end_user_pfn;
 
 extern u64 find_e820_area(u64 start, u64 end, u64 size, u64 align);
 extern u64 find_e820_area_size(u64 start, u64 *sizep, u64 align);
+u64 find_e820_area_node(int nid, u64 start, u64 end, u64 size, u64 align);
 extern u64 early_reserve_e820(u64 startt, u64 sizet, u64 align);
 #include <linux/early_res.h>
 
arch/x86/kernel/e820.c +15 -0
index 740b440..05ee724 100644
@@ -787,6 +787,21 @@ u64 __init find_e820_area_size(u64 start, u64 *sizep, u64 align)
 	return -1ULL;
 }
 
+u64 __init find_e820_area_node(int nid, u64 start, u64 end, u64 size, u64 align)
+{
+	u64 addr;
+	/*
+	 * need to call this function after e820_register_active_regions
+	 * so early_node_map[] is set
+	 */
+	addr = find_memory_core_early(nid, size, align, start, end);
+	if (addr != -1ULL)
+		return addr;
+
+	/* fallback, should already have start end in the node range */
+	return find_e820_area(start, end, size, align);
+}
+
 /*
  * pre allocated 4k and reserved it in e820
  */
arch/x86/mm/numa_64.c +2 -2
index 8948f47..ffc5ad5 100644
@@ -174,7 +174,7 @@ static void * __init early_node_mem(int nodeid, unsigned long start,
 	if (start < (MAX_DMA32_PFN<<PAGE_SHIFT) &&
 	    end > (MAX_DMA32_PFN<<PAGE_SHIFT))
 		start = MAX_DMA32_PFN<<PAGE_SHIFT;
-	mem = find_e820_area(start, end, size, align);
+	mem = find_e820_area_node(nodeid, start, end, size, align);
 	if (mem != -1L)
 		return __va(mem);
 
@@ -184,7 +184,7 @@ static void * __init early_node_mem(int nodeid, unsigned long start,
 		start = MAX_DMA32_PFN<<PAGE_SHIFT;
 	else
 		start = MAX_DMA_PFN<<PAGE_SHIFT;
-	mem = find_e820_area(start, end, size, align);
+	mem = find_e820_area_node(nodeid, start, end, size, align);
 	if (mem != -1L)
 		return __va(mem);
 
include/linux/mm.h +2 -0
index e70f21b..5c2d17e 100644
@@ -1160,6 +1160,8 @@ extern void free_bootmem_with_active_regions(int nid,
 						unsigned long max_low_pfn);
 int add_from_early_node_map(struct range *range, int az,
 				   int nr_range, int nid);
+u64 __init find_memory_core_early(int nid, u64 size, u64 align,
+					u64 goal, u64 limit);
 void *__alloc_memory_core_early(int nodeid, u64 size, u64 align,
 				 u64 goal, u64 limit);
 typedef int (*work_fn_t)(unsigned long, unsigned long, void *);
mm/page_alloc.c +23 -14
index d03c946..eef3757 100644
@@ -3408,12 +3408,11 @@ int __init add_from_early_node_map(struct range *range, int az,
 	return nr_range;
 }
 
-#ifdef CONFIG_NO_BOOTMEM
-void * __init __alloc_memory_core_early(int nid, u64 size, u64 align,
+#ifdef CONFIG_HAVE_EARLY_RES
+u64 __init find_memory_core_early(int nid, u64 size, u64 align,
 					u64 goal, u64 limit)
 {
 	int i;
-	void *ptr;
 
 	/* need to go over early_node_map to find out good range for node */
 	for_each_active_range_index_in_nid(i, nid) {
@@ -3430,20 +3429,30 @@ void * __init __alloc_memory_core_early(int nid, u64 size, u64 align,
 		if (addr == -1ULL)
 			continue;
 
-#if 0
-		printk(KERN_DEBUG "alloc (nid=%d %llx - %llx) (%llx - %llx) %llx %llx => %llx\n",
-				nid,
-				ei_start, ei_last, goal, limit, size,
-				align, addr);
+		return addr;
+	}
+
+	return -1ULL;
+}
 #endif
 
-		ptr = phys_to_virt(addr);
-		memset(ptr, 0, size);
-		reserve_early_without_check(addr, addr + size, "BOOTMEM");
-		return ptr;
-	}
+#ifdef CONFIG_NO_BOOTMEM
+void * __init __alloc_memory_core_early(int nid, u64 size, u64 align,
+					u64 goal, u64 limit)
+{
+	void *ptr;
 
-	return NULL;
+	u64 addr;
+
+	addr = find_memory_core_early(nid, size, align, goal, limit);
+
+	if (addr == -1ULL)
+		return NULL;
+
+	ptr = phys_to_virt(addr);
+	memset(ptr, 0, size);
+	reserve_early_without_check(addr, addr + size, "BOOTMEM");
+	return ptr;
 }
 #endif
 
Signature · 1 line
1.6.4.2
author
#3 lore raw

PATCH 3/4 x86: add sanitize_e820_map

In reply to Yinghai Lu

so we could not take e820.map directly.

and could change e820_saved to initdata

---
 arch/x86/include/asm/e820.h |    5 ++---
 arch/x86/kernel/e820.c      |   26 ++++++++++++++++++--------
 arch/x86/kernel/efi.c       |    2 +-
 arch/x86/kernel/setup.c     |   10 +++++-----
 arch/x86/xen/setup.c        |    4 +---
 5 files changed, 27 insertions(+), 20 deletions(-)
arch/x86/include/asm/e820.h +2 -3
index 41553af..01bc987 100644
@@ -75,15 +75,14 @@ struct e820map {
 #ifdef __KERNEL__
 /* see comment in arch/x86/kernel/e820.c */
 extern struct e820map e820;
-extern struct e820map e820_saved;
 
 extern unsigned long pci_mem_start;
 extern int e820_any_mapped(u64 start, u64 end, unsigned type);
 extern int e820_all_mapped(u64 start, u64 end, unsigned type);
 extern void e820_add_region(u64 start, u64 size, int type);
 extern void e820_print_map(char *who);
-extern int
-sanitize_e820_map(struct e820entry *biosmap, int max_nr_map, u32 *pnr_map);
+int sanitize_e820_map(void);
+void save_e820_map(void);
 extern u64 e820_update_range(u64 start, u64 size, unsigned old_type,
 			       unsigned new_type);
 extern u64 e820_remove_range(u64 start, u64 size, unsigned old_type,
arch/x86/kernel/e820.c +18 -8
index 05ee724..0c7143b 100644
@@ -35,7 +35,7 @@
  * next kernel with full memory.
  */
 struct e820map e820;
-struct e820map e820_saved;
+static struct e820map __initdata e820_saved;
 
 /* For PCI or other memory-mapped resources */
 unsigned long pci_mem_start = 0xaeedbabe;
@@ -224,7 +224,7 @@ void __init e820_print_map(char *who)
  *	   ______________________4_
  */
 
-int __init sanitize_e820_map(struct e820entry *biosmap, int max_nr_map,
+static int __init __sanitize_e820_map(struct e820entry *biosmap, int max_nr_map,
 			     u32 *pnr_map)
 {
 	struct change_member {
@@ -383,6 +383,11 @@ int __init sanitize_e820_map(struct e820entry *biosmap, int max_nr_map,
 	return 0;
 }
 
+int __init sanitize_e820_map(void)
+{
+	return __sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
+}
+
 static int __init __append_e820_map(struct e820entry *biosmap, int nr_map)
 {
 	while (nr_map) {
@@ -555,7 +560,7 @@ void __init update_e820(void)
 	u32 nr_map;
 
 	nr_map = e820.nr_map;
-	if (sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &nr_map))
+	if (__sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &nr_map))
 		return;
 	e820.nr_map = nr_map;
 	printk(KERN_INFO "modified physical RAM map:\n");
@@ -566,7 +571,7 @@ static void __init update_e820_saved(void)
 	u32 nr_map;
 
 	nr_map = e820_saved.nr_map;
-	if (sanitize_e820_map(e820_saved.map, ARRAY_SIZE(e820_saved.map), &nr_map))
+	if (__sanitize_e820_map(e820_saved.map, ARRAY_SIZE(e820_saved.map), &nr_map))
 		return;
 	e820_saved.nr_map = nr_map;
 }
@@ -661,7 +666,7 @@ void __init parse_e820_ext(struct setup_data *sdata, unsigned long pa_data)
 		sdata = early_ioremap(pa_data, map_len);
 	extmap = (struct e820entry *)(sdata->data);
 	__append_e820_map(extmap, entries);
-	sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
+	sanitize_e820_map();
 	if (map_len > PAGE_SIZE)
 		early_iounmap(sdata, map_len);
 	printk(KERN_INFO "extended physical RAM map:\n");
@@ -1043,7 +1048,7 @@ void __init finish_e820_parsing(void)
 	if (userdef) {
 		u32 nr = e820.nr_map;
 
-		if (sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &nr) < 0)
+		if (__sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &nr) < 0)
 			early_panic("Invalid user supplied memory map");
 		e820.nr_map = nr;
 
@@ -1173,7 +1178,7 @@ char *__init default_machine_specific_memory_setup(void)
 	 * the next section from 1mb->appropriate_mem_k
 	 */
 	new_nr = boot_params.e820_entries;
-	sanitize_e820_map(boot_params.e820_map,
+	__sanitize_e820_map(boot_params.e820_map,
 			ARRAY_SIZE(boot_params.e820_map),
 			&new_nr);
 	boot_params.e820_entries = new_nr;
@@ -1200,12 +1205,17 @@ char *__init default_machine_specific_memory_setup(void)
 	return who;
 }
 
+void __init save_e820_map(void)
+{
+	memcpy(&e820_saved, &e820, sizeof(struct e820map));
+}
+
 void __init setup_memory_map(void)
 {
 	char *who;
 
 	who = x86_init.resources.memory_setup();
-	memcpy(&e820_saved, &e820, sizeof(struct e820map));
+	save_e820_map();
 	printk(KERN_INFO "BIOS-provided physical RAM map:\n");
 	e820_print_map(who);
 }
arch/x86/kernel/efi.c +1 -1
index c2fa9b8..299f03f 100644
@@ -272,7 +272,7 @@ static void __init do_add_efi_memmap(void)
 		}
 		e820_add_region(start, size, e820_type);
 	}
-	sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
+	sanitize_e820_map();
 }
 
 void __init efi_reserve_early(void)
arch/x86/kernel/setup.c +5 -5
index 5d7ba1a..3787a82 100644
@@ -461,8 +461,8 @@ static void __init e820_reserve_setup_data(void)
 	if (!found)
 		return;
 
-	sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
-	memcpy(&e820_saved, &e820, sizeof(struct e820map));
+	sanitize_e820_map();
+	save_e820_map();
 	printk(KERN_INFO "extended physical RAM map:\n");
 	e820_print_map("reserve setup_data");
 }
@@ -614,7 +614,7 @@ static int __init dmi_low_memory_corruption(const struct dmi_system_id *d)
 		d->ident);
 
 	e820_update_range(0, 0x10000, E820_RAM, E820_RESERVED);
-	sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
+	sanitize_e820_map();
 
 	return 0;
 }
@@ -683,7 +683,7 @@ static void __init trim_bios_range(void)
 	 * take them out.
 	 */
 	e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
-	sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
+	sanitize_e820_map();
 }
 
 /*
@@ -854,7 +854,7 @@ void __init setup_arch(char **cmdline_p)
 	if (ppro_with_ram_bug()) {
 		e820_update_range(0x70000000ULL, 0x40000ULL, E820_RAM,
 				  E820_RESERVED);
-		sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
+		sanitize_e820_map();
 		printk(KERN_INFO "fixed physical RAM map:\n");
 		e820_print_map("bad_ppro");
 	}
arch/x86/xen/setup.c +1 -3
index ad0047f..3f2c411 100644
@@ -43,8 +43,6 @@ char * __init xen_memory_setup(void)
 
 	max_pfn = min(MAX_DOMAIN_PAGES, max_pfn);
 
-	e820.nr_map = 0;
-
 	e820_add_region(0, PFN_PHYS((u64)max_pfn), E820_RAM);
 
 	/*
@@ -65,7 +63,7 @@ char * __init xen_memory_setup(void)
 		      __pa(xen_start_info->pt_base),
 			"XEN START INFO");
 
-	sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
+	sanitize_e820_map();
 
 	return "Xen";
 }
Signature · 1 line
1.6.4.2
author
#4 lore raw

RFC PATCH 4/4 x86: use lmb to replace early_res

In reply to Yinghai Lu

still keep kernel/early_res.c for the extension.

should move those file to lib/lmb.c later?

-v2: fix NO_BOOTMEM hang with printk

---
 arch/x86/Kconfig               |    1 +
 arch/x86/include/asm/e820.h    |   38 ++-
 arch/x86/include/asm/lmb.h     |    8 +
 arch/x86/kernel/e820.c         |  163 ++----------
 arch/x86/kernel/head.c         |    2 +-
 arch/x86/kernel/head32.c       |    4 +-
 arch/x86/kernel/head64.c       |    2 +
 arch/x86/kernel/setup.c        |    2 +
 arch/x86/kernel/setup_percpu.c |    6 -
 include/linux/early_res.h      |    9 +-
 include/linux/lmb.h            |    5 +-
 kernel/early_res.c             |  593 +++++++++++++++------------------------
 lib/lmb.c                      |   11 +-
 mm/page_alloc.c                |    2 +-
 mm/sparse-vmemmap.c            |    4 +-
 15 files changed, 317 insertions(+), 533 deletions(-)
 create mode 100644 arch/x86/include/asm/lmb.h
arch/x86/Kconfig +1 -0
index 6a80bce..585f611 100644
@@ -27,6 +27,7 @@ config X86
 	select HAVE_PERF_EVENTS if (!M386 && !M486)
 	select HAVE_IOREMAP_PROT
 	select HAVE_KPROBES
+	select HAVE_LMB
 	select ARCH_WANT_OPTIONAL_GPIOLIB
 	select ARCH_WANT_FRAME_POINTERS
 	select HAVE_DMA_ATTRS
arch/x86/include/asm/e820.h +26 -12
index 01bc987..2b57ff6 100644
@@ -113,22 +113,36 @@ static inline void early_memtest(unsigned long start, unsigned long end)
 
 extern unsigned long end_user_pfn;
 
-extern u64 find_e820_area(u64 start, u64 end, u64 size, u64 align);
-extern u64 find_e820_area_size(u64 start, u64 *sizep, u64 align);
-u64 find_e820_area_node(int nid, u64 start, u64 end, u64 size, u64 align);
-extern u64 early_reserve_e820(u64 startt, u64 sizet, u64 align);
 #include <linux/early_res.h>
+static inline u64 find_e820_area(u64 start, u64 end, u64 size, u64 align)
+{
+	return find_lmb_area(start, end, size, align);
+}
+static inline u64 find_e820_area_size(u64 start, u64 *sizep, u64 align)
+{
+	return find_lmb_area_size(start, sizep, align);
+}
+static inline u64
+find_e820_area_node(int nid, u64 start, u64 end, u64 size, u64 align)
+{
+	return find_lmb_area_node(nid, start, end, size, align);
+}
+extern u64 early_reserve_e820(u64 startt, u64 sizet, u64 align);
 
 extern unsigned long e820_end_of_ram_pfn(void);
 extern unsigned long e820_end_of_low_ram_pfn(void);
-extern int e820_find_active_region(const struct e820entry *ei,
-				  unsigned long start_pfn,
-				  unsigned long last_pfn,
-				  unsigned long *ei_startpfn,
-				  unsigned long *ei_endpfn);
-extern void e820_register_active_regions(int nid, unsigned long start_pfn,
-					 unsigned long end_pfn);
-extern u64 e820_hole_size(u64 start, u64 end);
+static inline void e820_register_active_regions(int nid,
+					 unsigned long start_pfn,
+					 unsigned long end_pfn)
+{
+	lmb_register_active_regions(nid, start_pfn, end_pfn);
+}
+static inline u64 e820_hole_size(u64 start, u64 end)
+{
+	return lmb_hole_size(start, end);
+}
+void init_lmb_memory(void);
+void fill_lmb_memory(void);
 extern void finish_e820_parsing(void);
 extern void e820_reserve_resources(void);
 extern void e820_reserve_resources_late(void);
arch/x86/include/asm/lmb.h new file +8 -0
new file mode 100644
index 0000000..d8fbdbd
@@ -0,0 +1,8 @@
+#ifndef _X86_LMB_H
+#define _X86_LMB_H
+
+#define LMB_DBG(fmt...) printk(fmt)
+
+#define LMB_REAL_LIMIT	0
+
+#endif
arch/x86/kernel/e820.c +23 -140

193 lines not on this page · raw message

arch/x86/kernel/head.c +1 -1
index 3e66bd3..e0d0ce5 100644
@@ -51,5 +51,5 @@ void __init reserve_ebda_region(void)
 		lowmem = 0x9f000;
 
 	/* reserve all memory between lowmem and the 1MB mark */
-	reserve_early_overlap_ok(lowmem, 0x100000, "BIOS reserved");
+	reserve_early(lowmem, 0x100000, "BIOS reserved");
 }
arch/x86/kernel/head32.c +3 -1
index adedeef..1b723e3 100644
@@ -29,13 +29,15 @@ static void __init i386_default_early_setup(void)
 
 void __init i386_start_kernel(void)
 {
+
+	init_lmb_memory();
 #ifdef CONFIG_X86_TRAMPOLINE
 	/*
 	 * But first pinch a few for the stack/trampoline stuff
 	 * FIXME: Don't need the extra page at 4K, but need to fix
 	 * trampoline before removing it. (see the GDT stuff)
 	 */
-	reserve_early_overlap_ok(PAGE_SIZE, PAGE_SIZE + PAGE_SIZE,
+	reserve_early(PAGE_SIZE, PAGE_SIZE + PAGE_SIZE,
 					 "EX TRAMPOLINE");
 #endif
 
arch/x86/kernel/head64.c +2 -0
index b5a9896..86e6a9b 100644
@@ -96,6 +96,8 @@ void __init x86_64_start_kernel(char * real_mode_data)
 
 void __init x86_64_start_reservations(char *real_mode_data)
 {
+	init_lmb_memory();
+
 	copy_bootdata(__va(real_mode_data));
 
 	reserve_early(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
arch/x86/kernel/setup.c +2 -0
index 3787a82..d1530f4 100644
@@ -894,6 +894,8 @@ void __init setup_arch(char **cmdline_p)
 	max_pfn_mapped = KERNEL_IMAGE_SIZE >> PAGE_SHIFT;
 #endif
 
+	fill_lmb_memory();
+
 #ifdef CONFIG_X86_CHECK_BIOS_CORRUPTION
 	setup_bios_corruption_check();
 #endif
arch/x86/kernel/setup_percpu.c +0 -6
index ef6370b..35abcb8 100644
@@ -137,13 +137,7 @@ static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size, size_t align)
 
 static void __init pcpu_fc_free(void *ptr, size_t size)
 {
-#ifdef CONFIG_NO_BOOTMEM
-	u64 start = __pa(ptr);
-	u64 end = start + size;
-	free_early_partial(start, end);
-#else
 	free_bootmem(__pa(ptr), size);
-#endif
 }
 
 static int __init pcpu_cpu_distance(unsigned int from, unsigned int to)
include/linux/early_res.h +6 -3
index 29c09f5..991be64 100644
@@ -5,15 +5,18 @@
 extern void reserve_early(u64 start, u64 end, char *name);
 extern void reserve_early_overlap_ok(u64 start, u64 end, char *name);
 extern void free_early(u64 start, u64 end);
-void free_early_partial(u64 start, u64 end);
 extern void early_res_to_bootmem(u64 start, u64 end);
 
-void reserve_early_without_check(u64 start, u64 end, char *name);
 u64 find_early_area(u64 ei_start, u64 ei_last, u64 start, u64 end,
 			 u64 size, u64 align);
 u64 find_early_area_size(u64 ei_start, u64 ei_last, u64 start,
 			 u64 *sizep, u64 align);
-u64 find_fw_memmap_area(u64 start, u64 end, u64 size, u64 align);
+u64 find_lmb_area(u64 start, u64 end, u64 size, u64 align);
+u64 find_lmb_area_size(u64 start, u64 *sizep, u64 align);
+u64 find_lmb_area_node(int nid, u64 start, u64 end, u64 size, u64 align);
+void lmb_register_active_regions(int nid, unsigned long start_pfn,
+					 unsigned long last_pfn);
+u64 lmb_hole_size(u64 start, u64 end);
 u64 get_max_mapped(void);
 #include <linux/range.h>
 int get_free_all_memory_range(struct range **rangep, int nodeid);
include/linux/lmb.h +4 -1
index f3d1433..8799015 100644
@@ -26,7 +26,8 @@ struct lmb_property {
 struct lmb_region {
 	unsigned long cnt;
 	u64 size;
-	struct lmb_property region[MAX_LMB_REGIONS+1];
+	struct lmb_property *region;
+	unsigned long region_array_size;
 };
 
 struct lmb {
@@ -37,6 +38,8 @@ struct lmb {
 };
 
 extern struct lmb lmb;
+extern struct lmb_property lmb_memory_region[MAX_LMB_REGIONS + 1];
+extern struct lmb_property lmb_reserved_region[MAX_LMB_REGIONS + 1];
 
 extern void __init lmb_init(void);
 extern void __init lmb_analyze(void);
kernel/early_res.c +228 -365

737 lines not on this page · raw message

lib/lmb.c +10 -1
index b1fc526..2fe35a2 100644
@@ -18,6 +18,8 @@
 #define LMB_ALLOC_ANYWHERE	0
 
 struct lmb lmb;
+struct lmb_property lmb_memory_region[MAX_LMB_REGIONS + 1];
+struct lmb_property lmb_reserved_region[MAX_LMB_REGIONS + 1];
 
 static int lmb_debug;
 
@@ -106,6 +108,11 @@ static void lmb_coalesce_regions(struct lmb_region *rgn,
 
 void __init lmb_init(void)
 {
+	lmb.memory.region   = lmb_memory_region;
+	lmb.memory.region_array_size   = ARRAY_SIZE(lmb_memory_region);
+	lmb.reserved.region = lmb_reserved_region;
+	lmb.reserved.region_array_size = ARRAY_SIZE(lmb_reserved_region);
+
 	/* Create a dummy zero size LMB which will get coalesced away later.
 	 * This simplifies the lmb_add() code below...
 	 */
@@ -169,7 +176,7 @@ static long lmb_add_region(struct lmb_region *rgn, u64 base, u64 size)
 
 	if (coalesced)
 		return coalesced;
-	if (rgn->cnt >= MAX_LMB_REGIONS)
+	if (rgn->cnt >= (rgn->region_array_size - 1))
 		return -1;
 
 	/* Couldn't coalesce the LMB, so add it to the sorted table. */
@@ -539,3 +546,5 @@ int lmb_find(struct lmb_property *res)
 	}
 	return -1;
 }
+
+
mm/page_alloc.c +1 -1
index eef3757..04c241a 100644
@@ -3451,7 +3451,7 @@ void * __init __alloc_memory_core_early(int nid, u64 size, u64 align,
 
 	ptr = phys_to_virt(addr);
 	memset(ptr, 0, size);
-	reserve_early_without_check(addr, addr + size, "BOOTMEM");
+	reserve_early(addr, addr + size, "BOOTMEM");
 	return ptr;
 }
 #endif
mm/sparse-vmemmap.c +2 -2
index 392b9bb..ca56c5d 100644
@@ -225,8 +225,8 @@ void __init sparse_mem_maps_populate_node(struct page **map_map,
 			char name[15];
 
 			snprintf(name, sizeof(name), "MEMMAP %d", nodeid);
-			reserve_early_without_check(__pa(vmemmap_buf_start),
-						    __pa(vmemmap_buf), name);
+			reserve_early(__pa(vmemmap_buf_start),
+					 __pa(vmemmap_buf), name);
 		}
 #else
 		free_bootmem(__pa(vmemmap_buf), vmemmap_buf_end - vmemmap_buf);
Signature · 1 line
1.6.4.2
#5 lore raw

Re: [RFC PATCH -v2 4/4] x86: use lmb to replace early_res

Quoted 5 lines · Yinghai Lu

still keep kernel/early_res.c for the extension.

should move those file to lib/lmb.c later?

-v2: fix NO_BOOTMEM hang with printk

Would be nice to track known TODO items - that way people dont feel that you are ignoring (or have missed) their feedback. For example are the list of 4 improvements i suggested in the previous mail planned, or do you disagree with some of that?

Thanks,

Ingo

author
#6 lore raw

RFC PATCH 1/2 lmb: seperate region array from lmb_region struct

In reply to Yinghai Lu

lmb_init() connect them back.

also add region_array_size in lmb_region to tack the region array size.

-v3: seperate lmb core change to seperated patch

---
 include/linux/lmb.h |    5 ++++-
 lib/lmb.c           |   11 ++++++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)
include/linux/lmb.h +4 -1
Index: linux-2.6/include/linux/lmb.h
===================================================================
@@ -26,7 +26,8 @@ struct lmb_property {
 struct lmb_region {
 	unsigned long cnt;
 	u64 size;
-	struct lmb_property region[MAX_LMB_REGIONS+1];
+	struct lmb_property *region;
+	unsigned long region_array_size;
 };
 
 struct lmb {
@@ -37,6 +38,8 @@ struct lmb {
 };
 
 extern struct lmb lmb;
+extern struct lmb_property lmb_memory_region[MAX_LMB_REGIONS + 1];
+extern struct lmb_property lmb_reserved_region[MAX_LMB_REGIONS + 1];
 
 extern void __init lmb_init(void);
 extern void __init lmb_analyze(void);
lib/lmb.c +8 -1
Index: linux-2.6/lib/lmb.c
===================================================================
@@ -18,6 +18,8 @@
 #define LMB_ALLOC_ANYWHERE	0
 
 struct lmb lmb;
+struct lmb_property lmb_memory_region[MAX_LMB_REGIONS + 1];
+struct lmb_property lmb_reserved_region[MAX_LMB_REGIONS + 1];
 
 static int lmb_debug;
 
@@ -106,6 +108,11 @@ static void lmb_coalesce_regions(struct
 
 void __init lmb_init(void)
 {
+	lmb.memory.region   = lmb_memory_region;
+	lmb.memory.region_array_size   = ARRAY_SIZE(lmb_memory_region);
+	lmb.reserved.region = lmb_reserved_region;
+	lmb.reserved.region_array_size = ARRAY_SIZE(lmb_reserved_region);
+
 	/* Create a dummy zero size LMB which will get coalesced away later.
 	 * This simplifies the lmb_add() code below...
 	 */
@@ -169,7 +176,7 @@ static long lmb_add_region(struct lmb_re
 
 	if (coalesced)
 		return coalesced;
-	if (rgn->cnt >= MAX_LMB_REGIONS)
+	if (rgn->cnt >= (rgn->region_array_size - 1))
 		return -1;
 
 	/* Couldn't coalesce the LMB, so add it to the sorted table. */
#7 lore raw

Re: [RFC PATCH -v3 1/2] lmb: seperate region array from lmb_region struct

lib/lmb.c static void lmb_coalesce_regions(struct · line 115

Quoted 7 lines · Yinghai Lu

void __init lmb_init(void)
{

lib/lmb.c +5 -0
+	lmb.memory.region   = lmb_memory_region;
+	lmb.memory.region_array_size   = ARRAY_SIZE(lmb_memory_region);
+	lmb.reserved.region = lmb_reserved_region;
+	lmb.reserved.region_array_size = ARRAY_SIZE(lmb_reserved_region);
+

That's rather unreadable and has random whitespace noise.

Should be something like:

	lmb.memory.region		= lmb_memory_region;
	lmb.memory.region_array_size	= ARRAY_SIZE(lmb_memory_region);
	lmb.reserved.region		= lmb_reserved_region;
	lmb.reserved.region_array_size	= ARRAY_SIZE(lmb_reserved_region);

also, i'd suggest to shorten region_array_size to region_size (we know it's an array), so it would become:

	lmb.memory.region	 = lmb_memory_region;
	lmb.memory.region_size	 = ARRAY_SIZE(lmb_memory_region);

	lmb.reserved.region	 = lmb_reserved_region;
	lmb.reserved.region_size = ARRAY_SIZE(lmb_reserved_region);

lib/lmb.c static long lmb_add_region(struct lmb_re · line 180

Quoted 3 lines
lib/lmb.c +1 -1
-	if (rgn->cnt >= MAX_LMB_REGIONS)
+	if (rgn->cnt >= (rgn->region_array_size - 1))
 		return -1;

'x >= y-1' is equivalent to 'x > y', so that should be:

	if (rgn->cnt > rgn->region_size)

	Ingo
#8 lore raw

Re: [RFC PATCH -v3 1/2] lmb: seperate region array from lmb_region struct

Quoted 20 lines · Ingo Molnar

lib/lmb.c static void lmb_coalesce_regions(struct · line 115

Quoted 7 lines · Yinghai Lu

void __init lmb_init(void)
{

lib/lmb.c +5 -0
+	lmb.memory.region   = lmb_memory_region;
+	lmb.memory.region_array_size   = ARRAY_SIZE(lmb_memory_region);
+	lmb.reserved.region = lmb_reserved_region;
+	lmb.reserved.region_array_size = ARRAY_SIZE(lmb_reserved_region);
+

That's rather unreadable and has random whitespace noise.

Should be something like:

	lmb.memory.region		= lmb_memory_region;
	lmb.memory.region_array_size	= ARRAY_SIZE(lmb_memory_region);
	lmb.reserved.region		= lmb_reserved_region;
	lmb.reserved.region_array_size	= ARRAY_SIZE(lmb_reserved_region);
Quoted 6 lines

also, i'd suggest to shorten region_array_size to region_size (we know it's an array), so it would become:

	lmb.memory.region	 = lmb_memory_region;
	lmb.memory.region_size	 = ARRAY_SIZE(lmb_memory_region);

I don't mean to be pedantic, but the LMB code already has a lot of region.size references so region_size looks a bit awkward. All of the accessors in linux/lmb.h use region_nr as the array index, so perhaps nr_regions would be less ambiguous.

author
#9 lore raw

Re: [RFC PATCH -v3 1/2] lmb: seperate region array from lmb_region struct

Quoted 24 lines · Paul Mundt
Quoted 23 lines · Ingo Molnar

lib/lmb.c static void lmb_coalesce_regions(struct · line 115

Quoted 7 lines · Yinghai Lu

void __init lmb_init(void)
{

lib/lmb.c +5 -0
+	lmb.memory.region   = lmb_memory_region;
+	lmb.memory.region_array_size   = ARRAY_SIZE(lmb_memory_region);
+	lmb.reserved.region = lmb_reserved_region;
+	lmb.reserved.region_array_size = ARRAY_SIZE(lmb_reserved_region);
+

That's rather unreadable and has random whitespace noise.

Should be something like:

	lmb.memory.region		= lmb_memory_region;
	lmb.memory.region_array_size	= ARRAY_SIZE(lmb_memory_region);
	lmb.reserved.region		= lmb_reserved_region;
	lmb.reserved.region_array_size	= ARRAY_SIZE(lmb_reserved_region);

also, i'd suggest to shorten region_array_size to region_size (we know it's an array), so it would become:

Quoted 7 lines
Quoted 3 lines
	lmb.memory.region	 = lmb_memory_region;
	lmb.memory.region_size	 = ARRAY_SIZE(lmb_memory_region);

I don't mean to be pedantic, but the LMB code already has a lot of region.size references so region_size looks a bit awkward. All of the accessors in linux/lmb.h use region_nr as the array index, so perhaps nr_regions would be less ambiguous.

@@ -26,7 +26,8 @@ struct lmb_property {
struct lmb_region {
unsigned long cnt;
u64 size;
- struct lmb_property region[MAX_LMB_REGIONS+1];
+ struct lmb_property *region;
+ unsigned long region_array_size;
};

cnt is number of slots used.
size is memory size

can we use rgn_sz for region array size?

YH

#10 lore raw

Re: [RFC PATCH -v3 1/2] lmb: seperate region array from lmb_region struct

Quoted 22 lines · Yinghai Lu
Quoted 11 lines · Paul Mundt
Quoted 6 lines · Ingo Molnar

also, i'd suggest to shorten region_array_size to region_size (we know it's an array), so it would become:

	lmb.memory.region	 = lmb_memory_region;
	lmb.memory.region_size	 = ARRAY_SIZE(lmb_memory_region);

I don't mean to be pedantic, but the LMB code already has a lot of region.size references so region_size looks a bit awkward. All of the accessors in linux/lmb.h use region_nr as the array index, so perhaps nr_regions would be less ambiguous.

include/linux/lmb.h +2 -1
@@ -26,7 +26,8 @@ struct lmb_property {
 struct lmb_region {
 	unsigned long cnt;
 	u64 size;
-	struct lmb_property region[MAX_LMB_REGIONS+1];
+	struct lmb_property *region;
+	unsigned long region_array_size;
 };
 
Quoted 3 lines

cnt is number of slots used.
size is memory size

I'm fully aware of what each of these things are, and I have no idea what any of that has to do with the point I raised above.

Quoted 2 lines

can we use rgn_sz for region array size?

No.

#11 lore raw

Re: [RFC PATCH -v3 1/2] lmb: seperate region array from lmb_region struct

In reply to Ingo Molnar
Quoted 14 lines · Ingo Molnar

lib/lmb.c static void lmb_coalesce_regions(struct · line 115

Quoted 7 lines · Yinghai Lu

void __init lmb_init(void)
{

lib/lmb.c +5 -0
+	lmb.memory.region   = lmb_memory_region;
+	lmb.memory.region_array_size   = ARRAY_SIZE(lmb_memory_region);
+	lmb.reserved.region = lmb_reserved_region;
+	lmb.reserved.region_array_size = ARRAY_SIZE(lmb_reserved_region);
+

That's rather unreadable and has random whitespace noise.

Should be something like:

Quoted 7 lines
	lmb.memory.region		= lmb_memory_region;
	lmb.memory.region_array_size	= ARRAY_SIZE(lmb_memory_region);
	lmb.reserved.region		= lmb_reserved_region;
	lmb.reserved.region_array_size	= ARRAY_SIZE(lmb_reserved_region);

also, i'd suggest to shorten region_array_size to region_size (we know it's an array), so it would become:

I dislike those arrays anyways. See my other message about turning them into lists, which would get rid of capacity constraints completely. What do you think ?

Cheers,
Ben.

author
#12 lore raw

RFC PATCH v4 1/2 lmb: seperate region array from lmb_region struct

lmb_init() connect them back.

also add nr_regions in lmb_region to tack the region array size.

-v3: seperate lmb core change to seperated patch
-v4: according to Ingo, change >= x -1 to > x
change region_array_size to nr_regions

---
 include/linux/lmb.h |    5 ++++-
 lib/lmb.c           |    9 ++++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)
include/linux/lmb.h +4 -1
Index: linux-2.6/include/linux/lmb.h
===================================================================
@@ -26,7 +26,8 @@ struct lmb_property {
 struct lmb_region {
 	unsigned long cnt;
 	u64 size;
-	struct lmb_property region[MAX_LMB_REGIONS+1];
+	struct lmb_property *region;
+	unsigned long nr_regions;
 };
 
 struct lmb {
@@ -37,6 +38,8 @@ struct lmb {
 };
 
 extern struct lmb lmb;
+extern struct lmb_property lmb_memory_region[MAX_LMB_REGIONS + 1];
+extern struct lmb_property lmb_reserved_region[MAX_LMB_REGIONS + 1];
 
 extern void __init lmb_init(void);
 extern void __init lmb_analyze(void);
lib/lmb.c +8 -1
Index: linux-2.6/lib/lmb.c
===================================================================
@@ -18,6 +18,8 @@
 #define LMB_ALLOC_ANYWHERE	0
 
 struct lmb lmb;
+struct lmb_property lmb_memory_region[MAX_LMB_REGIONS + 1];
+struct lmb_property lmb_reserved_region[MAX_LMB_REGIONS + 1];
 
 static int lmb_debug;
 
@@ -106,6 +108,11 @@ static void lmb_coalesce_regions(struct
 
 void __init lmb_init(void)
 {
+	lmb.memory.region   = lmb_memory_region;
+	lmb.reserved.region = lmb_reserved_region;
+	lmb.memory.nr_regions   = ARRAY_SIZE(lmb_memory_region);
+	lmb.reserved.nr_regions = ARRAY_SIZE(lmb_reserved_region);
+
 	/* Create a dummy zero size LMB which will get coalesced away later.
 	 * This simplifies the lmb_add() code below...
 	 */
@@ -169,7 +176,7 @@ static long lmb_add_region(struct lmb_re
 
 	if (coalesced)
 		return coalesced;
-	if (rgn->cnt >= MAX_LMB_REGIONS)
+	if (rgn->cnt > rgn->nr_regions)
 		return -1;
 
 	/* Couldn't coalesce the LMB, so add it to the sorted table. */
author
#13 lore raw

RFC PATCH 2/2 x86: use lmb to replace early_res

In reply to Benjamin Herrenschmidt

still keep kernel/early_res.c for the extension.

should move those file to lib/lmb.c later?

in early_res.c
1. change find_e820_area_xxx, to find_lmb_area_xxx
2. e820_register_active_regions to lmb_register_active_regions.
3. reserve_early will call lmb_reserve directly.
4. free_early will call lmb_free directly.
5. remove functions that are used by old reserve_early and free_early
6. get_free_all_memory_range use lmb.reserved.
7. early_res_to_bootmem use lmb.reserved
8. add fill_lmb_memory() to fill lmb.memory according e820 RAM entries

-v2: fix NO_BOOTMEM hang with printk
-v4: add add_lmb_memory that could increase lmb.memory.region size
change region_array_size to nr_regions
make sure some find_lmb_area<_size> are called after fill_lmb_memory

todo:
1. make early_memtest to depend on early_res. and move it to mm/
2. make all lmb user to use extend early_res/nobootmem
3. merge lmb.c and early_res.c, move it to mm/
4. make other platform to use lmb/early_res/nobootmem
5. remove BOOTMEM related code

---
 arch/x86/Kconfig               |    1 
 arch/x86/include/asm/e820.h    |   38 +-
 arch/x86/include/asm/lmb.h     |    8 
 arch/x86/kernel/check.c        |   14 
 arch/x86/kernel/e820.c         |  171 +----------
 arch/x86/kernel/head.c         |    2 
 arch/x86/kernel/head32.c       |    5 
 arch/x86/kernel/head64.c       |    2 
 arch/x86/kernel/setup.c        |    9 
 arch/x86/kernel/setup_percpu.c |    6 
 arch/x86/mm/memtest.c          |    5 
 arch/x86/mm/numa_64.c          |    4 
 include/linux/early_res.h      |   19 -
 kernel/early_res.c             |  631 ++++++++++++++++-------------------------
 mm/page_alloc.c                |    2 
 mm/sparse-vmemmap.c            |   11 
 16 files changed, 344 insertions(+), 584 deletions(-)
arch/x86/Kconfig +1 -0
Index: linux-2.6/arch/x86/Kconfig
===================================================================
@@ -27,6 +27,7 @@ config X86
 	select HAVE_PERF_EVENTS if (!M386 && !M486)
 	select HAVE_IOREMAP_PROT
 	select HAVE_KPROBES
+	select HAVE_LMB
 	select ARCH_WANT_OPTIONAL_GPIOLIB
 	select ARCH_WANT_FRAME_POINTERS
 	select HAVE_DMA_ATTRS
arch/x86/include/asm/e820.h +22 -16
Index: linux-2.6/arch/x86/include/asm/e820.h
===================================================================
@@ -111,24 +111,30 @@ static inline void early_memtest(unsigne
 }
 #endif
 
-extern unsigned long end_user_pfn;
-
-extern u64 find_e820_area(u64 start, u64 end, u64 size, u64 align);
-extern u64 find_e820_area_size(u64 start, u64 *sizep, u64 align);
-u64 find_e820_area_node(int nid, u64 start, u64 end, u64 size, u64 align);
-extern u64 early_reserve_e820(u64 startt, u64 sizet, u64 align);
-#include <linux/early_res.h>
-
 extern unsigned long e820_end_of_ram_pfn(void);
 extern unsigned long e820_end_of_low_ram_pfn(void);
-extern int e820_find_active_region(const struct e820entry *ei,
-				  unsigned long start_pfn,
-				  unsigned long last_pfn,
-				  unsigned long *ei_startpfn,
-				  unsigned long *ei_endpfn);
-extern void e820_register_active_regions(int nid, unsigned long start_pfn,
-					 unsigned long end_pfn);
-extern u64 e820_hole_size(u64 start, u64 end);
+#include <linux/early_res.h>
+extern u64 early_reserve_e820(u64 startt, u64 sizet, u64 align);
+
+/*
+ * next three functions will be removed, esp find_e820_area()
+ * can not be used before fill_lmb_memory()
+ */
+static inline u64 find_e820_area(u64 start, u64 end, u64 size, u64 align)
+{
+	return find_lmb_area(start, end, size, align);
+}
+static inline void e820_register_active_regions(int nid, unsigned long start_pfn, unsigned long end_pfn)
+{
+	lmb_register_active_regions(nid, start_pfn, end_pfn);
+}
+static inline u64 e820_hole_size(u64 start, u64 end)
+{
+	return lmb_hole_size(start, end);
+}
+
+void init_lmb_memory(void);
+void fill_lmb_memory(void);
 extern void finish_e820_parsing(void);
 extern void e820_reserve_resources(void);
 extern void e820_reserve_resources_late(void);
arch/x86/kernel/e820.c +26 -145

213 lines not on this page · raw message

arch/x86/kernel/head.c +1 -1
Index: linux-2.6/arch/x86/kernel/head.c
===================================================================
@@ -51,5 +51,5 @@ void __init reserve_ebda_region(void)
 		lowmem = 0x9f000;
 
 	/* reserve all memory between lowmem and the 1MB mark */
-	reserve_early_overlap_ok(lowmem, 0x100000, "BIOS reserved");
+	reserve_early(lowmem, 0x100000, "BIOS reserved");
 }
arch/x86/kernel/head32.c +3 -2
Index: linux-2.6/arch/x86/kernel/head32.c
===================================================================
@@ -29,14 +29,15 @@ static void __init i386_default_early_se
 
 void __init i386_start_kernel(void)
 {
+	init_lmb_memory();
+
 #ifdef CONFIG_X86_TRAMPOLINE
 	/*
 	 * But first pinch a few for the stack/trampoline stuff
 	 * FIXME: Don't need the extra page at 4K, but need to fix
 	 * trampoline before removing it. (see the GDT stuff)
 	 */
-	reserve_early_overlap_ok(PAGE_SIZE, PAGE_SIZE + PAGE_SIZE,
-					 "EX TRAMPOLINE");
+	reserve_early(PAGE_SIZE, PAGE_SIZE + PAGE_SIZE, "EX TRAMPOLINE");
 #endif
 
 	reserve_early(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
arch/x86/kernel/head64.c +2 -0
Index: linux-2.6/arch/x86/kernel/head64.c
===================================================================
@@ -96,6 +96,8 @@ void __init x86_64_start_kernel(char * r
 
 void __init x86_64_start_reservations(char *real_mode_data)
 {
+	init_lmb_memory();
+
 	copy_bootdata(__va(real_mode_data));
 
 	reserve_early(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
arch/x86/kernel/setup.c +6 -3
Index: linux-2.6/arch/x86/kernel/setup.c
===================================================================
@@ -868,8 +868,6 @@ void __init setup_arch(char **cmdline_p)
 	 */
 	max_pfn = e820_end_of_ram_pfn();
 
-	/* preallocate 4k for mptable mpc */
-	early_reserve_e820_mpc_new();
 	/* update e820 for memory not covered by WB MTRRs */
 	mtrr_bp_init();
 	if (mtrr_trim_uncached_memory(max_pfn))
@@ -894,6 +892,11 @@ void __init setup_arch(char **cmdline_p)
 	max_pfn_mapped = KERNEL_IMAGE_SIZE >> PAGE_SHIFT;
 #endif
 
+	fill_lmb_memory();
+
+	/* preallocate 4k for mptable mpc */
+	early_reserve_e820_mpc_new();
+
 #ifdef CONFIG_X86_CHECK_BIOS_CORRUPTION
 	setup_bios_corruption_check();
 #endif
@@ -970,7 +973,7 @@ void __init setup_arch(char **cmdline_p)
 
 	initmem_init(0, max_pfn, acpi, k8);
 #ifndef CONFIG_NO_BOOTMEM
-	early_res_to_bootmem(0, max_low_pfn<<PAGE_SHIFT);
+	lmb_reserved_to_bootmem(0, max_low_pfn<<PAGE_SHIFT);
 #endif
 
 	dma32_reserve_bootmem();
arch/x86/kernel/setup_percpu.c +0 -6
Index: linux-2.6/arch/x86/kernel/setup_percpu.c
===================================================================
@@ -137,13 +137,7 @@ static void * __init pcpu_fc_alloc(unsig
 
 static void __init pcpu_fc_free(void *ptr, size_t size)
 {
-#ifdef CONFIG_NO_BOOTMEM
-	u64 start = __pa(ptr);
-	u64 end = start + size;
-	free_early_partial(start, end);
-#else
 	free_bootmem(__pa(ptr), size);
-#endif
 }
 
 static int __init pcpu_cpu_distance(unsigned int from, unsigned int to)
include/linux/early_res.h +11 -8
Index: linux-2.6/include/linux/early_res.h
===================================================================
@@ -3,19 +3,22 @@
 #ifdef __KERNEL__
 
 extern void reserve_early(u64 start, u64 end, char *name);
-extern void reserve_early_overlap_ok(u64 start, u64 end, char *name);
 extern void free_early(u64 start, u64 end);
-void free_early_partial(u64 start, u64 end);
-extern void early_res_to_bootmem(u64 start, u64 end);
+void lmb_reserved_to_bootmem(u64 start, u64 end);
 
-void reserve_early_without_check(u64 start, u64 end, char *name);
 u64 find_early_area(u64 ei_start, u64 ei_last, u64 start, u64 end,
 			 u64 size, u64 align);
-u64 find_early_area_size(u64 ei_start, u64 ei_last, u64 start,
-			 u64 *sizep, u64 align);
-u64 find_fw_memmap_area(u64 start, u64 end, u64 size, u64 align);
+
+void add_lmb_memory(u64 start, u64 end);
+
+u64 find_lmb_area(u64 start, u64 end, u64 size, u64 align);
+u64 find_lmb_area_size(u64 start, u64 *sizep, u64 align);
+u64 find_lmb_area_node(int nid, u64 start, u64 end, u64 size, u64 align);
+void lmb_register_active_regions(int nid, unsigned long start_pfn,
+					 unsigned long last_pfn);
+u64 lmb_hole_size(u64 start, u64 end);
 u64 get_max_mapped(void);
-#include <linux/range.h>
+struct range;
 int get_free_all_memory_range(struct range **rangep, int nodeid);
 
 #endif /* __KERNEL__ */
kernel/early_res.c +251 -380

790 lines not on this page · raw message

mm/page_alloc.c +1 -1
Index: linux-2.6/mm/page_alloc.c
===================================================================
@@ -3451,7 +3451,7 @@ void * __init __alloc_memory_core_early(
 
 	ptr = phys_to_virt(addr);
 	memset(ptr, 0, size);
-	reserve_early_without_check(addr, addr + size, "BOOTMEM");
+	reserve_early(addr, addr + size, "BOOTMEM");
 	return ptr;
 }
 #endif
mm/sparse-vmemmap.c +0 -11
Index: linux-2.6/mm/sparse-vmemmap.c
===================================================================
@@ -219,18 +219,7 @@ void __init sparse_mem_maps_populate_nod
 
 	if (vmemmap_buf_start) {
 		/* need to free left buf */
-#ifdef CONFIG_NO_BOOTMEM
-		free_early(__pa(vmemmap_buf_start), __pa(vmemmap_buf_end));
-		if (vmemmap_buf_start < vmemmap_buf) {
-			char name[15];
-
-			snprintf(name, sizeof(name), "MEMMAP %d", nodeid);
-			reserve_early_without_check(__pa(vmemmap_buf_start),
-						    __pa(vmemmap_buf), name);
-		}
-#else
 		free_bootmem(__pa(vmemmap_buf), vmemmap_buf_end - vmemmap_buf);
-#endif
 		vmemmap_buf = NULL;
 		vmemmap_buf_end = NULL;
 	}
arch/x86/include/asm/lmb.h new file +8 -0
Index: linux-2.6/arch/x86/include/asm/lmb.h
===================================================================
@@ -0,0 +1,8 @@
+#ifndef _X86_LMB_H
+#define _X86_LMB_H
+
+#define LMB_DBG(fmt...) printk(fmt)
+
+#define LMB_REAL_LIMIT	0
+
+#endif
arch/x86/kernel/check.c +8 -6
Index: linux-2.6/arch/x86/kernel/check.c
===================================================================
@@ -2,7 +2,8 @@
 #include <linux/sched.h>
 #include <linux/kthread.h>
 #include <linux/workqueue.h>
-#include <asm/e820.h>
+#include <linux/early_res.h>
+
 #include <asm/proto.h>
 
 /*
@@ -18,10 +19,12 @@ static int __read_mostly memory_corrupti
 static unsigned __read_mostly corruption_check_size = 64*1024;
 static unsigned __read_mostly corruption_check_period = 60; /* seconds */
 
-static struct e820entry scan_areas[MAX_SCAN_AREAS];
+static struct scan_area {
+	u64 addr;
+	u64 size;
+} scan_areas[MAX_SCAN_AREAS];
 static int num_scan_areas;
 
-
 static __init int set_corruption_check(char *arg)
 {
 	char *end;
@@ -81,7 +84,7 @@ void __init setup_bios_corruption_check(
 
 	while (addr < corruption_check_size && num_scan_areas < MAX_SCAN_AREAS) {
 		u64 size;
-		addr = find_e820_area_size(addr, &size, PAGE_SIZE);
+		addr = find_lmb_area_size(addr, &size, PAGE_SIZE);
 
 		if (!(addr + 1))
 			break;
@@ -92,7 +95,7 @@ void __init setup_bios_corruption_check(
 		if ((addr + size) > corruption_check_size)
 			size = corruption_check_size - addr;
 
-		e820_update_range(addr, size, E820_RAM, E820_RESERVED);
+		reserve_early(addr, addr + size, "SCAN RAM");
 		scan_areas[num_scan_areas].addr = addr;
 		scan_areas[num_scan_areas].size = size;
 		num_scan_areas++;
@@ -105,7 +108,6 @@ void __init setup_bios_corruption_check(
 
 	printk(KERN_INFO "Scanning %d areas for low memory corruption\n",
 	       num_scan_areas);
-	update_e820();
 }
 
 
arch/x86/mm/memtest.c +2 -3
Index: linux-2.6/arch/x86/mm/memtest.c
===================================================================
@@ -6,8 +6,7 @@
 #include <linux/smp.h>
 #include <linux/init.h>
 #include <linux/pfn.h>
-
-#include <asm/e820.h>
+#include <linux/early_res.h>
 
 static u64 patterns[] __initdata = {
 	0,
@@ -74,7 +73,7 @@ static void __init do_one_pass(u64 patte
 	u64 size = 0;
 
 	while (start < end) {
-		start = find_e820_area_size(start, &size, 1);
+		start = find_lmb_area_size(start, &size, 1);
 
 		/* done ? */
 		if (start >= end)
arch/x86/mm/numa_64.c +2 -2
Index: linux-2.6/arch/x86/mm/numa_64.c
===================================================================
@@ -174,7 +174,7 @@ static void * __init early_node_mem(int
 	if (start < (MAX_DMA32_PFN<<PAGE_SHIFT) &&
 	    end > (MAX_DMA32_PFN<<PAGE_SHIFT))
 		start = MAX_DMA32_PFN<<PAGE_SHIFT;
-	mem = find_e820_area_node(nodeid, start, end, size, align);
+	mem = find_lmb_area_node(nodeid, start, end, size, align);
 	if (mem != -1L)
 		return __va(mem);
 
@@ -184,7 +184,7 @@ static void * __init early_node_mem(int
 		start = MAX_DMA32_PFN<<PAGE_SHIFT;
 	else
 		start = MAX_DMA_PFN<<PAGE_SHIFT;
-	mem = find_e820_area_node(nodeid, start, end, size, align);
+	mem = find_lmb_area_node(nodeid, start, end, size, align);
 	if (mem != -1L)
 		return __va(mem);
 
author
#14 lore raw

Re: [RFC PATCH -v3 1/2] lmb: seperate region array from lmb_region struct

In reply to Benjamin Herrenschmidt
Quoted 20 lines · Benjamin Herrenschmidt
Quoted 19 lines · Ingo Molnar

lib/lmb.c static void lmb_coalesce_regions(struct · line 115

Quoted 7 lines · Yinghai Lu

void __init lmb_init(void)
{

lib/lmb.c +5 -0
+	lmb.memory.region   = lmb_memory_region;
+	lmb.memory.region_array_size   = ARRAY_SIZE(lmb_memory_region);
+	lmb.reserved.region = lmb_reserved_region;
+	lmb.reserved.region_array_size = ARRAY_SIZE(lmb_reserved_region);
+

That's rather unreadable and has random whitespace noise.

Should be something like:

	lmb.memory.region		= lmb_memory_region;
	lmb.memory.region_array_size	= ARRAY_SIZE(lmb_memory_region);
	lmb.reserved.region		= lmb_reserved_region;
	lmb.reserved.region_array_size	= ARRAY_SIZE(lmb_reserved_region);
Quoted 7 lines
Quoted 2 lines

also, i'd suggest to shorten region_array_size to region_size (we know it's an array), so it would become:

I dislike those arrays anyways. See my other message about turning them into lists, which would get rid of capacity constraints completely. What do you think ?

2/2 introduce one new function that could double the array size

please check the v4.

the function rely on find_lmb_area().

it will check if there is enough space left, otherwise try to get new big array, and copy old array to new array.

final function like:

static void __init __check_and_double_region_array(struct lmb_region *type,

			 struct lmb_property *static_region,
			 u64 ex_start, u64 ex_end)
{
	u64 start, end, size, mem;
	struct lmb_property *new, *old;
	unsigned long rgnsz = type->nr_regions;

	/* do we have enough slots left ? */
	if ((rgnsz - type->cnt) > max_t(unsigned long, rgnsz/8, 2))
		return;

	old = type->region;
	/* double it */
	mem = -1ULL;
	size = sizeof(struct lmb_property) * rgnsz * 2;
	if (old == static_region)
		start = 0;
	else
		start = __pa(old) + sizeof(struct lmb_property) * rgnsz;
	end = ex_start;
	if (start + size < end)
		mem = find_lmb_area(start, end, size,
					 sizeof(struct lmb_property));
	if (mem == -1ULL) {
		start = ex_end;
		end = get_max_mapped();
		if (start + size < end)
			mem = find_lmb_area(start, end, size, sizeof(struct lmb_property));
	}
	if (mem == -1ULL)
		panic("can not find more space for lmb.reserved.region array");

	new = __va(mem);
	/* copy old to new */
	memcpy(&new[0], &old[0], sizeof(struct lmb_property) * rgnsz);
	memset(&new[rgnsz], 0, sizeof(struct lmb_property) * rgnsz);

	memset(&old[0], 0, sizeof(struct lmb_property) * rgnsz);
	type->region = new;
	type->nr_regions = rgnsz * 2;
	printk(KERN_DEBUG "lmb.reserved.region array is doubled to %ld at [%llx - %llx]\n",
		type->nr_regions, mem, mem + size - 1);

	/* reserve new array and free old one */
	lmb_reserve(mem, sizeof(struct lmb_property) * rgnsz * 2);
	if (old != static_region)
		lmb_free(__pa(old), sizeof(struct lmb_property) * rgnsz);
}

void __init add_lmb_memory(u64 start, u64 end)

{
	__check_and_double_region_array(&lmb.memory, &lmb_memory_region[0], start, end);
	lmb_add(start, end - start);
}

void __init reserve_early(u64 start, u64 end, char *name)

{
	if (start == end)
		return;

	if (WARN_ONCE(start > end, "reserve_early: wrong range [%#llx, %#llx]\n", start, end))
		return;

	__check_and_double_region_array(&lmb.reserved, &lmb_reserved_region[0], start, end);
	lmb_reserve(start, end - start);
}

void __init free_early(u64 start, u64 end)

{
	if (start == end)
		return;

	if (WARN_ONCE(start > end, "free_early: wrong range [%#llx, %#llx]\n", start, end))
		return;

	/* keep punching hole, could run out of slots too */
	__check_and_double_region_array(&lmb.reserved, &lmb_reserved_region[0], start, end);
	lmb_free(start, end - start);
}

with those function, we can replace the bootmem in x86.

Thanks

Yinghai

#15 lore raw

Re: [RFC PATCH -v3 1/2] lmb: seperate region array from lmb_region struct

Quoted 5 lines · Yinghai Lu

I dislike those arrays anyways. See my other message about turning them into lists, which would get rid of capacity constraints completely. What do you think ?

Quoted 1 line

2/2 introduce one new function that could double the array size

It's still bloody arrays with fixed sizes, arbitrary limits and arbitrary waste of BSS space ;-) To be honest, I much prefer my idea of linked lists... But I'll let others speak.

I think your double array size looks more like a band-aid than a proper fix. If we are going to use LMB in the long run for bootmem, we need to properly address its capacity constraints, not just paper over the problem.

Cheers,
Ben.

Quoted 110 lines

please check the v4.

the function rely on find_lmb_area().

it will check if there is enough space left, otherwise try to get new big array, and
copy old array to new array.

final function like:

static void __init __check_and_double_region_array(struct lmb_region *type,
struct lmb_property *static_region, u64 ex_start, u64 ex_end)

{
        u64 start, end, size, mem;
        struct lmb_property *new, *old;
        unsigned long rgnsz = type->nr_regions;

        /* do we have enough slots left ? */
        if ((rgnsz - type->cnt) > max_t(unsigned long, rgnsz/8, 2))
                return;

        old = type->region;
        /* double it */
        mem = -1ULL;
        size = sizeof(struct lmb_property) * rgnsz * 2;
        if (old == static_region)
                start = 0;
        else
                start = __pa(old) + sizeof(struct lmb_property) *
rgnsz;
        end = ex_start;
        if (start + size < end)
                mem = find_lmb_area(start, end, size,
                                         sizeof(struct lmb_property));
        if (mem == -1ULL) {
                start = ex_end;
                end = get_max_mapped();
                if (start + size < end)
                        mem = find_lmb_area(start, end, size,
sizeof(struct lmb_property));
        }
        if (mem == -1ULL)
                panic("can not find more space for lmb.reserved.region

array");

        new = __va(mem);
        /* copy old to new */
        memcpy(&new[0], &old[0], sizeof(struct lmb_property) * rgnsz);
        memset(&new[rgnsz], 0, sizeof(struct lmb_property) * rgnsz);

        memset(&old[0], 0, sizeof(struct lmb_property) * rgnsz);
        type->region = new;
        type->nr_regions = rgnsz * 2;
        printk(KERN_DEBUG "lmb.reserved.region array is doubled to %ld
at [%llx - %llx]\n",
                type->nr_regions, mem, mem + size - 1);

        /* reserve new array and free old one */
        lmb_reserve(mem, sizeof(struct lmb_property) * rgnsz * 2);
        if (old != static_region)
                lmb_free(__pa(old), sizeof(struct lmb_property) *

rgnsz);
}

void __init add_lmb_memory(u64 start, u64 end) {
__check_and_double_region_array(&lmb.memory,

&lmb_memory_region[0], start, end);
        lmb_add(start, end - start);
}

void __init reserve_early(u64 start, u64 end, char *name)

{
        if (start == end)
                return;

        if (WARN_ONCE(start > end, "reserve_early: wrong range [%#llx,
%#llx]\n", start, end))
                return;

        __check_and_double_region_array(&lmb.reserved,
&lmb_reserved_region[0], start, end);
        lmb_reserve(start, end - start);
}

void __init free_early(u64 start, u64 end)

{
        if (start == end)
                return;

        if (WARN_ONCE(start > end, "free_early: wrong range [%#llx, %
#llx]\n", start, end))
                return;

        /* keep punching hole, could run out of slots too */
        __check_and_double_region_array(&lmb.reserved,
&lmb_reserved_region[0], start, end);
        lmb_free(start, end - start);
}

with those function, we can replace the bootmem in x86.

Thanks

Yinghai

#16 lore raw

Re: [RFC PATCH -v3 1/2] lmb: seperate region array from lmb_region struct

In reply to Yinghai Lu
Quoted 29 lines · Yinghai Lu

lmb_init() connect them back.

also add region_array_size in lmb_region to tack the region array size.

-v3: seperate lmb core change to seperated patch

---
 include/linux/lmb.h |    5 ++++-
 lib/lmb.c           |   11 ++++++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

Index: linux-2.6/include/linux/lmb.h
===================================================================

include/linux/lmb.h +2 -1
@@ -26,7 +26,8 @@ struct lmb_property {
 struct lmb_region {
 	unsigned long cnt;
 	u64 size;
-	struct lmb_property region[MAX_LMB_REGIONS+1];
+	struct lmb_property *region;
+	unsigned long region_array_size;
 };
 
 struct lmb {

include/linux/lmb.h struct lmb { · line 42

Quoted 5 lines
include/linux/lmb.h +2 -0
@@ -37,6 +38,8 @@ struct lmb {
 };
 
 extern struct lmb lmb;
+extern struct lmb_property lmb_memory_region[MAX_LMB_REGIONS + 1];
+extern struct lmb_property lmb_reserved_region[MAX_LMB_REGIONS + 1];

Is there a reason why this needs to be exported ?

Thanks,

tglx

author
#17 lore raw

Re: [RFC PATCH -v3 1/2] lmb: seperate region array from lmb_region struct

Quoted 33 lines · Thomas Gleixner
Quoted 31 lines · Yinghai Lu

lmb_init() connect them back.

also add region_array_size in lmb_region to tack the region array size.

-v3: seperate lmb core change to seperated patch

---
 include/linux/lmb.h |    5 ++++-
 lib/lmb.c           |   11 ++++++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

Index: linux-2.6/include/linux/lmb.h
===================================================================

include/linux/lmb.h +2 -1
@@ -26,7 +26,8 @@ struct lmb_property {
 struct lmb_region {
 	unsigned long cnt;
 	u64 size;
-	struct lmb_property region[MAX_LMB_REGIONS+1];
+	struct lmb_property *region;
+	unsigned long region_array_size;
 };
 
 struct lmb {
@@ -37,6 +38,8 @@ struct lmb {
 };
 
Quoted 6 lines

include/linux/lmb.h struct lmb { · line 42

Quoted 3 lines
include/linux/lmb.h +2 -0
 extern struct lmb lmb;
+extern struct lmb_property lmb_memory_region[MAX_LMB_REGIONS + 1];
+extern struct lmb_property lmb_reserved_region[MAX_LMB_REGIONS + 1];

Is there a reason why this needs to be exported ?

lmb_reserved_region is used in kernel/early_res.c::__check_and_double_early_res/subtract_early_res/early_res_to_bootmem

later if those functions are moved lmb.c, we can make lmb_reserved_region to be static

same thing to lmb_memory_region, that will be used by add_lmb_memory() later.

YH

#18 lore raw

Re: [RFC PATCH -v3 1/2] lmb: seperate region array from lmb_region struct

Quoted 41 lines · Yinghai Lu
Quoted 33 lines · Thomas Gleixner
Quoted 31 lines · Yinghai Lu

lmb_init() connect them back.

also add region_array_size in lmb_region to tack the region array size.

-v3: seperate lmb core change to seperated patch

---
 include/linux/lmb.h |    5 ++++-
 lib/lmb.c           |   11 ++++++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

Index: linux-2.6/include/linux/lmb.h
===================================================================

include/linux/lmb.h +2 -1
@@ -26,7 +26,8 @@ struct lmb_property {
 struct lmb_region {
 	unsigned long cnt;
 	u64 size;
-	struct lmb_property region[MAX_LMB_REGIONS+1];
+	struct lmb_property *region;
+	unsigned long region_array_size;
 };
 
 struct lmb {
@@ -37,6 +38,8 @@ struct lmb {
 };
 
Quoted 6 lines

include/linux/lmb.h struct lmb { · line 42

Quoted 3 lines
include/linux/lmb.h +2 -0
 extern struct lmb lmb;
+extern struct lmb_property lmb_memory_region[MAX_LMB_REGIONS + 1];
+extern struct lmb_property lmb_reserved_region[MAX_LMB_REGIONS + 1];

Is there a reason why this needs to be exported ?

Quoted 8 lines

lmb_reserved_region is used in kernel/early_res.c::__check_and_double_early_res/subtract_early_res/early_res_to_bootmem

later if those functions are moved lmb.c, we can make lmb_reserved_region to be static

same thing to lmb_memory_region, that will be used by add_lmb_memory() later.

I would strongly suggest for you to send the next (-v4) version to lkml only if it's 100% clean and complete in every known regard (with a good splitup and explanations in every commit), so that people dont repeat review or review an unclean aspect aspect that will go away in a next iteration.

Thanks,

Ingo

author
#19 lore raw

RFC PATCH 2/2 x86: use lmb to replace early_res

In reply to Yinghai Lu

still keep kernel/early_res.c for the extension.

should move those file to lib/lmb.c later?

in early_res.c
1. change find_e820_area_xxx, to find_lmb_area_xxx
2. e820_register_active_regions to lmb_register_active_regions.
3. reserve_early will call lmb_reserve directly.
4. free_early will call lmb_free directly.
5. remove functions that are used by old reserve_early and free_early
6. get_free_all_memory_range use lmb.reserved.
7. early_res_to_bootmem use lmb.reserved
8. add fill_lmb_memory() to fill lmb.memory according e820 RAM entries

-v2: fix NO_BOOTMEM hang with printk

---
 arch/x86/Kconfig               |    1 
 arch/x86/include/asm/e820.h    |   38 +-
 arch/x86/include/asm/lmb.h     |    8 
 arch/x86/kernel/e820.c         |  163 +----------
 arch/x86/kernel/head.c         |    2 
 arch/x86/kernel/head32.c       |    5 
 arch/x86/kernel/head64.c       |    2 
 arch/x86/kernel/setup.c        |    2 
 arch/x86/kernel/setup_percpu.c |    6 
 include/linux/early_res.h      |    9 
 kernel/early_res.c             |  592 +++++++++++++++--------------------------
 mm/page_alloc.c                |    2 
 mm/sparse-vmemmap.c            |    4 
 13 files changed, 301 insertions(+), 533 deletions(-)
arch/x86/Kconfig +1 -0
Index: linux-2.6/arch/x86/Kconfig
===================================================================
@@ -27,6 +27,7 @@ config X86
 	select HAVE_PERF_EVENTS if (!M386 && !M486)
 	select HAVE_IOREMAP_PROT
 	select HAVE_KPROBES
+	select HAVE_LMB
 	select ARCH_WANT_OPTIONAL_GPIOLIB
 	select ARCH_WANT_FRAME_POINTERS
 	select HAVE_DMA_ATTRS
arch/x86/include/asm/e820.h +26 -12
Index: linux-2.6/arch/x86/include/asm/e820.h
===================================================================
@@ -113,22 +113,36 @@ static inline void early_memtest(unsigne
 
 extern unsigned long end_user_pfn;
 
-extern u64 find_e820_area(u64 start, u64 end, u64 size, u64 align);
-extern u64 find_e820_area_size(u64 start, u64 *sizep, u64 align);
-u64 find_e820_area_node(int nid, u64 start, u64 end, u64 size, u64 align);
-extern u64 early_reserve_e820(u64 startt, u64 sizet, u64 align);
 #include <linux/early_res.h>
+static inline u64 find_e820_area(u64 start, u64 end, u64 size, u64 align)
+{
+	return find_lmb_area(start, end, size, align);
+}
+static inline u64 find_e820_area_size(u64 start, u64 *sizep, u64 align)
+{
+	return find_lmb_area_size(start, sizep, align);
+}
+static inline u64
+find_e820_area_node(int nid, u64 start, u64 end, u64 size, u64 align)
+{
+	return find_lmb_area_node(nid, start, end, size, align);
+}
+extern u64 early_reserve_e820(u64 startt, u64 sizet, u64 align);
 
 extern unsigned long e820_end_of_ram_pfn(void);
 extern unsigned long e820_end_of_low_ram_pfn(void);
-extern int e820_find_active_region(const struct e820entry *ei,
-				  unsigned long start_pfn,
-				  unsigned long last_pfn,
-				  unsigned long *ei_startpfn,
-				  unsigned long *ei_endpfn);
-extern void e820_register_active_regions(int nid, unsigned long start_pfn,
-					 unsigned long end_pfn);
-extern u64 e820_hole_size(u64 start, u64 end);
+static inline void e820_register_active_regions(int nid,
+					 unsigned long start_pfn,
+					 unsigned long end_pfn)
+{
+	lmb_register_active_regions(nid, start_pfn, end_pfn);
+}
+static inline u64 e820_hole_size(u64 start, u64 end)
+{
+	return lmb_hole_size(start, end);
+}
+void init_lmb_memory(void);
+void fill_lmb_memory(void);
 extern void finish_e820_parsing(void);
 extern void e820_reserve_resources(void);
 extern void e820_reserve_resources_late(void);
arch/x86/kernel/e820.c +23 -140

193 lines not on this page · raw message

arch/x86/kernel/head.c +1 -1
Index: linux-2.6/arch/x86/kernel/head.c
===================================================================
@@ -51,5 +51,5 @@ void __init reserve_ebda_region(void)
 		lowmem = 0x9f000;
 
 	/* reserve all memory between lowmem and the 1MB mark */
-	reserve_early_overlap_ok(lowmem, 0x100000, "BIOS reserved");
+	reserve_early(lowmem, 0x100000, "BIOS reserved");
 }
arch/x86/kernel/head32.c +3 -2
Index: linux-2.6/arch/x86/kernel/head32.c
===================================================================
@@ -29,14 +29,15 @@ static void __init i386_default_early_se
 
 void __init i386_start_kernel(void)
 {
+	init_lmb_memory();
+
 #ifdef CONFIG_X86_TRAMPOLINE
 	/*
 	 * But first pinch a few for the stack/trampoline stuff
 	 * FIXME: Don't need the extra page at 4K, but need to fix
 	 * trampoline before removing it. (see the GDT stuff)
 	 */
-	reserve_early_overlap_ok(PAGE_SIZE, PAGE_SIZE + PAGE_SIZE,
-					 "EX TRAMPOLINE");
+	reserve_early(PAGE_SIZE, PAGE_SIZE + PAGE_SIZE, "EX TRAMPOLINE");
 #endif
 
 	reserve_early(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
arch/x86/kernel/head64.c +2 -0
Index: linux-2.6/arch/x86/kernel/head64.c
===================================================================
@@ -96,6 +96,8 @@ void __init x86_64_start_kernel(char * r
 
 void __init x86_64_start_reservations(char *real_mode_data)
 {
+	init_lmb_memory();
+
 	copy_bootdata(__va(real_mode_data));
 
 	reserve_early(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
arch/x86/kernel/setup.c +2 -0
Index: linux-2.6/arch/x86/kernel/setup.c
===================================================================
@@ -894,6 +894,8 @@ void __init setup_arch(char **cmdline_p)
 	max_pfn_mapped = KERNEL_IMAGE_SIZE >> PAGE_SHIFT;
 #endif
 
+	fill_lmb_memory();
+
 #ifdef CONFIG_X86_CHECK_BIOS_CORRUPTION
 	setup_bios_corruption_check();
 #endif
arch/x86/kernel/setup_percpu.c +0 -6
Index: linux-2.6/arch/x86/kernel/setup_percpu.c
===================================================================
@@ -137,13 +137,7 @@ static void * __init pcpu_fc_alloc(unsig
 
 static void __init pcpu_fc_free(void *ptr, size_t size)
 {
-#ifdef CONFIG_NO_BOOTMEM
-	u64 start = __pa(ptr);
-	u64 end = start + size;
-	free_early_partial(start, end);
-#else
 	free_bootmem(__pa(ptr), size);
-#endif
 }
 
 static int __init pcpu_cpu_distance(unsigned int from, unsigned int to)
include/linux/early_res.h +6 -3
Index: linux-2.6/include/linux/early_res.h
===================================================================
@@ -5,15 +5,18 @@
 extern void reserve_early(u64 start, u64 end, char *name);
 extern void reserve_early_overlap_ok(u64 start, u64 end, char *name);
 extern void free_early(u64 start, u64 end);
-void free_early_partial(u64 start, u64 end);
 extern void early_res_to_bootmem(u64 start, u64 end);
 
-void reserve_early_without_check(u64 start, u64 end, char *name);
 u64 find_early_area(u64 ei_start, u64 ei_last, u64 start, u64 end,
 			 u64 size, u64 align);
 u64 find_early_area_size(u64 ei_start, u64 ei_last, u64 start,
 			 u64 *sizep, u64 align);
-u64 find_fw_memmap_area(u64 start, u64 end, u64 size, u64 align);
+u64 find_lmb_area(u64 start, u64 end, u64 size, u64 align);
+u64 find_lmb_area_size(u64 start, u64 *sizep, u64 align);
+u64 find_lmb_area_node(int nid, u64 start, u64 end, u64 size, u64 align);
+void lmb_register_active_regions(int nid, unsigned long start_pfn,
+					 unsigned long last_pfn);
+u64 lmb_hole_size(u64 start, u64 end);
 u64 get_max_mapped(void);
 #include <linux/range.h>
 int get_free_all_memory_range(struct range **rangep, int nodeid);
kernel/early_res.c +226 -366

737 lines not on this page · raw message

mm/page_alloc.c +1 -1
Index: linux-2.6/mm/page_alloc.c
===================================================================
@@ -3451,7 +3451,7 @@ void * __init __alloc_memory_core_early(
 
 	ptr = phys_to_virt(addr);
 	memset(ptr, 0, size);
-	reserve_early_without_check(addr, addr + size, "BOOTMEM");
+	reserve_early(addr, addr + size, "BOOTMEM");
 	return ptr;
 }
 #endif
mm/sparse-vmemmap.c +2 -2
Index: linux-2.6/mm/sparse-vmemmap.c
===================================================================
@@ -225,8 +225,8 @@ void __init sparse_mem_maps_populate_nod
 			char name[15];
 
 			snprintf(name, sizeof(name), "MEMMAP %d", nodeid);
-			reserve_early_without_check(__pa(vmemmap_buf_start),
-						    __pa(vmemmap_buf), name);
+			reserve_early(__pa(vmemmap_buf_start),
+					 __pa(vmemmap_buf), name);
 		}
 #else
 		free_bootmem(__pa(vmemmap_buf), vmemmap_buf_end - vmemmap_buf);
arch/x86/include/asm/lmb.h new file +8 -0
Index: linux-2.6/arch/x86/include/asm/lmb.h
===================================================================
@@ -0,0 +1,8 @@
+#ifndef _X86_LMB_H
+#define _X86_LMB_H
+
+#define LMB_DBG(fmt...) printk(fmt)
+
+#define LMB_REAL_LIMIT	0
+
+#endif