Commit aac65321 authored by David Hildenbrand's avatar David Hildenbrand Committed by Linus Torvalds

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: default avatarDavid Hildenbrand <david@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Reviewed-by: default avatarOscar Salvador <osalvador@suse.de>
Acked-by: default avatarMichal 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.comSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 3fa0c7c7
...@@ -625,31 +625,22 @@ void generic_online_page(struct page *page, unsigned int order) ...@@ -625,31 +625,22 @@ void generic_online_page(struct page *page, unsigned int order)
} }
EXPORT_SYMBOL_GPL(generic_online_page); EXPORT_SYMBOL_GPL(generic_online_page);
static int online_pages_range(unsigned long start_pfn, unsigned long nr_pages, static void online_pages_range(unsigned long start_pfn, unsigned long nr_pages)
void *arg)
{ {
const unsigned long end_pfn = start_pfn + nr_pages; const unsigned long end_pfn = start_pfn + nr_pages;
unsigned long pfn; unsigned long pfn;
int order;
/* /*
* Online the pages. The callback might decide to keep some pages * Online the pages in MAX_ORDER - 1 aligned chunks. The callback might
* PG_reserved (to add them to the buddy later), but we still account * decide to not expose all pages to the buddy (e.g., expose them
* them as being online/belonging to this zone ("present"). * later). We account all pages as being online and belonging to this
* zone ("present").
*/ */
for (pfn = start_pfn; pfn < end_pfn; pfn += 1ul << order) { for (pfn = start_pfn; pfn < end_pfn; pfn += MAX_ORDER_NR_PAGES)
order = min(MAX_ORDER - 1, get_order(PFN_PHYS(end_pfn - pfn))); (*online_page_callback)(pfn_to_page(pfn), MAX_ORDER - 1);
/* __free_pages_core() wants pfns to be aligned to the order */
if (WARN_ON_ONCE(!IS_ALIGNED(pfn, 1ul << order)))
order = 0;
(*online_page_callback)(pfn_to_page(pfn), order);
}
/* mark all involved sections as online */ /* mark all involved sections as online */
online_mem_sections(start_pfn, end_pfn); online_mem_sections(start_pfn, end_pfn);
*(unsigned long *)arg += nr_pages;
return 0;
} }
/* check which state of node_states will be changed when online memory */ /* 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, ...@@ -803,7 +794,6 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages,
int online_type, int nid) int online_type, int nid)
{ {
unsigned long flags; unsigned long flags;
unsigned long onlined_pages = 0;
struct zone *zone; struct zone *zone;
int need_zonelists_rebuild = 0; int need_zonelists_rebuild = 0;
int ret; int ret;
...@@ -839,19 +829,11 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages, ...@@ -839,19 +829,11 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages,
setup_zone_pageset(zone); setup_zone_pageset(zone);
} }
ret = walk_system_ram_range(pfn, nr_pages, &onlined_pages, online_pages_range(pfn, nr_pages);
online_pages_range); zone->present_pages += nr_pages;
if (ret) {
/* not a single memory resource was applicable */
if (need_zonelists_rebuild)
zone_pcp_reset(zone);
goto failed_addition;
}
zone->present_pages += onlined_pages;
pgdat_resize_lock(zone->zone_pgdat, &flags); pgdat_resize_lock(zone->zone_pgdat, &flags);
zone->zone_pgdat->node_present_pages += onlined_pages; zone->zone_pgdat->node_present_pages += nr_pages;
pgdat_resize_unlock(zone->zone_pgdat, &flags); pgdat_resize_unlock(zone->zone_pgdat, &flags);
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment