Skip to content

Commit 55ac590

Browse files
tang-chentorvalds
authored andcommitted
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. [akpm@linux-foundation.org: coding-style fixes] Signed-off-by: Tang Chen <tangchen@cn.fujitsu.com> Signed-off-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 a0acda9 commit 55ac590

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

‎include/linux/memblock.h‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ struct memblock {
4747

4848
extern struct memblock memblock;
4949
extern int memblock_debug;
50+
#ifdef CONFIG_MOVABLE_NODE
51+
/* If movable_node boot option specified */
52+
extern bool movable_node_enabled;
53+
#endif /* CONFIG_MOVABLE_NODE */
5054

5155
#define memblock_dbg(fmt, ...) \
5256
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);
6569
void memblock_trim_memory(phys_addr_t align);
6670
int memblock_mark_hotplug(phys_addr_t base, phys_addr_t size);
6771
int memblock_clear_hotplug(phys_addr_t base, phys_addr_t size);
72+
#ifdef CONFIG_MOVABLE_NODE
73+
static inline bool memblock_is_hotpluggable(struct memblock_region *m)
74+
{
75+
return m->flags & MEMBLOCK_HOTPLUG;
76+
}
77+
78+
static inline bool movable_node_is_enabled(void)
79+
{
80+
return movable_node_enabled;
81+
}
82+
#else
83+
static inline bool memblock_is_hotpluggable(struct memblock_region *m)
84+
{
85+
return false;
86+
}
87+
static inline bool movable_node_is_enabled(void)
88+
{
89+
return false;
90+
}
91+
#endif
6892

6993
#ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP
7094
int memblock_search_pfn_nid(unsigned long pfn, unsigned long *start_pfn,

‎mm/memblock.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ struct memblock memblock __initdata_memblock = {
3939
};
4040

4141
int memblock_debug __initdata_memblock;
42+
#ifdef CONFIG_MOVABLE_NODE
43+
bool movable_node_enabled __initdata_memblock = false;
44+
#endif
4245
static int memblock_can_resize __initdata_memblock;
4346
static int memblock_memory_in_slab __initdata_memblock = 0;
4447
static int memblock_reserved_in_slab __initdata_memblock = 0;
@@ -820,6 +823,11 @@ void __init_memblock __next_free_mem_range(u64 *idx, int nid,
820823
* @out_nid: ptr to int for nid of the range, can be %NULL
821824
*
822825
* Reverse of __next_free_mem_range().
826+
*
827+
* Linux kernel cannot migrate pages used by itself. Memory hotplug users won't
828+
* be able to hot-remove hotpluggable memory used by the kernel. So this
829+
* function skip hotpluggable regions if needed when allocating memory for the
830+
* kernel.
823831
*/
824832
void __init_memblock __next_free_mem_range_rev(u64 *idx, int nid,
825833
phys_addr_t *out_start,
@@ -844,6 +852,10 @@ void __init_memblock __next_free_mem_range_rev(u64 *idx, int nid,
844852
if (nid != MAX_NUMNODES && nid != memblock_get_region_node(m))
845853
continue;
846854

855+
/* skip hotpluggable memory regions if needed */
856+
if (movable_node_is_enabled() && memblock_is_hotpluggable(m))
857+
continue;
858+
847859
/* scan areas before each reservation for intersection */
848860
for ( ; ri >= 0; ri--) {
849861
struct memblock_region *r = &rsv->regions[ri];

‎mm/memory_hotplug.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,7 @@ static int __init cmdline_parse_movable_node(char *p)
14461446
* the kernel away from hotpluggable memory.
14471447
*/
14481448
memblock_set_bottom_up(true);
1449+
movable_node_enabled = true;
14491450
#else
14501451
pr_warn("movable_node option not supported\n");
14511452
#endif

0 commit comments

Comments
 (0)