[PATCH v2 13/18] x86, numa, mem_hotplug: Skip all the regions the kernel resides in.

From: Tang Chen
Date: Thu Aug 01 2013 - 03:09:32 EST


At early time, memblock will reserve some memory for the kernel,
such as the kernel code and data segments, initrd file, and so onï
which means the kernel resides in these memory regions.

Even if these memory regions are hotpluggable, we should not
mark them as hotpluggable. Otherwise the kernel won't have enough
memory to boot.

This patch finds out which memory regions the kernel resides in,
and skip them when finding all hotpluggable memory regions.

Signed-off-by: Tang Chen <tangchen@xxxxxxxxxxxxxx>
Reviewed-by: Zhang Yanfei <zhangyanfei@xxxxxxxxxxxxxx>
---
mm/memory_hotplug.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 326e2f2..b800c9c 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -31,6 +31,7 @@
#include <linux/firmware-map.h>
#include <linux/stop_machine.h>
#include <linux/acpi.h>
+#include <linux/memblock.h>

#include <asm/tlbflush.h>

@@ -93,6 +94,40 @@ static void release_memory_resource(struct resource *res)

#ifdef CONFIG_ACPI_NUMA
/**
+ * kernel_resides_in_range - Check if kernel resides in a memory region.
+ * @base: The base address of the memory region.
+ * @length: The length of the memory region.
+ *
+ * This function is used at early time. It iterates memblock.reserved and check
+ * if the kernel has used any memory in [@base, @base + @length).
+ *
+ * Return true if the kernel resides in the memory region, false otherwise.
+ */
+static bool __init kernel_resides_in_region(phys_addr_t base, u64 length)
+{
+ int i;
+ phys_addr_t start, end;
+ struct memblock_region *region;
+ struct memblock_type *reserved = &memblock.reserved;
+
+ for (i = 0; i < reserved->cnt; i++) {
+ region = &reserved->regions[i];
+
+ if (region->flags != MEMBLOCK_HOTPLUG)
+ continue;
+
+ start = region->base;
+ end = region->base + region->size;
+ if (end <= base || start >= base + length)
+ continue;
+
+ return true;
+ }
+
+ return false;
+}
+
+/**
* find_hotpluggable_memory - Find out hotpluggable memory from ACPI SRAT.
*
* This function did the following:
@@ -129,6 +164,16 @@ void __init find_hotpluggable_memory(void)

while (ACPI_SUCCESS(acpi_hotplug_mem_affinity(srat_vaddr, &base,
&size, &offset))) {
+ /*
+ * At early time, memblock will reserve some memory for the
+ * kernel, such as the kernel code and data segments, initrd
+ * file, and so onïwhich means the kernel resides in these
+ * memory regions. These regions should not be hotpluggable.
+ * So do not mark them as hotpluggable.
+ */
+ if (kernel_resides_in_region(base, size))
+ continue;
+
/* Will mark hotpluggable memory regions here */
}

--
1.7.1

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