Message ID | 20180724235520.10200-4-pasha.tatashin@oracle.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | memmap_init_zone improvements | expand |
On Tue, 24 Jul 2018 19:55:20 -0400 Pavel Tatashin <pasha.tatashin@oracle.com> wrote: > memmap_init_zone, is getting complex, because it is called from different > contexts: hotplug, and during boot, and also because it must handle some > architecture quirks. One of them is mirroed memory. > > Move the code that decides whether to skip mirrored memory outside of > memmap_init_zone, into a separate function. Conflicts a bit with the page_alloc.c hunk from http://ozlabs.org/~akpm/mmots/broken-out/mm-page_alloc-remain-memblock_next_valid_pfn-on-arm-arm64.patch. Please check my fixup: void __meminit memmap_init_zone(unsigned long size, int nid, unsigned long zone, unsigned long start_pfn, enum memmap_context context, struct vmem_altmap *altmap) { unsigned long pfn, end_pfn = start_pfn + size; struct page *page; if (highest_memmap_pfn < end_pfn - 1) highest_memmap_pfn = end_pfn - 1; /* * Honor reservation requested by the driver for this ZONE_DEVICE * memory */ if (altmap && start_pfn == altmap->base_pfn) start_pfn += altmap->reserve; for (pfn = start_pfn; pfn < end_pfn; pfn++) { /* * There can be holes in boot-time mem_map[]s handed to this * function. They do not exist on hotplugged memory. */ if (context == MEMMAP_EARLY) { if (!early_pfn_valid(pfn)) { pfn = next_valid_pfn(pfn) - 1; continue; } if (!early_pfn_in_nid(pfn, nid)) continue; if (overlap_memmap_init(zone, &pfn)) continue; if (defer_init(nid, pfn, end_pfn)) break; } page = pfn_to_page(pfn); __init_single_page(page, pfn, zone, nid); if (context == MEMMAP_HOTPLUG) SetPageReserved(page); /* * Mark the block movable so that blocks are reserved for * movable at startup. This will force kernel allocations * to reserve their blocks rather than leaking throughout * the address space during boot when many long-lived * kernel allocations are made. * * bitmap is created for zone's valid pfn range. but memmap * can be created for invalid pages (for alignment) * check here not to call set_pageblock_migratetype() against * pfn out of zone. */ if (!(pfn & (pageblock_nr_pages - 1))) { set_pageblock_migratetype(page, MIGRATE_MOVABLE); cond_resched(); } } }
On Tue, Jul 24, 2018 at 9:18 PM Andrew Morton <akpm@linux-foundation.org> wrote: > > On Tue, 24 Jul 2018 19:55:20 -0400 Pavel Tatashin <pasha.tatashin@oracle.com> wrote: > > > memmap_init_zone, is getting complex, because it is called from different > > contexts: hotplug, and during boot, and also because it must handle some > > architecture quirks. One of them is mirroed memory. > > > > Move the code that decides whether to skip mirrored memory outside of > > memmap_init_zone, into a separate function. > > Conflicts a bit with the page_alloc.c hunk from > http://ozlabs.org/~akpm/mmots/broken-out/mm-page_alloc-remain-memblock_next_valid_pfn-on-arm-arm64.patch. Please check my fixup: The merge looks good to me. Thank you. > > void __meminit memmap_init_zone(unsigned long size, int nid, unsigned long zone, > unsigned long start_pfn, enum memmap_context context, > struct vmem_altmap *altmap) > { > unsigned long pfn, end_pfn = start_pfn + size; > struct page *page; > > if (highest_memmap_pfn < end_pfn - 1) > highest_memmap_pfn = end_pfn - 1; > > /* > * Honor reservation requested by the driver for this ZONE_DEVICE > * memory > */ > if (altmap && start_pfn == altmap->base_pfn) > start_pfn += altmap->reserve; > > for (pfn = start_pfn; pfn < end_pfn; pfn++) { > /* > * There can be holes in boot-time mem_map[]s handed to this > * function. They do not exist on hotplugged memory. > */ > if (context == MEMMAP_EARLY) { > if (!early_pfn_valid(pfn)) { > pfn = next_valid_pfn(pfn) - 1; I wish we did not have to do next_valid_pfn(pfn) - 1, and instead could do something like: for (pfn = start_pfn; pfn < end_pfn; pfn = next_valid_pfn(pfn)) Of course the performance of next_valid_pfn() should be optimized on arm for the common case where next valid pfn is pfn++. Pavel
On Tue, Jul 24, 2018 at 07:55:20PM -0400, Pavel Tatashin wrote: > memmap_init_zone, is getting complex, because it is called from different > contexts: hotplug, and during boot, and also because it must handle some > architecture quirks. One of them is mirroed memory. > > Move the code that decides whether to skip mirrored memory outside of > memmap_init_zone, into a separate function. > > Signed-off-by: Pavel Tatashin <pasha.tatashin@oracle.com> Hi Pavel, this looks good to me. Over the past days I thought if it would make sense to have two memmap_init_zone functions, one for hotplug and another one for early init, so we could get rid of the altmap stuff in the early init, and also the MEMMAP_EARLY/HOTPLUG context thing could be gone. But I think that they would just share too much of the code, so I do not think it is worth. I am working to do that for free_area_init_core, let us see what I come up with. Anyway, this looks nicer, so thanks for that. I also gave it a try, and early init and memhotplug code seems to work fine. Reviewed-by: Oscar Salvador <osalvador@suse.de> Thanks
diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 86c678cec6bd..d7dce4ccefd5 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5454,6 +5454,29 @@ void __ref build_all_zonelists(pg_data_t *pgdat) #endif } +/* If zone is ZONE_MOVABLE but memory is mirrored, it is an overlapped init */ +static inline bool overlap_memmap_init(unsigned long zone, unsigned long *pfn) +{ +#ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP + static struct memblock_region *r; + + if (mirrored_kernelcore && zone == ZONE_MOVABLE) { + if (!r || *pfn >= memblock_region_memory_end_pfn(r)) { + for_each_memblock(memory, r) { + if (*pfn < memblock_region_memory_end_pfn(r)) + break; + } + } + if (*pfn >= memblock_region_memory_base_pfn(r) && + memblock_is_mirror(r)) { + *pfn = memblock_region_memory_end_pfn(r); + return true; + } + } +#endif + return false; +} + /* * Initially all pages are reserved - free ones are freed * up by free_all_bootmem() once the early boot process is @@ -5463,12 +5486,8 @@ void __meminit memmap_init_zone(unsigned long size, int nid, unsigned long zone, unsigned long start_pfn, enum memmap_context context, struct vmem_altmap *altmap) { - unsigned long end_pfn = start_pfn + size; - unsigned long pfn; + unsigned long pfn, end_pfn = start_pfn + size; struct page *page; -#ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP - struct memblock_region *r = NULL, *tmp; -#endif if (highest_memmap_pfn < end_pfn - 1) highest_memmap_pfn = end_pfn - 1; @@ -5485,39 +5504,17 @@ void __meminit memmap_init_zone(unsigned long size, int nid, unsigned long zone, * There can be holes in boot-time mem_map[]s handed to this * function. They do not exist on hotplugged memory. */ - if (context != MEMMAP_EARLY) - goto not_early; - - if (!early_pfn_valid(pfn)) - continue; - if (!early_pfn_in_nid(pfn, nid)) - continue; - -#ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP - /* - * Check given memblock attribute by firmware which can affect - * kernel memory layout. If zone==ZONE_MOVABLE but memory is - * mirrored, it's an overlapped memmap init. skip it. - */ - if (mirrored_kernelcore && zone == ZONE_MOVABLE) { - if (!r || pfn >= memblock_region_memory_end_pfn(r)) { - for_each_memblock(memory, tmp) - if (pfn < memblock_region_memory_end_pfn(tmp)) - break; - r = tmp; - } - if (pfn >= memblock_region_memory_base_pfn(r) && - memblock_is_mirror(r)) { - /* already initialized as NORMAL */ - pfn = memblock_region_memory_end_pfn(r); + if (context == MEMMAP_EARLY) { + if (!early_pfn_valid(pfn)) continue; - } + if (!early_pfn_in_nid(pfn, nid)) + continue; + if (overlap_memmap_init(zone, &pfn)) + continue; + if (defer_init(nid, pfn, end_pfn)) + break; } -#endif - if (defer_init(nid, pfn, end_pfn)) - break; -not_early: page = pfn_to_page(pfn); __init_single_page(page, pfn, zone, nid); if (context == MEMMAP_HOTPLUG) @@ -5534,9 +5531,6 @@ void __meminit memmap_init_zone(unsigned long size, int nid, unsigned long zone, * can be created for invalid pages (for alignment) * check here not to call set_pageblock_migratetype() against * pfn out of zone. - * - * Please note that MEMMAP_HOTPLUG path doesn't clear memmap - * because this is done early in sparse_add_one_section */ if (!(pfn & (pageblock_nr_pages - 1))) { set_pageblock_migratetype(page, MIGRATE_MOVABLE);
memmap_init_zone, is getting complex, because it is called from different contexts: hotplug, and during boot, and also because it must handle some architecture quirks. One of them is mirroed memory. Move the code that decides whether to skip mirrored memory outside of memmap_init_zone, into a separate function. Signed-off-by: Pavel Tatashin <pasha.tatashin@oracle.com> --- mm/page_alloc.c | 70 ++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 38 deletions(-)