mm, memory_hotplug: cleanup memory offline path
authorMichal Hocko <mhocko@suse.com>
Tue, 14 May 2019 00:21:24 +0000 (17:21 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 14 May 2019 16:47:49 +0000 (09:47 -0700)
check_pages_isolated_cb currently accounts the whole pfn range as being
offlined if test_pages_isolated suceeds on the range.  This is based on
the assumption that all pages in the range are freed which is currently
the case in most cases but it won't be with later changes, as pages marked
as vmemmap won't be isolated.

Move the offlined pages counting to offline_isolated_pages_cb and rely on
__offline_isolated_pages to return the correct value.
check_pages_isolated_cb will still do it's primary job and check the pfn
range.

While we are at it remove check_pages_isolated and offline_isolated_pages
and use directly walk_system_ram_range as do in online_pages.

Link: http://lkml.kernel.org/r/20190408082633.2864-2-osalvador@suse.de
Reviewed-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Oscar Salvador <osalvador@suse.de>
Cc: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/memory_hotplug.h
mm/memory_hotplug.c
mm/page_alloc.c

index 8ade08c50d26bd3a0d3dc2ef2b391a8be046ab83..3c8cf347804c38e8e129c39e2f7f64b879f9565e 100644 (file)
@@ -87,7 +87,8 @@ extern int add_one_highpage(struct page *page, int pfn, int bad_ppro);
 extern int online_pages(unsigned long, unsigned long, int);
 extern int test_pages_in_a_zone(unsigned long start_pfn, unsigned long end_pfn,
        unsigned long *valid_start, unsigned long *valid_end);
-extern void __offline_isolated_pages(unsigned long, unsigned long);
+extern unsigned long __offline_isolated_pages(unsigned long start_pfn,
+                                               unsigned long end_pfn);
 
 typedef void (*online_page_callback_t)(struct page *page, unsigned int order);
 
index a279671b996856d4957b6622ff64aa0b5f87bafa..75f9f659067755afd0c31053b047435d9a3b6238 100644 (file)
@@ -1449,15 +1449,10 @@ static int
 offline_isolated_pages_cb(unsigned long start, unsigned long nr_pages,
                        void *data)
 {
-       __offline_isolated_pages(start, start + nr_pages);
-       return 0;
-}
+       unsigned long *offlined_pages = (unsigned long *)data;
 
-static void
-offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn)
-{
-       walk_system_ram_range(start_pfn, end_pfn - start_pfn, NULL,
-                               offline_isolated_pages_cb);
+       *offlined_pages += __offline_isolated_pages(start, start + nr_pages);
+       return 0;
 }
 
 /*
@@ -1467,26 +1462,7 @@ static int
 check_pages_isolated_cb(unsigned long start_pfn, unsigned long nr_pages,
                        void *data)
 {
-       int ret;
-       long offlined = *(long *)data;
-       ret = test_pages_isolated(start_pfn, start_pfn + nr_pages, true);
-       offlined = nr_pages;
-       if (!ret)
-               *(long *)data += offlined;
-       return ret;
-}
-
-static long
-check_pages_isolated(unsigned long start_pfn, unsigned long end_pfn)
-{
-       long offlined = 0;
-       int ret;
-
-       ret = walk_system_ram_range(start_pfn, end_pfn - start_pfn, &offlined,
-                       check_pages_isolated_cb);
-       if (ret < 0)
-               offlined = (long)ret;
-       return offlined;
+       return test_pages_isolated(start_pfn, start_pfn + nr_pages, true);
 }
 
 static int __init cmdline_parse_movable_node(char *p)
@@ -1571,7 +1547,7 @@ static int __ref __offline_pages(unsigned long start_pfn,
                  unsigned long end_pfn)
 {
        unsigned long pfn, nr_pages;
-       long offlined_pages;
+       unsigned long offlined_pages = 0;
        int ret, node, nr_isolate_pageblock;
        unsigned long flags;
        unsigned long valid_start, valid_end;
@@ -1647,14 +1623,15 @@ static int __ref __offline_pages(unsigned long start_pfn,
                        goto failed_removal_isolated;
                }
                /* check again */
-               offlined_pages = check_pages_isolated(start_pfn, end_pfn);
-       } while (offlined_pages < 0);
+               ret = walk_system_ram_range(start_pfn, end_pfn - start_pfn,
+                                           NULL, check_pages_isolated_cb);
+       } while (ret);
 
-       pr_info("Offlined Pages %ld\n", offlined_pages);
        /* Ok, all of our target is isolated.
           We cannot do rollback at this point. */
-       offline_isolated_pages(start_pfn, end_pfn);
-
+       walk_system_ram_range(start_pfn, end_pfn - start_pfn,
+                             &offlined_pages, offline_isolated_pages_cb);
+       pr_info("Offlined Pages %ld\n", offlined_pages);
        /*
         * Onlining will reset pagetype flags and makes migrate type
         * MOVABLE, so just need to decrease the number of isolated
index 96ca65636e40b5d67f3581c6b954825fb8eb4c20..c45da9fe3ce178b845cd3de20071e52a225a4a40 100644 (file)
@@ -8453,7 +8453,7 @@ void zone_pcp_reset(struct zone *zone)
  * All pages in the range must be in a single zone and isolated
  * before calling this.
  */
-void
+unsigned long
 __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn)
 {
        struct page *page;
@@ -8461,12 +8461,15 @@ __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn)
        unsigned int order, i;
        unsigned long pfn;
        unsigned long flags;
+       unsigned long offlined_pages = 0;
+
        /* find the first valid pfn */
        for (pfn = start_pfn; pfn < end_pfn; pfn++)
                if (pfn_valid(pfn))
                        break;
        if (pfn == end_pfn)
-               return;
+               return offlined_pages;
+
        offline_mem_sections(pfn, end_pfn);
        zone = page_zone(pfn_to_page(pfn));
        spin_lock_irqsave(&zone->lock, flags);
@@ -8484,12 +8487,14 @@ __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn)
                if (unlikely(!PageBuddy(page) && PageHWPoison(page))) {
                        pfn++;
                        SetPageReserved(page);
+                       offlined_pages++;
                        continue;
                }
 
                BUG_ON(page_count(page));
                BUG_ON(!PageBuddy(page));
                order = page_order(page);
+               offlined_pages += 1 << order;
 #ifdef CONFIG_DEBUG_VM
                pr_info("remove from free list %lx %d %lx\n",
                        pfn, 1 << order, end_pfn);
@@ -8502,6 +8507,8 @@ __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn)
                pfn += (1 << order);
        }
        spin_unlock_irqrestore(&zone->lock, flags);
+
+       return offlined_pages;
 }
 #endif