The patch titled Subject: mm/hotplug: add mem-hotplug restrictions for remove_memory() has been added to the -mm tree. Its filename is mm-hotplug-add-mem-hotplug-restrictions-for-remove_memory.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/mm-hotplug-add-mem-hotplug-restrictions-for-remove_memory.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/mm-hotplug-add-mem-hotplug-restrictions-for-remove_memory.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: Dan Williams <dan.j.williams@xxxxxxxxx> Subject: mm/hotplug: add mem-hotplug restrictions for remove_memory() Teach the arch_remove_memory() path to consult the same 'struct mhp_restrictions' context as was specified at arch_add_memory() time. No functional change, this is a preparation step for teaching __remove_pages() about how and when to allow sub-section hot-remove, and a cleanup for an unnecessary "is_dev_zone()" special case. Link: http://lkml.kernel.org/r/155552636696.2015392.12612320706815016081.stgit@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Signed-off-by: Dan Williams <dan.j.williams@xxxxxxxxx> Cc: Michal Hocko <mhocko@xxxxxxxx> Cc: Logan Gunthorpe <logang@xxxxxxxxxxxx> Cc: David Hildenbrand <david@xxxxxxxxxx> Cc: Jeff Moyer <jmoyer@xxxxxxxxxx> Cc: Jérôme Glisse <jglisse@xxxxxxxxxx> Cc: Toshi Kani <toshi.kani@xxxxxxx> Cc: Vlastimil Babka <vbabka@xxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- arch/ia64/mm/init.c | 4 ++-- arch/powerpc/mm/mem.c | 5 +++-- arch/s390/mm/init.c | 2 +- arch/sh/mm/init.c | 4 ++-- arch/x86/mm/init_32.c | 4 ++-- arch/x86/mm/init_64.c | 5 +++-- include/linux/memory_hotplug.h | 5 +++-- kernel/memremap.c | 14 ++++++++------ mm/memory_hotplug.c | 17 ++++++++--------- 9 files changed, 32 insertions(+), 28 deletions(-) --- a/arch/ia64/mm/init.c~mm-hotplug-add-mem-hotplug-restrictions-for-remove_memory +++ a/arch/ia64/mm/init.c @@ -683,14 +683,14 @@ int arch_add_memory(int nid, u64 start, #ifdef CONFIG_MEMORY_HOTREMOVE void arch_remove_memory(int nid, u64 start, u64 size, - struct vmem_altmap *altmap) + struct mhp_restrictions *restrictions) { unsigned long start_pfn = start >> PAGE_SHIFT; unsigned long nr_pages = size >> PAGE_SHIFT; struct zone *zone; zone = page_zone(pfn_to_page(start_pfn)); - __remove_pages(zone, start_pfn, nr_pages, altmap); + __remove_pages(zone, start_pfn, nr_pages, restrictions); } #endif #endif --- a/arch/powerpc/mm/mem.c~mm-hotplug-add-mem-hotplug-restrictions-for-remove_memory +++ a/arch/powerpc/mm/mem.c @@ -132,10 +132,11 @@ int __meminit arch_add_memory(int nid, u #ifdef CONFIG_MEMORY_HOTREMOVE void __meminit arch_remove_memory(int nid, u64 start, u64 size, - struct vmem_altmap *altmap) + struct mhp_restrictions *restrictions) { unsigned long start_pfn = start >> PAGE_SHIFT; unsigned long nr_pages = size >> PAGE_SHIFT; + struct vmem_altmap *altmap = restrictions->altmap; struct page *page; int ret; @@ -147,7 +148,7 @@ void __meminit arch_remove_memory(int ni if (altmap) page += vmem_altmap_offset(altmap); - __remove_pages(page_zone(page), start_pfn, nr_pages, altmap); + __remove_pages(page_zone(page), start_pfn, nr_pages, restrictions); /* Remove htab bolted mappings for this section of memory */ start = (unsigned long)__va(start); --- a/arch/s390/mm/init.c~mm-hotplug-add-mem-hotplug-restrictions-for-remove_memory +++ a/arch/s390/mm/init.c @@ -235,7 +235,7 @@ int arch_add_memory(int nid, u64 start, #ifdef CONFIG_MEMORY_HOTREMOVE void arch_remove_memory(int nid, u64 start, u64 size, - struct vmem_altmap *altmap) + struct mhp_restrictions *restrictions) { /* * There is no hardware or firmware interface which could trigger a --- a/arch/sh/mm/init.c~mm-hotplug-add-mem-hotplug-restrictions-for-remove_memory +++ a/arch/sh/mm/init.c @@ -430,14 +430,14 @@ EXPORT_SYMBOL_GPL(memory_add_physaddr_to #ifdef CONFIG_MEMORY_HOTREMOVE void arch_remove_memory(int nid, u64 start, u64 size, - struct vmem_altmap *altmap) + struct mhp_restrictions *restrictions) { unsigned long start_pfn = PFN_DOWN(start); unsigned long nr_pages = size >> PAGE_SHIFT; struct zone *zone; zone = page_zone(pfn_to_page(start_pfn)); - __remove_pages(zone, start_pfn, nr_pages, altmap); + __remove_pages(zone, start_pfn, nr_pages, restrictions); } #endif #endif /* CONFIG_MEMORY_HOTPLUG */ --- a/arch/x86/mm/init_32.c~mm-hotplug-add-mem-hotplug-restrictions-for-remove_memory +++ a/arch/x86/mm/init_32.c @@ -861,14 +861,14 @@ int arch_add_memory(int nid, u64 start, #ifdef CONFIG_MEMORY_HOTREMOVE void arch_remove_memory(int nid, u64 start, u64 size, - struct vmem_altmap *altmap) + struct mhp_restrictions *restrictions) { unsigned long start_pfn = start >> PAGE_SHIFT; unsigned long nr_pages = size >> PAGE_SHIFT; struct zone *zone; zone = page_zone(pfn_to_page(start_pfn)); - __remove_pages(zone, start_pfn, nr_pages, altmap); + __remove_pages(zone, start_pfn, nr_pages, restrictions); } #endif #endif --- a/arch/x86/mm/init_64.c~mm-hotplug-add-mem-hotplug-restrictions-for-remove_memory +++ a/arch/x86/mm/init_64.c @@ -1142,8 +1142,9 @@ kernel_physical_mapping_remove(unsigned } void __ref arch_remove_memory(int nid, u64 start, u64 size, - struct vmem_altmap *altmap) + struct mhp_restrictions *restrictions) { + struct vmem_altmap *altmap = restrictions->altmap; unsigned long start_pfn = start >> PAGE_SHIFT; unsigned long nr_pages = size >> PAGE_SHIFT; struct page *page = pfn_to_page(start_pfn); @@ -1153,7 +1154,7 @@ void __ref arch_remove_memory(int nid, u if (altmap) page += vmem_altmap_offset(altmap); zone = page_zone(page); - __remove_pages(zone, start_pfn, nr_pages, altmap); + __remove_pages(zone, start_pfn, nr_pages, restrictions); kernel_physical_mapping_remove(start, start + size); } #endif --- a/include/linux/memory_hotplug.h~mm-hotplug-add-mem-hotplug-restrictions-for-remove_memory +++ a/include/linux/memory_hotplug.h @@ -125,9 +125,10 @@ static inline bool movable_node_is_enabl #ifdef CONFIG_MEMORY_HOTREMOVE extern void arch_remove_memory(int nid, u64 start, u64 size, - struct vmem_altmap *altmap); + struct mhp_restrictions *restrictions); extern void __remove_pages(struct zone *zone, unsigned long start_pfn, - unsigned long nr_pages, struct vmem_altmap *altmap); + unsigned long nr_pages, + struct mhp_restrictions *restrictions); #endif /* CONFIG_MEMORY_HOTREMOVE */ /* --- a/kernel/memremap.c~mm-hotplug-add-mem-hotplug-restrictions-for-remove_memory +++ a/kernel/memremap.c @@ -108,8 +108,11 @@ static void devm_memremap_pages_release( __remove_pages(page_zone(pfn_to_page(pfn)), pfn, align_size >> PAGE_SHIFT, NULL); } else { - arch_remove_memory(nid, align_start, align_size, - pgmap->altmap_valid ? &pgmap->altmap : NULL); + struct mhp_restrictions restrictions = { + .altmap = pgmap->altmap_valid ? &pgmap->altmap : NULL, + }; + + arch_remove_memory(nid, align_start, align_size, &restrictions); kasan_remove_zero_shadow(__va(align_start), align_size); } mem_hotplug_done(); @@ -142,15 +145,14 @@ static void devm_memremap_pages_release( void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap) { resource_size_t align_start, align_size, align_end; - struct vmem_altmap *altmap = pgmap->altmap_valid ? - &pgmap->altmap : NULL; struct resource *res = &pgmap->res; struct dev_pagemap *conflict_pgmap; struct mhp_restrictions restrictions = { /* * We do not want any optional features only our own memmap */ - .altmap = altmap, + + .altmap = pgmap->altmap_valid ? &pgmap->altmap : NULL, }; pgprot_t pgprot = PAGE_KERNEL; int error, nid, is_ram; @@ -235,7 +237,7 @@ void *devm_memremap_pages(struct device zone = &NODE_DATA(nid)->node_zones[ZONE_DEVICE]; move_pfn_range_to_zone(zone, align_start >> PAGE_SHIFT, - align_size >> PAGE_SHIFT, altmap); + align_size >> PAGE_SHIFT, restrictions.altmap); } mem_hotplug_done(); --- a/mm/memory_hotplug.c~mm-hotplug-add-mem-hotplug-restrictions-for-remove_memory +++ a/mm/memory_hotplug.c @@ -542,7 +542,7 @@ static void __remove_section(struct zone * @zone: zone from which pages need to be removed * @phys_start_pfn: starting pageframe (must be aligned to start of a section) * @nr_pages: number of pages to remove (must be multiple of section size) - * @altmap: alternative device page map or %NULL if default memmap is used + * @restrictions: optional alternative device page map and other features * * Generic helper function to remove section mappings and sysfs entries * for the section of the memory we are removing. Caller needs to make @@ -550,17 +550,15 @@ static void __remove_section(struct zone * calling offline_pages(). */ void __remove_pages(struct zone *zone, unsigned long phys_start_pfn, - unsigned long nr_pages, struct vmem_altmap *altmap) + unsigned long nr_pages, struct mhp_restrictions *restrictions) { unsigned long i; - unsigned long map_offset = 0; int sections_to_remove; + unsigned long map_offset = 0; + struct vmem_altmap *altmap = restrictions->altmap; - /* In the ZONE_DEVICE case device driver owns the memory region */ - if (is_dev_zone(zone)) { - if (altmap) - map_offset = vmem_altmap_offset(altmap); - } + if (altmap) + map_offset = vmem_altmap_offset(altmap); clear_zone_contiguous(zone); @@ -1830,6 +1828,7 @@ static void __release_memory_resource(u6 */ void __ref __remove_memory(int nid, u64 start, u64 size) { + struct mhp_restrictions restrictions = { 0 }; int ret; BUG_ON(check_hotplug_memory_range(start, size)); @@ -1851,7 +1850,7 @@ void __ref __remove_memory(int nid, u64 memblock_free(start, size); memblock_remove(start, size); - arch_remove_memory(nid, start, size, NULL); + arch_remove_memory(nid, start, size, &restrictions); __release_memory_resource(start, size); try_offline_node(nid); _ Patches currently in -mm which might be from dan.j.williams@xxxxxxxxx are init-initialize-jump-labels-before-command-line-option-parsing.patch mm-sparsemem-introduce-struct-mem_section_usage.patch mm-sparsemem-introduce-common-definitions-for-the-size-and-mask-of-a-section.patch mm-sparsemem-add-helpers-track-active-portions-of-a-section-at-boot.patch mm-hotplug-prepare-shrink_zone-pgdat_span-for-sub-section-removal.patch mm-sparsemem-convert-kmalloc_section_memmap-to-populate_section_memmap.patch mm-hotplug-add-mem-hotplug-restrictions-for-remove_memory.patch mm-kill-is_dev_zone-helper.patch mm-sparsemem-prepare-for-sub-section-ranges.patch mm-sparsemem-support-sub-section-hotplug.patch mm-devm_memremap_pages-enable-sub-section-remap.patch libnvdimm-pfn-fix-fsdax-mode-namespace-info-block-zero-fields.patch libnvdimm-pfn-stop-padding-pmem-namespaces-to-section-alignment.patch mm-shuffle-initial-free-memory-to-improve-memory-side-cache-utilization.patch mm-shuffle-initial-free-memory-to-improve-memory-side-cache-utilization-fix.patch mm-move-buddy-list-manipulations-into-helpers.patch mm-move-buddy-list-manipulations-into-helpers-fix.patch mm-maintain-randomization-of-page-free-lists.patch