Skip to content

Commit a0acda9

Browse files
tang-chentorvalds
authored andcommitted
acpi, numa, mem_hotplug: mark all nodes the kernel resides un-hotpluggable
At very early time, the kernel have to use some memory such as loading the kernel image. We cannot prevent this anyway. So any node the kernel resides in should be un-hotpluggable. Signed-off-by: Tang Chen <tangchen@cn.fujitsu.com> Reviewed-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: "Rafael J . Wysocki" <rjw@sisk.pl> Cc: Chen Tang <imtangchen@gmail.com> Cc: Gong Chen <gong.chen@linux.intel.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Jiang Liu <jiang.liu@huawei.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Lai Jiangshan <laijs@cn.fujitsu.com> Cc: Larry Woodman <lwoodman@redhat.com> Cc: Len Brown <lenb@kernel.org> Cc: Liu Jiang <jiang.liu@huawei.com> Cc: Mel Gorman <mgorman@suse.de> Cc: Michal Nazarewicz <mina86@mina86.com> Cc: Minchan Kim <minchan@kernel.org> Cc: Prarit Bhargava <prarit@redhat.com> Cc: Rik van Riel <riel@redhat.com> Cc: Taku Izumi <izumi.taku@jp.fujitsu.com> Cc: Tejun Heo <tj@kernel.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Thomas Renninger <trenn@suse.de> Cc: Toshi Kani <toshi.kani@hp.com> Cc: Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com> Cc: Wanpeng Li <liwanp@linux.vnet.ibm.com> Cc: Wen Congyang <wency@cn.fujitsu.com> Cc: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com> Cc: Yinghai Lu <yinghai@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 05d1d8c commit a0acda9

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

‎arch/x86/mm/numa.c‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,14 @@ static int __init numa_register_memblks(struct numa_meminfo *mi)
493493
struct numa_memblk *mb = &mi->blk[i];
494494
memblock_set_node(mb->start, mb->end - mb->start,
495495
&memblock.memory, mb->nid);
496+
497+
/*
498+
* At this time, all memory regions reserved by memblock are
499+
* used by the kernel. Set the nid in memblock.reserved will
500+
* mark out all the nodes the kernel resides in.
501+
*/
502+
memblock_set_node(mb->start, mb->end - mb->start,
503+
&memblock.reserved, mb->nid);
496504
}
497505

498506
/*
@@ -554,6 +562,30 @@ static void __init numa_init_array(void)
554562
}
555563
}
556564

565+
static void __init numa_clear_kernel_node_hotplug(void)
566+
{
567+
int i, nid;
568+
nodemask_t numa_kernel_nodes;
569+
unsigned long start, end;
570+
struct memblock_type *type = &memblock.reserved;
571+
572+
/* Mark all kernel nodes. */
573+
for (i = 0; i < type->cnt; i++)
574+
node_set(type->regions[i].nid, numa_kernel_nodes);
575+
576+
/* Clear MEMBLOCK_HOTPLUG flag for memory in kernel nodes. */
577+
for (i = 0; i < numa_meminfo.nr_blks; i++) {
578+
nid = numa_meminfo.blk[i].nid;
579+
if (!node_isset(nid, numa_kernel_nodes))
580+
continue;
581+
582+
start = numa_meminfo.blk[i].start;
583+
end = numa_meminfo.blk[i].end;
584+
585+
memblock_clear_hotplug(start, end - start);
586+
}
587+
}
588+
557589
static int __init numa_init(int (*init_func)(void))
558590
{
559591
int i;
@@ -568,6 +600,8 @@ static int __init numa_init(int (*init_func)(void))
568600
memset(&numa_meminfo, 0, sizeof(numa_meminfo));
569601
WARN_ON(memblock_set_node(0, ULLONG_MAX, &memblock.memory,
570602
MAX_NUMNODES));
603+
WARN_ON(memblock_set_node(0, ULLONG_MAX, &memblock.reserved,
604+
MAX_NUMNODES));
571605
/* In case that parsing SRAT failed. */
572606
WARN_ON(memblock_clear_hotplug(0, ULLONG_MAX));
573607
numa_reset_distance();
@@ -605,6 +639,16 @@ static int __init numa_init(int (*init_func)(void))
605639
numa_clear_node(i);
606640
}
607641
numa_init_array();
642+
643+
/*
644+
* At very early time, the kernel have to use some memory such as
645+
* loading the kernel image. We cannot prevent this anyway. So any
646+
* node the kernel resides in should be un-hotpluggable.
647+
*
648+
* And when we come here, numa_init() won't fail.
649+
*/
650+
numa_clear_kernel_node_hotplug();
651+
608652
return 0;
609653
}
610654

0 commit comments

Comments
 (0)