From: Yinghai Lu on
Generic version is going from high to low, and it seems it can not find
right area compact enough.

the x86 version will go from goal to limit and just like the way We used
for early_res

use ARCH_FIND_LMB_AREA to select from them.

-v2: default to no

Signed-off-by: Yinghai Lu <yinghai(a)kernel.org>
---
arch/x86/Kconfig | 8 ++++++
arch/x86/mm/lmb.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 75 insertions(+), 0 deletions(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 6f77afa..e4d6bc0 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -587,6 +587,14 @@ config PARAVIRT_DEBUG
Enable to debug paravirt_ops internals. Specifically, BUG if
a paravirt_op is missing when it is called.

+config ARCH_LMB_FIND_AREA
+ default n
+ bool "Use x86 own lmb_find_in_range()"
+ ---help---
+ Use lmb_find_in_range() version instead of generic version, it get free
+ area up from low.
+ Generic one try to get free area down from limit.
+
config NO_BOOTMEM
default y
bool "Disable Bootmem code"
diff --git a/arch/x86/mm/lmb.c b/arch/x86/mm/lmb.c
index 209f25b..2cc83d6 100644
--- a/arch/x86/mm/lmb.c
+++ b/arch/x86/mm/lmb.c
@@ -396,3 +396,70 @@ u64 __init lmb_hole_size(u64 start, u64 end)
return end - start - ((u64)ram << PAGE_SHIFT);
}

+#ifdef CONFIG_ARCH_LMB_FIND_AREA
+/* Check for already reserved areas */
+static inline bool __init bad_addr(u64 *addrp, u64 size, u64 align)
+{
+ u64 addr = *addrp;
+ bool changed = false;
+ struct lmb_region *r;
+again:
+ for_each_lmb(reserved, r) {
+ if ((addr + size) > r->base && addr < (r->base + r->size)) {
+ addr = round_up(r->base + r->size, align);
+ changed = true;
+ goto again;
+ }
+ }
+
+ if (changed)
+ *addrp = addr;
+
+ return changed;
+}
+
+static u64 __init __lmb_find_in_range(u64 ei_start, u64 ei_last, u64 start, u64 end,
+ u64 size, u64 align)
+{
+ u64 addr, last;
+
+ addr = round_up(ei_start, align);
+ if (addr < start)
+ addr = round_up(start, align);
+ if (addr >= ei_last)
+ goto out;
+ while (bad_addr(&addr, size, align) && addr+size <= ei_last)
+ ;
+ last = addr + size;
+ if (last > ei_last)
+ goto out;
+ if (last > end)
+ goto out;
+
+ return addr;
+
+out:
+ return LMB_ERROR;
+}
+
+/*
+ * Find a free area with specified alignment in a specific range.
+ */
+u64 __init lmb_find_in_range(u64 start, u64 end, u64 size, u64 align)
+{
+ struct lmb_region *r;
+
+ for_each_lmb(memory, r) {
+ u64 ei_start = r->base;
+ u64 ei_last = ei_start + r->size;
+ u64 addr;
+
+ addr = __lmb_find_in_range(ei_start, ei_last, start, end,
+ size, align);
+
+ if (addr != LMB_ERROR)
+ return addr;
+ }
+ return LMB_ERROR;
+}
+#endif
--
1.6.4.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/