Skip to content

Commit aac6532

Browse files
davidhildenbrandtorvalds
authored andcommitted
mm/memory_hotplug: simplify page onlining
We don't allow to offline memory with holes, all boot memory is online, and all hotplugged memory cannot have holes. We can now simplify onlining of pages. As we only allow to online/offline full sections and sections always span full MAX_ORDER_NR_PAGES, we can just process MAX_ORDER - 1 pages without further special handling. The number of onlined pages simply corresponds to the number of pages we were requested to online. While at it, refine the comment regarding the callback not exposing all pages to the buddy. Signed-off-by: David Hildenbrand <david@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Oscar Salvador <osalvador@suse.de> Acked-by: Michal Hocko <mhocko@suse.com> Cc: Wei Yang <richard.weiyang@linux.alibaba.com> Cc: Baoquan He <bhe@redhat.com> Cc: Pankaj Gupta <pankaj.gupta.linux@gmail.com> Cc: Charan Teja Reddy <charante@codeaurora.org> Cc: Dan Williams <dan.j.williams@intel.com> Cc: Fenghua Yu <fenghua.yu@intel.com> Cc: Logan Gunthorpe <logang@deltatee.com> Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org> Cc: Mel Gorman <mgorman@suse.de> Cc: Mel Gorman <mgorman@techsingularity.net> Cc: Michel Lespinasse <walken@google.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Tony Luck <tony.luck@intel.com> Link: https://lkml.kernel.org/r/20200819175957.28465-8-david@redhat.com Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 3fa0c7c commit aac6532

File tree

1 file changed

+10
-28
lines changed

1 file changed

+10
-28
lines changed

mm/memory_hotplug.c

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -625,31 +625,22 @@ void generic_online_page(struct page *page, unsigned int order)
625625
}
626626
EXPORT_SYMBOL_GPL(generic_online_page);
627627

628-
static int online_pages_range(unsigned long start_pfn, unsigned long nr_pages,
629-
void *arg)
628+
static void online_pages_range(unsigned long start_pfn, unsigned long nr_pages)
630629
{
631630
const unsigned long end_pfn = start_pfn + nr_pages;
632631
unsigned long pfn;
633-
int order;
634632

635633
/*
636-
* Online the pages. The callback might decide to keep some pages
637-
* PG_reserved (to add them to the buddy later), but we still account
638-
* them as being online/belonging to this zone ("present").
634+
* Online the pages in MAX_ORDER - 1 aligned chunks. The callback might
635+
* decide to not expose all pages to the buddy (e.g., expose them
636+
* later). We account all pages as being online and belonging to this
637+
* zone ("present").
639638
*/
640-
for (pfn = start_pfn; pfn < end_pfn; pfn += 1ul << order) {
641-
order = min(MAX_ORDER - 1, get_order(PFN_PHYS(end_pfn - pfn)));
642-
/* __free_pages_core() wants pfns to be aligned to the order */
643-
if (WARN_ON_ONCE(!IS_ALIGNED(pfn, 1ul << order)))
644-
order = 0;
645-
(*online_page_callback)(pfn_to_page(pfn), order);
646-
}
639+
for (pfn = start_pfn; pfn < end_pfn; pfn += MAX_ORDER_NR_PAGES)
640+
(*online_page_callback)(pfn_to_page(pfn), MAX_ORDER - 1);
647641

648642
/* mark all involved sections as online */
649643
online_mem_sections(start_pfn, end_pfn);
650-
651-
*(unsigned long *)arg += nr_pages;
652-
return 0;
653644
}
654645

655646
/* check which state of node_states will be changed when online memory */
@@ -803,7 +794,6 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages,
803794
int online_type, int nid)
804795
{
805796
unsigned long flags;
806-
unsigned long onlined_pages = 0;
807797
struct zone *zone;
808798
int need_zonelists_rebuild = 0;
809799
int ret;
@@ -839,19 +829,11 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages,
839829
setup_zone_pageset(zone);
840830
}
841831

842-
ret = walk_system_ram_range(pfn, nr_pages, &onlined_pages,
843-
online_pages_range);
844-
if (ret) {
845-
/* not a single memory resource was applicable */
846-
if (need_zonelists_rebuild)
847-
zone_pcp_reset(zone);
848-
goto failed_addition;
849-
}
850-
851-
zone->present_pages += onlined_pages;
832+
online_pages_range(pfn, nr_pages);
833+
zone->present_pages += nr_pages;
852834

853835
pgdat_resize_lock(zone->zone_pgdat, &flags);
854-
zone->zone_pgdat->node_present_pages += onlined_pages;
836+
zone->zone_pgdat->node_present_pages += nr_pages;
855837
pgdat_resize_unlock(zone->zone_pgdat, &flags);
856838

857839
/*

0 commit comments

Comments
 (0)