[lkml]   [2019]   [Jun]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[PATCH AUTOSEL 5.1 013/186] mm/memory_hotplug: release memory resource after arch_remove_memory()
From: David Hildenbrand <>

[ Upstream commit d9eb1417c77df7ce19abd2e41619e9dceccbdf2a ]

Patch series "mm/memory_hotplug: Better error handling when removing
memory", v1.

Error handling when removing memory is somewhat messed up right now. Some
errors result in warnings, others are completely ignored. Memory unplug
code can essentially not deal with errors properly as of now.
remove_memory() will never fail.

We have basically two choices:
1. Allow arch_remov_memory() and friends to fail, propagating errors via
remove_memory(). Might be problematic (e.g. DIMMs consisting of multiple
pieces added/removed separately).
2. Don't allow the functions to fail, handling errors in a nicer way.

It seems like most errors that can theoretically happen are really corner
cases and mostly theoretical (e.g. "section not valid"). However e.g.
aborting removal of sections while all callers simply continue in case of
errors is not nice.

If we can gurantee that removal of memory always works (and WARN/skip in
case of theoretical errors so we can figure out what is going on), we can
go ahead and implement better error handling when adding memory.

E.g. via add_memory():

ret = do_stuff()
if (ret) {
goto error;

Handling here that arch_remove_memory() might fail is basically
impossible. So I suggest, let's avoid reporting errors while removing
memory, warning on theoretical errors instead and continuing instead of

This patch (of 4):

__add_pages() doesn't add the memory resource, so __remove_pages()
shouldn't remove it. Let's factor it out. Especially as it is a special
case for memory used as system memory, added via add_memory() and friends.

We now remove the resource after removing the sections instead of doing it
the other way around. I don't think this change is problematic.

register memory resource

release memory resource

While at it, explain why we ignore errors and that it only happeny if
we remove memory in a different granularity as we added it.

[ fix printk warning]
Signed-off-by: David Hildenbrand <>
Reviewed-by: Oscar Salvador <>
Cc: Michal Hocko <>
Cc: David Hildenbrand <>
Cc: Pavel Tatashin <>
Cc: Wei Yang <>
Cc: Qian Cai <>
Cc: Arun KS <>
Cc: Mathieu Malaterre <>
Cc: Andrew Banman <>
Cc: Andy Lutomirski <>
Cc: Benjamin Herrenschmidt <>
Cc: Borislav Petkov <>
Cc: Christophe Leroy <>
Cc: Dave Hansen <>
Cc: Fenghua Yu <>
Cc: Geert Uytterhoeven <>
Cc: Greg Kroah-Hartman <>
Cc: Heiko Carstens <>
Cc: "H. Peter Anvin" <>
Cc: Ingo Molnar <>
Cc: Ingo Molnar <>
Cc: Joonsoo Kim <>
Cc: "Kirill A. Shutemov" <>
Cc: Martin Schwidefsky <>
Cc: Masahiro Yamada <>
Cc: Michael Ellerman <>
Cc: Mike Rapoport <>
Cc: Mike Travis <>
Cc: Nicholas Piggin <>
Cc: Oscar Salvador <>
Cc: Paul Mackerras <>
Cc: Peter Zijlstra <>
Cc: "Rafael J. Wysocki" <>
Cc: Rich Felker <>
Cc: Rob Herring <>
Cc: Stefan Agner <>
Cc: Thomas Gleixner <>
Cc: Tony Luck <>
Cc: Vasily Gorbik <>
Cc: Yoshinori Sato <>
Signed-off-by: Andrew Morton <>
Signed-off-by: Linus Torvalds <>
Signed-off-by: Sasha Levin <>
mm/memory_hotplug.c | 35 +++++++++++++++++++++--------------
1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index b236069ff0d82..28587f2901090 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -561,20 +561,6 @@ int __remove_pages(struct zone *zone, unsigned long phys_start_pfn,
if (is_dev_zone(zone)) {
if (altmap)
map_offset = vmem_altmap_offset(altmap);
- } else {
- resource_size_t start, size;
- start = phys_start_pfn << PAGE_SHIFT;
- size = nr_pages * PAGE_SIZE;
- ret = release_mem_region_adjustable(&iomem_resource, start,
- size);
- if (ret) {
- resource_size_t endres = start + size - 1;
- pr_warn("Unable to release resource <%pa-%pa> (%d)\n",
- &start, &endres, ret);
- }

@@ -1843,6 +1829,26 @@ void try_offline_node(int nid)

+static void __release_memory_resource(resource_size_t start,
+ resource_size_t size)
+ int ret;
+ /*
+ * When removing memory in the same granularity as it was added,
+ * this function never fails. It might only fail if resources
+ * have to be adjusted or split. We'll ignore the error, as
+ * removing of memory cannot fail.
+ */
+ ret = release_mem_region_adjustable(&iomem_resource, start, size);
+ if (ret) {
+ resource_size_t endres = start + size - 1;
+ pr_warn("Unable to release resource <%pa-%pa> (%d)\n",
+ &start, &endres, ret);
+ }
* remove_memory
* @nid: the node ID
@@ -1877,6 +1883,7 @@ void __ref __remove_memory(int nid, u64 start, u64 size)
memblock_remove(start, size);

arch_remove_memory(nid, start, size, NULL);
+ __release_memory_resource(start, size);


 \ /
  Last update: 2019-06-01 15:18    [W:0.273 / U:7.024 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site