Commit 55ac590c authored by Tang Chen's avatar Tang Chen Committed by Linus Torvalds
Browse files

memblock, mem_hotplug: make memblock skip hotpluggable regions if needed

Linux kernel cannot migrate pages used by the kernel.  As a result,
hotpluggable memory used by the kernel won't be able to be hot-removed.
To solve this problem, the basic idea is to prevent memblock from
allocating hotpluggable memory for the kernel at early time, and arrange
all hotpluggable memory in ACPI SRAT(System Resource Affinity Table) as
ZONE_MOVABLE when initializing zones.

In the previous patches, we have marked hotpluggable memory regions with
MEMBLOCK_HOTPLUG flag in memblock.memory.

In this patch, we make memblock skip these hotpluggable memory regions
in the default top-down allocation function if movable_node boot option
is specified.

[ coding-style fixes]
Signed-off-by: default avatarTang Chen <>
Signed-off-by: default avatarZhang Yanfei <>
Cc: "H. Peter Anvin" <>
Cc: "Rafael J . Wysocki" <>
Cc: Chen Tang <>
Cc: Gong Chen <>
Cc: Ingo Molnar <>
Cc: Jiang Liu <>
Cc: Johannes Weiner <>
Cc: Lai Jiangshan <>
Cc: Larry Woodman <>
Cc: Len Brown <>
Cc: Liu Jiang <>
Cc: Mel Gorman <>
Cc: Michal Nazarewicz <>
Cc: Minchan Kim <>
Cc: Prarit Bhargava <>
Cc: Rik van Riel <>
Cc: Taku Izumi <>
Cc: Tejun Heo <>
Cc: Thomas Gleixner <>
Cc: Thomas Renninger <>
Cc: Toshi Kani <>
Cc: Vasilis Liaskovitis <>
Cc: Wanpeng Li <>
Cc: Wen Congyang <>
Cc: Yasuaki Ishimatsu <>
Cc: Yinghai Lu <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent a0acda91
......@@ -47,6 +47,10 @@ struct memblock {
extern struct memblock memblock;
extern int memblock_debug;
/* If movable_node boot option specified */
extern bool movable_node_enabled;
#define memblock_dbg(fmt, ...) \
if (memblock_debug) printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
......@@ -65,6 +69,26 @@ int memblock_reserve(phys_addr_t base, phys_addr_t size);
void memblock_trim_memory(phys_addr_t align);
int memblock_mark_hotplug(phys_addr_t base, phys_addr_t size);
int memblock_clear_hotplug(phys_addr_t base, phys_addr_t size);
static inline bool memblock_is_hotpluggable(struct memblock_region *m)
return m->flags & MEMBLOCK_HOTPLUG;
static inline bool movable_node_is_enabled(void)
return movable_node_enabled;
static inline bool memblock_is_hotpluggable(struct memblock_region *m)
return false;
static inline bool movable_node_is_enabled(void)
return false;
int memblock_search_pfn_nid(unsigned long pfn, unsigned long *start_pfn,
......@@ -39,6 +39,9 @@ struct memblock memblock __initdata_memblock = {
int memblock_debug __initdata_memblock;
bool movable_node_enabled __initdata_memblock = false;
static int memblock_can_resize __initdata_memblock;
static int memblock_memory_in_slab __initdata_memblock = 0;
static int memblock_reserved_in_slab __initdata_memblock = 0;
......@@ -820,6 +823,11 @@ void __init_memblock __next_free_mem_range(u64 *idx, int nid,
* @out_nid: ptr to int for nid of the range, can be %NULL
* Reverse of __next_free_mem_range().
* Linux kernel cannot migrate pages used by itself. Memory hotplug users won't
* be able to hot-remove hotpluggable memory used by the kernel. So this
* function skip hotpluggable regions if needed when allocating memory for the
* kernel.
void __init_memblock __next_free_mem_range_rev(u64 *idx, int nid,
phys_addr_t *out_start,
......@@ -844,6 +852,10 @@ void __init_memblock __next_free_mem_range_rev(u64 *idx, int nid,
if (nid != MAX_NUMNODES && nid != memblock_get_region_node(m))
/* skip hotpluggable memory regions if needed */
if (movable_node_is_enabled() && memblock_is_hotpluggable(m))
/* scan areas before each reservation for intersection */
for ( ; ri >= 0; ri--) {
struct memblock_region *r = &rsv->regions[ri];
......@@ -1446,6 +1446,7 @@ static int __init cmdline_parse_movable_node(char *p)
* the kernel away from hotpluggable memory.
movable_node_enabled = true;
pr_warn("movable_node option not supported\n");
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment