Skip to content

Commit 52219ae

Browse files
David Hildenbrandtorvalds
authored andcommitted
mm/memory_hotplug: handle memblocks only with CONFIG_ARCH_KEEP_MEMBLOCK
The comment in add_memory_resource() is stale: hotadd_new_pgdat() will no longer call get_pfn_range_for_nid(), as a hotadded pgdat will simply span no pages at all, until memory is moved to the zone/node via move_pfn_range_to_zone() - e.g., when onlining memory blocks. The only archs that care about memblocks for hotplugged memory (either for iterating over all system RAM or testing for memory validity) are arm64, s390x, and powerpc - due to CONFIG_ARCH_KEEP_MEMBLOCK. Without CONFIG_ARCH_KEEP_MEMBLOCK, we can simply stop messing with memblocks. Signed-off-by: David Hildenbrand <david@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Acked-by: Mike Rapoport <rppt@linux.ibm.com> Acked-by: Michal Hocko <mhocko@suse.com> Cc: Michal Hocko <mhocko@kernel.org> Cc: Baoquan He <bhe@redhat.com> Cc: Oscar Salvador <osalvador@suse.de> Cc: Pankaj Gupta <pankaj.gupta.linux@gmail.com> Cc: Mike Rapoport <rppt@linux.ibm.com> Cc: Anshuman Khandual <anshuman.khandual@arm.com> Link: http://lkml.kernel.org/r/20200422155353.25381-3-david@redhat.com Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent c68ab18 commit 52219ae

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

‎mm/Kconfig‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ config HAVE_FAST_GUP
133133
depends on MMU
134134
bool
135135

136+
# Don't discard allocated memory used to track "memory" and "reserved" memblocks
137+
# after early boot, so it can still be used to test for validity of memory.
138+
# Also, memblocks are updated with memory hot(un)plug.
136139
config ARCH_KEEP_MEMBLOCK
137140
bool
138141

‎mm/memory_hotplug.c‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,13 +1021,8 @@ int __ref add_memory_resource(int nid, struct resource *res)
10211021

10221022
mem_hotplug_begin();
10231023

1024-
/*
1025-
* Add new range to memblock so that when hotadd_new_pgdat() is called
1026-
* to allocate new pgdat, get_pfn_range_for_nid() will be able to find
1027-
* this new range and calculate total pages correctly. The range will
1028-
* be removed at hot-remove time.
1029-
*/
1030-
memblock_add_node(start, size, nid);
1024+
if (IS_ENABLED(CONFIG_ARCH_KEEP_MEMBLOCK))
1025+
memblock_add_node(start, size, nid);
10311026

10321027
ret = __try_online_node(nid, false);
10331028
if (ret < 0)
@@ -1076,7 +1071,8 @@ int __ref add_memory_resource(int nid, struct resource *res)
10761071
/* rollback pgdat allocation and others */
10771072
if (new_node)
10781073
rollback_node_hotadd(nid);
1079-
memblock_remove(start, size);
1074+
if (IS_ENABLED(CONFIG_ARCH_KEEP_MEMBLOCK))
1075+
memblock_remove(start, size);
10801076
mem_hotplug_done();
10811077
return ret;
10821078
}
@@ -1673,8 +1669,12 @@ static int __ref try_remove_memory(int nid, u64 start, u64 size)
16731669
mem_hotplug_begin();
16741670

16751671
arch_remove_memory(nid, start, size, NULL);
1676-
memblock_free(start, size);
1677-
memblock_remove(start, size);
1672+
1673+
if (IS_ENABLED(CONFIG_ARCH_KEEP_MEMBLOCK)) {
1674+
memblock_free(start, size);
1675+
memblock_remove(start, size);
1676+
}
1677+
16781678
__release_memory_resource(start, size);
16791679

16801680
try_offline_node(nid);

0 commit comments

Comments
 (0)