mm/memory_hotplug: Factor out memory block device handling
Subsystems (10)
cover mm/memory_hotplug: Factor out memory block device handling
We only want memory block devices for memory to be onlined/offlined (add/remove from the buddy). This is required so user space can online/offline memory and kdump gets notified about newly onlined memory.
Only such memory has the requirement of having to span whole memory blocks. Let's factor out creation/removal of memory block devices. This helps to further cleanup arch_add_memory/arch_remove_memory() and to make implementation of new features (e.g. sub-section hot-add) easier.
Patch 1 makes sure the memory block size granularity is always respected. Patch 2 implements arch_remove_memory() on s390x. Patch 3 prepares arch_remove_memory() to be also called without CONFIG_MEMORY_HOTREMOVE. Patch 4,5 and 6 factor out creation/removal of memory block devices. Patch 7 gets rid of some unlikely errors that could have happened, not removinf links between memory block devices and nodes, previously brought up by Oscar.
Did a quick sanity test with DIMM plug/unplug, making sure all devices and sysfs links properly get added/removed. Compile tested on s390x and x86-64.
Based on git://git.cmpxchg.org/linux-mmots.git
David Hildenbrand (7):
mm/memory_hotplug: Simplify and fix check_hotplug_memory_range() s390x/mm: Implement arch_remove_memory() mm/memory_hotplug: arch_remove_memory() and __remove_pages() with
CONFIG_MEMORY_HOTPLUG
mm/memory_hotplug: Create memory block devices after arch_add_memory() mm/memory_hotplug: Drop MHP_MEMBLOCK_API mm/memory_hotplug: Remove memory block devices before
arch_remove_memory()
mm/memory_hotplug: Make unregister_memory_block_under_nodes() never
fail
arch/ia64/mm/init.c | 2 - arch/powerpc/mm/mem.c | 2 - arch/s390/mm/init.c | 15 +++-- arch/sh/mm/init.c | 2 - arch/x86/mm/init_32.c | 2 - arch/x86/mm/init_64.c | 2 - drivers/base/memory.c | 109 +++++++++++++++++++-------------- drivers/base/node.c | 27 +++----- include/linux/memory.h | 6 +- include/linux/memory_hotplug.h | 10 --- include/linux/node.h | 7 +-- mm/memory_hotplug.c | 42 +++++-------- mm/sparse.c | 6 -- 13 files changed, 100 insertions(+), 132 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/7 mm/memory_hotplug: Simplify and fix check_hotplug_memory_range()
By converting start and size to page granularity, we actually ignore unaligned parts within a page instead of properly bailing out with an error.
--- mm/memory_hotplug.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
mm/memory_hotplug.c +3 -8
@@ -1050,16 +1050,11 @@ int try_online_node(int nid)static int check_hotplug_memory_range (u64 start,u64 size) { -unsigned long block_sz =memory_block_size_bytes (); -u64 block_nr_pages = block_sz >>PAGE_SHIFT ; -u64 nr_pages = size >>PAGE_SHIFT ; -u64 start_pfn =PFN_DOWN (start); -/* memory range must be block size aligned */ -if (!nr_pages || !IS_ALIGNED (start_pfn, block_nr_pages) || - !IS_ALIGNED (nr_pages, block_nr_pages)) { +if (!size || !IS_ALIGNED (start,memory_block_size_bytes ()) || + !IS_ALIGNED (size,memory_block_size_bytes ())) {pr_err ("Block size [%#lx] unaligned hotplug range: start %#llx, size %#llx" , - block_sz, start, size); +memory_block_size_bytes (), start, size);return -EINVAL ; }
Signature · 1 line
2.20.1
PATCH 2/7 s390x/mm: Implement arch_remove_memory()
In reply to David HildenbrandWill come in handy when wanting to handle errors after arch_add_memory().
--- arch/s390/mm/init.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
arch/s390/mm/init.c +7 -6
@@ -237,12 +237,13 @@ int arch_add_memory(int nid, u64 start, u64 size,void arch_remove_memory (int nid,u64 start,u64 size,struct vmem_altmap *altmap) { -/* -* There is no hardware or firmware interface which could trigger a -* hot memory remove on s390. So there is nothing that needs to be -* implemented. -*/ -BUG (); +unsigned long start_pfn = start >>PAGE_SHIFT ; +unsigned long nr_pages = size >>PAGE_SHIFT ; +struct zone *zone; + +vmem_remove_mapping (start, size); + zone =page_zone (pfn_to_page (start_pfn)); +__remove_pages (zone, start_pfn, nr_pages, altmap); }#endif #endif /* CONFIG_MEMORY_HOTPLUG */
Signature · 1 line
2.20.1
PATCH 3/7 mm/memory_hotplug: arch_remove_memory() and __remove_pages() with CONFIG_MEMORY_HOTPLUG
In reply to David HildenbrandLet's prepare for better error handling while adding memory by allowing to use arch_remove_memory() and __remove_pages() even if CONFIG_MEMORY_HOTREMOVE is not set. CONFIG_MEMORY_HOTREMOVE effectively covers
- Offlining of system ram (memory block devices) - offline_pages()
- Unplug of system ram - remove_memory()
- Unplug/remap of device memory - devm_memremap()
This allows e.g. for handling like
arch_add_memory()
rc = do_something();
if (rc) {
arch_remove_memory();
}Whereby do_something() will for example be memory block device creation after it has been factored out.
--- arch/ia64/mm/init.c | 2 -- arch/powerpc/mm/mem.c | 2 -- arch/s390/mm/init.c | 2 -- arch/sh/mm/init.c | 2 -- arch/x86/mm/init_32.c | 2 -- arch/x86/mm/init_64.c | 2 -- drivers/base/memory.c | 2 -- include/linux/memory.h | 2 -- include/linux/memory_hotplug.h | 2 -- mm/memory_hotplug.c | 2 -- mm/sparse.c | 6 ------ 11 files changed, 26 deletions(-)
arch/ia64/mm/init.c +0 -2
@@ -681,7 +681,6 @@ int arch_add_memory(int nid, u64 start, u64 size,return ret; } -#ifdef CONFIG_MEMORY_HOTREMOVE void arch_remove_memory (int nid,u64 start,u64 size,struct vmem_altmap *altmap) {
@@ -693,4 +692,3 @@ void arch_remove_memory(int nid, u64 start, u64 size, __remove_pages(zone, start_pfn, nr_pages, altmap); }#endif -#endif
arch/powerpc/mm/mem.c +0 -2
@@ -131,7 +131,6 @@ int __ref arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmreturn __add_pages (nid, start_pfn, nr_pages, restrictions); } -#ifdef CONFIG_MEMORY_HOTREMOVE int __ref arch_remove_memory (int nid,u64 start,u64 size,struct vmem_altmap *altmap) {
@@ -164,7 +163,6 @@ int __ref arch_remove_memory(int nid, u64 start, u64 size, resize_hpt_for_hotplug(memblock_phys_mem_size()); }#endif -#endif /* CONFIG_MEMORY_HOTPLUG */ #ifndef CONFIG_NEED_MULTIPLE_NODES void __init mem_topology_setup (void )
arch/s390/mm/init.c +0 -2
@@ -233,7 +233,6 @@ int arch_add_memory(int nid, u64 start, u64 size,return rc; } -#ifdef CONFIG_MEMORY_HOTREMOVE void arch_remove_memory (int nid,u64 start,u64 size,struct vmem_altmap *altmap) {
@@ -245,5 +244,4 @@ void arch_remove_memory(int nid, u64 start, u64 size, zone =page_zone (pfn_to_page (start_pfn)); __remove_pages(zone, start_pfn, nr_pages, altmap); } -#endif #endif /* CONFIG_MEMORY_HOTPLUG */
arch/sh/mm/init.c +0 -2
@@ -428,7 +428,6 @@ int memory_add_physaddr_to_nid(u64 addr)EXPORT_SYMBOL_GPL (memory_add_physaddr_to_nid);#endif -#ifdef CONFIG_MEMORY_HOTREMOVE void arch_remove_memory (int nid,u64 start,u64 size,struct vmem_altmap *altmap) {
@@ -439,5 +438,4 @@ void arch_remove_memory(int nid, u64 start, u64 size, zone =page_zone (pfn_to_page (start_pfn)); __remove_pages(zone, start_pfn, nr_pages, altmap); } -#endif #endif /* CONFIG_MEMORY_HOTPLUG */
arch/x86/mm/init_32.c +0 -2
@@ -859,7 +859,6 @@ int arch_add_memory(int nid, u64 start, u64 size,return __add_pages (nid, start_pfn, nr_pages, restrictions); } -#ifdef CONFIG_MEMORY_HOTREMOVE void arch_remove_memory (int nid,u64 start,u64 size,struct vmem_altmap *altmap) {
@@ -871,7 +870,6 @@ void arch_remove_memory(int nid, u64 start, u64 size, __remove_pages(zone, start_pfn, nr_pages, altmap); }#endif -#endif int kernel_set_to_readonly__read_mostly ;
arch/x86/mm/init_64.c +0 -2
@@ -1131,7 +1131,6 @@ void __ref vmemmap_free(unsigned long start, unsigned long end,remove_pagetable (start, end, false, altmap); } -#ifdef CONFIG_MEMORY_HOTREMOVE static void __meminit kernel_physical_mapping_remove (unsigned long start,unsigned long end) {
@@ -1156,7 +1155,6 @@ void __ref arch_remove_memory(int nid, u64 start, u64 size,__remove_pages (zone, start_pfn, nr_pages, altmap); kernel_physical_mapping_remove(start, start + size); } -#endif #endif /* CONFIG_MEMORY_HOTPLUG */ static struct kcore_list kcore_vsyscall;
drivers/base/memory.c +0 -2
@@ -728,7 +728,6 @@ int hotplug_memory_register(int nid, struct mem_section *section)return ret; } -#ifdef CONFIG_MEMORY_HOTREMOVE static void unregister_memory (struct memory_block *memory) {
@@ -767,7 +766,6 @@ void unregister_memory_section(struct mem_section *section) out_unlock:mutex_unlock (&mem_sysfs_mutex); } -#endif /* CONFIG_MEMORY_HOTREMOVE */ /* return true if the memory block is offlined, otherwise, return false */ bool is_memblock_offlined (struct memory_block *mem)
include/linux/memory.h +0 -2
@@ -112,9 +112,7 @@ extern void unregister_memory_notifier(struct notifier_block *nb);extern int register_memory_isolate_notifier (struct notifier_block *nb);extern void unregister_memory_isolate_notifier (struct notifier_block *nb);int hotplug_memory_register (int nid,struct mem_section *section); -#ifdef CONFIG_MEMORY_HOTREMOVE extern void unregister_memory_section (struct mem_section *); -#endif extern int memory_dev_init (void );extern int memory_notify (unsigned long val,void *v);extern int memory_isolate_notify (unsigned long val,void *v);
include/linux/memory_hotplug.h +0 -2
@@ -123,12 +123,10 @@ static inline bool movable_node_is_enabled(void)return movable_node_enabled; } -#ifdef CONFIG_MEMORY_HOTREMOVE extern void arch_remove_memory (int nid,u64 start,u64 size,struct vmem_altmap *altmap);extern void __remove_pages (struct zone *zone,unsigned long start_pfn,unsigned long nr_pages,struct vmem_altmap *altmap); -#endif /* CONFIG_MEMORY_HOTREMOVE */ /* * Do we want sysfs memblock files created. This will allow userspace to online
mm/memory_hotplug.c +0 -2
@@ -317,7 +317,6 @@ int __ref __add_pages(int nid, unsigned long phys_start_pfn,return err; } -#ifdef CONFIG_MEMORY_HOTREMOVE /* find the smallest valid pfn in the range [start_pfn, end_pfn) */ static unsigned long find_smallest_section_pfn(int nid, struct zone *zone, unsigned long start_pfn,
@@ -581,7 +580,6 @@ void __remove_pages(struct zone *zone, unsigned long phys_start_pfn,set_zone_contiguous (zone); } -#endif /* CONFIG_MEMORY_HOTREMOVE */ int set_online_page_callback (online_page_callback_t callback) {
mm/sparse.c +0 -6
@@ -604,7 +604,6 @@ static void __kfree_section_memmap(struct page *memmap,vmemmap_free (start, end, altmap); } -#ifdef CONFIG_MEMORY_HOTREMOVE static void free_map_bootmem (struct page *memmap) {unsigned long start = (unsigned long )memmap;
@@ -612,7 +611,6 @@ static void free_map_bootmem(struct page *memmap) vmemmap_free(start, end, NULL); } -#endif /* CONFIG_MEMORY_HOTREMOVE */ #else static struct page *__kmalloc_section_memmap (void ) {
@@ -651,7 +649,6 @@ static void __kfree_section_memmap(struct page *memmap, get_order(sizeof(struct page) * PAGES_PER_SECTION)); } -#ifdef CONFIG_MEMORY_HOTREMOVE static void free_map_bootmem (struct page *memmap) {unsigned long maps_section_nr, removing_section_nr, i;
@@ -681,7 +678,6 @@ static void free_map_bootmem(struct page *memmap) put_page_bootmem(page); } } -#endif /* CONFIG_MEMORY_HOTREMOVE */ #endif /* CONFIG_SPARSEMEM_VMEMMAP */ /**
@@ -746,7 +742,6 @@ int __meminit sparse_add_one_section(int nid, unsigned long start_pfn,return ret; } -#ifdef CONFIG_MEMORY_HOTREMOVE#ifdef CONFIG_MEMORY_FAILURE static void clear_hwpoisoned_pages (struct page *memmap,int nr_pages) {
@@ -823,5 +818,4 @@ void sparse_remove_one_section(struct zone *zone, struct mem_section *ms, PAGES_PER_SECTION - map_offset); free_section_usemap(memmap, usemap, altmap); } -#endif /* CONFIG_MEMORY_HOTREMOVE */ #endif /* CONFIG_MEMORY_HOTPLUG */
Signature · 1 line
2.20.1
PATCH 4/7 mm/memory_hotplug: Create memory block devices after arch_add_memory()
In reply to David HildenbrandOnly memory to be added to the buddy and to be onlined/offlined by user space using memory block devices needs (and should have!) memory block devices.
Factor out creation of memory block devices Create all devices after arch_add_memory() succeeded. We can later drop the want_memblock parameter, because it is now effectively stale.
Only after memory block devices have been added, memory can be onlined by user space. This implies, that memory is not visible to user space at all before arch_add_memory() succeeded.
--- drivers/base/memory.c | 70 ++++++++++++++++++++++++++---------------- include/linux/memory.h | 2 +- mm/memory_hotplug.c | 15 ++++----- 3 files changed, 53 insertions(+), 34 deletions(-)
drivers/base/memory.c +44 -26
@@ -701,44 +701,62 @@ static int add_memory_block(int base_section_nr)return 0 ; } +static void unregister_memory (struct memory_block *memory) +{ +BUG_ON (memory->dev.bus != &memory_subsys); + +/* drop the ref. we got via find_memory_block() */ +put_device (&memory->dev); +device_unregister (&memory->dev); +} +/* -* need an interface for the VM to add new memory regions, -* but without onlining it. +* Create memory block devices for the given memory area. Start and size +* have to be aligned to memory block granularity. Memory block devices +* will be initialized as offline. */ -int hotplug_memory_register (int nid,struct mem_section *section) +int hotplug_memory_register (unsigned long start,unsigned long size) { -int ret =0 ; +unsigned long block_nr_pages =memory_block_size_bytes () >>PAGE_SHIFT ; +unsigned long start_pfn =PFN_DOWN (start); +unsigned long end_pfn = start_pfn + (size >>PAGE_SHIFT ); +unsigned long pfn;struct memory_block *mem; +int ret =0 ; -mutex_lock (&mem_sysfs_mutex); +BUG_ON (!IS_ALIGNED (start,memory_block_size_bytes ())); +BUG_ON (!IS_ALIGNED (size,memory_block_size_bytes ())); - mem =find_memory_block (section); -if (mem) { - mem->section_count++; -put_device (&mem->dev); - }else { - ret =init_memory_block (&mem, section,MEM_OFFLINE ); +mutex_lock (&mem_sysfs_mutex); +for (pfn = start_pfn; pfn != end_pfn; pfn += block_nr_pages) { + mem =find_memory_block (__pfn_to_section (pfn)); +if (mem) { +WARN_ON_ONCE (false); +put_device (&mem->dev); +continue ; + } + ret =init_memory_block (&mem,__pfn_to_section (pfn), +MEM_OFFLINE );if (ret) - goto out; - mem->section_count++; +break ; + mem->section_count =memory_block_size_bytes () / +MIN_MEMORY_BLOCK_SIZE ; + } +if (ret) { + end_pfn = pfn; +for (pfn = start_pfn; pfn != end_pfn; pfn += block_nr_pages) { + mem =find_memory_block (__pfn_to_section (pfn)); +if (!mem) +continue ; + mem->section_count =0 ; +unregister_memory (mem); + } } - -out:mutex_unlock (&mem_sysfs_mutex);return ret; } -static void -unregister_memory (struct memory_block *memory) -{ -BUG_ON (memory->dev.bus != &memory_subsys); - -/* drop the ref. we got via find_memory_block() */ -put_device (&memory->dev); -device_unregister (&memory->dev); -} - -void unregister_memory_section (struct mem_section *section) +static int remove_memory_section (struct mem_section *section) {struct memory_block *mem;
include/linux/memory.h +1 -1
@@ -111,7 +111,7 @@ extern int register_memory_notifier(struct notifier_block *nb);extern void unregister_memory_notifier (struct notifier_block *nb);extern int register_memory_isolate_notifier (struct notifier_block *nb);extern void unregister_memory_isolate_notifier (struct notifier_block *nb); -int hotplug_memory_register (int nid,struct mem_section *section); +int hotplug_memory_register (unsigned long start,unsigned long size);extern void unregister_memory_section (struct mem_section *);extern int memory_dev_init (void );extern int memory_notify (unsigned long val,void *v);
mm/memory_hotplug.c +8 -7
@@ -258,13 +258,7 @@ static int __meminit __add_section(int nid, unsigned long phys_start_pfn,return -EEXIST ; ret =sparse_add_one_section (nid, phys_start_pfn, altmap); -if (ret <0 ) -return ret; - -if (!want_memblock) -return 0 ; - -return hotplug_memory_register (nid,__pfn_to_section (phys_start_pfn)); +return ret <0 ? ret :0 ; }/*
@@ -1106,6 +1100,13 @@ int __ref add_memory_resource(int nid, struct resource *res)if (ret <0 ) goto error; +/* create memory block devices after memory was added */ + ret =hotplug_memory_register (start, size); +if (ret) { +arch_remove_memory (nid, start, size,NULL ); + goto error; + } +if (new_node) {/* If sysfs file of new node can't be created, cpu on the node * can't be hot-added. There is no rollback way now.
Signature · 1 line
2.20.1
PATCH 5/7 mm/memory_hotplug: Drop MHP_MEMBLOCK_API
In reply to David HildenbrandNo longer needed, the callers of arch_add_memory() can handle this manually.
--- include/linux/memory_hotplug.h | 8 -------- mm/memory_hotplug.c | 9 +++------ 2 files changed, 3 insertions(+), 14 deletions(-)
include/linux/memory_hotplug.h +0 -8
@@ -128,14 +128,6 @@ extern void arch_remove_memory(int nid, u64 start, u64 size,extern void __remove_pages (struct zone *zone,unsigned long start_pfn,unsigned long nr_pages,struct vmem_altmap *altmap); -/* -* Do we want sysfs memblock files created. This will allow userspace to online -* and offline memory explicitly. Lack of this bit means that the caller has to -* call move_pfn_range_to_zone to finish the initialization. -*/ - -#define MHP_MEMBLOCK_API (1<<0) -/* reasonably generic interface to expand the physical pages */ extern int __add_pages (int nid,unsigned long start_pfn,unsigned long nr_pages,struct mhp_restrictions *restrictions);
mm/memory_hotplug.c +3 -6
@@ -250,7 +250,7 @@ void __init register_page_bootmem_info_node(struct pglist_data *pgdat)#endif /* CONFIG_HAVE_BOOTMEM_INFO_NODE */ static int __meminit __add_section (int nid,unsigned long phys_start_pfn, -struct vmem_altmap *altmap,bool want_memblock) +struct vmem_altmap *altmap) {int ret;
@@ -293,8 +293,7 @@ int __ref __add_pages(int nid, unsigned long phys_start_pfn, }for (i = start_sec; i <= end_sec; i++) { - err =__add_section (nid,section_nr_to_pfn (i), altmap, - restrictions->flags &MHP_MEMBLOCK_API ); + err =__add_section (nid,section_nr_to_pfn (i), altmap);/* * EEXIST is finally dealt with by ioresource collision
@@ -1066,9 +1065,7 @@ static int online_memory_block(struct memory_block *mem, void *arg)*/ int __ref add_memory_resource (int nid,struct resource *res) { -struct mhp_restrictions restrictions = { - .flags =MHP_MEMBLOCK_API , - }; +struct mhp_restrictions restrictions = {};u64 start, size;bool new_node = false;int ret;
Signature · 1 line
2.20.1
PATCH 6/7 mm/memory_hotplug: Remove memory block devices before arch_remove_memory()
In reply to David HildenbrandLet's factor out removing of memory block devices, which is only necessary for memory added via add_memory() and friends that created memory block devices. Remove the devices before calling arch_remove_memory().
This finishes factoring out memory block device handling from arch_add_memory() and arch_remove_memory().
--- drivers/base/memory.c | 39 +++++++++++++++++++-------------------- drivers/base/node.c | 11 ++++++----- include/linux/memory.h | 2 +- include/linux/node.h | 6 ++---- mm/memory_hotplug.c | 5 +++-- 5 files changed, 31 insertions(+), 32 deletions(-)
drivers/base/memory.c +19 -20
@@ -756,32 +756,31 @@ int hotplug_memory_register(unsigned long start, unsigned long size)return ret; } -static int remove_memory_section (struct mem_section *section) +/* +* Remove memory block devices for the given memory area. Start and size +* have to be aligned to memory block granularity. Memory block devices +* have to be offline. +*/ +void hotplug_memory_unregister (unsigned long start,unsigned long size) { +unsigned long block_nr_pages =memory_block_size_bytes () >>PAGE_SHIFT ; +unsigned long start_pfn =PFN_DOWN (start); +unsigned long end_pfn = start_pfn + (size >>PAGE_SHIFT );struct memory_block *mem; +unsigned long pfn; -if (WARN_ON_ONCE (!present_section (section))) -return ; +BUG_ON (!IS_ALIGNED (start,memory_block_size_bytes ())); +BUG_ON (!IS_ALIGNED (size,memory_block_size_bytes ()));mutex_lock (&mem_sysfs_mutex); - -/* -* Some users of the memory hotplug do not want/need memblock to -* track all sections. Skip over those. -*/ - mem =find_memory_block (section); -if (!mem) - goto out_unlock; - -unregister_mem_sect_under_nodes (mem,__section_nr (section)); - - mem->section_count--; -if (mem->section_count =0 ) +for (pfn = start_pfn; pfn != end_pfn; pfn += block_nr_pages) { + mem =find_memory_block (__pfn_to_section (pfn)); +if (!mem) +continue ; + mem->section_count =0 ; +unregister_memory_block_under_nodes (mem);unregister_memory (mem); -else -put_device (&mem->dev); - -out_unlock: + }mutex_unlock (&mem_sysfs_mutex); }
drivers/base/node.c +6 -5
@@ -801,9 +801,10 @@ int register_mem_sect_under_node(struct memory_block *mem_blk, void *arg)return 0 ; } -/* unregister memory section under all nodes that it spans */ -int unregister_mem_sect_under_nodes (struct memory_block *mem_blk, -unsigned long phys_index) +/* +* Unregister memory block device under all nodes that it spans. +*/ +int unregister_memory_block_under_nodes (struct memory_block *mem_blk) {NODEMASK_ALLOC (nodemask_t, unlinked_nodes,GFP_KERNEL );unsigned long pfn, sect_start_pfn, sect_end_pfn;
@@ -816,8 +817,8 @@ int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,return -ENOMEM ;nodes_clear (*unlinked_nodes); - sect_start_pfn =section_nr_to_pfn (phys_index); - sect_end_pfn = sect_start_pfn +PAGES_PER_SECTION -1 ; + sect_start_pfn =section_nr_to_pfn (mem_blk->start_section_nr); + sect_end_pfn =section_nr_to_pfn (mem_blk->end_section_nr);for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) {int nid;
include/linux/memory.h +1 -1
@@ -112,7 +112,7 @@ extern void unregister_memory_notifier(struct notifier_block *nb);extern int register_memory_isolate_notifier (struct notifier_block *nb);extern void unregister_memory_isolate_notifier (struct notifier_block *nb);int hotplug_memory_register (unsigned long start,unsigned long size); -extern void unregister_memory_section (struct mem_section *); +void hotplug_memory_unregister (unsigned long start,unsigned long size);extern int memory_dev_init (void );extern int memory_notify (unsigned long val,void *v);extern int memory_isolate_notify (unsigned long val,void *v);
include/linux/node.h +2 -4
@@ -139,8 +139,7 @@ extern int register_cpu_under_node(unsigned int cpu, unsigned int nid);extern int unregister_cpu_under_node (unsigned int cpu,unsigned int nid);extern int register_mem_sect_under_node (struct memory_block *mem_blk,void *arg); -extern int unregister_mem_sect_under_nodes (struct memory_block *mem_blk, -unsigned long phys_index); +extern int unregister_memory_block_under_nodes (struct memory_block *mem_blk); extern int register_memory_node_under_compute_node(unsigned int mem_nid, unsigned int cpu_nid,
@@ -176,8 +175,7 @@ static inline int register_mem_sect_under_node(struct memory_block *mem_blk, {return 0 ; } -static inline int unregister_mem_sect_under_nodes (struct memory_block *mem_blk, -unsigned long phys_index) +static inline int unregister_memory_block_under_nodes (struct memory_block *mem_blk) {return 0 ; }
mm/memory_hotplug.c +3 -2
@@ -519,8 +519,6 @@ static void __remove_section(struct zone *zone, struct mem_section *ms,if (WARN_ON_ONCE (!valid_section (ms)))return ; -unregister_memory_section (ms); - scn_nr =__section_nr (ms); start_pfn =section_nr_to_pfn ((unsigned long )scn_nr);__remove_zone (zone, start_pfn);
@@ -1844,6 +1842,9 @@ void __ref __remove_memory(int nid, u64 start, u64 size)memblock_free (start, size);memblock_remove (start, size); +/* remove memory block devices before removing memory */ +hotplug_memory_unregister (start, size); +arch_remove_memory (nid, start, size,NULL );__release_memory_resource (start, size);
Signature · 1 line
2.20.1
PATCH 7/7 mm/memory_hotplug: Make unregister_memory_block_under_nodes() never fail
In reply to David HildenbrandWe really don't want anything during memory hotunplug to fail. We always pass a valid memory block device, that check can go. Avoid allocating memory and eventually failing. As we are always called under lock, we can use a static piece of memory. This avoids having to put the structure onto the stack, having to guess about the stack size of callers.
Patch inspired by a patch from Oscar Salvador.
In the future, there might be no need to iterate over nodes at all. mem->nid should tell us exactly what to remove. Memory block devices with mixed nodes (added during boot) should properly fenced off and never removed.
--- drivers/base/node.c | 18 +++++------------- include/linux/node.h | 5 ++--- 2 files changed, 7 insertions(+), 16 deletions(-)
drivers/base/node.c +5 -13
@@ -803,20 +803,14 @@ int register_mem_sect_under_node(struct memory_block *mem_blk, void *arg)/* * Unregister memory block device under all nodes that it spans. +* Has to be called with mem_sysfs_mutex held (due to unlinked_nodes). */ -int unregister_memory_block_under_nodes (struct memory_block *mem_blk) +void unregister_memory_block_under_nodes (struct memory_block *mem_blk) { -NODEMASK_ALLOC (nodemask_t, unlinked_nodes,GFP_KERNEL );unsigned long pfn, sect_start_pfn, sect_end_pfn; +static nodemask_t unlinked_nodes; -if (!mem_blk) { -NODEMASK_FREE (unlinked_nodes); -return -EFAULT ; - } -if (!unlinked_nodes) -return -ENOMEM ; -nodes_clear (*unlinked_nodes); - +nodes_clear (unlinked_nodes); sect_start_pfn =section_nr_to_pfn (mem_blk->start_section_nr); sect_end_pfn =section_nr_to_pfn (mem_blk->end_section_nr);for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) {
@@ -827,15 +821,13 @@ int unregister_memory_block_under_nodes(struct memory_block *mem_blk)continue ;if (!node_online (nid))continue ; -if (node_test_and_set (nid, *unlinked_nodes)) +if (node_test_and_set (nid, unlinked_nodes))continue ;sysfs_remove_link (&node_devices[nid]->dev.kobj,kobject_name (&mem_blk->dev.kobj));sysfs_remove_link (&mem_blk->dev.kobj,kobject_name (&node_devices[nid]->dev.kobj)); } -NODEMASK_FREE (unlinked_nodes); -return 0 ; }int link_mem_sections (int nid,unsigned long start_pfn,unsigned long end_pfn)
include/linux/node.h +2 -3
@@ -139,7 +139,7 @@ extern int register_cpu_under_node(unsigned int cpu, unsigned int nid);extern int unregister_cpu_under_node (unsigned int cpu,unsigned int nid);extern int register_mem_sect_under_node (struct memory_block *mem_blk,void *arg); -extern int unregister_memory_block_under_nodes (struct memory_block *mem_blk); +extern void unregister_memory_block_under_nodes (struct memory_block *mem_blk); extern int register_memory_node_under_compute_node(unsigned int mem_nid, unsigned int cpu_nid,
@@ -175,9 +175,8 @@ static inline int register_mem_sect_under_node(struct memory_block *mem_blk, {return 0 ; } -static inline int unregister_memory_block_under_nodes (struct memory_block *mem_blk) +static inline void unregister_memory_block_under_nodes (struct memory_block *mem_blk) { -return 0 ; } static inline void register_hugetlbfs_with_node(node_registration_func_t reg,
Signature · 1 line
2.20.1
Re: [PATCH v1 2/7] s390x/mm: Implement arch_remove_memory()
In reply to David HildenbrandQuoted 27 lines · David Hildenbrand
Will come in handy when wanting to handle errors after
arch_add_memory().Cc Martin Schwidefsky <[email protected]>Cc Heiko Carstens <[email protected]>Cc Andrew Morton <[email protected]>Cc Michal Hocko <[email protected]>Cc Mike Rapoport <[email protected]>Cc David Hildenbrand <[email protected]>Cc Vasily Gorbik <[email protected]>Cc Oscar Salvador <[email protected]>Signed-off-by David Hildenbrand <[email protected]>--- arch/s390/mm/init.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)arch/s390/mm/init.c +0
-3@@ -237,12 +237,13 @@ int arch_add_memory(int nid, u64 start, u64 size,void arch_remove_memory (int nid,u64 start,u64 size,struct vmem_altmap *altmap) { -/* -* There is no hardware or firmware interface which could trigger a -* hot memory remove on s390. So there is nothing that needs to be
arch/s390/mm/init.c int arch_add_memory(int nid, u64 start, u64 size, · line 246
Quoted 10 lines
arch/s390/mm/init.c +7
-3-* implemented. -*/ -BUG (); +unsigned long start_pfn = start >>PAGE_SHIFT ; +unsigned long nr_pages = size >>PAGE_SHIFT ; +struct zone *zone; + +vmem_remove_mapping (start, size); + zone =page_zone (pfn_to_page (start_pfn)); +__remove_pages (zone, start_pfn, nr_pages, altmap);
I guess the correct way is to remove the mapping after __remove_pages. But as the pages should not be touched by anybody, it shouldn't really matter. Will change when I resend.
Quoted 4 lines
arch/s390/mm/init.c +0
-0}#endif #endif /* CONFIG_MEMORY_HOTPLUG */
Signature · 3 lines
Thanks, David / dhildenb