Skip to contentSkip to conversation

Use lmb with x86

PATCH In review Yinghai Lu 4 participants 40 messages May 8, 2010 – May 12, 2010

Subsystems (11)
lore
Share & tools
lore

Yinghai Lu

author
#0 lore raw

cover Use lmb with x86

the new lmb could be used to replace early_res in x86.

Suggested by: David, Ben, and Thomas

-v6: change sequence as requested by Thomas
-v7: seperate them to more patches
-v8: add boundary checking to make sure not free partial page. -v9: use lmb_debug to control print out of reserve_lmb.
add e820 clean up, and e820 become __initdata
-v10:use lmb.rmo_size and ARCH_DISCARD_LMB according to Michael
change name to lmb_find_area/reserve_lmb_area/free_lmb_area,
according to Michael
update find_lmb_area to use __lmb_alloc_base according to ben
-v11:move find_lmb_area_size back to x86.
x86 has own find_lmb_area, and could be disabled by ARCH_LMB_FIND_AREA
because _lmb_find_base has different behavoir from x86's old one. one from high to high and one from low to high
need more test
tested for x86 32bit/64bit, numa/nonuma, nobootmem/bootmem.
-v12:refresh the series with current tip
seperate nobootmem.c, so could remove some #ifdef
still keep CONFIG_NO_BOOTMEM, in x86 .c, and could use the as tags so other lmb could refer them to use NO_BOOTMEM.

-v14:refresh to current tip

-v15:remove x86 version lmb_find_area
remove other nobootmem and x86 e820 from this patchset

Only first three patches in this set could affect original lmb users. lmb.c lines from 567 to 996
If lmb guys are still not happy, we could move that 360 lines to arch/x86/mm/lmb.c

still hope Ben could do lmb clean up on top of this patchset.

Thanks

Yinghai

author
#1 lore raw

PATCH 1/22 lmb: Move lmb.c to mm/

lmb.c is memory related, so move it to mm/. It is suggested by Ingo

---
 lib/Makefile      |    2 --
 mm/Makefile       |    2 ++
 {lib => mm}/lmb.c |    0
 3 files changed, 2 insertions(+), 2 deletions(-)
 rename {lib => mm}/lmb.c (100%)
lib/Makefile +0 -2
index 9e6d3c2..a8f7d48 100644
@@ -88,8 +88,6 @@ obj-$(CONFIG_FAULT_INJECTION) += fault-inject.o
 
 lib-$(CONFIG_GENERIC_BUG) += bug.o
 
-obj-$(CONFIG_HAVE_LMB) += lmb.o
-
 obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.o
 
 obj-$(CONFIG_DYNAMIC_DEBUG) += dynamic_debug.o
mm/Makefile +2 -0
index 6c2a73a..52492f9 100644
@@ -15,6 +15,8 @@ obj-y			:= bootmem.o filemap.o mempool.o oom_kill.o fadvise.o \
 			   $(mmu-y)
 obj-y += init-mm.o
 
+obj-$(CONFIG_HAVE_LMB) += lmb.o
+
 obj-$(CONFIG_BOUNCE)	+= bounce.o
 obj-$(CONFIG_SWAP)	+= page_io.o swap_state.o swapfile.o thrash.o
 obj-$(CONFIG_HAS_DMA)	+= dmapool.o
mm/lmb.c renamed from lib/lmb.c +0 -0
similarity index 100%
rename from lib/lmb.c
rename to mm/lmb.c
Signature · 1 line
1.6.4.2
author
#2 lore raw

PATCH 2/22 lmb: Seperate region array from lmb_region struct

In reply to Yinghai Lu

lmb_init() will connect them back.
Add nr_regions in struct lmb_region to track region array size.

So later We can install dynamically allocated region array to that pointer

---
 include/linux/lmb.h |    3 ++-
 mm/lmb.c            |    9 ++++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)
include/linux/lmb.h +2 -1
index f3d1433..e14ea8d 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 nr_regions;
 };
 
 struct lmb {
mm/lmb.c +8 -1
index b1fc526..d49c589 100644
@@ -18,6 +18,8 @@
 #define LMB_ALLOC_ANYWHERE	0
 
 struct lmb lmb;
+static struct lmb_property lmb_memory_region[MAX_LMB_REGIONS];
+static struct lmb_property lmb_reserved_region[MAX_LMB_REGIONS];
 
 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.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_region *rgn, u64 base, u64 size)
 
 	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. */
Signature · 1 line
1.6.4.2
author
#3 lore raw

PATCH 3/22 lmb: Seperate __lmb_find_base() from __lmb_alloc_base()

In reply to Yinghai Lu

So We can construct one generic __find_lmb_area() later

-v2: Add LMB_ERROR according to Ben.

---
 include/linux/lmb.h |    1 +
 mm/lmb.c            |   21 +++++++++++++++++----
 2 files changed, 18 insertions(+), 4 deletions(-)
include/linux/lmb.h +1 -0
index e14ea8d..d2e456b 100644
@@ -17,6 +17,7 @@
 #include <linux/mm.h>
 
 #define MAX_LMB_REGIONS 128
+#define LMB_ERROR	(-1ULL)
 
 struct lmb_property {
 	u64 base;
mm/lmb.c +17 -4
index d49c589..d130527 100644
@@ -393,7 +393,7 @@ u64 __init lmb_alloc_base(u64 size, u64 align, u64 max_addr)
 	return alloc;
 }
 
-u64 __init __lmb_alloc_base(u64 size, u64 align, u64 max_addr)
+static u64 __init __lmb_find_base(u64 size, u64 align, u64 max_addr)
 {
 	long i, j;
 	u64 base = 0;
@@ -426,8 +426,6 @@ u64 __init __lmb_alloc_base(u64 size, u64 align, u64 max_addr)
 			j = lmb_overlaps_region(&lmb.reserved, base, size);
 			if (j < 0) {
 				/* this area isn't reserved, take it */
-				if (lmb_add_region(&lmb.reserved, base, size) < 0)
-					return 0;
 				return base;
 			}
 			res_base = lmb.reserved.region[j].base;
@@ -436,7 +434,22 @@ u64 __init __lmb_alloc_base(u64 size, u64 align, u64 max_addr)
 			base = lmb_align_down(res_base - size, align);
 		}
 	}
-	return 0;
+	return LMB_ERROR;
+}
+
+u64 __init __lmb_alloc_base(u64 size, u64 align, u64 max_addr)
+{
+	u64 base;
+
+	base = __lmb_find_base(size, align, max_addr);
+
+	if (base == LMB_ERROR)
+		return 0;
+
+	if (lmb_add_region(&lmb.reserved, base, size) < 0)
+		return 0;
+
+	return base;
 }
 
 /* You must call lmb_analyze() before this. */
Signature · 1 line
1.6.4.2
author
#4 lore raw

PATCH 4/22 lmb: Add lmb_find_area()

In reply to Yinghai Lu

It will try find area according with size/align in specified range (start, end).

lmb_find_area() will honor goal/limit.

also make it more easy for x86 to use lmb.
x86 early_res is using find/reserve pattern instead of alloc.

When we need temporaray buff for range array etc for range work, if We are using lmb_alloc(), We will need to add some post fix code for buffer that is used by range array, because it is in the lmb.reserved already. and have to call extra lmb_free().

-v2: Change name to lmb_find_area() according to Michael Ellerman -v3: Add generic weak version __lmb_find_area()

---
 include/linux/lmb.h |    4 ++++
 mm/lmb.c            |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 0 deletions(-)
include/linux/lmb.h +4 -0
index d2e456b..211cece 100644
@@ -84,6 +84,10 @@ lmb_end_pfn(struct lmb_region *type, unsigned long region_nr)
 	       lmb_size_pages(type, region_nr);
 }
 
+u64 __lmb_find_area(u64 ei_start, u64 ei_last, u64 start, u64 end,
+			 u64 size, u64 align);
+u64 lmb_find_area(u64 start, u64 end, u64 size, u64 align);
+
 #include <asm/lmb.h>
 
 #endif /* __KERNEL__ */
mm/lmb.c +48 -0

60 lines not on this page · raw message

Signature · 1 line
1.6.4.2
author
#5 lore raw

PATCH 5/22 lmb: Add lmb_reserve_area/lmb_free_area

In reply to Yinghai Lu

They will check if the region array is big enough.

__check_and_double_region_array will try to double the region array if that array spare slots is not big enough. Old array will be copied to new array.

Arch code should set lmb.default_alloc_limit accordingly, so the new array is in accessiable address.

-v2: change get_max_mapped() to lmb.default_alloc_limit according to Michael
Ellerman and Ben
change to lmb_reserve_area and lmb_free_area according to Michael Ellerman
-v3: call check_and_double after reserve/free, so could avoid to use
find_lmb_area. Suggested by Michael Ellerman

---
 include/linux/lmb.h |    4 +++
 mm/lmb.c            |   66 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+), 0 deletions(-)
include/linux/lmb.h +4 -0
index 211cece..b1c1b9b 100644
@@ -34,6 +34,7 @@ struct lmb_region {
 struct lmb {
 	unsigned long debug;
 	u64 rmo_size;
+	u64 default_alloc_limit;
 	struct lmb_region memory;
 	struct lmb_region reserved;
 };
@@ -84,6 +85,9 @@ lmb_end_pfn(struct lmb_region *type, unsigned long region_nr)
 	       lmb_size_pages(type, region_nr);
 }
 
+void lmb_reserve_area(u64 start, u64 end, char *name);
+void lmb_free_area(u64 start, u64 end);
+void lmb_add_memory(u64 start, u64 end);
 u64 __lmb_find_area(u64 ei_start, u64 ei_last, u64 start, u64 end,
 			 u64 size, u64 align);
 u64 lmb_find_area(u64 start, u64 end, u64 size, u64 align);
mm/lmb.c +66 -0

72 lines not on this page · raw message

Signature · 1 line
1.6.4.2
#6 lore raw

Re: [PATCH 05/22] lmb: Add lmb_reserve_area/lmb_free_area

Quoted 7 lines · Yinghai Lu

They will check if the region array is big enough.

__check_and_double_region_array will try to double the region array if that array spare slots is not big enough. Old array will be copied to new array.

Arch code should set lmb.default_alloc_limit accordingly, so the new array is in accessiable address.

More issues...

Quoted 8 lines
mm/lmb.c +8 -0
+static void __init __check_and_double_region_array(struct lmb_region *type,
+			 struct lmb_property *static_region)
+{
+	u64 size, mem;
+	struct lmb_property *new, *old;
+	unsigned long rgnsz = type->nr_regions;
+
+	/* Do we have enough slots left ? */

mm/lmb.c int lmb_find(struct lmb_property *res) · line 584

Quoted 10 lines
mm/lmb.c +10 -0
+	if ((rgnsz - type->cnt) > 2)
+		return;
+
+	old = type->region;
+	/* Double the array size */
+	size = sizeof(struct lmb_property) * rgnsz * 2;
+
+	mem = __lmb_alloc_base(size, sizeof(struct lmb_property), lmb.default_alloc_limit);
+	if (mem == 0)
+		panic("can not find more space for lmb.reserved.region array");

Now, that is not right because we do memory hotplug. Thus lmb_add() must be able to deal with things running past LMB init.

slab_is_available() will do the job for now, unless somebody has bootmem and tries to lmb_add() memory while bootmem is active, but screw that for now. See the code I'll post tonight.

Quoted 5 lines
mm/lmb.c +5 -0
+	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);
+

mm/lmb.c int lmb_find(struct lmb_property *res) · line 600

Quoted 10 lines
mm/lmb.c +10 -0
+	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);
+
+	/* Free old one ?*/
+	if (old != static_region)
+		lmb_free(__pa(old), sizeof(struct lmb_property) * rgnsz);
+}

Similar comment, don't bother if slab is available.

mm/lmb.c int lmb_find(struct lmb_property *res) · line 606

Quoted 5 lines
mm/lmb.c +5 -0
+void __init lmb_add_memory(u64 start, u64 end)
+{
+	lmb_add_region(&lmb.memory, start, end - start);
+	__check_and_double_region_array(&lmb.memory, &lmb_memory_region[0]);
+}

So you duplicate lmb_add() gratuituously ?

mm/lmb.c int lmb_find(struct lmb_property *res) · line 618

Quoted 11 lines
mm/lmb.c +11 -0
+void __init lmb_reserve_area(u64 start, u64 end, char *name)
+{
+	if (start == end)
+		return;
+
+	if (WARN_ONCE(start > end, "lmb_reserve_area: wrong range [%#llx, %#llx]\n", start, end))
+		return;
+
+	lmb_add_region(&lmb.reserved, start, end - start);
+	__check_and_double_region_array(&lmb.reserved, &lmb_reserved_region[0]);
+}

And lmb_reserve() ?

Do we want to end up with 5 copies of the same API with subtle differences just for fun ?

Cheers,
Ben.

#7 lore raw

Re: [PATCH 05/22] lmb: Add lmb_reserve_area/lmb_free_area

Quoted 77 lines · Benjamin Herrenschmidt
Quoted 7 lines · Yinghai Lu

They will check if the region array is big enough.

__check_and_double_region_array will try to double the region array if that array spare slots is not big enough. Old array will be copied to new array.

Arch code should set lmb.default_alloc_limit accordingly, so the new array is in accessiable address.

More issues...

Quoted 8 lines
mm/lmb.c +8 -0
+static void __init __check_and_double_region_array(struct lmb_region *type,
+			 struct lmb_property *static_region)
+{
+	u64 size, mem;
+	struct lmb_property *new, *old;
+	unsigned long rgnsz = type->nr_regions;
+
+	/* Do we have enough slots left ? */

mm/lmb.c int lmb_find(struct lmb_property *res) · line 584

Quoted 10 lines
mm/lmb.c +10 -0
+	if ((rgnsz - type->cnt) > 2)
+		return;
+
+	old = type->region;
+	/* Double the array size */
+	size = sizeof(struct lmb_property) * rgnsz * 2;
+
+	mem = __lmb_alloc_base(size, sizeof(struct lmb_property), lmb.default_alloc_limit);
+	if (mem == 0)
+		panic("can not find more space for lmb.reserved.region array");

Now, that is not right because we do memory hotplug. Thus lmb_add() must be able to deal with things running past LMB init.

slab_is_available() will do the job for now, unless somebody has bootmem and tries to lmb_add() memory while bootmem is active, but screw that for now. See the code I'll post tonight.

Quoted 5 lines
mm/lmb.c +5 -0
+	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);
+

mm/lmb.c int lmb_find(struct lmb_property *res) · line 600

Quoted 10 lines
mm/lmb.c +10 -0
+	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);
+
+	/* Free old one ?*/
+	if (old != static_region)
+		lmb_free(__pa(old), sizeof(struct lmb_property) * rgnsz);
+}

Similar comment, don't bother if slab is available.

mm/lmb.c int lmb_find(struct lmb_property *res) · line 606

Quoted 5 lines
mm/lmb.c +5 -0
+void __init lmb_add_memory(u64 start, u64 end)
+{
+	lmb_add_region(&lmb.memory, start, end - start);
+	__check_and_double_region_array(&lmb.memory, &lmb_memory_region[0]);
+}

So you duplicate lmb_add() gratuituously ?

mm/lmb.c int lmb_find(struct lmb_property *res) · line 618

Quoted 11 lines
mm/lmb.c +11 -0
+void __init lmb_reserve_area(u64 start, u64 end, char *name)
+{
+	if (start == end)
+		return;
+
+	if (WARN_ONCE(start > end, "lmb_reserve_area: wrong range [%#llx, %#llx]\n", start, end))
+		return;
+
+	lmb_add_region(&lmb.reserved, start, end - start);
+	__check_and_double_region_array(&lmb.reserved, &lmb_reserved_region[0]);
+}

And lmb_reserve() ?

Quoted 2 lines

Do we want to end up with 5 copies of the same API with subtle differences just for fun ?

those functions have __init markers, and only can be used on boot stage. so do need to worry about hotplug mem.

what I do is: use current lmb code for x86, and keep the affects to original lmb users to minimum. (should be near 0)

YH

#8 lore raw

Re: [PATCH 05/22] lmb: Add lmb_reserve_area/lmb_free_area

So promote them to meminit...

Quoted 86 lines · Yinghai
Quoted 77 lines · Benjamin Herrenschmidt
Quoted 7 lines · Yinghai Lu

They will check if the region array is big enough.

__check_and_double_region_array will try to double the region array if that array spare slots is not big enough. Old array will be copied to new array.

Arch code should set lmb.default_alloc_limit accordingly, so the new array is in accessiable address.

More issues...

Quoted 8 lines
mm/lmb.c +8 -0
+static void __init __check_and_double_region_array(struct lmb_region *type,
+			 struct lmb_property *static_region)
+{
+	u64 size, mem;
+	struct lmb_property *new, *old;
+	unsigned long rgnsz = type->nr_regions;
+
+	/* Do we have enough slots left ? */

mm/lmb.c int lmb_find(struct lmb_property *res) · line 584

Quoted 10 lines
mm/lmb.c +10 -0
+	if ((rgnsz - type->cnt) > 2)
+		return;
+
+	old = type->region;
+	/* Double the array size */
+	size = sizeof(struct lmb_property) * rgnsz * 2;
+
+	mem = __lmb_alloc_base(size, sizeof(struct lmb_property), lmb.default_alloc_limit);
+	if (mem == 0)
+		panic("can not find more space for lmb.reserved.region array");

Now, that is not right because we do memory hotplug. Thus lmb_add() must be able to deal with things running past LMB init.

slab_is_available() will do the job for now, unless somebody has bootmem and tries to lmb_add() memory while bootmem is active, but screw that for now. See the code I'll post tonight.

Quoted 5 lines
mm/lmb.c +5 -0
+	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);
+

mm/lmb.c int lmb_find(struct lmb_property *res) · line 600

Quoted 10 lines
mm/lmb.c +10 -0
+	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);
+
+	/* Free old one ?*/
+	if (old != static_region)
+		lmb_free(__pa(old), sizeof(struct lmb_property) * rgnsz);
+}

Similar comment, don't bother if slab is available.

mm/lmb.c int lmb_find(struct lmb_property *res) · line 606

Quoted 5 lines
mm/lmb.c +5 -0
+void __init lmb_add_memory(u64 start, u64 end)
+{
+	lmb_add_region(&lmb.memory, start, end - start);
+	__check_and_double_region_array(&lmb.memory, &lmb_memory_region[0]);
+}

So you duplicate lmb_add() gratuituously ?

mm/lmb.c int lmb_find(struct lmb_property *res) · line 618

Quoted 11 lines
mm/lmb.c +11 -0
+void __init lmb_reserve_area(u64 start, u64 end, char *name)
+{
+	if (start == end)
+		return;
+
+	if (WARN_ONCE(start > end, "lmb_reserve_area: wrong range [%#llx, %#llx]\n", start, end))
+		return;
+
+	lmb_add_region(&lmb.reserved, start, end - start);
+	__check_and_double_region_array(&lmb.reserved, &lmb_reserved_region[0]);
+}

And lmb_reserve() ?

Quoted 2 lines

Do we want to end up with 5 copies of the same API with subtle differences just for fun ?

those functions have __init markers, and only can be used on boot stage. so do need to worry about hotplug mem.

what I do is: use current lmb code for x86, and keep the affects to original lmb users to minimum. (should be near 0)

YH

Signature · 1 line
Sent from my Android phone with K-9 Mail. Please excuse my brevity.
#9 lore raw

Re: [PATCH 05/22] lmb: Add lmb_reserve_area/lmb_free_area

In reply to Yinghai
Quoted 5 lines · Yinghai

those functions have __init markers, and only can be used on boot stage. so do need to worry about hotplug mem.

what I do is: use current lmb code for x86, and keep the affects to original lmb users to minimum. (should be near 0)

But that's just wrong. You are just duplicating functionality all over the place. That doesn't make any sense.

Cheers,
Ben.

author
#10 lore raw

PATCH 6/22 bootmem, x86: Add weak version of reserve_bootmem_generic

In reply to Yinghai Lu

It will be used lmb_to_bootmem converting

It is an wrapper for reserve_bootmem, and x86 64bit is using special one.

Also clean up that version for x86_64. We don't need to take care of numa path for that, bootmem can handle it how

---
 arch/x86/mm/init_32.c |    6 ------
 arch/x86/mm/init_64.c |   20 ++------------------
 mm/bootmem.c          |    6 ++++++
 3 files changed, 8 insertions(+), 24 deletions(-)
arch/x86/mm/init_32.c +0 -6
index bca7909..90e0545 100644
@@ -1069,9 +1069,3 @@ void mark_rodata_ro(void)
 #endif
 }
 #endif
-
-int __init reserve_bootmem_generic(unsigned long phys, unsigned long len,
-				   int flags)
-{
-	return reserve_bootmem(phys, len, flags);
-}
arch/x86/mm/init_64.c +2 -18
index ee41bba..634fa08 100644
@@ -799,13 +799,10 @@ void mark_rodata_ro(void)
 
 #endif
 
+#ifndef CONFIG_NO_BOOTMEM
 int __init reserve_bootmem_generic(unsigned long phys, unsigned long len,
 				   int flags)
 {
-#ifdef CONFIG_NUMA
-	int nid, next_nid;
-	int ret;
-#endif
 	unsigned long pfn = phys >> PAGE_SHIFT;
 
 	if (pfn >= max_pfn) {
@@ -821,21 +818,7 @@ int __init reserve_bootmem_generic(unsigned long phys, unsigned long len,
 		return -EFAULT;
 	}
 
-	/* Should check here against the e820 map to avoid double free */
-#ifdef CONFIG_NUMA
-	nid = phys_to_nid(phys);
-	next_nid = phys_to_nid(phys + len - 1);
-	if (nid == next_nid)
-		ret = reserve_bootmem_node(NODE_DATA(nid), phys, len, flags);
-	else
-		ret = reserve_bootmem(phys, len, flags);
-
-	if (ret != 0)
-		return ret;
-
-#else
 	reserve_bootmem(phys, len, flags);
-#endif
 
 	if (phys+len <= MAX_DMA_PFN*PAGE_SIZE) {
 		dma_reserve += len / PAGE_SIZE;
@@ -844,6 +827,7 @@ int __init reserve_bootmem_generic(unsigned long phys, unsigned long len,
 
 	return 0;
 }
+#endif
 
 int kern_addr_valid(unsigned long addr)
 {
mm/bootmem.c +6 -0
index 58c66cc..ee31b95 100644
@@ -526,6 +526,12 @@ int __init reserve_bootmem(unsigned long addr, unsigned long size,
 }
 
 #ifndef CONFIG_NO_BOOTMEM
+int __weak __init reserve_bootmem_generic(unsigned long phys, unsigned long len,
+				   int flags)
+{
+	return reserve_bootmem(phys, len, flags);
+}
+
 static unsigned long __init align_idx(struct bootmem_data *bdata,
 				      unsigned long idx, unsigned long step)
 {
Signature · 1 line
1.6.4.2
author
#11 lore raw

PATCH 7/22 lmb: Add lmb_to_bootmem()

In reply to Yinghai Lu

lmb_to_bootmem() will reserve lmb.reserved.region in bootmem after bootmem is set up.

We can use it to with all arches that support lmb later.

---
 include/linux/lmb.h |    2 ++
 mm/lmb.c            |   32 ++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 0 deletions(-)
include/linux/lmb.h +2 -0
index b1c1b9b..2c008b9 100644
@@ -92,6 +92,8 @@ u64 __lmb_find_area(u64 ei_start, u64 ei_last, u64 start, u64 end,
 			 u64 size, u64 align);
 u64 lmb_find_area(u64 start, u64 end, u64 size, u64 align);
 
+void lmb_to_bootmem(u64 start, u64 end);
+
 #include <asm/lmb.h>
 
 #endif /* __KERNEL__ */
mm/lmb.c +32 -0
index e3f87d0..ccbc76d 100644
@@ -630,6 +630,38 @@ void __init lmb_free_area(u64 start, u64 end)
 	__check_and_double_region_array(&lmb.reserved, &lmb_reserved_region[0]);
 }
 
+#ifndef CONFIG_NO_BOOTMEM
+void __init lmb_to_bootmem(u64 start, u64 end)
+{
+	int i, count;
+	u64 final_start, final_end;
+
+	/* Take out region array itself */
+	if (lmb.reserved.region != lmb_reserved_region)
+		lmb_free(__pa(lmb.reserved.region), sizeof(struct lmb_property) * lmb.reserved.nr_regions);
+
+	count  = lmb.reserved.cnt;
+	pr_info("(%d early reservations) ==> bootmem [%010llx - %010llx]\n", count, start, end);
+	for (i = 0; i < count; i++) {
+		struct lmb_property *r = &lmb.reserved.region[i];
+		pr_info("  #%d [%010llx - %010llx] ", i, r->base, r->base + r->size);
+		final_start = max(start, r->base);
+		final_end = min(end, r->base + r->size);
+		if (final_start >= final_end) {
+			pr_cont("\n");
+			continue;
+		}
+		pr_cont(" ==> [%010llx - %010llx]\n", final_start, final_end);
+		reserve_bootmem_generic(final_start, final_end - final_start, BOOTMEM_DEFAULT);
+	}
+	/* Clear them to avoid misusing ? */
+	memset(&lmb.reserved.region[0], 0, sizeof(struct lmb_property) * lmb.reserved.nr_regions);
+	lmb.reserved.region = NULL;
+	lmb.reserved.nr_regions = 0;
+	lmb.reserved.cnt = 0;
+}
+#endif
+
 u64 __init __weak __lmb_find_area(u64 ei_start, u64 ei_last, u64 start, u64 end,
 				 u64 size, u64 align)
 {
Signature · 1 line
1.6.4.2
#12 lore raw

Re: [PATCH 07/22] lmb: Add lmb_to_bootmem()

Quoted 4 lines · Yinghai Lu

lmb_to_bootmem() will reserve lmb.reserved.region in bootmem after bootmem is set up.

We can use it to with all arches that support lmb later.

This is clumsy. Doesn't work with NUMA either. Also, reserve_bootmem_generic() only exists on x86 afaik.

I also disagree with the clearing of the region, I'd like to keep the arrays around for debug purposes, especially since I'm going to expose them in debugfs, but I suppose we can make that an option. In any case, I don't think it's the right place to introduce such a "side effect".

In any case, I'm not convinced there's much interrest at this stage in putting that code in the generic lmb.c, with my patches this stuff boils down to:

	for_each_lmb(reserved, reg) {
		unsigned long top = reg->base + reg->size - 1;
		if (top < lowmem_end_addr)
			reserve_bootmem(reg->base, reg->size, BOOTMEM_DEFAULT);
		else if (reg->base < lowmem_end_addr) {
			unsigned long trunc_size = lowmem_end_addr - reg->base;
			reserve_bootmem(reg->base, trunc_size, BOOTMEM_DEFAULT);
		}
	}

In the non-numa case, but let's keep that in arch for now. We might be able to reconcile the NUMA case, I'm looking at that, it's non trivial, in which case that stuff would become a better candidate for being in the generic code, but not for now.

Cheers,
Ben.

Quoted 62 lines
---
 include/linux/lmb.h |    2 ++
 mm/lmb.c            |   32 ++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 0 deletions(-)
include/linux/lmb.h +2 -0
index b1c1b9b..2c008b9 100644
@@ -92,6 +92,8 @@ u64 __lmb_find_area(u64 ei_start, u64 ei_last, u64 start, u64 end,
 			 u64 size, u64 align);
 u64 lmb_find_area(u64 start, u64 end, u64 size, u64 align);
 
+void lmb_to_bootmem(u64 start, u64 end);
+
 #include <asm/lmb.h>
 
 #endif /* __KERNEL__ */
mm/lmb.c +32 -0
index e3f87d0..ccbc76d 100644
@@ -630,6 +630,38 @@ void __init lmb_free_area(u64 start, u64 end)
 	__check_and_double_region_array(&lmb.reserved, &lmb_reserved_region[0]);
 }
 
+#ifndef CONFIG_NO_BOOTMEM
+void __init lmb_to_bootmem(u64 start, u64 end)
+{
+	int i, count;
+	u64 final_start, final_end;
+
+	/* Take out region array itself */
+	if (lmb.reserved.region != lmb_reserved_region)
+		lmb_free(__pa(lmb.reserved.region), sizeof(struct lmb_property) * lmb.reserved.nr_regions);
+
+	count  = lmb.reserved.cnt;
+	pr_info("(%d early reservations) ==> bootmem [%010llx - %010llx]\n", count, start, end);
+	for (i = 0; i < count; i++) {
+		struct lmb_property *r = &lmb.reserved.region[i];
+		pr_info("  #%d [%010llx - %010llx] ", i, r->base, r->base + r->size);
+		final_start = max(start, r->base);
+		final_end = min(end, r->base + r->size);
+		if (final_start >= final_end) {
+			pr_cont("\n");
+			continue;
+		}
+		pr_cont(" ==> [%010llx - %010llx]\n", final_start, final_end);
+		reserve_bootmem_generic(final_start, final_end - final_start, BOOTMEM_DEFAULT);
+	}
+	/* Clear them to avoid misusing ? */
+	memset(&lmb.reserved.region[0], 0, sizeof(struct lmb_property) * lmb.reserved.nr_regions);
+	lmb.reserved.region = NULL;
+	lmb.reserved.nr_regions = 0;
+	lmb.reserved.cnt = 0;
+}
+#endif
+
 u64 __init __weak __lmb_find_area(u64 ei_start, u64 ei_last, u64 start, u64 end,
 				 u64 size, u64 align)
 {
#13 lore raw

Re: [PATCH 07/22] lmb: Add lmb_to_bootmem()

Quoted 7 lines · Benjamin Herrenschmidt
Quoted 4 lines · Yinghai Lu

lmb_to_bootmem() will reserve lmb.reserved.region in bootmem after bootmem is set up.

We can use it to with all arches that support lmb later.

This is clumsy. Doesn't work with NUMA either. Also,

it works NUMA. for x86 we managed to call that one time from 2.6.34-rc1. (still called early_res_to_bootmem().
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=1842f90cc98625d4d9bf8f8b927f17705ceb4e9c

Quoted 1 line

reserve_bootmem_generic() only exists on x86 afaik.

previous patch add weak version
[PATCH 06/22] bootmem, x86: Add weak version of reserve_bootmem_generic

YH

#14 lore raw

Re: [PATCH 07/22] lmb: Add lmb_to_bootmem()

Quoted 11 lines · Yinghai
Quoted 1 line

This is clumsy. Doesn't work with NUMA either. Also,

it works NUMA. for x86 we managed to call that one time from 2.6.34-rc1. (still called early_res_to_bootmem().
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=1842f90cc98625d4d9bf8f8b927f17705ceb4e9c

Quoted 1 line

reserve_bootmem_generic() only exists on x86 afaik.

previous patch add weak version
[PATCH 06/22] bootmem, x86: Add weak version of
reserve_bootmem_generic

It might work on x86, it won't work on sparc as far as I understand. In any case, I don't think that should be in lmb.c, that's boilerplate crap that eventually will go away.

One thing you don't seem to get is that several archs already have some code to move from lmb to bootmem.

The right approach when making something "generic" like that is not to make up another one deep into x86 gunkyness and make -that- generic ignoring the existing implementations.

Instead, make sure that the existing implementations are in sync, and then move -that- to a generic place, eventually adding (in a separate patch) the changes needed by x86 if any.

Cheers,
Ben.

#15 lore raw

Re: [PATCH 07/22] lmb: Add lmb_to_bootmem()

Quoted 20 lines · Benjamin Herrenschmidt
Quoted 11 lines · Yinghai
Quoted 1 line

This is clumsy. Doesn't work with NUMA either. Also,

it works NUMA. for x86 we managed to call that one time from 2.6.34-rc1. (still called early_res_to_bootmem().
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=1842f90cc98625d4d9bf8f8b927f17705ceb4e9c

Quoted 1 line

reserve_bootmem_generic() only exists on x86 afaik.

previous patch add weak version
[PATCH 06/22] bootmem, x86: Add weak version of
reserve_bootmem_generic

It might work on x86, it won't work on sparc as far as I understand. In any case, I don't think that should be in lmb.c, that's boilerplate crap that eventually will go away.

One thing you don't seem to get is that several archs already have some code to move from lmb to bootmem.

Quoted 8 lines

The right approach when making something "generic" like that is not to make up another one deep into x86 gunkyness and make -that- generic ignoring the existing implementations.

Instead, make sure that the existing implementations are in sync, and then move -that- to a generic place, eventually adding (in a separate patch) the changes needed by x86 if any.

Will move that back to arch/x86/mm/lmb.c

Quoted 1 line
author
#16 lore raw

PATCH 8/22 lmb: Add get_free_all_memory_range()

In reply to Yinghai Lu

get_free_all_memory_range is for CONFIG_NO_BOOTMEM=y, and will be called by free_all_memory_core_early().

It will use early_node_map aka active ranges subtract lmb.reserved to get all free range, and those ranges will convert to slab pages.

-v3: use __lmb_find_base() to get range free buffer.

---
 include/linux/lmb.h |    2 +
 mm/lmb.c            |   86 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 87 insertions(+), 1 deletions(-)
include/linux/lmb.h +2 -0
index 2c008b9..aaef2ca 100644
@@ -93,6 +93,8 @@ u64 __lmb_find_area(u64 ei_start, u64 ei_last, u64 start, u64 end,
 u64 lmb_find_area(u64 start, u64 end, u64 size, u64 align);
 
 void lmb_to_bootmem(u64 start, u64 end);
+struct range;
+int get_free_all_memory_range(struct range **rangep, int nodeid);
 
 #include <asm/lmb.h>
 
mm/lmb.c +85 -1

92 lines not on this page · raw message

Signature · 1 line
1.6.4.2
#17 lore raw

Re: [PATCH 08/22] lmb: Add get_free_all_memory_range()

Quoted 7 lines · Yinghai Lu

get_free_all_memory_range is for CONFIG_NO_BOOTMEM=y, and will be called by free_all_memory_core_early().

It will use early_node_map aka active ranges subtract lmb.reserved to get all free range, and those ranges will convert to slab pages.

-v3: use __lmb_find_base() to get range free buffer.

So that is more crap on top of crap that shouldn't have been upstream in the first place. That whole range management stuff that was taken out of x86 and made generic should just go away (or go back to x86 where it belongs).

Seriously Ingo, what the hell did you think when you merged that stuff ?

So the code here is extremely convluted, only meaningful in the nobootmem/early_res case and totally NOT something that should be in the generic lmb code either.

If you're going to do something half-sensible with nobootmem, which is to use LMB directly, then I see no point in keeping any of that stuff.

Ben.

Quoted 117 lines
---
 include/linux/lmb.h |    2 +
 mm/lmb.c            |   86 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 87 insertions(+), 1 deletions(-)
include/linux/lmb.h +2 -0
index 2c008b9..aaef2ca 100644
@@ -93,6 +93,8 @@ u64 __lmb_find_area(u64 ei_start, u64 ei_last, u64 start, u64 end,
 u64 lmb_find_area(u64 start, u64 end, u64 size, u64 align);
 
 void lmb_to_bootmem(u64 start, u64 end);
+struct range;
+int get_free_all_memory_range(struct range **rangep, int nodeid);
 
 #include <asm/lmb.h>
 
mm/lmb.c +85 -1
index ccbc76d..2e19df9 100644
@@ -630,7 +630,91 @@ void __init lmb_free_area(u64 start, u64 end)
 	__check_and_double_region_array(&lmb.reserved, &lmb_reserved_region[0]);
 }
 
-#ifndef CONFIG_NO_BOOTMEM
+static __init struct range *find_range_array(int count)
+{
+	u64 end, size, mem;
+	struct range *range;
+
+	size = sizeof(struct range) * count;
+	end = lmb.default_alloc_limit;
+
+	mem = __lmb_find_base(size, sizeof(struct range), end);
+	if (mem == -1ULL)
+		panic("can not find more space for range array");
+
+	/*
+	 * This range is tempoaray, so don't reserve it, it will not be
+	 * overlapped because We will not alloccate new buffer before
+	 * We discard this one
+	 */
+	range = __va(mem);
+	memset(range, 0, size);
+
+	return range;
+}
+
+#ifdef CONFIG_NO_BOOTMEM
+static void __init subtract_lmb_reserved(struct range *range, int az)
+{
+	int i, count;
+	u64 final_start, final_end;
+
+	/* Take out region array itself at first*/
+	if (lmb.reserved.region != lmb_reserved_region)
+		lmb_free(__pa(lmb.reserved.region), sizeof(struct lmb_property) * lmb.reserved.nr_regions);
+
+	count  = lmb.reserved.cnt;
+
+	pr_info("Subtract (%d early reservations)\n", count);
+
+	for (i = 0; i < count; i++) {
+		struct lmb_property *r = &lmb.reserved.region[i];
+		pr_info("  #%d [%010llx - %010llx]\n", i, r->base, r->base + r->size);
+		final_start = PFN_DOWN(r->base);
+		final_end = PFN_UP(r->base + r->size);
+		if (final_start >= final_end)
+			continue;
+		subtract_range(range, az, final_start, final_end);
+	}
+	/* Put region array back ? */
+	if (lmb.reserved.region != lmb_reserved_region)
+		lmb_reserve(__pa(lmb.reserved.region), sizeof(struct lmb_property) * lmb.reserved.nr_regions);
+}
+
+int __init get_free_all_memory_range(struct range **rangep, int nodeid)
+{
+	int count;
+	struct range *range;
+	int nr_range;
+
+	count = lmb.reserved.cnt * 2;
+
+	range = find_range_array(count);
+	nr_range = 0;
+
+	/*
+	 * Use early_node_map[] and lmb.reserved.region to get range array
+	 * at first
+	 */
+	nr_range = add_from_early_node_map(range, count, nr_range, nodeid);
+#ifdef CONFIG_X86_32
+	subtract_range(range, count, max_low_pfn, -1ULL);
+#endif
+	subtract_lmb_reserved(range, count);
+	nr_range = clean_sort_range(range, count);
+
+	/* Need to clear it ? */
+	if (nodeid == MAX_NUMNODES) {
+		memset(&lmb.reserved.region[0], 0, sizeof(struct lmb_property) * lmb.reserved.nr_regions);
+		lmb.reserved.region = NULL;
+		lmb.reserved.nr_regions = 0;
+		lmb.reserved.cnt = 0;
+	}
+
+	*rangep = range;
+	return nr_range;
+}
+#else
 void __init lmb_to_bootmem(u64 start, u64 end)
 {
 	int i, count;
#18 lore raw

Re: [PATCH 08/22] lmb: Add get_free_all_memory_range()

In reply to Yinghai Lu
Quoted 5 lines · Yinghai Lu

get_free_all_memory_range is for CONFIG_NO_BOOTMEM=y, and will be called by free_all_memory_core_early().

It will use early_node_map aka active ranges subtract lmb.reserved to get all free range, and those ranges will convert to slab pages.

Ok, so after looking more, and more or less understanding the very convoluted code path you have created there:

You basically end up calling into lmb to create that "range" array of ranges that represent the overlap of LMB's with a node ranges.

That itself is done by LMB itself calling into page_alloc.c which creates a struct range array of all the node ranges, LMB then does the intersection, sorts it, returns that to bootmem, which can finally iterate that, do the free's and discard it.

Wow !

All of that could fit in one single function, inside or outside LMB (I vote for outside for now, since it's all about NO_BOOTMEM).

Do like I do for my nid allocator: Call get_pfn_range_for_nid(), then walk the LMB array and pick up intersecting ranges & free them. Easy. One function, not 3 layers spread as many files, no need to allocate that range array thing etc...

BTW. You -really- need to get rid of that kernel/range.c and associated range.h. We don't need -yet-another- range management system in Linux, seriously.

So all that stuff goes out of LMB for now. Just rebase your shit on top of my patches when I post them, use my new for_each_lmb() along with get_pfn_range_for_nid() as explained above, and do that inside bootmem.c for now.

Note that the entire NO_BOOTMEM should be a sparate file. Call it bootmem-lmb.c and make it CONFIG_BOOTMEM_LMB or something like that to make it clear that it depends on ARCH_HAVE_LMB.

You should be able to remove a ton of crap code with that.

Cheers,
Ben.

author
#19 lore raw

PATCH 9/22 lmb: Add lmb_register_active_regions() and lmb_hole_size()

In reply to Yinghai Lu

lmb_register_active_regions() will be used to fill early_node_map, the result will be lmb.memory.region AND numa data

lmb_hole_size will be used to find hole size on lmb.memory.region with specified range.

---
 include/linux/lmb.h |    4 +++
 mm/lmb.c            |   68 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+), 0 deletions(-)
include/linux/lmb.h +4 -0
index aaef2ca..85918a4 100644
@@ -96,6 +96,10 @@ void lmb_to_bootmem(u64 start, u64 end);
 struct range;
 int get_free_all_memory_range(struct range **rangep, int nodeid);
 
+void lmb_register_active_regions(int nid, unsigned long start_pfn,
+					 unsigned long last_pfn);
+u64 lmb_hole_size(u64 start, u64 end);
+
 #include <asm/lmb.h>
 
 #endif /* __KERNEL__ */
mm/lmb.c +68 -0

71 lines not on this page · raw message

Signature · 1 line
1.6.4.2
author
#20 lore raw

PATCH 10/22 lmb: Prepare to include linux/lmb.h in core file

In reply to Yinghai Lu

Need to add protection in linux/lmb.h, to prepare to include it in
mm/page_alloc.c and mm/bootmem.c etc.

---
 include/linux/lmb.h |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
include/linux/lmb.h +3 -0
index 85918a4..58db7e9 100644
@@ -2,6 +2,7 @@
 #define _LINUX_LMB_H
 #ifdef __KERNEL__
 
+#ifdef CONFIG_HAVE_LMB
 /*
  * Logical memory blocks.
  *
@@ -102,6 +103,8 @@ u64 lmb_hole_size(u64 start, u64 end);
 
 #include <asm/lmb.h>
 
+#endif /* CONFIG_HAVE_LMB */
+
 #endif /* __KERNEL__ */
 
 #endif /* _LINUX_LMB_H */
Signature · 1 line
1.6.4.2
author
#21 lore raw

PATCH 11/22 lmb: Add find_memory_core_early()

In reply to Yinghai Lu

According to node range in early_node_map[] with __lmb_find_area to find free range.

Will be used by lmb_find_area_node()

lmb_find_area_node will be used to find right buffer for NODE_DATA

---
 include/linux/mm.h |    2 ++
 mm/page_alloc.c    |   29 +++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 0 deletions(-)
include/linux/mm.h +2 -0
index fb19bb9..7774e1d 100644
@@ -1159,6 +1159,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 +29 -0
index d03c946..72afd94 100644
@@ -21,6 +21,7 @@
 #include <linux/pagemap.h>
 #include <linux/jiffies.h>
 #include <linux/bootmem.h>
+#include <linux/lmb.h>
 #include <linux/compiler.h>
 #include <linux/kernel.h>
 #include <linux/kmemcheck.h>
@@ -3393,6 +3394,34 @@ void __init free_bootmem_with_active_regions(int nid,
 	}
 }
 
+#ifdef CONFIG_HAVE_LMB
+u64 __init find_memory_core_early(int nid, u64 size, u64 align,
+					u64 goal, u64 limit)
+{
+	int i;
+
+	/* Need to go over early_node_map to find out good range for node */
+	for_each_active_range_index_in_nid(i, nid) {
+		u64 addr;
+		u64 ei_start, ei_last;
+
+		ei_last = early_node_map[i].end_pfn;
+		ei_last <<= PAGE_SHIFT;
+		ei_start = early_node_map[i].start_pfn;
+		ei_start <<= PAGE_SHIFT;
+		addr = __lmb_find_area(ei_start, ei_last,
+					 goal, limit, size, align);
+
+		if (addr == LMB_ERROR)
+			continue;
+
+		return addr;
+	}
+
+	return -1ULL;
+}
+#endif
+
 int __init add_from_early_node_map(struct range *range, int az,
 				   int nr_range, int nid)
 {
Signature · 1 line
1.6.4.2
author
#22 lore raw

PATCH 12/22 lmb: Add lmb_find_area_node()

In reply to Yinghai Lu

It can be used to find NODE_DATA for numa.

Need to make sure early_node_map[] is filled before it is called, otherwise it will fallback to lmb_find_area(), with node range.

---
 include/linux/lmb.h |    1 +
 mm/lmb.c            |   15 +++++++++++++++
 2 files changed, 16 insertions(+), 0 deletions(-)
include/linux/lmb.h +1 -0
index 58db7e9..c75d0c9 100644
@@ -92,6 +92,7 @@ void lmb_add_memory(u64 start, u64 end);
 u64 __lmb_find_area(u64 ei_start, u64 ei_last, u64 start, u64 end,
 			 u64 size, u64 align);
 u64 lmb_find_area(u64 start, u64 end, u64 size, u64 align);
+u64 lmb_find_area_node(int nid, u64 start, u64 end, u64 size, u64 align);
 
 void lmb_to_bootmem(u64 start, u64 end);
 struct range;
mm/lmb.c +15 -0
index b9607fc..36b3f63 100644
@@ -790,6 +790,21 @@ u64 __init __weak lmb_find_area(u64 start, u64 end, u64 size, u64 align)
 	return LMB_ERROR;
 }
 /*
+ * Need to call this function after lmb_register_active_regions,
+ * so early_node_map[] is filled already.
+ */
+u64 __init lmb_find_area_node(int nid, u64 start, u64 end, u64 size, u64 align)
+{
+	u64 addr;
+	addr = find_memory_core_early(nid, size, align, start, end);
+	if (addr != LMB_ERROR)
+		return addr;
+
+	/* Fallback, should already have start end within node range */
+	return lmb_find_area(start, end, size, align);
+}
+
+/*
  * Finds an active region in the address range from start_pfn to last_pfn and
  * returns its range in ei_startpfn and ei_endpfn for the lmb entry.
  */
Signature · 1 line
1.6.4.2
#23 lore raw

Re: [PATCH 12/22] lmb: Add lmb_find_area_node()

Quoted 3 lines · Yinghai Lu

+ * Need to call this function after lmb_register_active_regions,
+ * so early_node_map[] is filled already.
+ */

This is easily replaced by something simpler using my current WIP branch and its nid allocator. IE, You don't need to add find_memory_core_early(0 or any of that. It can be made a lot more simply.

Cheers,
Ben.

Quoted 13 lines

+u64 __init lmb_find_area_node(int nid, u64 start, u64 end, u64 size, u64 align)

mm/lmb.c +7 -0
+{
+       u64 addr;
+       addr = find_memory_core_early(nid, size, align, start, end);
+       if (addr != LMB_ERROR)
+               return addr;
+
+       /* Fallback, should already have start end within node range

*/

mm/lmb.c +3 -0
+       return lmb_find_area(start, end, size, align);
+}
+ 
author
#24 lore raw

PATCH 13/22 lmb: Add lmb_free_memory_size()

In reply to Yinghai Lu

It will return free memory size in specified range.

We can not use memory_size - reserved_size here, because some reserved area may not be in the scope of lmb.memory.region.

Use lmb.memory.region subtracting lmb.reserved.region to get free range array. then count size of all free ranges.

---
 include/linux/lmb.h |    1 +
 mm/lmb.c            |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 0 deletions(-)
include/linux/lmb.h +1 -0
index c75d0c9..22be96d 100644
@@ -101,6 +101,7 @@ int get_free_all_memory_range(struct range **rangep, int nodeid);
 void lmb_register_active_regions(int nid, unsigned long start_pfn,
 					 unsigned long last_pfn);
 u64 lmb_hole_size(u64 start, u64 end);
+u64 lmb_free_memory_size(u64 addr, u64 limit);
 
 #include <asm/lmb.h>
 
mm/lmb.c +51 -0

57 lines not on this page · raw message

Signature · 1 line
1.6.4.2
#25 lore raw

Re: [PATCH 13/22] lmb: Add lmb_free_memory_size()

Quoted 7 lines · Yinghai Lu

It will return free memory size in specified range.

We can not use memory_size - reserved_size here, because some reserved area may not be in the scope of lmb.memory.region.

Use lmb.memory.region subtracting lmb.reserved.region to get free range array. then count size of all free ranges.

The name sucks. Something like lmb_free_memory_in_range() would be better, but why do you need that in the first place ? You often tend to fail to explain why you introduce a given function, it's not always obvious and in many case I suspect they are added layers that aren't actually useful.

Cheers,
Ben.

Quoted 80 lines
---
 include/linux/lmb.h |    1 +
 mm/lmb.c            |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 0 deletions(-)
include/linux/lmb.h +1 -0
index c75d0c9..22be96d 100644
@@ -101,6 +101,7 @@ int get_free_all_memory_range(struct range **rangep, int nodeid);
 void lmb_register_active_regions(int nid, unsigned long start_pfn,
 					 unsigned long last_pfn);
 u64 lmb_hole_size(u64 start, u64 end);
+u64 lmb_free_memory_size(u64 addr, u64 limit);
 
 #include <asm/lmb.h>
 
mm/lmb.c +51 -0
index 36b3f63..4bc125c 100644
@@ -746,6 +746,57 @@ void __init lmb_to_bootmem(u64 start, u64 end)
 }
 #endif
 
+u64 __init lmb_free_memory_size(u64 addr, u64 limit)
+{
+	int i, count;
+	struct range *range;
+	int nr_range;
+	u64 final_start, final_end;
+	u64 free_size;
+
+	count = lmb.reserved.cnt * 2;
+
+	range = find_range_array(count);
+	nr_range = 0;
+
+	addr = PFN_UP(addr);
+	limit = PFN_DOWN(limit);
+
+	for (i = 0; i < lmb.memory.cnt; i++) {
+		struct lmb_property *r = &lmb.memory.region[i];
+
+		final_start = PFN_UP(r->base);
+		final_end = PFN_DOWN(r->base + r->size);
+		if (final_start >= final_end)
+			continue;
+		if (final_start >= limit || final_end <= addr)
+			continue;
+
+		nr_range = add_range(range, count, nr_range, final_start, final_end);
+	}
+	subtract_range(range, count, 0, addr);
+	subtract_range(range, count, limit, -1ULL);
+	for (i = 0; i < lmb.reserved.cnt; i++) {
+		struct lmb_property *r = &lmb.reserved.region[i];
+
+		final_start = PFN_DOWN(r->base);
+		final_end = PFN_UP(r->base + r->size);
+		if (final_start >= final_end)
+			continue;
+		if (final_start >= limit || final_end <= addr)
+			continue;
+
+		subtract_range(range, count, final_start, final_end);
+	}
+	nr_range = clean_sort_range(range, count);
+
+	free_size = 0;
+	for (i = 0; i < nr_range; i++)
+		free_size += range[i].end - range[i].start;
+
+	return free_size << PAGE_SHIFT;
+}
+
 u64 __init __weak __lmb_find_area(u64 ei_start, u64 ei_last, u64 start, u64 end,
 				 u64 size, u64 align)
 {
author
#26 lore raw

PATCH 14/22 lmb: Add lmb_memory_size()

In reply to Yinghai Lu

It will return memory size in specified range according to lmb.memory.region

Try to share some code with lmb_free_memory_size() by passing get_free to __lmb_memory_size().

---
 include/linux/lmb.h |    1 +
 mm/lmb.c            |   18 +++++++++++++++++-
 2 files changed, 18 insertions(+), 1 deletions(-)
include/linux/lmb.h +1 -0
index 22be96d..90022c1 100644
@@ -102,6 +102,7 @@ void lmb_register_active_regions(int nid, unsigned long start_pfn,
 					 unsigned long last_pfn);
 u64 lmb_hole_size(u64 start, u64 end);
 u64 lmb_free_memory_size(u64 addr, u64 limit);
+u64 lmb_memory_size(u64 addr, u64 limit);
 
 #include <asm/lmb.h>
 
mm/lmb.c +17 -1
index 4bc125c..2870dd9 100644
@@ -746,7 +746,7 @@ void __init lmb_to_bootmem(u64 start, u64 end)
 }
 #endif
 
-u64 __init lmb_free_memory_size(u64 addr, u64 limit)
+static u64 __init __lmb_memory_size(u64 addr, u64 limit, bool get_free)
 {
 	int i, count;
 	struct range *range;
@@ -776,6 +776,10 @@ u64 __init lmb_free_memory_size(u64 addr, u64 limit)
 	}
 	subtract_range(range, count, 0, addr);
 	subtract_range(range, count, limit, -1ULL);
+
+	/* Subtract lmb.reserved.region in range ? */
+	if (!get_free)
+		goto sort_and_count_them;
 	for (i = 0; i < lmb.reserved.cnt; i++) {
 		struct lmb_property *r = &lmb.reserved.region[i];
 
@@ -788,6 +792,8 @@ u64 __init lmb_free_memory_size(u64 addr, u64 limit)
 
 		subtract_range(range, count, final_start, final_end);
 	}
+
+sort_and_count_them:
 	nr_range = clean_sort_range(range, count);
 
 	free_size = 0;
@@ -797,6 +803,16 @@ u64 __init lmb_free_memory_size(u64 addr, u64 limit)
 	return free_size << PAGE_SHIFT;
 }
 
+u64 __init lmb_free_memory_size(u64 addr, u64 limit)
+{
+	return __lmb_memory_size(addr, limit, true);
+}
+
+u64 __init lmb_memory_size(u64 addr, u64 limit)
+{
+	return __lmb_memory_size(addr, limit, false);
+}
+
 u64 __init __weak __lmb_find_area(u64 ei_start, u64 ei_last, u64 start, u64 end,
 				 u64 size, u64 align)
 {
Signature · 1 line
1.6.4.2
#27 lore raw

Re: [PATCH 14/22] lmb: Add lmb_memory_size()

Quoted 4 lines · Yinghai Lu

It will return memory size in specified range according to lmb.memory.region

Try to share some code with lmb_free_memory_size() by passing get_free to __lmb_memory_size().

Similar comment about name and purpose.

Cheers,
Ben.

Quoted 68 lines
---
 include/linux/lmb.h |    1 +
 mm/lmb.c            |   18 +++++++++++++++++-
 2 files changed, 18 insertions(+), 1 deletions(-)
include/linux/lmb.h +1 -0
index 22be96d..90022c1 100644
@@ -102,6 +102,7 @@ void lmb_register_active_regions(int nid, unsigned long start_pfn,
 					 unsigned long last_pfn);
 u64 lmb_hole_size(u64 start, u64 end);
 u64 lmb_free_memory_size(u64 addr, u64 limit);
+u64 lmb_memory_size(u64 addr, u64 limit);
 
 #include <asm/lmb.h>
 
mm/lmb.c +17 -1
index 4bc125c..2870dd9 100644
@@ -746,7 +746,7 @@ void __init lmb_to_bootmem(u64 start, u64 end)
 }
 #endif
 
-u64 __init lmb_free_memory_size(u64 addr, u64 limit)
+static u64 __init __lmb_memory_size(u64 addr, u64 limit, bool get_free)
 {
 	int i, count;
 	struct range *range;
@@ -776,6 +776,10 @@ u64 __init lmb_free_memory_size(u64 addr, u64 limit)
 	}
 	subtract_range(range, count, 0, addr);
 	subtract_range(range, count, limit, -1ULL);
+
+	/* Subtract lmb.reserved.region in range ? */
+	if (!get_free)
+		goto sort_and_count_them;
 	for (i = 0; i < lmb.reserved.cnt; i++) {
 		struct lmb_property *r = &lmb.reserved.region[i];
 
@@ -788,6 +792,8 @@ u64 __init lmb_free_memory_size(u64 addr, u64 limit)
 
 		subtract_range(range, count, final_start, final_end);
 	}
+
+sort_and_count_them:
 	nr_range = clean_sort_range(range, count);
 
 	free_size = 0;
@@ -797,6 +803,16 @@ u64 __init lmb_free_memory_size(u64 addr, u64 limit)
 	return free_size << PAGE_SHIFT;
 }
 
+u64 __init lmb_free_memory_size(u64 addr, u64 limit)
+{
+	return __lmb_memory_size(addr, limit, true);
+}
+
+u64 __init lmb_memory_size(u64 addr, u64 limit)
+{
+	return __lmb_memory_size(addr, limit, false);
+}
+
 u64 __init __weak __lmb_find_area(u64 ei_start, u64 ei_last, u64 start, u64 end,
 				 u64 size, u64 align)
 {
author
#28 lore raw

PATCH 15/22 lmb: Add lmb_reserve_area_overlap_ok()

In reply to Yinghai Lu

Some areas from firmware could be reserved several times from different callers.

If these area are overlapped, We may have overlapped entries in lmb.reserved.

Try to free the area at first, before rerserve them again.

---
 include/linux/lmb.h |    1 +
 mm/lmb.c            |   27 +++++++++++++++++++++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)
include/linux/lmb.h +1 -0
index 90022c1..47b9d7f 100644
@@ -87,6 +87,7 @@ lmb_end_pfn(struct lmb_region *type, unsigned long region_nr)
 }
 
 void lmb_reserve_area(u64 start, u64 end, char *name);
+void lmb_reserve_area_overlap_ok(u64 start, u64 end, char *name);
 void lmb_free_area(u64 start, u64 end);
 void lmb_add_memory(u64 start, u64 end);
 u64 __lmb_find_area(u64 ei_start, u64 ei_last, u64 start, u64 end,
mm/lmb.c +25 -2
index 2870dd9..decea60 100644
@@ -605,6 +605,12 @@ void __init lmb_add_memory(u64 start, u64 end)
 	__check_and_double_region_array(&lmb.memory, &lmb_memory_region[0]);
 }
 
+static void __init __lmb_reserve_area(u64 start, u64 end, char *name)
+{
+	lmb_add_region(&lmb.reserved, start, end - start);
+	__check_and_double_region_array(&lmb.reserved, &lmb_reserved_region[0]);
+}
+
 void __init lmb_reserve_area(u64 start, u64 end, char *name)
 {
 	if (start == end)
@@ -613,8 +619,25 @@ void __init lmb_reserve_area(u64 start, u64 end, char *name)
 	if (WARN_ONCE(start > end, "lmb_reserve_area: wrong range [%#llx, %#llx]\n", start, end))
 		return;
 
-	lmb_add_region(&lmb.reserved, start, end - start);
-	__check_and_double_region_array(&lmb.reserved, &lmb_reserved_region[0]);
+	__lmb_reserve_area(start, end, name);
+}
+
+/*
+ * Could be used to avoid having overlap entries in lmb.reserved.region.
+ *  Don't need to use it with area that is from lmb_find_area()
+ *  Only use it for the area that fw hidden area.
+ */
+void __init lmb_reserve_area_overlap_ok(u64 start, u64 end, char *name)
+{
+	if (start == end)
+		return;
+
+	if (WARN_ONCE(start > end, "lmb_reserve_area_overlap_ok: wrong range [%#llx, %#llx]\n", start, end))
+		return;
+
+	/* Free that region at first */
+	lmb_free(start, end - start);
+	__lmb_reserve_area(start, end, name);
 }
 
 void __init lmb_free_area(u64 start, u64 end)
Signature · 1 line
1.6.4.2
#29 lore raw

Re: [PATCH 15/22] lmb: Add lmb_reserve_area_overlap_ok()

Quoted 5 lines · Yinghai Lu

Some areas from firmware could be reserved several times from different callers.

If these area are overlapped, We may have overlapped entries in lmb.reserved.

Try to free the area at first, before rerserve them again.

I explained earlier that name sucked :-)

We just need to make lmb_reserve() capable of dealing with overlaps instead. I like the idea of implementing that with a free.

Cheers,
Ben.

Quoted 63 lines
---
 include/linux/lmb.h |    1 +
 mm/lmb.c            |   27 +++++++++++++++++++++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)
include/linux/lmb.h +1 -0
index 90022c1..47b9d7f 100644
@@ -87,6 +87,7 @@ lmb_end_pfn(struct lmb_region *type, unsigned long region_nr)
 }
 
 void lmb_reserve_area(u64 start, u64 end, char *name);
+void lmb_reserve_area_overlap_ok(u64 start, u64 end, char *name);
 void lmb_free_area(u64 start, u64 end);
 void lmb_add_memory(u64 start, u64 end);
 u64 __lmb_find_area(u64 ei_start, u64 ei_last, u64 start, u64 end,
mm/lmb.c +25 -2
index 2870dd9..decea60 100644
@@ -605,6 +605,12 @@ void __init lmb_add_memory(u64 start, u64 end)
 	__check_and_double_region_array(&lmb.memory, &lmb_memory_region[0]);
 }
 
+static void __init __lmb_reserve_area(u64 start, u64 end, char *name)
+{
+	lmb_add_region(&lmb.reserved, start, end - start);
+	__check_and_double_region_array(&lmb.reserved, &lmb_reserved_region[0]);
+}
+
 void __init lmb_reserve_area(u64 start, u64 end, char *name)
 {
 	if (start == end)
@@ -613,8 +619,25 @@ void __init lmb_reserve_area(u64 start, u64 end, char *name)
 	if (WARN_ONCE(start > end, "lmb_reserve_area: wrong range [%#llx, %#llx]\n", start, end))
 		return;
 
-	lmb_add_region(&lmb.reserved, start, end - start);
-	__check_and_double_region_array(&lmb.reserved, &lmb_reserved_region[0]);
+	__lmb_reserve_area(start, end, name);
+}
+
+/*
+ * Could be used to avoid having overlap entries in lmb.reserved.region.
+ *  Don't need to use it with area that is from lmb_find_area()
+ *  Only use it for the area that fw hidden area.
+ */
+void __init lmb_reserve_area_overlap_ok(u64 start, u64 end, char *name)
+{
+	if (start == end)
+		return;
+
+	if (WARN_ONCE(start > end, "lmb_reserve_area_overlap_ok: wrong range [%#llx, %#llx]\n", start, end))
+		return;
+
+	/* Free that region at first */
+	lmb_free(start, end - start);
+	__lmb_reserve_area(start, end, name);
 }
 
 void __init lmb_free_area(u64 start, u64 end)
author
#30 lore raw

PATCH 16/22 lmb: Use lmb_debug to control debug message print out

In reply to Yinghai Lu

Also let lmb_reserve_area/lmb_free_area could print out name if lmb=debug is specified

will also print ther name when reserve_lmb_area/free_lmb_area are called.

---
 mm/lmb.c |   29 +++++++++++++++++++++--------
 1 files changed, 21 insertions(+), 8 deletions(-)
mm/lmb.c +21 -8
index decea60..db2264d 100644
@@ -591,8 +591,9 @@ static void __init __check_and_double_region_array(struct lmb_region *type,
 	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);
+	if (lmb_debug)
+		pr_info("lmb.reserved.region array is doubled to %ld at [%010llx - %010llx]\n",
+				type->nr_regions, mem, mem + size - 1);
 
 	/* Free old one ?*/
 	if (old != static_region)
@@ -619,6 +620,8 @@ void __init lmb_reserve_area(u64 start, u64 end, char *name)
 	if (WARN_ONCE(start > end, "lmb_reserve_area: wrong range [%#llx, %#llx]\n", start, end))
 		return;
 
+	if (lmb_debug)
+		pr_info("    lmb_reserve_area: [%010llx, %010llx] %16s\n", start, end, name);
 	__lmb_reserve_area(start, end, name);
 }
 
@@ -635,6 +638,8 @@ void __init lmb_reserve_area_overlap_ok(u64 start, u64 end, char *name)
 	if (WARN_ONCE(start > end, "lmb_reserve_area_overlap_ok: wrong range [%#llx, %#llx]\n", start, end))
 		return;
 
+	if (lmb_debug)
+		pr_info("    lmb_reserve_area_overlap_ok: [%010llx, %010llx] %16s\n", start, end, name);
 	/* Free that region at first */
 	lmb_free(start, end - start);
 	__lmb_reserve_area(start, end, name);
@@ -648,6 +653,8 @@ void __init lmb_free_area(u64 start, u64 end)
 	if (WARN_ONCE(start > end, "lmb_free_area: wrong range [%#llx, %#llx]\n", start, end))
 		return;
 
+	if (lmb_debug)
+		pr_info("       lmb_free_area: [%010llx, %010llx]\n", start, end);
 	/* keep punching hole, could run out of slots too */
 	lmb_free(start, end - start);
 	__check_and_double_region_array(&lmb.reserved, &lmb_reserved_region[0]);
@@ -688,11 +695,13 @@ static void __init subtract_lmb_reserved(struct range *range, int az)
 
 	count  = lmb.reserved.cnt;
 
-	pr_info("Subtract (%d early reservations)\n", count);
+	if (lmb_debug)
+		pr_info("Subtract (%d early reservations)\n", count);
 
 	for (i = 0; i < count; i++) {
 		struct lmb_property *r = &lmb.reserved.region[i];
-		pr_info("  #%d [%010llx - %010llx]\n", i, r->base, r->base + r->size);
+		if (lmb_debug)
+			pr_info("  #%03d [%010llx - %010llx]\n", i, r->base, r->base + r->size);
 		final_start = PFN_DOWN(r->base);
 		final_end = PFN_UP(r->base + r->size);
 		if (final_start >= final_end)
@@ -748,17 +757,21 @@ void __init lmb_to_bootmem(u64 start, u64 end)
 		lmb_free(__pa(lmb.reserved.region), sizeof(struct lmb_property) * lmb.reserved.nr_regions);
 
 	count  = lmb.reserved.cnt;
-	pr_info("(%d early reservations) ==> bootmem [%010llx - %010llx]\n", count, start, end);
+	if (lmb_debug)
+		pr_info("(%d early reservations) ==> bootmem [%010llx - %010llx]\n", count, start, end);
 	for (i = 0; i < count; i++) {
 		struct lmb_property *r = &lmb.reserved.region[i];
-		pr_info("  #%d [%010llx - %010llx] ", i, r->base, r->base + r->size);
+		if (lmb_debug)
+			pr_info("  #%03d [%010llx - %010llx] ", i, r->base, r->base + r->size);
 		final_start = max(start, r->base);
 		final_end = min(end, r->base + r->size);
 		if (final_start >= final_end) {
-			pr_cont("\n");
+			if (lmb_debug)
+				pr_cont("\n");
 			continue;
 		}
-		pr_cont(" ==> [%010llx - %010llx]\n", final_start, final_end);
+		if (lmb_debug)
+			pr_cont(" ==> [%010llx - %010llx]\n", final_start, final_end);
 		reserve_bootmem_generic(final_start, final_end - final_start, BOOTMEM_DEFAULT);
 	}
 	/* Clear them to avoid misusing ? */
Signature · 1 line
1.6.4.2
author
#31 lore raw

PATCH 17/22 lmb: Add ARCH_DISCARD_LMB to put lmb code to .init

In reply to Yinghai Lu

So those lmb bits could be released after kernel is booted up.

Arch code could define ARCH_DISCARD_LMB in asm/lmb.h, __init_lmb will become __init, __initdata_lmb will becom __initdata

x86 code will use that.

-v2: use ARCH_DISCARD_LMB according to Michael Ellerman

---
 include/linux/lmb.h |    8 +++++++
 mm/lmb.c            |   54 ++++++++++++++++++++++++++++++--------------------
 2 files changed, 40 insertions(+), 22 deletions(-)
include/linux/lmb.h +8 -0
index 47b9d7f..e486572 100644
@@ -107,6 +107,14 @@ u64 lmb_memory_size(u64 addr, u64 limit);
 
 #include <asm/lmb.h>
 
+#ifdef ARCH_DISCARD_LMB
+#define __init_lmb __init
+#define __initdata_lmb __initdata
+#else
+#define __init_lmb
+#define __initdata_lmb
+#endif
+
 #endif /* CONFIG_HAVE_LMB */
 
 #endif /* __KERNEL__ */
mm/lmb.c +32 -22

210 lines not on this page · raw message

Signature · 1 line
1.6.4.2
#32 lore raw

Re: [PATCH 17/22] lmb: Add ARCH_DISCARD_LMB to put lmb code to .init

Quoted 7 lines · Yinghai Lu

So those lmb bits could be released after kernel is booted up.

Arch code could define ARCH_DISCARD_LMB in asm/lmb.h, __init_lmb will become __init, __initdata_lmb will becom __initdata

x86 code will use that.

-v2: use ARCH_DISCARD_LMB according to Michael Ellerman

So first, you don't define ARCH_DISCARD_LMB on any arch, so they will all use __init_lmb, but thta isnt defined by this patch afaik, so you have just broken everything no ?

Also, why do you want that precisely ? bootmem is __init so that's fine to discard. We also already don't discard the lmb arrays. So what are you trying to achieve ?

Cheers,
Ben.

Quoted 261 lines
---
 include/linux/lmb.h |    8 +++++++
 mm/lmb.c            |   54 ++++++++++++++++++++++++++++++--------------------
 2 files changed, 40 insertions(+), 22 deletions(-)
include/linux/lmb.h +8 -0
index 47b9d7f..e486572 100644
@@ -107,6 +107,14 @@ u64 lmb_memory_size(u64 addr, u64 limit);
 
 #include <asm/lmb.h>
 
+#ifdef ARCH_DISCARD_LMB
+#define __init_lmb __init
+#define __initdata_lmb __initdata
+#else
+#define __init_lmb
+#define __initdata_lmb
+#endif
+
 #endif /* CONFIG_HAVE_LMB */
 
 #endif /* __KERNEL__ */
mm/lmb.c +32 -22
index db2264d..c2c6bff 100644
@@ -21,11 +21,11 @@
 
 #define LMB_ALLOC_ANYWHERE	0
 
-struct lmb lmb;
-static struct lmb_property lmb_memory_region[MAX_LMB_REGIONS];
-static struct lmb_property lmb_reserved_region[MAX_LMB_REGIONS];
+struct lmb lmb __initdata_lmb;
+static struct lmb_property lmb_memory_region[MAX_LMB_REGIONS] __initdata_lmb;
+static struct lmb_property lmb_reserved_region[MAX_LMB_REGIONS] __initdata_lmb;
 
-static int lmb_debug;
+static int lmb_debug __initdata_lmb;
 
 static int __init early_lmb(char *p)
 {
@@ -35,7 +35,7 @@ static int __init early_lmb(char *p)
 }
 early_param("lmb", early_lmb);
 
-static void lmb_dump(struct lmb_region *region, char *name)
+static void __init_lmb lmb_dump(struct lmb_region *region, char *name)
 {
 	unsigned long long base, size;
 	int i;
@@ -51,7 +51,7 @@ static void lmb_dump(struct lmb_region *region, char *name)
 	}
 }
 
-void lmb_dump_all(void)
+void __init_lmb lmb_dump_all(void)
 {
 	if (!lmb_debug)
 		return;
@@ -64,13 +64,13 @@ void lmb_dump_all(void)
 	lmb_dump(&lmb.reserved, "reserved");
 }
 
-static unsigned long lmb_addrs_overlap(u64 base1, u64 size1, u64 base2,
+static unsigned long __init_lmb lmb_addrs_overlap(u64 base1, u64 size1, u64 base2,
 					u64 size2)
 {
 	return ((base1 < (base2 + size2)) && (base2 < (base1 + size1)));
 }
 
-static long lmb_addrs_adjacent(u64 base1, u64 size1, u64 base2, u64 size2)
+static long __init_lmb lmb_addrs_adjacent(u64 base1, u64 size1, u64 base2, u64 size2)
 {
 	if (base2 == base1 + size1)
 		return 1;
@@ -80,7 +80,7 @@ static long lmb_addrs_adjacent(u64 base1, u64 size1, u64 base2, u64 size2)
 	return 0;
 }
 
-static long lmb_regions_adjacent(struct lmb_region *rgn,
+static long __init_lmb lmb_regions_adjacent(struct lmb_region *rgn,
 		unsigned long r1, unsigned long r2)
 {
 	u64 base1 = rgn->region[r1].base;
@@ -91,7 +91,7 @@ static long lmb_regions_adjacent(struct lmb_region *rgn,
 	return lmb_addrs_adjacent(base1, size1, base2, size2);
 }
 
-static void lmb_remove_region(struct lmb_region *rgn, unsigned long r)
+static void __init_lmb lmb_remove_region(struct lmb_region *rgn, unsigned long r)
 {
 	unsigned long i;
 
@@ -103,7 +103,7 @@ static void lmb_remove_region(struct lmb_region *rgn, unsigned long r)
 }
 
 /* Assumption: base addr of region 1 < base addr of region 2 */
-static void lmb_coalesce_regions(struct lmb_region *rgn,
+static void __init_lmb lmb_coalesce_regions(struct lmb_region *rgn,
 		unsigned long r1, unsigned long r2)
 {
 	rgn->region[r1].size += rgn->region[r2].size;
@@ -140,7 +140,7 @@ void __init lmb_analyze(void)
 		lmb.memory.size += lmb.memory.region[i].size;
 }
 
-static long lmb_add_region(struct lmb_region *rgn, u64 base, u64 size)
+static long __init_lmb lmb_add_region(struct lmb_region *rgn, u64 base, u64 size)
 {
 	unsigned long coalesced = 0;
 	long adjacent, i;
@@ -204,7 +204,7 @@ static long lmb_add_region(struct lmb_region *rgn, u64 base, u64 size)
 	return 0;
 }
 
-long lmb_add(u64 base, u64 size)
+long __init_lmb lmb_add(u64 base, u64 size)
 {
 	struct lmb_region *_rgn = &lmb.memory;
 
@@ -216,7 +216,7 @@ long lmb_add(u64 base, u64 size)
 
 }
 
-static long __lmb_remove(struct lmb_region *rgn, u64 base, u64 size)
+static long __init_lmb __lmb_remove(struct lmb_region *rgn, u64 base, u64 size)
 {
 	u64 rgnbegin, rgnend;
 	u64 end = base + size;
@@ -264,7 +264,7 @@ static long __lmb_remove(struct lmb_region *rgn, u64 base, u64 size)
 	return lmb_add_region(rgn, end, rgnend - end);
 }
 
-long lmb_remove(u64 base, u64 size)
+long __init_lmb lmb_remove(u64 base, u64 size)
 {
 	return __lmb_remove(&lmb.memory, base, size);
 }
@@ -283,7 +283,7 @@ long __init lmb_reserve(u64 base, u64 size)
 	return lmb_add_region(_rgn, base, size);
 }
 
-long lmb_overlaps_region(struct lmb_region *rgn, u64 base, u64 size)
+long __init_lmb lmb_overlaps_region(struct lmb_region *rgn, u64 base, u64 size)
 {
 	unsigned long i;
 
@@ -297,12 +297,12 @@ long lmb_overlaps_region(struct lmb_region *rgn, u64 base, u64 size)
 	return (i < rgn->cnt) ? i : -1;
 }
 
-static u64 lmb_align_down(u64 addr, u64 size)
+static u64 __init_lmb lmb_align_down(u64 addr, u64 size)
 {
 	return addr & ~(size - 1);
 }
 
-static u64 lmb_align_up(u64 addr, u64 size)
+static u64 __init_lmb lmb_align_up(u64 addr, u64 size)
 {
 	return (addr + (size - 1)) & ~(size - 1);
 }
@@ -462,7 +462,7 @@ u64 __init lmb_phys_mem_size(void)
 	return lmb.memory.size;
 }
 
-u64 lmb_end_of_DRAM(void)
+u64 __init_lmb lmb_end_of_DRAM(void)
 {
 	int idx = lmb.memory.cnt - 1;
 
@@ -526,7 +526,7 @@ int __init lmb_is_reserved(u64 addr)
 	return 0;
 }
 
-int lmb_is_region_reserved(u64 base, u64 size)
+int __init_lmb lmb_is_region_reserved(u64 base, u64 size)
 {
 	return lmb_overlaps_region(&lmb.reserved, base, size);
 }
@@ -535,7 +535,7 @@ int lmb_is_region_reserved(u64 base, u64 size)
  * Given a <base, len>, find which memory regions belong to this range.
  * Adjust the request and return a contiguous chunk.
  */
-int lmb_find(struct lmb_property *res)
+int __init_lmb lmb_find(struct lmb_property *res)
 {
 	int i;
 	u64 rstart, rend;
@@ -689,10 +689,11 @@ static void __init subtract_lmb_reserved(struct range *range, int az)
 	int i, count;
 	u64 final_start, final_end;
 
+#ifdef ARCH_DISCARD_LMB
 	/* Take out region array itself at first*/
 	if (lmb.reserved.region != lmb_reserved_region)
 		lmb_free(__pa(lmb.reserved.region), sizeof(struct lmb_property) * lmb.reserved.nr_regions);
-
+#endif
 	count  = lmb.reserved.cnt;
 
 	if (lmb_debug)
@@ -708,9 +709,11 @@ static void __init subtract_lmb_reserved(struct range *range, int az)
 			continue;
 		subtract_range(range, az, final_start, final_end);
 	}
+#ifdef ARCH_DISCARD_LMB
 	/* Put region array back ? */
 	if (lmb.reserved.region != lmb_reserved_region)
 		lmb_reserve(__pa(lmb.reserved.region), sizeof(struct lmb_property) * lmb.reserved.nr_regions);
+#endif
 }
 
 int __init get_free_all_memory_range(struct range **rangep, int nodeid)
@@ -735,6 +738,7 @@ int __init get_free_all_memory_range(struct range **rangep, int nodeid)
 	subtract_lmb_reserved(range, count);
 	nr_range = clean_sort_range(range, count);
 
+#ifdef ARCH_DISCARD_LMB
 	/* Need to clear it ? */
 	if (nodeid == MAX_NUMNODES) {
 		memset(&lmb.reserved.region[0], 0, sizeof(struct lmb_property) * lmb.reserved.nr_regions);
@@ -742,6 +746,7 @@ int __init get_free_all_memory_range(struct range **rangep, int nodeid)
 		lmb.reserved.nr_regions = 0;
 		lmb.reserved.cnt = 0;
 	}
+#endif
 
 	*rangep = range;
 	return nr_range;
@@ -752,9 +757,11 @@ void __init lmb_to_bootmem(u64 start, u64 end)
 	int i, count;
 	u64 final_start, final_end;
 
+#ifdef ARCH_DISCARD_LMB
 	/* Take out region array itself */
 	if (lmb.reserved.region != lmb_reserved_region)
 		lmb_free(__pa(lmb.reserved.region), sizeof(struct lmb_property) * lmb.reserved.nr_regions);
+#endif
 
 	count  = lmb.reserved.cnt;
 	if (lmb_debug)
@@ -774,11 +781,14 @@ void __init lmb_to_bootmem(u64 start, u64 end)
 			pr_cont(" ==> [%010llx - %010llx]\n", final_start, final_end);
 		reserve_bootmem_generic(final_start, final_end - final_start, BOOTMEM_DEFAULT);
 	}
+
+#ifdef ARCH_DISCARD_LMB
 	/* Clear them to avoid misusing ? */
 	memset(&lmb.reserved.region[0], 0, sizeof(struct lmb_property) * lmb.reserved.nr_regions);
 	lmb.reserved.region = NULL;
 	lmb.reserved.nr_regions = 0;
 	lmb.reserved.cnt = 0;
+#endif
 }
 #endif
 
author
#33 lore raw

PATCH 18/22 lmb: Add __free/__reserve/__clear_lmb_reserved_region_array()

In reply to Yinghai Lu

Seperate those three functions and could be shared by related callers.

---
 mm/lmb.c |   63 +++++++++++++++++++++++++++++++++++--------------------------
 1 files changed, 36 insertions(+), 27 deletions(-)
mm/lmb.c +36 -27
index c2c6bff..20befd3 100644
@@ -684,16 +684,41 @@ static __init struct range *find_range_array(int count)
 }
 
 #ifdef CONFIG_NO_BOOTMEM
-static void __init subtract_lmb_reserved(struct range *range, int az)
+static void __init __free_lmb_reserved_region_array(void)
 {
-	int i, count;
-	u64 final_start, final_end;
-
 #ifdef ARCH_DISCARD_LMB
 	/* Take out region array itself at first*/
 	if (lmb.reserved.region != lmb_reserved_region)
 		lmb_free(__pa(lmb.reserved.region), sizeof(struct lmb_property) * lmb.reserved.nr_regions);
 #endif
+}
+static void __init __reserve_lmb_reserved_region_array(void)
+{
+#ifdef ARCH_DISCARD_LMB
+	/* Put region array back ? */
+	if (lmb.reserved.region != lmb_reserved_region)
+		lmb_reserve(__pa(lmb.reserved.region), sizeof(struct lmb_property) * lmb.reserved.nr_regions);
+#endif
+}
+
+static void __init __clear_lmb_reserved_region_array(void)
+{
+#ifdef ARCH_DISCARD_LMB
+	memset(&lmb.reserved.region[0], 0, sizeof(struct lmb_property) * lmb.reserved.nr_regions);
+	lmb.reserved.region = NULL;
+	lmb.reserved.nr_regions = 0;
+	lmb.reserved.cnt = 0;
+#endif
+}
+
+static void __init subtract_lmb_reserved(struct range *range, int az)
+{
+	int i, count;
+	u64 final_start, final_end;
+
+	/* Take out region array itself at first*/
+	__free_lmb_reserved_region_array();
+
 	count  = lmb.reserved.cnt;
 
 	if (lmb_debug)
@@ -709,11 +734,9 @@ static void __init subtract_lmb_reserved(struct range *range, int az)
 			continue;
 		subtract_range(range, az, final_start, final_end);
 	}
-#ifdef ARCH_DISCARD_LMB
+
 	/* Put region array back ? */
-	if (lmb.reserved.region != lmb_reserved_region)
-		lmb_reserve(__pa(lmb.reserved.region), sizeof(struct lmb_property) * lmb.reserved.nr_regions);
-#endif
+	__reserve_lmb_reserved_region_array();
 }
 
 int __init get_free_all_memory_range(struct range **rangep, int nodeid)
@@ -738,15 +761,9 @@ int __init get_free_all_memory_range(struct range **rangep, int nodeid)
 	subtract_lmb_reserved(range, count);
 	nr_range = clean_sort_range(range, count);
 
-#ifdef ARCH_DISCARD_LMB
 	/* Need to clear it ? */
-	if (nodeid == MAX_NUMNODES) {
-		memset(&lmb.reserved.region[0], 0, sizeof(struct lmb_property) * lmb.reserved.nr_regions);
-		lmb.reserved.region = NULL;
-		lmb.reserved.nr_regions = 0;
-		lmb.reserved.cnt = 0;
-	}
-#endif
+	if (nodeid == MAX_NUMNODES)
+		__clear_lmb_reserved_region_array();
 
 	*rangep = range;
 	return nr_range;
@@ -757,11 +774,8 @@ void __init lmb_to_bootmem(u64 start, u64 end)
 	int i, count;
 	u64 final_start, final_end;
 
-#ifdef ARCH_DISCARD_LMB
 	/* Take out region array itself */
-	if (lmb.reserved.region != lmb_reserved_region)
-		lmb_free(__pa(lmb.reserved.region), sizeof(struct lmb_property) * lmb.reserved.nr_regions);
-#endif
+	__free_lmb_reserved_region_array();
 
 	count  = lmb.reserved.cnt;
 	if (lmb_debug)
@@ -782,13 +796,8 @@ void __init lmb_to_bootmem(u64 start, u64 end)
 		reserve_bootmem_generic(final_start, final_end - final_start, BOOTMEM_DEFAULT);
 	}
 
-#ifdef ARCH_DISCARD_LMB
-	/* Clear them to avoid misusing ? */
-	memset(&lmb.reserved.region[0], 0, sizeof(struct lmb_property) * lmb.reserved.nr_regions);
-	lmb.reserved.region = NULL;
-	lmb.reserved.nr_regions = 0;
-	lmb.reserved.cnt = 0;
-#endif
+	/* Assume lmb_to_bootmem is only called one time */
+	__clear_lmb_reserved_region_array();
 }
 #endif
 
Signature · 1 line
1.6.4.2
#34 lore raw

Re: [PATCH 18/22] lmb: Add __free/__reserve/__clear_lmb_reserved_region_array()

Quoted 1 line · Yinghai Lu

Seperate those three functions and could be shared by related callers.

You just created those functions, so why don't you create them the "right way" in the first place ?

I still have issues with that anyways, but we'll come to that one thing at a time.

Cheers,
Ben.

Quoted 116 lines
---
 mm/lmb.c |   63 +++++++++++++++++++++++++++++++++++--------------------------
 1 files changed, 36 insertions(+), 27 deletions(-)
mm/lmb.c +36 -27
index c2c6bff..20befd3 100644
@@ -684,16 +684,41 @@ static __init struct range *find_range_array(int count)
 }
 
 #ifdef CONFIG_NO_BOOTMEM
-static void __init subtract_lmb_reserved(struct range *range, int az)
+static void __init __free_lmb_reserved_region_array(void)
 {
-	int i, count;
-	u64 final_start, final_end;
-
 #ifdef ARCH_DISCARD_LMB
 	/* Take out region array itself at first*/
 	if (lmb.reserved.region != lmb_reserved_region)
 		lmb_free(__pa(lmb.reserved.region), sizeof(struct lmb_property) * lmb.reserved.nr_regions);
 #endif
+}
+static void __init __reserve_lmb_reserved_region_array(void)
+{
+#ifdef ARCH_DISCARD_LMB
+	/* Put region array back ? */
+	if (lmb.reserved.region != lmb_reserved_region)
+		lmb_reserve(__pa(lmb.reserved.region), sizeof(struct lmb_property) * lmb.reserved.nr_regions);
+#endif
+}
+
+static void __init __clear_lmb_reserved_region_array(void)
+{
+#ifdef ARCH_DISCARD_LMB
+	memset(&lmb.reserved.region[0], 0, sizeof(struct lmb_property) * lmb.reserved.nr_regions);
+	lmb.reserved.region = NULL;
+	lmb.reserved.nr_regions = 0;
+	lmb.reserved.cnt = 0;
+#endif
+}
+
+static void __init subtract_lmb_reserved(struct range *range, int az)
+{
+	int i, count;
+	u64 final_start, final_end;
+
+	/* Take out region array itself at first*/
+	__free_lmb_reserved_region_array();
+
 	count  = lmb.reserved.cnt;
 
 	if (lmb_debug)
@@ -709,11 +734,9 @@ static void __init subtract_lmb_reserved(struct range *range, int az)
 			continue;
 		subtract_range(range, az, final_start, final_end);
 	}
-#ifdef ARCH_DISCARD_LMB
+
 	/* Put region array back ? */
-	if (lmb.reserved.region != lmb_reserved_region)
-		lmb_reserve(__pa(lmb.reserved.region), sizeof(struct lmb_property) * lmb.reserved.nr_regions);
-#endif
+	__reserve_lmb_reserved_region_array();
 }
 
 int __init get_free_all_memory_range(struct range **rangep, int nodeid)
@@ -738,15 +761,9 @@ int __init get_free_all_memory_range(struct range **rangep, int nodeid)
 	subtract_lmb_reserved(range, count);
 	nr_range = clean_sort_range(range, count);
 
-#ifdef ARCH_DISCARD_LMB
 	/* Need to clear it ? */
-	if (nodeid == MAX_NUMNODES) {
-		memset(&lmb.reserved.region[0], 0, sizeof(struct lmb_property) * lmb.reserved.nr_regions);
-		lmb.reserved.region = NULL;
-		lmb.reserved.nr_regions = 0;
-		lmb.reserved.cnt = 0;
-	}
-#endif
+	if (nodeid == MAX_NUMNODES)
+		__clear_lmb_reserved_region_array();
 
 	*rangep = range;
 	return nr_range;
@@ -757,11 +774,8 @@ void __init lmb_to_bootmem(u64 start, u64 end)
 	int i, count;
 	u64 final_start, final_end;
 
-#ifdef ARCH_DISCARD_LMB
 	/* Take out region array itself */
-	if (lmb.reserved.region != lmb_reserved_region)
-		lmb_free(__pa(lmb.reserved.region), sizeof(struct lmb_property) * lmb.reserved.nr_regions);
-#endif
+	__free_lmb_reserved_region_array();
 
 	count  = lmb.reserved.cnt;
 	if (lmb_debug)
@@ -782,13 +796,8 @@ void __init lmb_to_bootmem(u64 start, u64 end)
 		reserve_bootmem_generic(final_start, final_end - final_start, BOOTMEM_DEFAULT);
 	}
 
-#ifdef ARCH_DISCARD_LMB
-	/* Clear them to avoid misusing ? */
-	memset(&lmb.reserved.region[0], 0, sizeof(struct lmb_property) * lmb.reserved.nr_regions);
-	lmb.reserved.region = NULL;
-	lmb.reserved.nr_regions = 0;
-	lmb.reserved.cnt = 0;
-#endif
+	/* Assume lmb_to_bootmem is only called one time */
+	__clear_lmb_reserved_region_array();
 }
 #endif
 
author
#35 lore raw

PATCH 19/22 x86, lmb: Add lmb_find_area_size()

In reply to Yinghai Lu

size is returned according free range.
Will be used to find free ranges for early_memtest and memory corruption check

Do not mess it up with mm/lmb.c yet.

---
 arch/x86/mm/Makefile |    2 +
 arch/x86/mm/lmb.c    |   88 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 90 insertions(+), 0 deletions(-)
 create mode 100644 arch/x86/mm/lmb.c
arch/x86/mm/Makefile +2 -0
index a4c7683..8ab0505 100644
@@ -26,4 +26,6 @@ obj-$(CONFIG_NUMA)		+= numa.o numa_$(BITS).o
 obj-$(CONFIG_K8_NUMA)		+= k8topology_64.o
 obj-$(CONFIG_ACPI_NUMA)		+= srat_$(BITS).o
 
+obj-$(CONFIG_HAVE_LMB)		+= lmb.o
+
 obj-$(CONFIG_MEMTEST)		+= memtest.o
arch/x86/mm/lmb.c new file +88 -0

88 lines not on this page · raw message

Signature · 1 line
1.6.4.2
author
#36 lore raw

PATCH 20/22 x86: Use lmb to replace early_res

In reply to Yinghai Lu

1. replace find_e820_area with lmb_find_area
2. replace reserve_early with lmb_reserve_area
3. replace free_early with lmb_free_area.
4. NO_BOOTMEM will switch to use lmb too.
5. use _e820, _early wrap in the patch, in following patch, will replace them all
6. because lmb_free_area support partial free, we can remove some special care
7. Need to make sure that lmb_find_area() is called after fill_lmb_memory() so adjust some calling later in setup.c::setup_arch()
-- corruption_check and mptable_update

-v2: Move reserve_brk() early
Before fill_lmb_area, to avoid overlap between brk and lmb_find_area() that could happen We have more then 128 RAM entry in E820 tables, and fill_lmb_memory() could use lmb_find_area() to find a new place for lmb.memory.region array.
and We don't need to use extend_brk() after fill_lmb_area()
So move reserve_brk() early before fill_lmb_area().
-v3: Move find_smp_config early
To make sure lmb_find_area not find wrong place, if BIOS doesn't put mptable in right place.
-v4: Treat RESERVED_KERN as RAM in lmb.memory. and they are already in
lmb.reserved already..
use __NOT_KEEP_LMB to make sure lmb related code could be freed later.
-v5: Generic version __lmb_find_area() is going from high to low, and for 32bit
active_region for 32bit does include high pages
need to replace the limit with lmb.default_alloc_limit, aka get_max_mapped()

---
 arch/x86/Kconfig               |    9 +--
 arch/x86/include/asm/e820.h    |   15 +++--
 arch/x86/include/asm/lmb.h     |   12 +++
 arch/x86/kernel/check.c        |   14 ++--
 arch/x86/kernel/e820.c         |  147 ++++++++++-----------------------------
 arch/x86/kernel/head.c         |    3 +-
 arch/x86/kernel/head32.c       |    6 +-
 arch/x86/kernel/head64.c       |    3 +
 arch/x86/kernel/mpparse.c      |    5 +-
 arch/x86/kernel/setup.c        |   46 +++++++++----
 arch/x86/kernel/setup_percpu.c |    6 --
 arch/x86/mm/numa_64.c          |    5 +-
 kernel/Makefile                |    1 -
 mm/bootmem.c                   |    1 +
 mm/page_alloc.c                |   36 +++-------
 mm/sparse-vmemmap.c            |   11 ---
 16 files changed, 129 insertions(+), 191 deletions(-)
 create mode 100644 arch/x86/include/asm/lmb.h
arch/x86/Kconfig +3 -6
index d80d2ab..22d6953 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
@@ -193,9 +194,6 @@ config ARCH_SUPPORTS_OPTIMIZED_INLINING
 config ARCH_SUPPORTS_DEBUG_PAGEALLOC
 	def_bool y
 
-config HAVE_EARLY_RES
-	def_bool y
-
 config HAVE_INTEL_TXT
 	def_bool y
 	depends on EXPERIMENTAL && DMAR && ACPI
@@ -588,14 +586,13 @@ config NO_BOOTMEM
 	default y
 	bool "Disable Bootmem code"
 	---help---
-	  Use early_res directly instead of bootmem before slab is ready.
+	  Use lmb directly instead of bootmem before slab is ready.
 		- allocator (buddy) [generic]
 		- early allocator (bootmem) [generic]
-		- very early allocator (reserve_early*()) [x86]
+		- very early allocator (lmb) [some generic]
 		- very very early allocator (early brk model) [x86]
 	  So reduce one layer between early allocator to final allocator
 
-
 config MEMTEST
 	bool "Memtest"
 	---help---
arch/x86/include/asm/e820.h +9 -6
index ec8a52d..38adac8 100644
@@ -117,24 +117,27 @@ 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);
 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);
+
+extern u64 early_reserve_e820(u64 startt, u64 sizet, u64 align);
+
+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);
 extern void setup_memory_map(void);
 extern char *default_machine_specific_memory_setup(void);
 
+void reserve_early(u64 start, u64 end, char *name);
+void free_early(u64 start, u64 end);
+
 /*
  * Returns true iff the specified range [s,e) is completely contained inside
  * the ISA region.
arch/x86/include/asm/lmb.h new file +12 -0
new file mode 100644
index 0000000..e43c57a
@@ -0,0 +1,12 @@
+#ifndef _X86_LMB_H
+#define _X86_LMB_H
+
+u64 lmb_find_area_size(u64 start, u64 *sizep, u64 align);
+
+#define LMB_DBG(fmt...) printk(fmt)
+
+#define LMB_REAL_LIMIT 0
+
+#define ARCH_DISCARD_LMB
+
+#endif
arch/x86/kernel/check.c +8 -6
index fc999e6..fcb3f11 100644
@@ -2,7 +2,8 @@
 #include <linux/sched.h>
 #include <linux/kthread.h>
 #include <linux/workqueue.h>
-#include <asm/e820.h>
+#include <linux/lmb.h>
+
 #include <asm/proto.h>
 
 /*
@@ -18,10 +19,12 @@ static int __read_mostly memory_corruption_check = -1;
 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(void)
 
 	while (addr < corruption_check_size && num_scan_areas < MAX_SCAN_AREAS) {
 		u64 size;
-		addr = find_e820_area_size(addr, &size, PAGE_SIZE);
+		addr = lmb_find_area_size(addr, &size, PAGE_SIZE);
 
 		if (!(addr + 1))
 			break;
@@ -92,7 +95,7 @@ void __init setup_bios_corruption_check(void)
 		if ((addr + size) > corruption_check_size)
 			size = corruption_check_size - addr;
 
-		e820_update_range(addr, size, E820_RAM, E820_RESERVED);
+		lmb_reserve_area(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(void)
 
 	printk(KERN_INFO "Scanning %d areas for low memory corruption\n",
 	       num_scan_areas);
-	update_e820();
 }
 
 
arch/x86/kernel/e820.c +38 -109

203 lines not on this page · raw message

arch/x86/kernel/head.c +2 -1
index 3e66bd3..5802287 100644
@@ -1,5 +1,6 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
+#include <linux/lmb.h>
 
 #include <asm/setup.h>
 #include <asm/bios_ebda.h>
@@ -51,5 +52,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");
+	lmb_reserve_area_overlap_ok(lowmem, 0x100000, "BIOS reserved");
 }
arch/x86/kernel/head32.c +4 -2
index b2e2460..ab3e366 100644
@@ -8,6 +8,7 @@
 #include <linux/init.h>
 #include <linux/start_kernel.h>
 #include <linux/mm.h>
+#include <linux/lmb.h>
 
 #include <asm/setup.h>
 #include <asm/sections.h>
@@ -30,14 +31,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,
-					 "EX TRAMPOLINE");
+	lmb_reserve_area(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 +3 -0
index 7147143..89dd2de 100644
@@ -12,6 +12,7 @@
 #include <linux/percpu.h>
 #include <linux/start_kernel.h>
 #include <linux/io.h>
+#include <linux/lmb.h>
 
 #include <asm/processor.h>
 #include <asm/proto.h>
@@ -96,6 +97,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/mpparse.c +3 -2
index 5ae5d24..e5a7873 100644
@@ -11,6 +11,7 @@
 #include <linux/init.h>
 #include <linux/delay.h>
 #include <linux/bootmem.h>
+#include <linux/lmb.h>
 #include <linux/kernel_stat.h>
 #include <linux/mc146818rtc.h>
 #include <linux/bitops.h>
@@ -641,7 +642,7 @@ static void __init smp_reserve_memory(struct mpf_intel *mpf)
 {
 	unsigned long size = get_mpc_size(mpf->physptr);
 
-	reserve_early_overlap_ok(mpf->physptr, mpf->physptr+size, "MP-table mpc");
+	lmb_reserve_area_overlap_ok(mpf->physptr, mpf->physptr+size, "MP-table mpc");
 }
 
 static int __init smp_scan_config(unsigned long base, unsigned long length)
@@ -670,7 +671,7 @@ static int __init smp_scan_config(unsigned long base, unsigned long length)
 			       mpf, (u64)virt_to_phys(mpf));
 
 			mem = virt_to_phys(mpf);
-			reserve_early_overlap_ok(mem, mem + sizeof(*mpf), "MP-table mpf");
+			lmb_reserve_area_overlap_ok(mem, mem + sizeof(*mpf), "MP-table mpf");
 			if (mpf->physptr)
 				smp_reserve_memory(mpf);
 
arch/x86/kernel/setup.c +33 -13

94 lines not on this page · raw message

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)
arch/x86/mm/numa_64.c +3 -2
index 8948f47..6e0f896 100644
@@ -7,6 +7,7 @@
 #include <linux/string.h>
 #include <linux/init.h>
 #include <linux/bootmem.h>
+#include <linux/lmb.h>
 #include <linux/mmzone.h>
 #include <linux/ctype.h>
 #include <linux/module.h>
@@ -174,7 +175,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 = lmb_find_area_node(nodeid, start, end, size, align);
 	if (mem != -1L)
 		return __va(mem);
 
@@ -184,7 +185,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 = lmb_find_area_node(nodeid, start, end, size, align);
 	if (mem != -1L)
 		return __va(mem);
 
kernel/Makefile +0 -1
index d5c3006..754bf79 100644
@@ -11,7 +11,6 @@ obj-y     = sched.o fork.o exec_domain.o panic.o printk.o \
 	    hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \
 	    notifier.o ksysfs.o pm_qos_params.o sched_clock.o cred.o \
 	    async.o range.o
-obj-$(CONFIG_HAVE_EARLY_RES) += early_res.o
 obj-y += groups.o
 
 ifdef CONFIG_FUNCTION_TRACER
mm/bootmem.c +1 -0
index ee31b95..dac3f56 100644
@@ -15,6 +15,7 @@
 #include <linux/module.h>
 #include <linux/kmemleak.h>
 #include <linux/range.h>
+#include <linux/lmb.h>
 
 #include <asm/bug.h>
 #include <asm/io.h>
mm/page_alloc.c +10 -26
index 72afd94..07f4831 100644
@@ -3441,38 +3441,22 @@ int __init add_from_early_node_map(struct range *range, int az,
 void * __init __alloc_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) {
-		u64 addr;
-		u64 ei_start, ei_last;
-
-		ei_last = early_node_map[i].end_pfn;
-		ei_last <<= PAGE_SHIFT;
-		ei_start = early_node_map[i].start_pfn;
-		ei_start <<= PAGE_SHIFT;
-		addr = find_early_area(ei_start, ei_last,
-					 goal, limit, size, align);
+	u64 addr;
 
-		if (addr == -1ULL)
-			continue;
+	if (limit > lmb.default_alloc_limit)
+		limit = lmb.default_alloc_limit;
 
-#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);
-#endif
+	addr = find_memory_core_early(nid, size, align, goal, limit);
 
-		ptr = phys_to_virt(addr);
-		memset(ptr, 0, size);
-		reserve_early_without_check(addr, addr + size, "BOOTMEM");
-		return ptr;
-	}
+	if (addr == LMB_ERROR)
+		return NULL;
 
-	return NULL;
+	ptr = phys_to_virt(addr);
+	memset(ptr, 0, size);
+	lmb_reserve_area(addr, addr + size, "BOOTMEM");
+	return ptr;
 }
 #endif
 
mm/sparse-vmemmap.c +0 -11
index aa33fd6..29d6cbf 100644
@@ -220,18 +220,7 @@ void __init sparse_mem_maps_populate_node(struct page **map_map,
 
 	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;
 	}
Signature · 1 line
1.6.4.2
author
#37 lore raw

PATCH 21/22 x86: Replace e820_/_early string with lmb_

In reply to Yinghai Lu

1.include linux/lmb.h directly. so later could reduce e820.h reference. 2 this patch is done by sed scripts mainly

---
 arch/x86/include/asm/efi.h      |    2 +-
 arch/x86/kernel/acpi/sleep.c    |    5 +++--
 arch/x86/kernel/apic/numaq_32.c |    3 ++-
 arch/x86/kernel/efi.c           |    5 +++--
 arch/x86/kernel/head32.c        |    4 ++--
 arch/x86/kernel/head64.c        |    4 ++--
 arch/x86/kernel/setup.c         |   25 ++++++++++++-------------
 arch/x86/kernel/trampoline.c    |    6 +++---
 arch/x86/mm/init.c              |    5 +++--
 arch/x86/mm/init_32.c           |   10 ++++++----
 arch/x86/mm/init_64.c           |    9 +++++----
 arch/x86/mm/k8topology_64.c     |    4 +++-
 arch/x86/mm/memtest.c           |    7 +++----
 arch/x86/mm/numa_32.c           |   17 +++++++++--------
 arch/x86/mm/numa_64.c           |   32 ++++++++++++++++----------------
 arch/x86/mm/srat_32.c           |    3 ++-
 arch/x86/mm/srat_64.c           |    9 +++++----
 arch/x86/xen/mmu.c              |    5 +++--
 arch/x86/xen/setup.c            |    3 ++-
 mm/bootmem.c                    |    4 ++--
 20 files changed, 87 insertions(+), 75 deletions(-)
arch/x86/include/asm/efi.h +1 -1
index 8406ed7..06703f3 100644
@@ -90,7 +90,7 @@ extern void __iomem *efi_ioremap(unsigned long addr, unsigned long size,
 #endif /* CONFIG_X86_32 */
 
 extern int add_efi_memmap;
-extern void efi_reserve_early(void);
+extern void efi_lmb_reserve_area(void);
 extern void efi_call_phys_prelog(void);
 extern void efi_call_phys_epilog(void);
 
arch/x86/kernel/acpi/sleep.c +3 -2
index f996103..4502470 100644
@@ -7,6 +7,7 @@
 
 #include <linux/acpi.h>
 #include <linux/bootmem.h>
+#include <linux/lmb.h>
 #include <linux/dmi.h>
 #include <linux/cpumask.h>
 #include <asm/segment.h>
@@ -133,7 +134,7 @@ void __init acpi_reserve_wakeup_memory(void)
 		return;
 	}
 
-	mem = find_e820_area(0, 1<<20, WAKEUP_SIZE, PAGE_SIZE);
+	mem = lmb_find_area(0, 1<<20, WAKEUP_SIZE, PAGE_SIZE);
 
 	if (mem == -1L) {
 		printk(KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n");
@@ -141,7 +142,7 @@ void __init acpi_reserve_wakeup_memory(void)
 	}
 	acpi_realmode = (unsigned long) phys_to_virt(mem);
 	acpi_wakeup_address = mem;
-	reserve_early(mem, mem + WAKEUP_SIZE, "ACPI WAKEUP");
+	lmb_reserve_area(mem, mem + WAKEUP_SIZE, "ACPI WAKEUP");
 }
 
 
arch/x86/kernel/apic/numaq_32.c +2 -1
index 3e28401..c71e494 100644
@@ -26,6 +26,7 @@
 #include <linux/nodemask.h>
 #include <linux/topology.h>
 #include <linux/bootmem.h>
+#include <linux/lmb.h>
 #include <linux/threads.h>
 #include <linux/cpumask.h>
 #include <linux/kernel.h>
@@ -88,7 +89,7 @@ static inline void numaq_register_node(int node, struct sys_cfg_data *scd)
 	node_end_pfn[node] =
 		 MB_TO_PAGES(eq->hi_shrd_mem_start + eq->hi_shrd_mem_size);
 
-	e820_register_active_regions(node, node_start_pfn[node],
+	lmb_register_active_regions(node, node_start_pfn[node],
 						node_end_pfn[node]);
 
 	memory_present(node, node_start_pfn[node], node_end_pfn[node]);
arch/x86/kernel/efi.c +3 -2
index c2fa9b8..ebe7c09 100644
@@ -30,6 +30,7 @@
 #include <linux/init.h>
 #include <linux/efi.h>
 #include <linux/bootmem.h>
+#include <linux/lmb.h>
 #include <linux/spinlock.h>
 #include <linux/uaccess.h>
 #include <linux/time.h>
@@ -275,7 +276,7 @@ static void __init do_add_efi_memmap(void)
 	sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
 }
 
-void __init efi_reserve_early(void)
+void __init efi_lmb_reserve_area(void)
 {
 	unsigned long pmap;
 
@@ -290,7 +291,7 @@ void __init efi_reserve_early(void)
 		boot_params.efi_info.efi_memdesc_size;
 	memmap.desc_version = boot_params.efi_info.efi_memdesc_version;
 	memmap.desc_size = boot_params.efi_info.efi_memdesc_size;
-	reserve_early(pmap, pmap + memmap.nr_map * memmap.desc_size,
+	lmb_reserve_area(pmap, pmap + memmap.nr_map * memmap.desc_size,
 		      "EFI memmap");
 }
 
arch/x86/kernel/head32.c +2 -2
index ab3e366..ecd12a9 100644
@@ -42,7 +42,7 @@ void __init i386_start_kernel(void)
 	lmb_reserve_area(PAGE_SIZE, PAGE_SIZE + PAGE_SIZE, "EX TRAMPOLINE");
 #endif
 
-	reserve_early(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
+	lmb_reserve_area(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
 
 #ifdef CONFIG_BLK_DEV_INITRD
 	/* Reserve INITRD */
@@ -51,7 +51,7 @@ void __init i386_start_kernel(void)
 		u64 ramdisk_image = boot_params.hdr.ramdisk_image;
 		u64 ramdisk_size  = boot_params.hdr.ramdisk_size;
 		u64 ramdisk_end   = PAGE_ALIGN(ramdisk_image + ramdisk_size);
-		reserve_early(ramdisk_image, ramdisk_end, "RAMDISK");
+		lmb_reserve_area(ramdisk_image, ramdisk_end, "RAMDISK");
 	}
 #endif
 
arch/x86/kernel/head64.c +2 -2
index 89dd2de..4063134 100644
@@ -101,7 +101,7 @@ void __init x86_64_start_reservations(char *real_mode_data)
 
 	copy_bootdata(__va(real_mode_data));
 
-	reserve_early(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
+	lmb_reserve_area(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
 
 #ifdef CONFIG_BLK_DEV_INITRD
 	/* Reserve INITRD */
@@ -110,7 +110,7 @@ void __init x86_64_start_reservations(char *real_mode_data)
 		unsigned long ramdisk_image = boot_params.hdr.ramdisk_image;
 		unsigned long ramdisk_size  = boot_params.hdr.ramdisk_size;
 		unsigned long ramdisk_end   = PAGE_ALIGN(ramdisk_image + ramdisk_size);
-		reserve_early(ramdisk_image, ramdisk_end, "RAMDISK");
+		lmb_reserve_area(ramdisk_image, ramdisk_end, "RAMDISK");
 	}
 #endif
 
arch/x86/kernel/setup.c +12 -13
index 7485a19..b79b46f 100644
@@ -302,7 +302,7 @@ static inline void init_gbpages(void)
 static void __init reserve_brk(void)
 {
 	if (_brk_end > _brk_start)
-		reserve_early(__pa(_brk_start), __pa(_brk_end), "BRK");
+		lmb_reserve_area(__pa(_brk_start), __pa(_brk_end), "BRK");
 
 	/* Mark brk area as locked down and no longer taking any
 	   new allocations */
@@ -324,7 +324,7 @@ static void __init relocate_initrd(void)
 	char *p, *q;
 
 	/* We need to move the initrd down into lowmem */
-	ramdisk_here = find_e820_area(0, end_of_lowmem, area_size,
+	ramdisk_here = lmb_find_area(0, end_of_lowmem, area_size,
 					 PAGE_SIZE);
 
 	if (ramdisk_here == -1ULL)
@@ -333,8 +333,7 @@ static void __init relocate_initrd(void)
 
 	/* Note: this includes all the lowmem currently occupied by
 	   the initrd, we rely on that fact to keep the data intact. */
-	reserve_early(ramdisk_here, ramdisk_here + area_size,
-			 "NEW RAMDISK");
+	lmb_reserve_area(ramdisk_here, ramdisk_here + area_size, "NEW RAMDISK");
 	initrd_start = ramdisk_here + PAGE_OFFSET;
 	initrd_end   = initrd_start + ramdisk_size;
 	printk(KERN_INFO "Allocated new RAMDISK: %08llx - %08llx\n",
@@ -390,7 +389,7 @@ static void __init reserve_initrd(void)
 	initrd_start = 0;
 
 	if (ramdisk_size >= (end_of_lowmem>>1)) {
-		free_early(ramdisk_image, ramdisk_end);
+		lmb_free_area(ramdisk_image, ramdisk_end);
 		printk(KERN_ERR "initrd too large to handle, "
 		       "disabling initrd\n");
 		return;
@@ -413,7 +412,7 @@ static void __init reserve_initrd(void)
 
 	relocate_initrd();
 
-	free_early(ramdisk_image, ramdisk_end);
+	lmb_free_area(ramdisk_image, ramdisk_end);
 }
 #else
 static void __init reserve_initrd(void)
@@ -469,7 +468,7 @@ static void __init e820_reserve_setup_data(void)
 	e820_print_map("reserve setup_data");
 }
 
-static void __init reserve_early_setup_data(void)
+static void __init lmb_reserve_area_setup_data(void)
 {
 	struct setup_data *data;
 	u64 pa_data;
@@ -481,7 +480,7 @@ static void __init reserve_early_setup_data(void)
 	while (pa_data) {
 		data = early_memremap(pa_data, sizeof(*data));
 		sprintf(buf, "setup data %x", data->type);
-		reserve_early(pa_data, pa_data+sizeof(*data)+data->len, buf);
+		lmb_reserve_area(pa_data, pa_data+sizeof(*data)+data->len, buf);
 		pa_data = data->next;
 		early_iounmap(data, sizeof(*data));
 	}
@@ -519,7 +518,7 @@ static void __init reserve_crashkernel(void)
 	if (crash_base <= 0) {
 		const unsigned long long alignment = 16<<20;	/* 16M */
 
-		crash_base = find_e820_area(alignment, ULONG_MAX, crash_size,
+		crash_base = lmb_find_area(alignment, ULONG_MAX, crash_size,
 				 alignment);
 		if (crash_base == -1ULL) {
 			pr_info("crashkernel reservation failed - No suitable area found.\n");
@@ -528,14 +527,14 @@ static void __init reserve_crashkernel(void)
 	} else {
 		unsigned long long start;
 
-		start = find_e820_area(crash_base, ULONG_MAX, crash_size,
+		start = lmb_find_area(crash_base, ULONG_MAX, crash_size,
 				 1<<20);
 		if (start != crash_base) {
 			pr_info("crashkernel reservation failed - memory is in use.\n");
 			return;
 		}
 	}
-	reserve_early(crash_base, crash_base + crash_size, "CRASH KERNEL");
+	lmb_reserve_area(crash_base, crash_base + crash_size, "CRASH KERNEL");
 
 	printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
 			"for crashkernel (System RAM: %ldMB)\n",
@@ -774,7 +773,7 @@ void __init setup_arch(char **cmdline_p)
 #endif
 	 4)) {
 		efi_enabled = 1;
-		efi_reserve_early();
+		efi_lmb_reserve_area();
 	}
 #endif
 
@@ -834,7 +833,7 @@ void __init setup_arch(char **cmdline_p)
 	vmi_activate();
 
 	/* after early param, so could get panic from serial */
-	reserve_early_setup_data();
+	lmb_reserve_area_setup_data();
 
 	if (acpi_mps_check()) {
 #ifdef CONFIG_X86_LOCAL_APIC
arch/x86/kernel/trampoline.c +3 -3
index c652ef6..1192dcb 100644
@@ -1,7 +1,7 @@
 #include <linux/io.h>
+#include <linux/lmb.h>
 
 #include <asm/trampoline.h>
-#include <asm/e820.h>
 
 #if defined(CONFIG_X86_64) && defined(CONFIG_ACPI_SLEEP)
 #define __trampinit
@@ -19,12 +19,12 @@ void __init reserve_trampoline_memory(void)
 	unsigned long mem;
 
 	/* Has to be in very low memory so we can execute real-mode AP code. */
-	mem = find_e820_area(0, 1<<20, TRAMPOLINE_SIZE, PAGE_SIZE);
+	mem = lmb_find_area(0, 1<<20, TRAMPOLINE_SIZE, PAGE_SIZE);
 	if (mem == -1L)
 		panic("Cannot allocate trampoline\n");
 
 	trampoline_base = __va(mem);
-	reserve_early(mem, mem + TRAMPOLINE_SIZE, "TRAMPOLINE");
+	lmb_reserve_area(mem, mem + TRAMPOLINE_SIZE, "TRAMPOLINE");
 }
 
 /*
arch/x86/mm/init.c +3 -2
index b278535..94f7cb9 100644
@@ -2,6 +2,7 @@
 #include <linux/initrd.h>
 #include <linux/ioport.h>
 #include <linux/swap.h>
+#include <linux/lmb.h>
 
 #include <asm/cacheflush.h>
 #include <asm/e820.h>
@@ -75,7 +76,7 @@ static void __init find_early_table_space(unsigned long end, int use_pse,
 #else
 	start = 0x8000;
 #endif
-	e820_table_start = find_e820_area(start, max_pfn_mapped<<PAGE_SHIFT,
+	e820_table_start = lmb_find_area(start, max_pfn_mapped<<PAGE_SHIFT,
 					tables, PAGE_SIZE);
 	if (e820_table_start == -1UL)
 		panic("Cannot find space for the kernel page tables");
@@ -299,7 +300,7 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
 	__flush_tlb_all();
 
 	if (!after_bootmem && e820_table_end > e820_table_start)
-		reserve_early(e820_table_start << PAGE_SHIFT,
+		lmb_reserve_area(e820_table_start << PAGE_SHIFT,
 				 e820_table_end << PAGE_SHIFT, "PGTABLE");
 
 	if (!after_bootmem)
arch/x86/mm/init_32.c +6 -4
index 90e0545..c01c711 100644
@@ -25,6 +25,7 @@
 #include <linux/pfn.h>
 #include <linux/poison.h>
 #include <linux/bootmem.h>
+#include <linux/lmb.h>
 #include <linux/proc_fs.h>
 #include <linux/memory_hotplug.h>
 #include <linux/initrd.h>
@@ -712,14 +713,14 @@ void __init initmem_init(unsigned long start_pfn, unsigned long end_pfn,
 	highstart_pfn = highend_pfn = max_pfn;
 	if (max_pfn > max_low_pfn)
 		highstart_pfn = max_low_pfn;
-	e820_register_active_regions(0, 0, highend_pfn);
+	lmb_register_active_regions(0, 0, highend_pfn);
 	sparse_memory_present_with_active_regions(0);
 	printk(KERN_NOTICE "%ldMB HIGHMEM available.\n",
 		pages_to_mb(highend_pfn - highstart_pfn));
 	num_physpages = highend_pfn;
 	high_memory = (void *) __va(highstart_pfn * PAGE_SIZE - 1) + 1;
 #else
-	e820_register_active_regions(0, 0, max_low_pfn);
+	lmb_register_active_regions(0, 0, max_low_pfn);
 	sparse_memory_present_with_active_regions(0);
 	num_physpages = max_low_pfn;
 	high_memory = (void *) __va(max_low_pfn * PAGE_SIZE - 1) + 1;
@@ -781,11 +782,11 @@ void __init setup_bootmem_allocator(void)
 	 * Initialize the boot-time allocator (with low memory only):
 	 */
 	bootmap_size = bootmem_bootmap_pages(max_low_pfn)<<PAGE_SHIFT;
-	bootmap = find_e820_area(0, max_pfn_mapped<<PAGE_SHIFT, bootmap_size,
+	bootmap = lmb_find_area(0, max_pfn_mapped<<PAGE_SHIFT, bootmap_size,
 				 PAGE_SIZE);
 	if (bootmap == -1L)
 		panic("Cannot find bootmem map of size %ld\n", bootmap_size);
-	reserve_early(bootmap, bootmap + bootmap_size, "BOOTMAP");
+	lmb_reserve_area(bootmap, bootmap + bootmap_size, "BOOTMAP");
 #endif
 
 	printk(KERN_INFO "  mapped low ram: 0 - %08lx\n",
@@ -1069,3 +1070,4 @@ void mark_rodata_ro(void)
 #endif
 }
 #endif
+
arch/x86/mm/init_64.c +5 -4
index 634fa08..0d2252c 100644
@@ -21,6 +21,7 @@
 #include <linux/initrd.h>
 #include <linux/pagemap.h>
 #include <linux/bootmem.h>
+#include <linux/lmb.h>
 #include <linux/proc_fs.h>
 #include <linux/pci.h>
 #include <linux/pfn.h>
@@ -577,18 +578,18 @@ void __init initmem_init(unsigned long start_pfn, unsigned long end_pfn,
 	unsigned long bootmap_size, bootmap;
 
 	bootmap_size = bootmem_bootmap_pages(end_pfn)<<PAGE_SHIFT;
-	bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT, bootmap_size,
+	bootmap = lmb_find_area(0, end_pfn<<PAGE_SHIFT, bootmap_size,
 				 PAGE_SIZE);
 	if (bootmap == -1L)
 		panic("Cannot find bootmem map of size %ld\n", bootmap_size);
-	reserve_early(bootmap, bootmap + bootmap_size, "BOOTMAP");
+	lmb_reserve_area(bootmap, bootmap + bootmap_size, "BOOTMAP");
 	/* don't touch min_low_pfn */
 	bootmap_size = init_bootmem_node(NODE_DATA(0), bootmap >> PAGE_SHIFT,
 					 0, end_pfn);
-	e820_register_active_regions(0, start_pfn, end_pfn);
+	lmb_register_active_regions(0, start_pfn, end_pfn);
 	free_bootmem_with_active_regions(0, end_pfn);
 #else
-	e820_register_active_regions(0, start_pfn, end_pfn);
+	lmb_register_active_regions(0, start_pfn, end_pfn);
 #endif
 }
 #endif
arch/x86/mm/k8topology_64.c +3 -1
index 970ed57..d7d031b 100644
@@ -11,6 +11,8 @@
 #include <linux/string.h>
 #include <linux/module.h>
 #include <linux/nodemask.h>
+#include <linux/lmb.h>
+
 #include <asm/io.h>
 #include <linux/pci_ids.h>
 #include <linux/acpi.h>
@@ -222,7 +224,7 @@ int __init k8_scan_nodes(void)
 	for_each_node_mask(i, node_possible_map) {
 		int j;
 
-		e820_register_active_regions(i,
+		lmb_register_active_regions(i,
 				nodes[i].start >> PAGE_SHIFT,
 				nodes[i].end >> PAGE_SHIFT);
 		for (j = apicid_base; j < cores + apicid_base; j++)
arch/x86/mm/memtest.c +3 -4
index 18d244f..0e4a006 100644
@@ -6,8 +6,7 @@
 #include <linux/smp.h>
 #include <linux/init.h>
 #include <linux/pfn.h>
-
-#include <asm/e820.h>
+#include <linux/lmb.h>
 
 static u64 patterns[] __initdata = {
 	0,
@@ -35,7 +34,7 @@ static void __init reserve_bad_mem(u64 pattern, u64 start_bad, u64 end_bad)
 	       (unsigned long long) pattern,
 	       (unsigned long long) start_bad,
 	       (unsigned long long) end_bad);
-	reserve_early(start_bad, end_bad, "BAD RAM");
+	lmb_reserve_area(start_bad, end_bad, "BAD RAM");
 }
 
 static void __init memtest(u64 pattern, u64 start_phys, u64 size)
@@ -74,7 +73,7 @@ static void __init do_one_pass(u64 pattern, u64 start, u64 end)
 	u64 size = 0;
 
 	while (start < end) {
-		start = find_e820_area_size(start, &size, 1);
+		start = lmb_find_area_size(start, &size, 1);
 
 		/* done ? */
 		if (start >= end)
arch/x86/mm/numa_32.c +9 -8
index 809baaa..d8d655f 100644
@@ -24,6 +24,7 @@
 
 #include <linux/mm.h>
 #include <linux/bootmem.h>
+#include <linux/lmb.h>
 #include <linux/mmzone.h>
 #include <linux/highmem.h>
 #include <linux/initrd.h>
@@ -120,7 +121,7 @@ int __init get_memcfg_numa_flat(void)
 
 	node_start_pfn[0] = 0;
 	node_end_pfn[0] = max_pfn;
-	e820_register_active_regions(0, 0, max_pfn);
+	lmb_register_active_regions(0, 0, max_pfn);
 	memory_present(0, 0, max_pfn);
 	node_remap_size[0] = node_memmap_size_bytes(0, 0, max_pfn);
 
@@ -161,14 +162,14 @@ static void __init allocate_pgdat(int nid)
 		NODE_DATA(nid) = (pg_data_t *)node_remap_start_vaddr[nid];
 	else {
 		unsigned long pgdat_phys;
-		pgdat_phys = find_e820_area(min_low_pfn<<PAGE_SHIFT,
+		pgdat_phys = lmb_find_area(min_low_pfn<<PAGE_SHIFT,
 				 max_pfn_mapped<<PAGE_SHIFT,
 				 sizeof(pg_data_t),
 				 PAGE_SIZE);
 		NODE_DATA(nid) = (pg_data_t *)(pfn_to_kaddr(pgdat_phys>>PAGE_SHIFT));
 		memset(buf, 0, sizeof(buf));
 		sprintf(buf, "NODE_DATA %d",  nid);
-		reserve_early(pgdat_phys, pgdat_phys + sizeof(pg_data_t), buf);
+		lmb_reserve_area(pgdat_phys, pgdat_phys + sizeof(pg_data_t), buf);
 	}
 	printk(KERN_DEBUG "allocate_pgdat: node %d NODE_DATA %08lx\n",
 		nid, (unsigned long)NODE_DATA(nid));
@@ -291,7 +292,7 @@ static __init unsigned long calculate_numa_remap_pages(void)
 						 PTRS_PER_PTE);
 		node_kva_target <<= PAGE_SHIFT;
 		do {
-			node_kva_final = find_e820_area(node_kva_target,
+			node_kva_final = lmb_find_area(node_kva_target,
 					((u64)node_end_pfn[nid])<<PAGE_SHIFT,
 						((u64)size)<<PAGE_SHIFT,
 						LARGE_PAGE_BYTES);
@@ -318,9 +319,9 @@ static __init unsigned long calculate_numa_remap_pages(void)
 		 *  but we could have some hole in high memory, and it will only
 		 *  check page_is_ram(pfn) && !page_is_reserved_early(pfn) to decide
 		 *  to use it as free.
-		 *  So reserve_early here, hope we don't run out of that array
+		 *  So lmb_reserve_area here, hope we don't run out of that array
 		 */
-		reserve_early(node_kva_final,
+		lmb_reserve_area(node_kva_final,
 			      node_kva_final+(((u64)size)<<PAGE_SHIFT),
 			      "KVA RAM");
 
@@ -367,7 +368,7 @@ void __init initmem_init(unsigned long start_pfn, unsigned long end_pfn,
 
 	kva_target_pfn = round_down(max_low_pfn - kva_pages, PTRS_PER_PTE);
 	do {
-		kva_start_pfn = find_e820_area(kva_target_pfn<<PAGE_SHIFT,
+		kva_start_pfn = lmb_find_area(kva_target_pfn<<PAGE_SHIFT,
 					max_low_pfn<<PAGE_SHIFT,
 					kva_pages<<PAGE_SHIFT,
 					PTRS_PER_PTE<<PAGE_SHIFT) >> PAGE_SHIFT;
@@ -382,7 +383,7 @@ void __init initmem_init(unsigned long start_pfn, unsigned long end_pfn,
 	printk(KERN_INFO "max_pfn = %lx\n", max_pfn);
 
 	/* avoid clash with initrd */
-	reserve_early(kva_start_pfn<<PAGE_SHIFT,
+	lmb_reserve_area(kva_start_pfn<<PAGE_SHIFT,
 		      (kva_start_pfn + kva_pages)<<PAGE_SHIFT,
 		     "KVA PG");
 #ifdef CONFIG_HIGHMEM
arch/x86/mm/numa_64.c +16 -16
index 6e0f896..18d2296 100644
@@ -90,7 +90,7 @@ static int __init allocate_cachealigned_memnodemap(void)
 
 	addr = 0x8000;
 	nodemap_size = roundup(sizeof(s16) * memnodemapsize, L1_CACHE_BYTES);
-	nodemap_addr = find_e820_area(addr, max_pfn<<PAGE_SHIFT,
+	nodemap_addr = lmb_find_area(addr, max_pfn<<PAGE_SHIFT,
 				      nodemap_size, L1_CACHE_BYTES);
 	if (nodemap_addr == -1UL) {
 		printk(KERN_ERR
@@ -99,7 +99,7 @@ static int __init allocate_cachealigned_memnodemap(void)
 		return -1;
 	}
 	memnodemap = phys_to_virt(nodemap_addr);
-	reserve_early(nodemap_addr, nodemap_addr + nodemap_size, "MEMNODEMAP");
+	lmb_reserve_area(nodemap_addr, nodemap_addr + nodemap_size, "MEMNODEMAP");
 
 	printk(KERN_DEBUG "NUMA: Allocated memnodemap from %lx - %lx\n",
 	       nodemap_addr, nodemap_addr + nodemap_size);
@@ -230,7 +230,7 @@ setup_node_bootmem(int nodeid, unsigned long start, unsigned long end)
 	if (node_data[nodeid] == NULL)
 		return;
 	nodedata_phys = __pa(node_data[nodeid]);
-	reserve_early(nodedata_phys, nodedata_phys + pgdat_size, "NODE_DATA");
+	lmb_reserve_area(nodedata_phys, nodedata_phys + pgdat_size, "NODE_DATA");
 	printk(KERN_INFO "  NODE_DATA [%016lx - %016lx]\n", nodedata_phys,
 		nodedata_phys + pgdat_size - 1);
 	nid = phys_to_nid(nodedata_phys);
@@ -249,7 +249,7 @@ setup_node_bootmem(int nodeid, unsigned long start, unsigned long end)
 	 * Find a place for the bootmem map
 	 * nodedata_phys could be on other nodes by alloc_bootmem,
 	 * so need to sure bootmap_start not to be small, otherwise
-	 * early_node_mem will get that with find_e820_area instead
+	 * early_node_mem will get that with lmb_find_area instead
 	 * of alloc_bootmem, that could clash with reserved range
 	 */
 	bootmap_pages = bootmem_bootmap_pages(last_pfn - start_pfn);
@@ -261,12 +261,12 @@ setup_node_bootmem(int nodeid, unsigned long start, unsigned long end)
 	bootmap = early_node_mem(nodeid, bootmap_start, end,
 				 bootmap_pages<<PAGE_SHIFT, PAGE_SIZE);
 	if (bootmap == NULL)  {
-		free_early(nodedata_phys, nodedata_phys + pgdat_size);
+		lmb_free_area(nodedata_phys, nodedata_phys + pgdat_size);
 		node_data[nodeid] = NULL;
 		return;
 	}
 	bootmap_start = __pa(bootmap);
-	reserve_early(bootmap_start, bootmap_start+(bootmap_pages<<PAGE_SHIFT),
+	lmb_reserve_area(bootmap_start, bootmap_start+(bootmap_pages<<PAGE_SHIFT),
 			"BOOTMAP");
 
 	bootmap_size = init_bootmem_node(NODE_DATA(nodeid),
@@ -420,7 +420,7 @@ static int __init split_nodes_interleave(u64 addr, u64 max_addr,
 		nr_nodes = MAX_NUMNODES;
 	}
 
-	size = (max_addr - addr - e820_hole_size(addr, max_addr)) / nr_nodes;
+	size = (max_addr - addr - lmb_hole_size(addr, max_addr)) / nr_nodes;
 	/*
 	 * Calculate the number of big nodes that can be allocated as a result
 	 * of consolidating the remainder.
@@ -456,7 +456,7 @@ static int __init split_nodes_interleave(u64 addr, u64 max_addr,
 			 * non-reserved memory is less than the per-node size.
 			 */
 			while (end - physnodes[i].start -
-				e820_hole_size(physnodes[i].start, end) < size) {
+				lmb_hole_size(physnodes[i].start, end) < size) {
 				end += FAKE_NODE_MIN_SIZE;
 				if (end > physnodes[i].end) {
 					end = physnodes[i].end;
@@ -470,7 +470,7 @@ static int __init split_nodes_interleave(u64 addr, u64 max_addr,
 			 * this one must extend to the boundary.
 			 */
 			if (end < dma32_end && dma32_end - end -
-			    e820_hole_size(end, dma32_end) < FAKE_NODE_MIN_SIZE)
+			    lmb_hole_size(end, dma32_end) < FAKE_NODE_MIN_SIZE)
 				end = dma32_end;
 
 			/*
@@ -479,7 +479,7 @@ static int __init split_nodes_interleave(u64 addr, u64 max_addr,
 			 * physical node.
 			 */
 			if (physnodes[i].end - end -
-			    e820_hole_size(end, physnodes[i].end) < size)
+			    lmb_hole_size(end, physnodes[i].end) < size)
 				end = physnodes[i].end;
 
 			/*
@@ -507,7 +507,7 @@ static u64 __init find_end_of_node(u64 start, u64 max_addr, u64 size)
 {
 	u64 end = start + size;
 
-	while (end - start - e820_hole_size(start, end) < size) {
+	while (end - start - lmb_hole_size(start, end) < size) {
 		end += FAKE_NODE_MIN_SIZE;
 		if (end > max_addr) {
 			end = max_addr;
@@ -536,7 +536,7 @@ static int __init split_nodes_size_interleave(u64 addr, u64 max_addr, u64 size)
 	 * creates a uniform distribution of node sizes across the entire
 	 * machine (but not necessarily over physical nodes).
 	 */
-	min_size = (max_addr - addr - e820_hole_size(addr, max_addr)) /
+	min_size = (max_addr - addr - lmb_hole_size(addr, max_addr)) /
 						MAX_NUMNODES;
 	min_size = max(min_size, FAKE_NODE_MIN_SIZE);
 	if ((min_size & FAKE_NODE_MIN_HASH_MASK) < min_size)
@@ -569,7 +569,7 @@ static int __init split_nodes_size_interleave(u64 addr, u64 max_addr, u64 size)
 			 * this one must extend to the boundary.
 			 */
 			if (end < dma32_end && dma32_end - end -
-			    e820_hole_size(end, dma32_end) < FAKE_NODE_MIN_SIZE)
+			    lmb_hole_size(end, dma32_end) < FAKE_NODE_MIN_SIZE)
 				end = dma32_end;
 
 			/*
@@ -578,7 +578,7 @@ static int __init split_nodes_size_interleave(u64 addr, u64 max_addr, u64 size)
 			 * physical node.
 			 */
 			if (physnodes[i].end - end -
-			    e820_hole_size(end, physnodes[i].end) < size)
+			    lmb_hole_size(end, physnodes[i].end) < size)
 				end = physnodes[i].end;
 
 			/*
@@ -642,7 +642,7 @@ static int __init numa_emulation(unsigned long start_pfn,
 	 */
 	remove_all_active_ranges();
 	for_each_node_mask(i, node_possible_map) {
-		e820_register_active_regions(i, nodes[i].start >> PAGE_SHIFT,
+		lmb_register_active_regions(i, nodes[i].start >> PAGE_SHIFT,
 						nodes[i].end >> PAGE_SHIFT);
 		setup_node_bootmem(i, nodes[i].start, nodes[i].end);
 	}
@@ -695,7 +695,7 @@ void __init initmem_init(unsigned long start_pfn, unsigned long last_pfn,
 	node_set(0, node_possible_map);
 	for (i = 0; i < nr_cpu_ids; i++)
 		numa_set_node(i, 0);
-	e820_register_active_regions(0, start_pfn, last_pfn);
+	lmb_register_active_regions(0, start_pfn, last_pfn);
 	setup_node_bootmem(0, start_pfn << PAGE_SHIFT, last_pfn << PAGE_SHIFT);
 }
 
arch/x86/mm/srat_32.c +2 -1
index 9324f13..68dd606 100644
@@ -25,6 +25,7 @@
  */
 #include <linux/mm.h>
 #include <linux/bootmem.h>
+#include <linux/lmb.h>
 #include <linux/mmzone.h>
 #include <linux/acpi.h>
 #include <linux/nodemask.h>
@@ -264,7 +265,7 @@ int __init get_memcfg_from_srat(void)
 		if (node_read_chunk(chunk->nid, chunk))
 			continue;
 
-		e820_register_active_regions(chunk->nid, chunk->start_pfn,
+		lmb_register_active_regions(chunk->nid, chunk->start_pfn,
 					     min(chunk->end_pfn, max_pfn));
 	}
 	/* for out of order entries in SRAT */
arch/x86/mm/srat_64.c +5 -4
index f9897f7..23f274c 100644
@@ -16,6 +16,7 @@
 #include <linux/module.h>
 #include <linux/topology.h>
 #include <linux/bootmem.h>
+#include <linux/lmb.h>
 #include <linux/mm.h>
 #include <asm/proto.h>
 #include <asm/numa.h>
@@ -98,7 +99,7 @@ void __init acpi_numa_slit_init(struct acpi_table_slit *slit)
 	unsigned long phys;
 
 	length = slit->header.length;
-	phys = find_e820_area(0, max_pfn_mapped<<PAGE_SHIFT, length,
+	phys = lmb_find_area(0, max_pfn_mapped<<PAGE_SHIFT, length,
 		 PAGE_SIZE);
 
 	if (phys == -1L)
@@ -106,7 +107,7 @@ void __init acpi_numa_slit_init(struct acpi_table_slit *slit)
 
 	acpi_slit = __va(phys);
 	memcpy(acpi_slit, slit, length);
-	reserve_early(phys, phys + length, "ACPI SLIT");
+	lmb_reserve_area(phys, phys + length, "ACPI SLIT");
 }
 
 /* Callback for Proximity Domain -> x2APIC mapping */
@@ -324,7 +325,7 @@ static int __init nodes_cover_memory(const struct bootnode *nodes)
 			pxmram = 0;
 	}
 
-	e820ram = max_pfn - (e820_hole_size(0, max_pfn<<PAGE_SHIFT)>>PAGE_SHIFT);
+	e820ram = max_pfn - (lmb_hole_size(0, max_pfn<<PAGE_SHIFT)>>PAGE_SHIFT);
 	/* We seem to lose 3 pages somewhere. Allow 1M of slack. */
 	if ((long)(e820ram - pxmram) >= (1<<(20 - PAGE_SHIFT))) {
 		printk(KERN_ERR
@@ -421,7 +422,7 @@ int __init acpi_scan_nodes(unsigned long start, unsigned long end)
 	}
 
 	for_each_node_mask(i, nodes_parsed)
-		e820_register_active_regions(i, nodes[i].start >> PAGE_SHIFT,
+		lmb_register_active_regions(i, nodes[i].start >> PAGE_SHIFT,
 						nodes[i].end >> PAGE_SHIFT);
 	/* for out of order entries in SRAT */
 	sort_node_map();
arch/x86/xen/mmu.c +3 -2
index 914f046..28185a8 100644
@@ -44,6 +44,7 @@
 #include <linux/bug.h>
 #include <linux/module.h>
 #include <linux/gfp.h>
+#include <linux/lmb.h>
 
 #include <asm/pgtable.h>
 #include <asm/tlbflush.h>
@@ -1735,7 +1736,7 @@ __init pgd_t *xen_setup_kernel_pagetable(pgd_t *pgd,
 	__xen_write_cr3(true, __pa(pgd));
 	xen_mc_issue(PARAVIRT_LAZY_CPU);
 
-	reserve_early(__pa(xen_start_info->pt_base),
+	lmb_reserve_area(__pa(xen_start_info->pt_base),
 		      __pa(xen_start_info->pt_base +
 			   xen_start_info->nr_pt_frames * PAGE_SIZE),
 		      "XEN PAGETABLES");
@@ -1773,7 +1774,7 @@ __init pgd_t *xen_setup_kernel_pagetable(pgd_t *pgd,
 
 	pin_pagetable_pfn(MMUEXT_PIN_L3_TABLE, PFN_DOWN(__pa(swapper_pg_dir)));
 
-	reserve_early(__pa(xen_start_info->pt_base),
+	lmb_reserve_area(__pa(xen_start_info->pt_base),
 		      __pa(xen_start_info->pt_base +
 			   xen_start_info->nr_pt_frames * PAGE_SIZE),
 		      "XEN PAGETABLES");
arch/x86/xen/setup.c +2 -1
index ad0047f..be3fcf3 100644
@@ -8,6 +8,7 @@
 #include <linux/sched.h>
 #include <linux/mm.h>
 #include <linux/pm.h>
+#include <linux/lmb.h>
 
 #include <asm/elf.h>
 #include <asm/vdso.h>
@@ -61,7 +62,7 @@ char * __init xen_memory_setup(void)
 	 *  - xen_start_info
 	 * See comment above "struct start_info" in <xen/interface/xen.h>
 	 */
-	reserve_early(__pa(xen_start_info->mfn_list),
+	lmb_reserve_area(__pa(xen_start_info->mfn_list),
 		      __pa(xen_start_info->pt_base),
 			"XEN START INFO");
 
mm/bootmem.c +2 -2
index dac3f56..2a4c8b5 100644
@@ -435,7 +435,7 @@ void __init free_bootmem_node(pg_data_t *pgdat, unsigned long physaddr,
 			      unsigned long size)
 {
 #ifdef CONFIG_NO_BOOTMEM
-	free_early(physaddr, physaddr + size);
+	lmb_free_area(physaddr, physaddr + size);
 #else
 	unsigned long start, end;
 
@@ -460,7 +460,7 @@ void __init free_bootmem_node(pg_data_t *pgdat, unsigned long physaddr,
 void __init free_bootmem(unsigned long addr, unsigned long size)
 {
 #ifdef CONFIG_NO_BOOTMEM
-	free_early(addr, addr + size);
+	lmb_free_area(addr, addr + size);
 #else
 	unsigned long start, end;
 
Signature · 1 line
1.6.4.2
author
#38 lore raw

PATCH 22/22 x86: Remove not used early_res code

In reply to Yinghai Lu

and some functions in e820.c that are not used anymore

---
 arch/x86/include/asm/e820.h |   14 -
 arch/x86/kernel/e820.c      |   42 ---
 include/linux/early_res.h   |   23 --
 kernel/early_res.c          |  584 -------------------------------------------
 4 files changed, 0 insertions(+), 663 deletions(-)
 delete mode 100644 include/linux/early_res.h
 delete mode 100644 kernel/early_res.c
arch/x86/include/asm/e820.h +0 -14
index 38adac8..6fbd8cd 100644
@@ -112,32 +112,18 @@ static inline void early_memtest(unsigned long start, unsigned long end)
 }
 #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);
-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 void e820_register_active_regions(int nid, unsigned long start_pfn,
-					 unsigned long end_pfn);
-extern u64 e820_hole_size(u64 start, u64 end);
-
 extern u64 early_reserve_e820(u64 startt, u64 sizet, u64 align);
 
 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);
 extern void setup_memory_map(void);
 extern char *default_machine_specific_memory_setup(void);
 
-void reserve_early(u64 start, u64 end, char *name);
-void free_early(u64 start, u64 end);
-
 /*
  * Returns true iff the specified range [s,e) is completely contained inside
  * the ISA region.
arch/x86/kernel/e820.c +0 -42

54 lines not on this page · raw message

include/linux/early_res.h deleted +0 -23
deleted file mode 100644
index 29c09f5..0000000
@@ -1,23 +0,0 @@
-#ifndef _LINUX_EARLY_RES_H
-#define _LINUX_EARLY_RES_H
-#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 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 get_max_mapped(void);
-#include <linux/range.h>
-int get_free_all_memory_range(struct range **rangep, int nodeid);
-
-#endif /* __KERNEL__ */
-
-#endif /* _LINUX_EARLY_RES_H */
kernel/early_res.c deleted +0 -584

584 lines not on this page · raw message

Signature · 1 line
1.6.4.2
#39 lore raw
In reply to Yinghai Lu
Quoted 3 lines · Yinghai Lu

the new lmb could be used to replace early_res in x86.

Suggested by: David, Ben, and Thomas

.../...

Quoted 5 lines

Only first three patches in this set could affect original lmb users. lmb.c lines from 567 to 996
If lmb guys are still not happy, we could move that 360 lines to arch/x86/mm/lmb.c

still hope Ben could do lmb clean up on top of this patchset.

I would still like to do it the other way around :-)

My patches replace (and in some case are equivalent) to part of this series, though I believe are cleaner, provide more readable changeset comments and justifications, etc... it would be awkward to just apply your stuff with "cleanup" passes from me on top of it.

I really prefer providing you with all the LMB infrastructure you need so you can simply drop LMB changes from your series.

I'll be working on that today, finishing what I plan to finish and if I get a chance (it's hard with one of the kids having a double ear infection) see if I can rebase your work and at least compile test it.

Stay tuned...

Cheers,
Ben.