The patch titled Subject: mm, memory_hotplug: deobfuscate migration part of offlining has been added to the -mm tree. Its filename is mm-memory_hotplug-deobfuscate-migration-part-of-offlining.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/mm-memory_hotplug-deobfuscate-migration-part-of-offlining.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/mm-memory_hotplug-deobfuscate-migration-part-of-offlining.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Michal Hocko <mhocko@xxxxxxxx> Subject: mm, memory_hotplug: deobfuscate migration part of offlining Memory migration might fail during offlining and we keep retrying in that case. This is currently obfuscated by goto retry loop. The code is hard to follow and as a result it is even suboptimal becase each retry round scans the full range from start_pfn even though we have successfully scanned/migrated [start_pfn, pfn] range already. This is all only because check_pages_isolated failure has to rescan the full range again. De-obfuscate the migration retry loop by promoting it to a real for loop. In fact remove the goto altogether by making it a proper double loop (yeah, gotos are nasty in this specific case). In the end we will get a slightly more optimal code which is better readable. Link: http://lkml.kernel.org/r/20181211142741.2607-3-mhocko@xxxxxxxxxx Signed-off-by: Michal Hocko <mhocko@xxxxxxxx> Reviewed-by: David Hildenbrand <david@xxxxxxxxxx> Reviewed-by: Oscar Salvador <osalvador@xxxxxxx> Cc: Hugh Dickins <hughd@xxxxxxxxxx> Cc: Jan Kara <jack@xxxxxxx> Cc: Kirill A. Shutemov <kirill.shutemov@xxxxxxxxxxxxxxx> Cc: Pavel Tatashin <pasha.tatashin@xxxxxxxxxx> Cc: William Kucharski <william.kucharski@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/memory_hotplug.c | 58 +++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 29 deletions(-) --- a/mm/memory_hotplug.c~mm-memory_hotplug-deobfuscate-migration-part-of-offlining +++ a/mm/memory_hotplug.c @@ -1581,38 +1581,38 @@ static int __ref __offline_pages(unsigne goto failed_removal_isolated; } - pfn = start_pfn; -repeat: - /* start memory hot removal */ - ret = -EINTR; - if (signal_pending(current)) { - reason = "signal backoff"; - goto failed_removal_isolated; - } + do { + for (pfn = start_pfn; pfn;) { + if (signal_pending(current)) { + ret = -EINTR; + reason = "signal backoff"; + goto failed_removal_isolated; + } - cond_resched(); - lru_add_drain_all(); - drain_all_pages(zone); + cond_resched(); + lru_add_drain_all(); + drain_all_pages(zone); - pfn = scan_movable_pages(start_pfn, end_pfn); - if (pfn) { /* We have movable pages */ - ret = do_migrate_range(pfn, end_pfn); - goto repeat; - } + pfn = scan_movable_pages(pfn, end_pfn); + if (pfn) { + /* TODO fatal migration failures should bail out */ + do_migrate_range(pfn, end_pfn); + } + } + + /* + * dissolve free hugepages in the memory block before doing offlining + * actually in order to make hugetlbfs's object counting consistent. + */ + ret = dissolve_free_huge_pages(start_pfn, end_pfn); + if (ret) { + reason = "failure to dissolve huge pages"; + goto failed_removal_isolated; + } + /* check again */ + offlined_pages = check_pages_isolated(start_pfn, end_pfn); + } while (offlined_pages < 0); - /* - * dissolve free hugepages in the memory block before doing offlining - * actually in order to make hugetlbfs's object counting consistent. - */ - ret = dissolve_free_huge_pages(start_pfn, end_pfn); - if (ret) { - reason = "failure to dissolve huge pages"; - goto failed_removal_isolated; - } - /* check again */ - offlined_pages = check_pages_isolated(start_pfn, end_pfn); - if (offlined_pages < 0) - goto repeat; pr_info("Offlined Pages %ld\n", offlined_pages); /* Ok, all of our target is isolated. We cannot do rollback at this point. */ _ Patches currently in -mm which might be from mhocko@xxxxxxxx are mm-print-more-information-about-mapping-in-__dump_page.patch mm-lower-the-printk-loglevel-for-__dump_page-messages.patch mm-memory_hotplug-drop-pointless-block-alignment-checks-from-__offline_pages.patch mm-memory_hotplug-print-reason-for-the-offlining-failure.patch mm-memory_hotplug-be-more-verbose-for-memory-offline-failures.patch mm-memory_hotplug-be-more-verbose-for-memory-offline-failures-update.patch mm-memory_hotplug-do-not-clear-numa_node-association-after-hot_remove.patch hwpoison-memory_hotplug-allow-hwpoisoned-pages-to-be-offlined.patch mm-proc-be-more-verbose-about-unstable-vma-flags-in-proc-pid-smaps.patch mm-thp-proc-report-thp-eligibility-for-each-vma.patch mm-proc-report-pr_set_thp_disable-in-proc.patch mm-memory_hotplug-try-to-migrate-full-pfn-range.patch mm-memory_hotplug-deobfuscate-migration-part-of-offlining.patch mm-fault_around-do-not-take-a-reference-to-a-locked-page.patch