History

mm/memory_hotplug: release memory resource after arch_remove_memory()

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(): arch_add_memory() ret = do_stuff() if (ret) { arch_remove_memory(); 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 aborting. 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. add_memory() register memory resource arch_add_memory() remove_memory arch_remove_memory() 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. [david@redhat.com: fix printk warning] Link: http://lkml.kernel.org/r/20190417120204.6997-1-david@redhat.com Link: http://lkml.kernel.org/r/20190409100148.24703-2-david@redhat.com Signed-off-by: David Hildenbrand <david@redhat.com> Reviewed-by: Oscar Salvador <osalvador@suse.de> Cc: Michal Hocko <mhocko@suse.com> Cc: David Hildenbrand <david@redhat.com> Cc: Pavel Tatashin <pasha.tatashin@soleen.com> Cc: Wei Yang <richard.weiyang@gmail.com> Cc: Qian Cai <cai@lca.pw> Cc: Arun KS <arunks@codeaurora.org> Cc: Mathieu Malaterre <malat@debian.org> Cc: Andrew Banman <andrew.banman@hpe.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Christophe Leroy <christophe.leroy@c-s.fr> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Fenghua Yu <fenghua.yu@intel.com> Cc: Geert Uytterhoeven <geert@linux-m68k.org> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Masahiro Yamada <yamada.masahiro@socionext.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Mike Rapoport <rppt@linux.ibm.com> Cc: Mike Travis <mike.travis@hpe.com> Cc: Nicholas Piggin <npiggin@gmail.com> Cc: Oscar Salvador <osalvador@suse.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: "Rafael J. Wysocki" <rafael@kernel.org> Cc: Rich Felker <dalias@libc.org> Cc: Rob Herring <robh@kernel.org> Cc: Stefan Agner <stefan@agner.ch> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Tony Luck <tony.luck@intel.com> Cc: Vasily Gorbik <gor@linux.ibm.com> Cc: Yoshinori Sato <ysato@users.sourceforge.jp> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

David Hildenbrand committed 7 years ago

Commit d9eb1411 parent 2346a561 file · +21 −14Browse files

Unified · Split

mm/memory_hotplug.c+21−14
@@ -561,20 +561,6 @@ int __remove_pages(struct zone *zone, unsigned long phys_start_pfn, · 560 unmodified lines
561 if (is_dev_zone(zone)) {561 if (is_dev_zone(zone)) {
562 if (altmap)562 if (altmap)
563 map_offset = vmem_altmap_offset(altmap);563 map_offset = vmem_altmap_offset(altmap);
564 } else {
565 resource_size_t start, size;
566
567 start = phys_start_pfn << PAGE_SHIFT;
568 size = nr_pages * PAGE_SIZE;
569
570 ret = release_mem_region_adjustable(&iomem_resource, start,
571 size);
572 if (ret) {
573 resource_size_t endres = start + size - 1;
574
575 pr_warn("Unable to release resource <%pa-%pa> (%d)\n",
576 &start, &endres, ret);
577 }
578 }564 }
579 565
580 clear_zone_contiguous(zone);566 clear_zone_contiguous(zone);
@@ -1818,6 +1804,26 @@ void try_offline_node(int nid) · 1237 unmodified lines
1818}1804}
1819EXPORT_SYMBOL(try_offline_node);1805EXPORT_SYMBOL(try_offline_node);
1820 1806
1807static void __release_memory_resource(resource_size_t start,
1808 resource_size_t size)
1809{
1810 int ret;
1811
1812 /*
1813 * When removing memory in the same granularity as it was added,
1814 * this function never fails. It might only fail if resources
1815 * have to be adjusted or split. We'll ignore the error, as
1816 * removing of memory cannot fail.
1817 */
1818 ret = release_mem_region_adjustable(&iomem_resource, start, size);
1819 if (ret) {
1820 resource_size_t endres = start + size - 1;
1821
1822 pr_warn("Unable to release resource <%pa-%pa> (%d)\n",
1823 &start, &endres, ret);
1824 }
1825}
1826
1821/**1827/**
1822 * remove_memory1828 * remove_memory
1823 * @nid: the node ID1829 * @nid: the node ID
@@ -1852,6 +1858,7 @@ void __ref __remove_memory(int nid, u64 start, u64 size) · 28 unmodified lines
1852 memblock_remove(start, size);1858 memblock_remove(start, size);
1853 1859
1854 arch_remove_memory(nid, start, size, NULL);1860 arch_remove_memory(nid, start, size, NULL);
1861 __release_memory_resource(start, size);
1855 1862
1856 try_offline_node(nid);1863 try_offline_node(nid);
1857 1864

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t