forked from mirrors/linux
		
	memory-hotplug: remove sysfs file of node
Introduce a new function try_offline_node() to remove sysfs file of node when all memory sections of this node are removed. If some memory sections of this node are not removed, this function does nothing. Signed-off-by: Wen Congyang <wency@cn.fujitsu.com> Signed-off-by: Tang Chen <tangchen@cn.fujitsu.com> Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Cc: Jiang Liu <jiang.liu@huawei.com> Cc: Jianguo Wu <wujianguo@huawei.com> Cc: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Lai Jiangshan <laijs@cn.fujitsu.com> Cc: Wu Jianguo <wujianguo@huawei.com> Cc: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: "H. Peter Anvin" <hpa@zytor.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
		
							parent
							
								
									815121d2b5
								
							
						
					
					
						commit
						60a5a19e74
					
				
					 3 changed files with 63 additions and 5 deletions
				
			
		| 
						 | 
					@ -280,9 +280,11 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int acpi_memory_remove_memory(struct acpi_memory_device *mem_device)
 | 
					static int acpi_memory_remove_memory(struct acpi_memory_device *mem_device)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int result = 0;
 | 
						int result = 0, nid;
 | 
				
			||||||
	struct acpi_memory_info *info, *n;
 | 
						struct acpi_memory_info *info, *n;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						nid = acpi_get_node(mem_device->device->handle);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	list_for_each_entry_safe(info, n, &mem_device->res_list, list) {
 | 
						list_for_each_entry_safe(info, n, &mem_device->res_list, list) {
 | 
				
			||||||
		if (info->failed)
 | 
							if (info->failed)
 | 
				
			||||||
			/* The kernel does not use this memory block */
 | 
								/* The kernel does not use this memory block */
 | 
				
			||||||
| 
						 | 
					@ -295,7 +297,9 @@ static int acpi_memory_remove_memory(struct acpi_memory_device *mem_device)
 | 
				
			||||||
			 */
 | 
								 */
 | 
				
			||||||
			return -EBUSY;
 | 
								return -EBUSY;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		result = remove_memory(info->start_addr, info->length);
 | 
							if (nid < 0)
 | 
				
			||||||
 | 
								nid = memory_add_physaddr_to_nid(info->start_addr);
 | 
				
			||||||
 | 
							result = remove_memory(nid, info->start_addr, info->length);
 | 
				
			||||||
		if (result)
 | 
							if (result)
 | 
				
			||||||
			return result;
 | 
								return result;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -248,7 +248,7 @@ extern int arch_add_memory(int nid, u64 start, u64 size);
 | 
				
			||||||
extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages);
 | 
					extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages);
 | 
				
			||||||
extern int offline_memory_block(struct memory_block *mem);
 | 
					extern int offline_memory_block(struct memory_block *mem);
 | 
				
			||||||
extern bool is_memblock_offlined(struct memory_block *mem);
 | 
					extern bool is_memblock_offlined(struct memory_block *mem);
 | 
				
			||||||
extern int remove_memory(u64 start, u64 size);
 | 
					extern int remove_memory(int nid, u64 start, u64 size);
 | 
				
			||||||
extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn,
 | 
					extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn,
 | 
				
			||||||
								int nr_pages);
 | 
													int nr_pages);
 | 
				
			||||||
extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms);
 | 
					extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -29,6 +29,7 @@
 | 
				
			||||||
#include <linux/suspend.h>
 | 
					#include <linux/suspend.h>
 | 
				
			||||||
#include <linux/mm_inline.h>
 | 
					#include <linux/mm_inline.h>
 | 
				
			||||||
#include <linux/firmware-map.h>
 | 
					#include <linux/firmware-map.h>
 | 
				
			||||||
 | 
					#include <linux/stop_machine.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <asm/tlbflush.h>
 | 
					#include <asm/tlbflush.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1679,7 +1680,58 @@ static int is_memblock_offlined_cb(struct memory_block *mem, void *arg)
 | 
				
			||||||
	return ret;
 | 
						return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int __ref remove_memory(u64 start, u64 size)
 | 
					static int check_cpu_on_node(void *data)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct pglist_data *pgdat = data;
 | 
				
			||||||
 | 
						int cpu;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for_each_present_cpu(cpu) {
 | 
				
			||||||
 | 
							if (cpu_to_node(cpu) == pgdat->node_id)
 | 
				
			||||||
 | 
								/*
 | 
				
			||||||
 | 
								 * the cpu on this node isn't removed, and we can't
 | 
				
			||||||
 | 
								 * offline this node.
 | 
				
			||||||
 | 
								 */
 | 
				
			||||||
 | 
								return -EBUSY;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* offline the node if all memory sections of this node are removed */
 | 
				
			||||||
 | 
					static void try_offline_node(int nid)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						unsigned long start_pfn = NODE_DATA(nid)->node_start_pfn;
 | 
				
			||||||
 | 
						unsigned long end_pfn = start_pfn + NODE_DATA(nid)->node_spanned_pages;
 | 
				
			||||||
 | 
						unsigned long pfn;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) {
 | 
				
			||||||
 | 
							unsigned long section_nr = pfn_to_section_nr(pfn);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (!present_section_nr(section_nr))
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (pfn_to_nid(pfn) != nid)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							 * some memory sections of this node are not removed, and we
 | 
				
			||||||
 | 
							 * can't offline node now.
 | 
				
			||||||
 | 
							 */
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (stop_machine(check_cpu_on_node, NODE_DATA(nid), NULL))
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * all memory/cpu of this node are removed, we can offline this
 | 
				
			||||||
 | 
						 * node now.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						node_set_offline(nid);
 | 
				
			||||||
 | 
						unregister_one_node(nid);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int __ref remove_memory(int nid, u64 start, u64 size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	unsigned long start_pfn, end_pfn;
 | 
						unsigned long start_pfn, end_pfn;
 | 
				
			||||||
	int ret = 0;
 | 
						int ret = 0;
 | 
				
			||||||
| 
						 | 
					@ -1734,6 +1786,8 @@ int __ref remove_memory(u64 start, u64 size)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	arch_remove_memory(start, size);
 | 
						arch_remove_memory(start, size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						try_offline_node(nid);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	unlock_memory_hotplug();
 | 
						unlock_memory_hotplug();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
| 
						 | 
					@ -1743,7 +1797,7 @@ int offline_pages(unsigned long start_pfn, unsigned long nr_pages)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	return -EINVAL;
 | 
						return -EINVAL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
int remove_memory(u64 start, u64 size)
 | 
					int remove_memory(int nid, u64 start, u64 size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	return -EINVAL;
 | 
						return -EINVAL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue