From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yasuaki Ishimatsu Subject: [RFC PATCH 0/12] memory-hotplug : hot-remove physical memory Date: Wed, 27 Jun 2012 14:39:20 +0900 Message-ID: <4FEA9C88.1070800@jp.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Return-path: Sender: owner-linux-mm@kvack.org To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org Cc: len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com List-Id: linux-acpi@vger.kernel.org This patch series aims to support physical memory hot-remove. [RFC PATCH 1/12] memory-hotplug : rename remove_memory to offline_memory [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages [RFC PATCH 3/12] memory-hotplug : add physical memory hotplug code to acpi_memory_device_remove [RFC PATCH 4/12] memory-hotplug : remove /sys/firmware/memmap/X sysfs [RFC PATCH 5/12] memory hotplug : does not release memory region in PAGES_PER_SECTION chunks [RFC PATCH 6/12] memory-hotplug : remove_memory calls __remove_pages [RFC PATCH 7/12] memory-hotplug : check page type in get_page_bootmem [RFC PATCH 8/12] memory-hotplug : move register_page_bootmem_info_node and put_page_bootmem for sparse-vmemmap [RFC PATCH 9/12] memory-hotplug : implement register_page_bootmem_info_section of sparse-vmemmap [RFC PATCH 10/12] memory-hotplug : free memmap of sparse-vmemmap [RFC PATCH 11/12] memory-hotplug : add node_device_release [RFC PATCH 12/12] memory-hotplug : remove sysfs file of node Even if you apply these patches, you cannot remove the physical memory completely since these patches are still under development. I want you to cooperate to improve the physical memory hot-remove. So please review these patches and give your comment/idea. The patches can free/remove following things: - acpi_memory_info : [RFC PATCH 3/12] - /sys/firmware/memmap/X/{end, start, type} : [RFC PATCH 4/12] - iomem_resource : [RFC PATCH 5/12] - mem_section and related sysfs files : [RFC PATCH 6-10/12] - node and related sysfs files : [RFC PATCH 11-12/12] The patches cannot do following things yet: - page table of removed memory If you find lack of function for physical memory hot-remove, please let me know. --- arch/powerpc/platforms/pseries/hotplug-memory.c | 16 +- arch/x86/mm/init_64.c | 142 ++++++++++++++++++++++++ drivers/acpi/acpi_memhotplug.c | 25 +++- drivers/base/memory.c | 24 +++- drivers/base/node.c | 7 + drivers/firmware/memmap.c | 71 ++++++++++++ include/linux/firmware-map.h | 6 + include/linux/memory.h | 1 include/linux/memory_hotplug.h | 17 -- include/linux/mm.h | 5 mm/memory_hotplug.c | 101 +++++++++++++---- mm/sparse.c | 5 12 files changed, 374 insertions(+), 46 deletions(-) -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yasuaki Ishimatsu Subject: [RFC PATCH 1/12] memory-hotplug : rename remove_memory to offline_memory Date: Wed, 27 Jun 2012 14:42:52 +0900 Message-ID: <4FEA9D5C.1080508@jp.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Return-path: Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:39691 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750994Ab2F0FnN (ORCPT ); Wed, 27 Jun 2012 01:43:13 -0400 In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Sender: linux-acpi-owner@vger.kernel.org List-Id: linux-acpi@vger.kernel.org To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org Cc: len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com remove_memory() does not remove memory but just offlines memory. The patch changes name of it to offline_memory(). CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- drivers/acpi/acpi_memhotplug.c | 2 +- drivers/base/memory.c | 4 ++-- include/linux/memory_hotplug.h | 2 +- mm/memory_hotplug.c | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) Index: linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c =================================================================== --- linux-3.5-rc4.orig/drivers/acpi/acpi_memhotplug.c 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c 2012-06-26 13:48:38.263940481 +0900 @@ -318,7 +318,7 @@ static int acpi_memory_disable_device(st */ list_for_each_entry_safe(info, n, &mem_device->res_list, list) { if (info->enabled) { - result = remove_memory(info->start_addr, info->length); + result = offline_memory(info->start_addr, info->length); if (result) return result; } Index: linux-3.5-rc4/drivers/base/memory.c =================================================================== --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:48:46.072842803 +0900 @@ -266,8 +266,8 @@ memory_block_action(unsigned long phys_i break; case MEM_OFFLINE: start_paddr = page_to_pfn(first_page) << PAGE_SHIFT; - ret = remove_memory(start_paddr, - nr_pages << PAGE_SHIFT); + ret = offline_memory(start_paddr, + nr_pages << PAGE_SHIFT); break; default: WARN(1, KERN_WARNING "%s(%ld, %ld) unknown action: " Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:46.072842803 +0900 @@ -990,7 +990,7 @@ out: return ret; } -int remove_memory(u64 start, u64 size) +int offline_memory(u64 start, u64 size) { unsigned long start_pfn, end_pfn; @@ -999,9 +999,9 @@ int remove_memory(u64 start, u64 size) return offline_pages(start_pfn, end_pfn, 120 * HZ); } #else -int remove_memory(u64 start, u64 size) +int offline_memory(u64 start, u64 size) { return -EINVAL; } #endif /* CONFIG_MEMORY_HOTREMOVE */ -EXPORT_SYMBOL_GPL(remove_memory); +EXPORT_SYMBOL_GPL(offline_memory); Index: linux-3.5-rc4/include/linux/memory_hotplug.h =================================================================== --- linux-3.5-rc4.orig/include/linux/memory_hotplug.h 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/include/linux/memory_hotplug.h 2012-06-26 13:48:38.264940468 +0900 @@ -233,7 +233,7 @@ static inline int is_mem_section_removab extern int mem_online_node(int nid); extern int add_memory(int nid, u64 start, u64 size); extern int arch_add_memory(int nid, u64 start, u64 size); -extern int remove_memory(u64 start, u64 size); +extern int offline_memory(u64 start, u64 size); extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn, int nr_pages); extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms); From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yasuaki Ishimatsu Subject: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages Date: Wed, 27 Jun 2012 14:44:17 +0900 Message-ID: <4FEA9DB1.7010303@jp.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Return-path: Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:39736 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750708Ab2F0Fof (ORCPT ); Wed, 27 Jun 2012 01:44:35 -0400 In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Sender: linux-acpi-owner@vger.kernel.org List-Id: linux-acpi@vger.kernel.org To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org Cc: len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com When offline_pages() is called to offlined memory, the function fails since all memory has been offlined. In this case, the function should succeed. The patch adds the check function into offline_pages(). CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- drivers/base/memory.c | 20 ++++++++++++++++++++ include/linux/memory.h | 1 + mm/memory_hotplug.c | 5 +++++ 3 files changed, 26 insertions(+) Index: linux-3.5-rc4/drivers/base/memory.c =================================================================== --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-26 13:28:16.726211752 +0900 +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:34:22.423639904 +0900 @@ -70,6 +70,26 @@ void unregister_memory_isolate_notifier( } EXPORT_SYMBOL(unregister_memory_isolate_notifier); +bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn) +{ + struct memory_block *mem; + struct mem_section *section; + unsigned long pfn, section_nr; + + for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { + section_nr = pfn_to_section_nr(pfn); + section = __nr_to_section(section_nr); + mem = find_memory_block(section); + if (!mem) + continue; + if (mem->state == MEM_OFFLINE) + continue; + return false; + } + + return true; +} + /* * register_memory - Setup a sysfs device for a memory block */ Index: linux-3.5-rc4/include/linux/memory.h =================================================================== --- linux-3.5-rc4.orig/include/linux/memory.h 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/include/linux/memory.h 2012-06-26 13:34:22.424639891 +0900 @@ -120,6 +120,7 @@ extern int memory_isolate_notify(unsigne extern struct memory_block *find_memory_block_hinted(struct mem_section *, struct memory_block *); extern struct memory_block *find_memory_block(struct mem_section *); +extern bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn); #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION< Subject: [RFC PATCH 3/12] memory-hotplug : add physical memory hotplug code to acpi_memory_device_remove Date: Wed, 27 Jun 2012 14:45:46 +0900 Message-ID: <4FEA9E0A.1040202@jp.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Return-path: Received: from fgwmail5.fujitsu.co.jp ([192.51.44.35]:38677 "EHLO fgwmail5.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750805Ab2F0FqJ (ORCPT ); Wed, 27 Jun 2012 01:46:09 -0400 In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Sender: linux-acpi-owner@vger.kernel.org List-Id: linux-acpi@vger.kernel.org To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org Cc: len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com acpi_memory_device_remove() has been prepared to remove physical memory. But, the function only frees acpi_memory_device currentlry. The patch adds following functions into acpi_memory_device_remove(): - offline memory - remove physical memory (only return -EBUSY) - free acpi_memory_device CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- drivers/acpi/acpi_memhotplug.c | 23 ++++++++++++++++++++++- include/linux/memory_hotplug.h | 1 + mm/memory_hotplug.c | 8 ++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) Index: linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c =================================================================== --- linux-3.5-rc4.orig/drivers/acpi/acpi_memhotplug.c 2012-06-26 13:28:16.722211802 +0900 +++ linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c 2012-06-26 13:38:01.085906251 +0900 @@ -452,12 +452,33 @@ static int acpi_memory_device_add(struct static int acpi_memory_device_remove(struct acpi_device *device, int type) { struct acpi_memory_device *mem_device = NULL; - + struct acpi_memory_info *info, *tmp; + int result; + int node; if (!device || !acpi_driver_data(device)) return -EINVAL; mem_device = acpi_driver_data(device); + + node = acpi_get_node(mem_device->device->handle); + + list_for_each_entry_safe(info, tmp, &mem_device->res_list, list) { + if (!info->enabled) + continue; + + result = offline_memory(info->start_addr, info->length); + if (result) + return result; + + result = remove_memory(node, info->start_addr, info->length); + if (result) + return result; + + list_del(&info->list); + kfree(info); + } + kfree(mem_device); return 0; Index: linux-3.5-rc4/include/linux/memory_hotplug.h =================================================================== --- linux-3.5-rc4.orig/include/linux/memory_hotplug.h 2012-06-26 13:28:16.773211163 +0900 +++ linux-3.5-rc4/include/linux/memory_hotplug.h 2012-06-26 13:37:30.545288962 +0900 @@ -233,6 +233,7 @@ static inline int is_mem_section_removab extern int mem_online_node(int nid); extern int add_memory(int nid, u64 start, u64 size); extern int arch_add_memory(int nid, u64 start, u64 size); +extern int remove_memory(int nid, u64 start, u64 size); extern int offline_memory(u64 start, u64 size); extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn, int nr_pages); Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:34:22.425639879 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:30.096046767 +0900 @@ -659,6 +659,14 @@ out: } EXPORT_SYMBOL_GPL(add_memory); +int remove_memory(int nid, u64 start, u64 size) +{ + return -EBUSY; + +} +EXPORT_SYMBOL_GPL(remove_memory); + + #ifdef CONFIG_MEMORY_HOTREMOVE /* * A free page on the buddy free lists (not the per-cpu lists) has PageBuddy From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yasuaki Ishimatsu Subject: [RFC PATCH 4/12] memory-hotplug : remove /sys/firmware/memmap/X sysfs Date: Wed, 27 Jun 2012 14:47:11 +0900 Message-ID: <4FEA9E5F.4070205@jp.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Return-path: Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:41064 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752676Ab2F0Fr2 (ORCPT ); Wed, 27 Jun 2012 01:47:28 -0400 In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Sender: linux-acpi-owner@vger.kernel.org List-Id: linux-acpi@vger.kernel.org To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org Cc: len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com When (hot)adding memory into system, /sys/firmware/memmap/X/{end, start, type} sysfs files are created. But there is no code to remove these files. The patch implements the function to remove them. Note : The code does not free firmware_map_entry since there is no way to free memory which is allocated by bootmem. CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- drivers/firmware/memmap.c | 71 +++++++++++++++++++++++++++++++++++++++++++ include/linux/firmware-map.h | 6 +++ mm/memory_hotplug.c | 6 +++ 3 files changed, 82 insertions(+), 1 deletion(-) Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:37:30.546288901 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:44:37.069955820 +0900 @@ -661,7 +661,11 @@ EXPORT_SYMBOL_GPL(add_memory); int remove_memory(int nid, u64 start, u64 size) { - return -EBUSY; + lock_memory_hotplug(); + /* remove memmap entry */ + firmware_map_remove(start, start + size, "System RAM"); + unlock_memory_hotplug(); + return 0; } EXPORT_SYMBOL_GPL(remove_memory); Index: linux-3.5-rc4/include/linux/firmware-map.h =================================================================== --- linux-3.5-rc4.orig/include/linux/firmware-map.h 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/include/linux/firmware-map.h 2012-06-26 13:44:37.070955807 +0900 @@ -25,6 +25,7 @@ int firmware_map_add_early(u64 start, u64 end, const char *type); int firmware_map_add_hotplug(u64 start, u64 end, const char *type); +int firmware_map_remove(u64 start, u64 end, const char *type); #else /* CONFIG_FIRMWARE_MEMMAP */ @@ -38,6 +39,11 @@ static inline int firmware_map_add_hotpl return 0; } +static inline int firmware_map_remove(u64 start, u64 end, const char *type) +{ + return 0; +} + #endif /* CONFIG_FIRMWARE_MEMMAP */ #endif /* _LINUX_FIRMWARE_MAP_H */ Index: linux-3.5-rc4/drivers/firmware/memmap.c =================================================================== --- linux-3.5-rc4.orig/drivers/firmware/memmap.c 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/drivers/firmware/memmap.c 2012-06-26 13:47:17.606948898 +0900 @@ -123,6 +123,16 @@ static int firmware_map_add_entry(u64 st return 0; } +/** + * firmware_map_remove_entry() - Does the real work to remove a firmware + * memmap entry. + * @entry: removed entry. + **/ +static inline void firmware_map_remove_entry(struct firmware_map_entry *entry) +{ + list_del(&entry->list); +} + /* * Add memmap entry on sysfs */ @@ -144,6 +154,31 @@ static int add_sysfs_fw_map_entry(struct return 0; } +/* + * Remove memmap entry on sysfs + */ +static inline void remove_sysfs_fw_map_entry(struct firmware_map_entry *entry) +{ + kobject_del(&entry->kobj); +} + +/* + * Search memmap entry + */ + +struct firmware_map_entry * __meminit +find_firmware_map_entry(u64 start, u64 end, const char *type) +{ + struct firmware_map_entry *entry; + + list_for_each_entry(entry, &map_entries, list) + if ((entry->start == start) && (entry->end == end) && + (!strcmp(entry->type, type))) + return entry; + + return NULL; +} + /** * firmware_map_add_hotplug() - Adds a firmware mapping entry when we do * memory hotplug. @@ -196,6 +231,42 @@ int __init firmware_map_add_early(u64 st return firmware_map_add_entry(start, end, type, entry); } +void release_firmware_map_entry(struct firmware_map_entry *entry) +{ + /* + * FIXME : There is no idea. + * How to free the entry which allocated bootmem? + */ +} + +/** + * firmware_map_remove() - remove a firmware mapping entry + * @start: Start of the memory range. + * @end: End of the memory range (inclusive). + * @type: Type of the memory range. + * + * removes a firmware mapping entry. + * + * Returns 0 on success, or -EINVAL if no entry. + **/ +int __meminit firmware_map_remove(u64 start, u64 end, const char *type) +{ + struct firmware_map_entry *entry; + + entry = find_firmware_map_entry(start, end, type); + if (!entry) + return -EINVAL; + + /* remove the memmap entry */ + remove_sysfs_fw_map_entry(entry); + + firmware_map_remove_entry(entry); + + release_firmware_map_entry(entry); + + return 0; +} + /* * Sysfs functions ------------------------------------------------------------- */ From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yasuaki Ishimatsu Subject: [RFC PATCH 5/12] memory-hotplug : does not release memory region in PAGES_PER_SECTION chunks Date: Wed, 27 Jun 2012 14:48:31 +0900 Message-ID: <4FEA9EAF.1060608@jp.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Sender: owner-linux-mm@kvack.org To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org Cc: len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com List-Id: linux-acpi@vger.kernel.org Since applying a patch(de7f0cba96786c), release_mem_region() has been changed as called in PAGES_PER_SECTION chunks because register_memory_resource() is called in PAGES_PER_SECTION chunks by add_memory(). But it seems firmware dependency. If CRS are written in the PAGES_PER_SECTION chunks in ACPI DSDT Table, register_memory_resource() is called in PAGES_PER_SECTION chunks. But if CRS are written in the DIMM unit in ACPI DSDT Table, register_memory_resource() is called in DIMM unit. So release_mem_region() should not be called in PAGES_PER_SECTION chunks. The patch fixes it. CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- arch/powerpc/platforms/pseries/hotplug-memory.c | 13 +++++++++---- mm/memory_hotplug.c | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:50:57.075205100 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:55:36.152716100 +0900 @@ -358,11 +358,11 @@ int __remove_pages(struct zone *zone, un BUG_ON(phys_start_pfn & ~PAGE_SECTION_MASK); BUG_ON(nr_pages % PAGES_PER_SECTION); + release_mem_region(phys_start_pfn << PAGE_SHIFT, nr_pages * PAGE_SIZE); + sections_to_remove = nr_pages / PAGES_PER_SECTION; for (i = 0; i < sections_to_remove; i++) { unsigned long pfn = phys_start_pfn + i*PAGES_PER_SECTION; - release_mem_region(pfn << PAGE_SHIFT, - PAGES_PER_SECTION << PAGE_SHIFT); ret = __remove_section(zone, __pfn_to_section(pfn)); if (ret) break; Index: linux-3.5-rc4/arch/powerpc/platforms/pseries/hotplug-memory.c =================================================================== --- linux-3.5-rc4.orig/arch/powerpc/platforms/pseries/hotplug-memory.c 2012-06-26 13:50:57.075205100 +0900 +++ linux-3.5-rc4/arch/powerpc/platforms/pseries/hotplug-memory.c 2012-06-26 13:55:36.153716088 +0900 @@ -77,7 +77,8 @@ static int pseries_remove_memblock(unsig { unsigned long start, start_pfn; struct zone *zone; - int ret; + int i, ret; + int sections_to_remove; start_pfn = base >> PAGE_SHIFT; @@ -97,9 +98,13 @@ static int pseries_remove_memblock(unsig * to sysfs "state" file and we can't remove sysfs entries * while writing to it. So we have to defer it to here. */ - ret = __remove_pages(zone, start_pfn, memblock_size >> PAGE_SHIFT); - if (ret) - return ret; + sections_to_remove = (memblock_size >> PAGE_SHIFT) / PAGES_PER_SECTION; + for (i = 0; i < sections_to_remove; i++) { + unsigned long pfn = start_pfn + i * PAGES_PER_SECTION; + ret = __remove_pages(zone, start_pfn, PAGES_PER_SECTION); + if (ret) + return ret; + } /* * Update memory regions for memory remove -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yasuaki Ishimatsu Subject: [RFC PATCH 6/12] memory-hotplug : remove_memory calls __remove_pages Date: Wed, 27 Jun 2012 14:52:11 +0900 Message-ID: <4FEA9F8B.30105@jp.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Return-path: Received: from fgwmail5.fujitsu.co.jp ([192.51.44.35]:38761 "EHLO fgwmail5.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750780Ab2F0Fw3 (ORCPT ); Wed, 27 Jun 2012 01:52:29 -0400 In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Sender: linux-acpi-owner@vger.kernel.org List-Id: linux-acpi@vger.kernel.org To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org Cc: len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com The patch adds __remove_pages() to remove_memory(). Then the range of phys_start_pfn argument and nr_pages argument in __remove_pagse() may have different zone. So zone argument is removed from __remove_pages() and __remove_pages() caluculates zone in each section. When CONFIG_SPARSEMEM_VMEMMAP is defined, there is no way to remove a memmap. So __remove_section only calls unregister_memory_section(). CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- arch/powerpc/platforms/pseries/hotplug-memory.c | 5 +---- include/linux/memory_hotplug.h | 3 +-- mm/memory_hotplug.c | 20 +++++++++++++------- 3 files changed, 15 insertions(+), 13 deletions(-) Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-27 09:07:49.124709164 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-27 09:08:30.612190446 +0900 @@ -275,11 +275,14 @@ static int __meminit __add_section(int n #ifdef CONFIG_SPARSEMEM_VMEMMAP static int __remove_section(struct zone *zone, struct mem_section *ms) { - /* - * XXX: Freeing memmap with vmemmap is not implement yet. - * This should be removed later. - */ - return -EBUSY; + int ret; + + if (!valid_section(ms)) + return ret; + + ret = unregister_memory_section(ms); + + return ret; } #else static int __remove_section(struct zone *zone, struct mem_section *ms) @@ -346,11 +349,11 @@ EXPORT_SYMBOL_GPL(__add_pages); * sure that pages are marked reserved and zones are adjust properly by * calling offline_pages(). */ -int __remove_pages(struct zone *zone, unsigned long phys_start_pfn, - unsigned long nr_pages) +int __remove_pages(unsigned long phys_start_pfn, unsigned long nr_pages) { unsigned long i, ret = 0; int sections_to_remove; + struct zone *zone; /* * We can only remove entire sections @@ -363,6 +366,7 @@ int __remove_pages(struct zone *zone, un sections_to_remove = nr_pages / PAGES_PER_SECTION; for (i = 0; i < sections_to_remove; i++) { unsigned long pfn = phys_start_pfn + i*PAGES_PER_SECTION; + zone = page_zone(pfn_to_page(pfn)); ret = __remove_section(zone, __pfn_to_section(pfn)); if (ret) break; @@ -664,6 +668,8 @@ int remove_memory(int nid, u64 start, u6 lock_memory_hotplug(); /* remove memmap entry */ firmware_map_remove(start, start + size, "System RAM"); + + __remove_pages(start >> PAGE_SHIFT, size >> PAGE_SHIFT); unlock_memory_hotplug(); return 0; Index: linux-3.5-rc4/include/linux/memory_hotplug.h =================================================================== --- linux-3.5-rc4.orig/include/linux/memory_hotplug.h 2012-06-27 09:06:35.616628141 +0900 +++ linux-3.5-rc4/include/linux/memory_hotplug.h 2012-06-27 09:08:30.612190446 +0900 @@ -89,8 +89,7 @@ extern bool is_pageblock_removable_noloc /* reasonably generic interface to expand the physical pages in a zone */ extern int __add_pages(int nid, struct zone *zone, unsigned long start_pfn, unsigned long nr_pages); -extern int __remove_pages(struct zone *zone, unsigned long start_pfn, - unsigned long nr_pages); +extern int __remove_pages(unsigned long start_pfn, unsigned long nr_pages); #ifdef CONFIG_NUMA extern int memory_add_physaddr_to_nid(u64 start); Index: linux-3.5-rc4/arch/powerpc/platforms/pseries/hotplug-memory.c =================================================================== --- linux-3.5-rc4.orig/arch/powerpc/platforms/pseries/hotplug-memory.c 2012-06-27 09:08:25.737248748 +0900 +++ linux-3.5-rc4/arch/powerpc/platforms/pseries/hotplug-memory.c 2012-06-27 09:08:30.613190434 +0900 @@ -76,7 +76,6 @@ unsigned long memory_block_size_bytes(vo static int pseries_remove_memblock(unsigned long base, unsigned int memblock_size) { unsigned long start, start_pfn; - struct zone *zone; int i, ret; int sections_to_remove; @@ -87,8 +86,6 @@ static int pseries_remove_memblock(unsig return 0; } - zone = page_zone(pfn_to_page(start_pfn)); - /* * Remove section mappings and sysfs entries for the * section of the memory we are removing. @@ -101,7 +98,7 @@ static int pseries_remove_memblock(unsig sections_to_remove = (memblock_size >> PAGE_SHIFT) / PAGES_PER_SECTION; for (i = 0; i < sections_to_remove; i++) { unsigned long pfn = start_pfn + i * PAGES_PER_SECTION; - ret = __remove_pages(zone, start_pfn, PAGES_PER_SECTION); + ret = __remove_pages(start_pfn, PAGES_PER_SECTION); if (ret) return ret; } From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yasuaki Ishimatsu Subject: [RFC PATCH 7/12] memory-hotplug : check page type in get_page_bootmem Date: Wed, 27 Jun 2012 14:53:17 +0900 Message-ID: <4FEA9FCD.6020405@jp.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Sender: owner-linux-mm@kvack.org To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org Cc: len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com List-Id: linux-acpi@vger.kernel.org There is a possibility that get_page_bootmem() is called to the same page many times. So when get_page_bootmem is called to the same page, the function only increments page->_count. CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:56:34.371988312 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 14:03:37.564697621 +0900 @@ -95,10 +95,17 @@ static void release_memory_resource(stru static void get_page_bootmem(unsigned long info, struct page *page, unsigned long type) { - page->lru.next = (struct list_head *) type; - SetPagePrivate(page); - set_page_private(page, info); - atomic_inc(&page->_count); + unsigned long page_type; + + page_type = (unsigned long) page->lru.next; + if (type < MEMORY_HOTPLUG_MIN_BOOTMEM_TYPE || + type > MEMORY_HOTPLUG_MAX_BOOTMEM_TYPE){ + page->lru.next = (struct list_head *) type; + SetPagePrivate(page); + set_page_private(page, info); + atomic_inc(&page->_count); + } else + atomic_inc(&page->_count); } /* reference to __meminit __free_pages_bootmem is valid -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yasuaki Ishimatsu Subject: [RFC PATCH 8/12] memory-hotplug : move register_page_bootmem_info_node and put_page_bootmem for sparse-vmemmap Date: Wed, 27 Jun 2012 14:54:33 +0900 Message-ID: <4FEAA019.7070302@jp.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Return-path: Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:58189 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751420Ab2F0Fyt (ORCPT ); Wed, 27 Jun 2012 01:54:49 -0400 In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Sender: linux-acpi-owner@vger.kernel.org List-Id: linux-acpi@vger.kernel.org To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org Cc: len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com For implementing register_page_bootmem_info_node of sparse-vmemmap, register_page_bootmem_info_node and put_page_bootmem are moved to memory_hotplug.c CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyan Signed-off-by: Yasuaki Ishimatsu --- include/linux/memory_hotplug.h | 9 --------- mm/memory_hotplug.c | 8 ++++++-- 2 files changed, 6 insertions(+), 11 deletions(-) Index: linux-3.5-rc4/include/linux/memory_hotplug.h =================================================================== --- linux-3.5-rc4.orig/include/linux/memory_hotplug.h 2012-06-26 13:56:34.372988299 +0900 +++ linux-3.5-rc4/include/linux/memory_hotplug.h 2012-06-26 14:05:16.603459518 +0900 @@ -160,17 +160,8 @@ static inline void arch_refresh_nodedata #endif /* CONFIG_NUMA */ #endif /* CONFIG_HAVE_ARCH_NODEDATA_EXTENSION */ -#ifdef CONFIG_SPARSEMEM_VMEMMAP -static inline void register_page_bootmem_info_node(struct pglist_data *pgdat) -{ -} -static inline void put_page_bootmem(struct page *page) -{ -} -#else extern void register_page_bootmem_info_node(struct pglist_data *pgdat); extern void put_page_bootmem(struct page *page); -#endif /* * Lock for memory hotplug guarantees 1) all callbacks for memory hotplug Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 14:03:37.564697621 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 14:05:16.604459506 +0900 @@ -91,7 +91,6 @@ static void release_memory_resource(stru } #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE -#ifndef CONFIG_SPARSEMEM_VMEMMAP static void get_page_bootmem(unsigned long info, struct page *page, unsigned long type) { @@ -127,6 +126,7 @@ void __ref put_page_bootmem(struct page } +#ifndef CONFIG_SPARSEMEM_VMEMMAP static void register_page_bootmem_info_section(unsigned long start_pfn) { unsigned long *usemap, mapsize, section_nr, i; @@ -163,6 +163,11 @@ static void register_page_bootmem_info_s get_page_bootmem(section_nr, page, MIX_SECTION_INFO); } +#else +static inline void register_page_bootmem_info_section(unsigned long start_pfn) +{ +} +#endif void register_page_bootmem_info_node(struct pglist_data *pgdat) { @@ -198,7 +203,6 @@ void register_page_bootmem_info_node(str register_page_bootmem_info_section(pfn); } -#endif /* !CONFIG_SPARSEMEM_VMEMMAP */ static void grow_zone_span(struct zone *zone, unsigned long start_pfn, unsigned long end_pfn) From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yasuaki Ishimatsu Subject: [RFC PATCH 9/12] memory-hotplug : implement register_page_bootmem_info_section of sparse-vmemmap Date: Wed, 27 Jun 2012 14:55:40 +0900 Message-ID: <4FEAA05C.6090204@jp.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Return-path: Received: from fgwmail5.fujitsu.co.jp ([192.51.44.35]:53753 "EHLO fgwmail5.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750780Ab2F0Fz7 (ORCPT ); Wed, 27 Jun 2012 01:55:59 -0400 In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Sender: linux-acpi-owner@vger.kernel.org List-Id: linux-acpi@vger.kernel.org To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org Cc: len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com For removing memmap region of sparse-vmemmap which is allocated bootmem, memmap region of sparse-vmemmap needs to be registered by get_page_bootmem(). So the patch searches pages of virtual mapping and registers the pages by get_page_bootmem(). CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- arch/x86/mm/init_64.c | 53 +++++++++++++++++++++++++++++++++++++++++ include/linux/memory_hotplug.h | 2 + include/linux/mm.h | 3 +- mm/memory_hotplug.c | 23 +++++++++++++++-- 4 files changed, 77 insertions(+), 4 deletions(-) Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 14:05:16.604459506 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 14:27:19.850916817 +0900 @@ -91,8 +91,8 @@ static void release_memory_resource(stru } #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE -static void get_page_bootmem(unsigned long info, struct page *page, - unsigned long type) +void get_page_bootmem(unsigned long info, struct page *page, + unsigned long type) { unsigned long page_type; @@ -164,8 +164,25 @@ static void register_page_bootmem_info_s } #else -static inline void register_page_bootmem_info_section(unsigned long start_pfn) +static void register_page_bootmem_info_section(unsigned long start_pfn) { + unsigned long mapsize, section_nr; + struct mem_section *ms; + struct page *page, *memmap; + + if (!pfn_valid(start_pfn)) + return; + + section_nr = pfn_to_section_nr(start_pfn); + ms = __nr_to_section(section_nr); + + memmap = sparse_decode_mem_map(ms->section_mem_map, section_nr); + + page = virt_to_page(memmap); + mapsize = sizeof(struct page) * PAGES_PER_SECTION; + mapsize = PAGE_ALIGN(mapsize) >> PAGE_SHIFT; + + register_page_bootmem_memmap(section_nr, memmap, PAGES_PER_SECTION); } #endif Index: linux-3.5-rc4/include/linux/mm.h =================================================================== --- linux-3.5-rc4.orig/include/linux/mm.h 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/include/linux/mm.h 2012-06-26 14:26:17.481696320 +0900 @@ -1586,7 +1586,8 @@ int vmemmap_populate_basepages(struct pa unsigned long pages, int node); int vmemmap_populate(struct page *start_page, unsigned long pages, int node); void vmemmap_populate_print_last(void); - +void register_page_bootmem_memmap(unsigned long section_nr, struct page *map, + unsigned long size); enum mf_flags { MF_COUNT_INCREASED = 1 << 0, Index: linux-3.5-rc4/arch/x86/mm/init_64.c =================================================================== --- linux-3.5-rc4.orig/arch/x86/mm/init_64.c 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/arch/x86/mm/init_64.c 2012-06-26 14:26:17.481696320 +0900 @@ -978,6 +978,59 @@ vmemmap_populate(struct page *start_page return 0; } +void __meminit +register_page_bootmem_memmap(unsigned long section_nr, struct page *start_page, + unsigned long size) +{ + unsigned long addr = (unsigned long)start_page; + unsigned long end = (unsigned long)(start_page + size); + unsigned long next; + pgd_t *pgd; + pud_t *pud; + pmd_t *pmd; + + for (; addr < end; addr = next) { + pte_t *pte = NULL; + + pgd = pgd_offset_k(addr); + if (pgd_none(*pgd)) { + next = (addr + PAGE_SIZE) & PAGE_MASK; + continue; + } + get_page_bootmem(section_nr, pgd_page(*pgd), MIX_SECTION_INFO); + + pud = pud_offset(pgd, addr); + if (pud_none(*pud)) { + next = (addr + PAGE_SIZE) & PAGE_MASK; + continue; + } + get_page_bootmem(section_nr, pud_page(*pud), MIX_SECTION_INFO); + + if (!cpu_has_pse) { + next = (addr + PAGE_SIZE) & PAGE_MASK; + pmd = pmd_offset(pud, addr); + if (pmd_none(*pmd)) + continue; + get_page_bootmem(section_nr, pmd_page(*pmd), + MIX_SECTION_INFO); + + pte = pte_offset_kernel(pmd, addr); + if (pte_none(*pte)) + continue; + get_page_bootmem(section_nr, pte_page(*pte), + SECTION_INFO); + } else { + next = pmd_addr_end(addr, end); + + pmd = pmd_offset(pud, addr); + if (pmd_none(*pmd)) + continue; + get_page_bootmem(section_nr, pmd_page(*pmd), + SECTION_INFO); + } + } +} + void __meminit vmemmap_populate_print_last(void) { if (p_start) { Index: linux-3.5-rc4/include/linux/memory_hotplug.h =================================================================== --- linux-3.5-rc4.orig/include/linux/memory_hotplug.h 2012-06-26 14:05:16.603459518 +0900 +++ linux-3.5-rc4/include/linux/memory_hotplug.h 2012-06-26 14:11:14.175989381 +0900 @@ -162,6 +162,8 @@ static inline void arch_refresh_nodedata extern void register_page_bootmem_info_node(struct pglist_data *pgdat); extern void put_page_bootmem(struct page *page); +extern void get_page_bootmem(unsigned long ingo, struct page *page, + unsigned long type); /* * Lock for memory hotplug guarantees 1) all callbacks for memory hotplug From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yasuaki Ishimatsu Subject: [RFC PATCH 10/12] memory-hotplug : free memmap of sparse-vmemmap Date: Wed, 27 Jun 2012 14:56:47 +0900 Message-ID: <4FEAA09F.5000907@jp.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Sender: owner-linux-mm@kvack.org To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org Cc: len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com List-Id: linux-acpi@vger.kernel.org I don't think that all pages of virtual mapping in removed memory can be freed, since page which type is MIX_SECTION_INFO is difficult to free. So, the patch only frees page which type is SECTION_INFO at first. CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- arch/x86/mm/init_64.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/mm.h | 2 + mm/memory_hotplug.c | 5 ++ mm/sparse.c | 5 +- 4 files changed, 99 insertions(+), 2 deletions(-) Index: linux-3.5-rc4/include/linux/mm.h =================================================================== --- linux-3.5-rc4.orig/include/linux/mm.h 2012-06-27 09:11:13.790150442 +0900 +++ linux-3.5-rc4/include/linux/mm.h 2012-06-27 09:11:16.433117400 +0900 @@ -1588,6 +1588,8 @@ int vmemmap_populate(struct page *start_ void vmemmap_populate_print_last(void); void register_page_bootmem_memmap(unsigned long section_nr, struct page *map, unsigned long size); +void vmemmap_kfree(struct page *memmpa, unsigned long nr_pages); +void vmemmap_free_bootmem(struct page *memmpa, unsigned long nr_pages); enum mf_flags { MF_COUNT_INCREASED = 1 << 0, Index: linux-3.5-rc4/mm/sparse.c =================================================================== --- linux-3.5-rc4.orig/mm/sparse.c 2012-06-27 09:06:35.317631878 +0900 +++ linux-3.5-rc4/mm/sparse.c 2012-06-27 09:11:16.434117388 +0900 @@ -614,12 +614,13 @@ static inline struct page *kmalloc_secti /* This will make the necessary allocations eventually. */ return sparse_mem_map_populate(pnum, nid); } -static void __kfree_section_memmap(struct page *memmap, unsigned long nr_pages) +static void __kfree_section_memmap(struct page *page, unsigned long nr_pages) { - return; /* XXX: Not implemented yet */ + vmemmap_kfree(page, nr_pages); } static void free_map_bootmem(struct page *page, unsigned long nr_pages) { + vmemmap_free_bootmem(page, nr_pages); } #else static struct page *__kmalloc_section_memmap(unsigned long nr_pages) Index: linux-3.5-rc4/arch/x86/mm/init_64.c =================================================================== --- linux-3.5-rc4.orig/arch/x86/mm/init_64.c 2012-06-27 09:11:13.791150430 +0900 +++ linux-3.5-rc4/arch/x86/mm/init_64.c 2012-06-27 09:11:59.254581998 +0900 @@ -978,6 +978,95 @@ vmemmap_populate(struct page *start_page return 0; } +unsigned long find_and_clear_pte_page(unsigned long addr, unsigned long end, + struct page *page) +{ + pgd_t *pgd; + pud_t *pud; + pmd_t *pmd; + pte_t *pte; + unsigned long next; + + page = NULL; + + pgd = pgd_offset_k(addr); + if (pgd_none(*pgd)) + return PAGE_SIZE; + + pud = pud_offset(pgd, addr); + if (pud_none(*pud)) + return PAGE_SIZE; + + if (!cpu_has_pse) { + next = (addr + PAGE_SIZE) & PAGE_MASK; + pmd = pmd_offset(pud, addr); + if (pmd_none(*pmd)) + return next; + + pte = pte_offset_kernel(pmd, addr); + if (pte_none(*pte)) + return next; + + page = pte_page(*pte); + pte_clear(&init_mm, addr, pte); + } else { + next = pmd_addr_end(addr, end); + + pmd = pmd_offset(pud, addr); + if (pmd_none(*pmd)) + return next; + + page = pmd_page(*pmd); + pmd_clear(pmd); + } + + return next; +} + +void __meminit +vmemmap_kfree(struct page *memmap, unsigned long nr_pages) +{ + unsigned long addr = (unsigned long)memmap; + unsigned long end = (unsigned long)(memmap + nr_pages); + unsigned long next; + unsigned int order; + struct page *page; + + for (; addr < end; addr = next) { + next = find_and_clear_pte_page(addr, end, page); + if (!page) + continue; + + if (is_vmalloc_addr(page)) + vfree(page); + else { + order = next - addr; + free_pages((unsigned long)page, + get_order(sizeof(struct page) * order)); + } + } +} + +void __meminit +vmemmap_free_bootmem(struct page *memmap, unsigned long nr_pages) +{ + unsigned long addr = (unsigned long)memmap; + unsigned long end = (unsigned long)(memmap + nr_pages); + unsigned long next; + struct page *page; + unsigned long magic; + + for (; addr < end; addr = next) { + next = find_and_clear_pte_page(addr, end, page); + if (!page) + continue; + + magic = (unsigned long) page->lru.next; + if (magic == SECTION_INFO) + put_page_bootmem(page); + } +} + void __meminit register_page_bootmem_memmap(unsigned long section_nr, struct page *start_page, unsigned long size) Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-27 09:11:13.789150454 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-27 09:11:16.436117363 +0900 @@ -303,6 +303,8 @@ static int __meminit __add_section(int n #ifdef CONFIG_SPARSEMEM_VMEMMAP static int __remove_section(struct zone *zone, struct mem_section *ms) { + unsigned long flags; + struct pglist_data *pgdat = zone->zone_pgdat; int ret; if (!valid_section(ms)) @@ -310,6 +312,9 @@ static int __remove_section(struct zone ret = unregister_memory_section(ms); + pgdat_resize_lock(pgdat, &flags); + sparse_remove_one_section(zone, ms); + pgdat_resize_unlock(pgdat, &flags); return ret; } #else -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yasuaki Ishimatsu Subject: [RFC PATCH 11/12] memory-hotplug : add node_device_release Date: Wed, 27 Jun 2012 14:57:54 +0900 Message-ID: <4FEAA0E2.2080003@jp.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Return-path: Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:36122 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750994Ab2F0F6Q (ORCPT ); Wed, 27 Jun 2012 01:58:16 -0400 In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Sender: linux-acpi-owner@vger.kernel.org List-Id: linux-acpi@vger.kernel.org To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org Cc: len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com When calling unregister_node(), the function shows following message at device_release(). Device 'node2' does not have a release() function, it is broken and must be fixed. So the patch implements node_device_release() CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu Index: linux-3.5-rc1/drivers/base/node.c =================================================================== --- linux-3.5-rc1.orig/drivers/base/node.c 2012-06-14 09:09:53.000000000 +0900 +++ linux-3.5-rc1/drivers/base/node.c 2012-06-25 18:40:45.810261969 +0900 @@ -252,6 +252,12 @@ static inline void hugetlb_register_node static inline void hugetlb_unregister_node(struct node *node) {} #endif +static void node_device_release(struct device *dev) +{ + struct node *node_dev = to_node(dev); + + memset(node_dev, 0, sizeof(struct node)); +} /* * register_node - Setup a sysfs device for a node. @@ -265,6 +271,7 @@ int register_node(struct node *node, int node->dev.id = num; node->dev.bus = &node_subsys; + node->dev.release = node_device_release; error = device_register(&node->dev); if (!error){ From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yasuaki Ishimatsu Subject: [RFC PATCH 12/12] memory-hotplug : remove sysfs file of node Date: Wed, 27 Jun 2012 14:59:07 +0900 Message-ID: <4FEAA12B.6070906@jp.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Return-path: Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:36174 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750994Ab2F0F71 (ORCPT ); Wed, 27 Jun 2012 01:59:27 -0400 In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Sender: linux-acpi-owner@vger.kernel.org List-Id: linux-acpi@vger.kernel.org To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org Cc: len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com The patch adds node_set_offline() and unregister_one_node() to remove_memory() for removing sysfs file of node. CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- mm/memory_hotplug.c | 5 +++++ 1 file changed, 5 insertions(+) Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 14:32:03.630368866 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 14:39:58.090437374 +0900 @@ -702,6 +702,11 @@ int remove_memory(int nid, u64 start, u6 /* remove memmap entry */ firmware_map_remove(start, start + size, "System RAM"); + if (!node_present_pages(nid)) { + node_set_offline(nid); + unregister_one_node(nid); + } + __remove_pages(start >> PAGE_SHIFT, size >> PAGE_SHIFT); unlock_memory_hotplug(); return 0; From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Rientjes Subject: Re: [RFC PATCH 1/12] memory-hotplug : rename remove_memory to offline_memory Date: Tue, 26 Jun 2012 23:10:32 -0700 (PDT) Message-ID: References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9D5C.1080508@jp.fujitsu.com> Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Return-path: In-Reply-To: <4FEA9D5C.1080508@jp.fujitsu.com> Sender: owner-linux-mm@kvack.org To: Yasuaki Ishimatsu Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com List-Id: linux-acpi@vger.kernel.org On Wed, 27 Jun 2012, Yasuaki Ishimatsu wrote: > remove_memory() does not remove memory but just offlines memory. The patch > changes name of it to offline_memory(). > The kernel is never going to physically remove the memory itself, so I don't see the big problem with calling it remove_memory(). If you're going to change it to offline_memory(), which is just as good but not better, then I'd suggest changing add_memory() to online_memory() for completeness. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Rientjes Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages Date: Tue, 26 Jun 2012 23:16:24 -0700 (PDT) Message-ID: References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Return-path: Received: from mail-pz0-f46.google.com ([209.85.210.46]:58261 "EHLO mail-pz0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755246Ab2F0GQ0 (ORCPT ); Wed, 27 Jun 2012 02:16:26 -0400 Received: by dady13 with SMTP id y13so939714dad.19 for ; Tue, 26 Jun 2012 23:16:26 -0700 (PDT) In-Reply-To: <4FEA9DB1.7010303@jp.fujitsu.com> Sender: linux-acpi-owner@vger.kernel.org List-Id: linux-acpi@vger.kernel.org To: Yasuaki Ishimatsu Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com On Wed, 27 Jun 2012, Yasuaki Ishimatsu wrote: > Index: linux-3.5-rc4/mm/memory_hotplug.c > =================================================================== > --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:28:16.743211538 +0900 > +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:38.264940468 +0900 > @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned > > lock_memory_hotplug(); > > + if (memory_is_offline(start_pfn, end_pfn)) { > + ret = 0; > + goto out; > + } > + > zone = page_zone(pfn_to_page(start_pfn)); > node = zone_to_nid(zone); > nr_pages = end_pfn - start_pfn; Are there additional prerequisites for this patch? Otherwise it changes the return value of offline_memory() which will now call acpi_memory_powerdown_device() in the acpi memhotplug case when disabling. Is that a problem? From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wen Congyang Subject: Re: [RFC PATCH 1/12] memory-hotplug : rename remove_memory to offline_memory Date: Wed, 27 Jun 2012 15:14:41 +0800 Message-ID: <4FEAB2E1.3090200@cn.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9D5C.1080508@jp.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <4FEA9D5C.1080508@jp.fujitsu.com> Sender: owner-linux-mm@kvack.org To: Yasuaki Ishimatsu Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com List-Id: linux-acpi@vger.kernel.org At 06/27/2012 01:42 PM, Yasuaki Ishimatsu Wrote: > remove_memory() does not remove memory but just offlines memory. The patch > changes name of it to offline_memory(). There are 3 functions in the kernel: 1. add_memory() 2. online_pages() 3. remove_memory() So I think offline_pages() is better than offline_memory(). Thanks Wen Congyang > > CC: Len Brown > CC: Benjamin Herrenschmidt > CC: Paul Mackerras > CC: Christoph Lameter > Cc: Minchan Kim > CC: Andrew Morton > CC: KOSAKI Motohiro > CC: Wen Congyang > Signed-off-by: Yasuaki Ishimatsu > > --- > drivers/acpi/acpi_memhotplug.c | 2 +- > drivers/base/memory.c | 4 ++-- > include/linux/memory_hotplug.h | 2 +- > mm/memory_hotplug.c | 6 +++--- > 4 files changed, 7 insertions(+), 7 deletions(-) > > Index: linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c > =================================================================== > --- linux-3.5-rc4.orig/drivers/acpi/acpi_memhotplug.c 2012-06-25 04:53:04.000000000 +0900 > +++ linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c 2012-06-26 13:48:38.263940481 +0900 > @@ -318,7 +318,7 @@ static int acpi_memory_disable_device(st > */ > list_for_each_entry_safe(info, n, &mem_device->res_list, list) { > if (info->enabled) { > - result = remove_memory(info->start_addr, info->length); > + result = offline_memory(info->start_addr, info->length); > if (result) > return result; > } > Index: linux-3.5-rc4/drivers/base/memory.c > =================================================================== > --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-25 04:53:04.000000000 +0900 > +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:48:46.072842803 +0900 > @@ -266,8 +266,8 @@ memory_block_action(unsigned long phys_i > break; > case MEM_OFFLINE: > start_paddr = page_to_pfn(first_page) << PAGE_SHIFT; > - ret = remove_memory(start_paddr, > - nr_pages << PAGE_SHIFT); > + ret = offline_memory(start_paddr, > + nr_pages << PAGE_SHIFT); > break; > default: > WARN(1, KERN_WARNING "%s(%ld, %ld) unknown action: " > Index: linux-3.5-rc4/mm/memory_hotplug.c > =================================================================== > --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-25 04:53:04.000000000 +0900 > +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:46.072842803 +0900 > @@ -990,7 +990,7 @@ out: > return ret; > } > > -int remove_memory(u64 start, u64 size) > +int offline_memory(u64 start, u64 size) > { > unsigned long start_pfn, end_pfn; > > @@ -999,9 +999,9 @@ int remove_memory(u64 start, u64 size) > return offline_pages(start_pfn, end_pfn, 120 * HZ); > } > #else > -int remove_memory(u64 start, u64 size) > +int offline_memory(u64 start, u64 size) > { > return -EINVAL; > } > #endif /* CONFIG_MEMORY_HOTREMOVE */ > -EXPORT_SYMBOL_GPL(remove_memory); > +EXPORT_SYMBOL_GPL(offline_memory); > Index: linux-3.5-rc4/include/linux/memory_hotplug.h > =================================================================== > --- linux-3.5-rc4.orig/include/linux/memory_hotplug.h 2012-06-25 04:53:04.000000000 +0900 > +++ linux-3.5-rc4/include/linux/memory_hotplug.h 2012-06-26 13:48:38.264940468 +0900 > @@ -233,7 +233,7 @@ static inline int is_mem_section_removab > extern int mem_online_node(int nid); > extern int add_memory(int nid, u64 start, u64 size); > extern int arch_add_memory(int nid, u64 start, u64 size); > -extern int remove_memory(u64 start, u64 size); > +extern int offline_memory(u64 start, u64 size); > extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn, > int nr_pages); > extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms); > > > > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ > -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wen Congyang Subject: Re: [RFC PATCH 1/12] memory-hotplug : rename remove_memory to offline_memory Date: Wed, 27 Jun 2012 16:47:13 +0800 Message-ID: <4FEAC891.7030808@cn.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9D5C.1080508@jp.fujitsu.com> <4FEAB2E1.3090200@cn.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <4FEAB2E1.3090200@cn.fujitsu.com> Sender: owner-linux-mm@kvack.org To: Yasuaki Ishimatsu Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com List-Id: linux-acpi@vger.kernel.org At 06/27/2012 03:14 PM, Wen Congyang Wrote: > At 06/27/2012 01:42 PM, Yasuaki Ishimatsu Wrote: >> remove_memory() does not remove memory but just offlines memory. The patch >> changes name of it to offline_memory(). > > There are 3 functions in the kernel: > 1. add_memory() > 2. online_pages() > 3. remove_memory() > > So I think offline_pages() is better than offline_memory(). There is already a function named offline_pages(). So we should call offline_pages() instead of remove_memory() in memory_block_action(), and there is no need to rename remove_memory(). Thanks Wen Congyang > > Thanks > Wen Congyang >> >> CC: Len Brown >> CC: Benjamin Herrenschmidt >> CC: Paul Mackerras >> CC: Christoph Lameter >> Cc: Minchan Kim >> CC: Andrew Morton >> CC: KOSAKI Motohiro >> CC: Wen Congyang >> Signed-off-by: Yasuaki Ishimatsu >> >> --- >> drivers/acpi/acpi_memhotplug.c | 2 +- >> drivers/base/memory.c | 4 ++-- >> include/linux/memory_hotplug.h | 2 +- >> mm/memory_hotplug.c | 6 +++--- >> 4 files changed, 7 insertions(+), 7 deletions(-) >> >> Index: linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c >> =================================================================== >> --- linux-3.5-rc4.orig/drivers/acpi/acpi_memhotplug.c 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c 2012-06-26 13:48:38.263940481 +0900 >> @@ -318,7 +318,7 @@ static int acpi_memory_disable_device(st >> */ >> list_for_each_entry_safe(info, n, &mem_device->res_list, list) { >> if (info->enabled) { >> - result = remove_memory(info->start_addr, info->length); >> + result = offline_memory(info->start_addr, info->length); >> if (result) >> return result; >> } >> Index: linux-3.5-rc4/drivers/base/memory.c >> =================================================================== >> --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:48:46.072842803 +0900 >> @@ -266,8 +266,8 @@ memory_block_action(unsigned long phys_i >> break; >> case MEM_OFFLINE: >> start_paddr = page_to_pfn(first_page) << PAGE_SHIFT; >> - ret = remove_memory(start_paddr, >> - nr_pages << PAGE_SHIFT); >> + ret = offline_memory(start_paddr, >> + nr_pages << PAGE_SHIFT); >> break; >> default: >> WARN(1, KERN_WARNING "%s(%ld, %ld) unknown action: " >> Index: linux-3.5-rc4/mm/memory_hotplug.c >> =================================================================== >> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:46.072842803 +0900 >> @@ -990,7 +990,7 @@ out: >> return ret; >> } >> >> -int remove_memory(u64 start, u64 size) >> +int offline_memory(u64 start, u64 size) >> { >> unsigned long start_pfn, end_pfn; >> >> @@ -999,9 +999,9 @@ int remove_memory(u64 start, u64 size) >> return offline_pages(start_pfn, end_pfn, 120 * HZ); >> } >> #else >> -int remove_memory(u64 start, u64 size) >> +int offline_memory(u64 start, u64 size) >> { >> return -EINVAL; >> } >> #endif /* CONFIG_MEMORY_HOTREMOVE */ >> -EXPORT_SYMBOL_GPL(remove_memory); >> +EXPORT_SYMBOL_GPL(offline_memory); >> Index: linux-3.5-rc4/include/linux/memory_hotplug.h >> =================================================================== >> --- linux-3.5-rc4.orig/include/linux/memory_hotplug.h 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/include/linux/memory_hotplug.h 2012-06-26 13:48:38.264940468 +0900 >> @@ -233,7 +233,7 @@ static inline int is_mem_section_removab >> extern int mem_online_node(int nid); >> extern int add_memory(int nid, u64 start, u64 size); >> extern int arch_add_memory(int nid, u64 start, u64 size); >> -extern int remove_memory(u64 start, u64 size); >> +extern int offline_memory(u64 start, u64 size); >> extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn, >> int nr_pages); >> extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms); >> >> >> >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >> Please read the FAQ at http://www.tux.org/lkml/ >> > > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ > -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wen Congyang Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages Date: Wed, 27 Jun 2012 16:49:26 +0800 Message-ID: <4FEAC916.7030506@cn.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <4FEA9DB1.7010303@jp.fujitsu.com> Sender: owner-linux-mm@kvack.org To: Yasuaki Ishimatsu Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com List-Id: linux-acpi@vger.kernel.org At 06/27/2012 01:44 PM, Yasuaki Ishimatsu Wrote: > When offline_pages() is called to offlined memory, the function fails since > all memory has been offlined. In this case, the function should succeed. > The patch adds the check function into offline_pages(). You miss such case: some pages are online, while some pages are offline. offline_pages() will fail too in such case. Thanks Wen Congyang > > CC: Len Brown > CC: Benjamin Herrenschmidt > CC: Paul Mackerras > CC: Christoph Lameter > Cc: Minchan Kim > CC: Andrew Morton > CC: KOSAKI Motohiro > CC: Wen Congyang > Signed-off-by: Yasuaki Ishimatsu > > --- > drivers/base/memory.c | 20 ++++++++++++++++++++ > include/linux/memory.h | 1 + > mm/memory_hotplug.c | 5 +++++ > 3 files changed, 26 insertions(+) > > Index: linux-3.5-rc4/drivers/base/memory.c > =================================================================== > --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-26 13:28:16.726211752 +0900 > +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:34:22.423639904 +0900 > @@ -70,6 +70,26 @@ void unregister_memory_isolate_notifier( > } > EXPORT_SYMBOL(unregister_memory_isolate_notifier); > > +bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn) > +{ > + struct memory_block *mem; > + struct mem_section *section; > + unsigned long pfn, section_nr; > + > + for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { > + section_nr = pfn_to_section_nr(pfn); > + section = __nr_to_section(section_nr); > + mem = find_memory_block(section); > + if (!mem) > + continue; > + if (mem->state == MEM_OFFLINE) > + continue; > + return false; > + } > + > + return true; > +} > + > /* > * register_memory - Setup a sysfs device for a memory block > */ > Index: linux-3.5-rc4/include/linux/memory.h > =================================================================== > --- linux-3.5-rc4.orig/include/linux/memory.h 2012-06-25 04:53:04.000000000 +0900 > +++ linux-3.5-rc4/include/linux/memory.h 2012-06-26 13:34:22.424639891 +0900 > @@ -120,6 +120,7 @@ extern int memory_isolate_notify(unsigne > extern struct memory_block *find_memory_block_hinted(struct mem_section *, > struct memory_block *); > extern struct memory_block *find_memory_block(struct mem_section *); > +extern bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn); > #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION< enum mem_add_context { BOOT, HOTPLUG }; > #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ > Index: linux-3.5-rc4/mm/memory_hotplug.c > =================================================================== > --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:28:16.743211538 +0900 > +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:38.264940468 +0900 > @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned > > lock_memory_hotplug(); > > + if (memory_is_offline(start_pfn, end_pfn)) { > + ret = 0; > + goto out; > + } > + > zone = page_zone(pfn_to_page(start_pfn)); > node = zone_to_nid(zone); > nr_pages = end_pfn - start_pfn; > > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ > -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yasuaki Ishimatsu Subject: Re: [RFC PATCH 1/12] memory-hotplug : rename remove_memory to offline_memory Date: Thu, 28 Jun 2012 12:01:02 +0900 Message-ID: <4FEBC8EE.7040207@jp.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9D5C.1080508@jp.fujitsu.com> <4FEAB2E1.3090200@cn.fujitsu.com> <4FEAC891.7030808@cn.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <4FEAC891.7030808@cn.fujitsu.com> Sender: owner-linux-mm@kvack.org To: Wen Congyang , rientjes@google.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com List-Id: linux-acpi@vger.kernel.org Hi David and Wen, Thank you for reviewing my patch. 2012/06/27 17:47, Wen Congyang wrote: > At 06/27/2012 03:14 PM, Wen Congyang Wrote: >> At 06/27/2012 01:42 PM, Yasuaki Ishimatsu Wrote: >>> remove_memory() does not remove memory but just offlines memory. The patch >>> changes name of it to offline_memory(). >> >> There are 3 functions in the kernel: >> 1. add_memory() >> 2. online_pages() >> 3. remove_memory() >> >> So I think offline_pages() is better than offline_memory(). > > There is already a function named offline_pages(). So we > should call offline_pages() instead of remove_memory() in > memory_block_action(), and there is no need to rename > remove_memory(). As Wen says, Linux has 4 functions for memory hotplug already. In my recognition, these functions are prepared for following purpose. 1. add_memory : add physical memory 2. online_pages : online logical memory 3. remove_memory : offline logical memory 4. offline_pages : offline logical memory add_memory() is used for adding physical memory. I think remove_memory() would rather be used for removing physical memory than be used for removing logical memory. So I renamed remove_memory() to offline_memory(). How do you think? Regards, Yasuaki Ishimatsu > > Thanks > Wen Congyang > >> >> Thanks >> Wen Congyang >>> >>> CC: Len Brown >>> CC: Benjamin Herrenschmidt >>> CC: Paul Mackerras >>> CC: Christoph Lameter >>> Cc: Minchan Kim >>> CC: Andrew Morton >>> CC: KOSAKI Motohiro >>> CC: Wen Congyang >>> Signed-off-by: Yasuaki Ishimatsu >>> >>> --- >>> drivers/acpi/acpi_memhotplug.c | 2 +- >>> drivers/base/memory.c | 4 ++-- >>> include/linux/memory_hotplug.h | 2 +- >>> mm/memory_hotplug.c | 6 +++--- >>> 4 files changed, 7 insertions(+), 7 deletions(-) >>> >>> Index: linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c >>> =================================================================== >>> --- linux-3.5-rc4.orig/drivers/acpi/acpi_memhotplug.c 2012-06-25 04:53:04.000000000 +0900 >>> +++ linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c 2012-06-26 13:48:38.263940481 +0900 >>> @@ -318,7 +318,7 @@ static int acpi_memory_disable_device(st >>> */ >>> list_for_each_entry_safe(info, n, &mem_device->res_list, list) { >>> if (info->enabled) { >>> - result = remove_memory(info->start_addr, info->length); >>> + result = offline_memory(info->start_addr, info->length); >>> if (result) >>> return result; >>> } >>> Index: linux-3.5-rc4/drivers/base/memory.c >>> =================================================================== >>> --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-25 04:53:04.000000000 +0900 >>> +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:48:46.072842803 +0900 >>> @@ -266,8 +266,8 @@ memory_block_action(unsigned long phys_i >>> break; >>> case MEM_OFFLINE: >>> start_paddr = page_to_pfn(first_page) << PAGE_SHIFT; >>> - ret = remove_memory(start_paddr, >>> - nr_pages << PAGE_SHIFT); >>> + ret = offline_memory(start_paddr, >>> + nr_pages << PAGE_SHIFT); >>> break; >>> default: >>> WARN(1, KERN_WARNING "%s(%ld, %ld) unknown action: " >>> Index: linux-3.5-rc4/mm/memory_hotplug.c >>> =================================================================== >>> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-25 04:53:04.000000000 +0900 >>> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:46.072842803 +0900 >>> @@ -990,7 +990,7 @@ out: >>> return ret; >>> } >>> >>> -int remove_memory(u64 start, u64 size) >>> +int offline_memory(u64 start, u64 size) >>> { >>> unsigned long start_pfn, end_pfn; >>> >>> @@ -999,9 +999,9 @@ int remove_memory(u64 start, u64 size) >>> return offline_pages(start_pfn, end_pfn, 120 * HZ); >>> } >>> #else >>> -int remove_memory(u64 start, u64 size) >>> +int offline_memory(u64 start, u64 size) >>> { >>> return -EINVAL; >>> } >>> #endif /* CONFIG_MEMORY_HOTREMOVE */ >>> -EXPORT_SYMBOL_GPL(remove_memory); >>> +EXPORT_SYMBOL_GPL(offline_memory); >>> Index: linux-3.5-rc4/include/linux/memory_hotplug.h >>> =================================================================== >>> --- linux-3.5-rc4.orig/include/linux/memory_hotplug.h 2012-06-25 04:53:04.000000000 +0900 >>> +++ linux-3.5-rc4/include/linux/memory_hotplug.h 2012-06-26 13:48:38.264940468 +0900 >>> @@ -233,7 +233,7 @@ static inline int is_mem_section_removab >>> extern int mem_online_node(int nid); >>> extern int add_memory(int nid, u64 start, u64 size); >>> extern int arch_add_memory(int nid, u64 start, u64 size); >>> -extern int remove_memory(u64 start, u64 size); >>> +extern int offline_memory(u64 start, u64 size); >>> extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn, >>> int nr_pages); >>> extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms); >>> >>> >>> >>> -- >>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in >>> the body of a message to majordomo@vger.kernel.org >>> More majordomo info at http://vger.kernel.org/majordomo-info.html >>> Please read the FAQ at http://www.tux.org/lkml/ >>> >> >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >> Please read the FAQ at http://www.tux.org/lkml/ >> > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: email@kvack.org > -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wen Congyang Subject: Re: [RFC PATCH 1/12] memory-hotplug : rename remove_memory to offline_memory Date: Thu, 28 Jun 2012 11:25:16 +0800 Message-ID: <4FEBCE9C.7030904@cn.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9D5C.1080508@jp.fujitsu.com> <4FEAB2E1.3090200@cn.fujitsu.com> <4FEAC891.7030808@cn.fujitsu.com> <4FEBC8EE.7040207@jp.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit Return-path: Received: from cn.fujitsu.com ([222.73.24.84]:53238 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1753686Ab2F1DUw (ORCPT ); Wed, 27 Jun 2012 23:20:52 -0400 In-Reply-To: <4FEBC8EE.7040207@jp.fujitsu.com> Sender: linux-acpi-owner@vger.kernel.org List-Id: linux-acpi@vger.kernel.org To: Yasuaki Ishimatsu Cc: rientjes@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com At 06/28/2012 11:01 AM, Yasuaki Ishimatsu Wrote: > Hi David and Wen, > > Thank you for reviewing my patch. > > 2012/06/27 17:47, Wen Congyang wrote: >> At 06/27/2012 03:14 PM, Wen Congyang Wrote: >>> At 06/27/2012 01:42 PM, Yasuaki Ishimatsu Wrote: >>>> remove_memory() does not remove memory but just offlines memory. The patch >>>> changes name of it to offline_memory(). >>> >>> There are 3 functions in the kernel: >>> 1. add_memory() >>> 2. online_pages() >>> 3. remove_memory() >>> >>> So I think offline_pages() is better than offline_memory(). >> >> There is already a function named offline_pages(). So we >> should call offline_pages() instead of remove_memory() in >> memory_block_action(), and there is no need to rename >> remove_memory(). > > As Wen says, Linux has 4 functions for memory hotplug already. > In my recognition, these functions are prepared for following purpose. > > 1. add_memory : add physical memory > 2. online_pages : online logical memory > 3. remove_memory : offline logical memory > 4. offline_pages : offline logical memory > > add_memory() is used for adding physical memory. I think remove_memory() > would rather be used for removing physical memory than be used for removing > logical memory. So I renamed remove_memory() to offline_memory(). > How do you think? Hmm, remove_memory() will revert all things we do in add_memory(), so I think there is no need to rename it. If we rename it to offline_memory(), we should also rename add_memory() to online_memory(). Thanks Wen Congyang > > Regards, > Yasuaki Ishimatsu > >> >> Thanks >> Wen Congyang >> >>> >>> Thanks >>> Wen Congyang >>>> From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yasuaki Ishimatsu Subject: Re: [RFC PATCH 1/12] memory-hotplug : rename remove_memory to offline_memory Date: Thu, 28 Jun 2012 13:50:08 +0900 Message-ID: <4FEBE280.4060107@jp.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9D5C.1080508@jp.fujitsu.com> <4FEAB2E1.3090200@cn.fujitsu.com> <4FEAC891.7030808@cn.fujitsu.com> <4FEBC8EE.7040207@jp.fujitsu.com> <4FEBCE9C.7030904@cn.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Return-path: Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:50476 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750750Ab2F1Eun (ORCPT ); Thu, 28 Jun 2012 00:50:43 -0400 In-Reply-To: <4FEBCE9C.7030904@cn.fujitsu.com> Sender: linux-acpi-owner@vger.kernel.org List-Id: linux-acpi@vger.kernel.org To: Wen Congyang Cc: rientjes@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com Hi Wen, 2012/06/28 12:25, Wen Congyang wrote: > At 06/28/2012 11:01 AM, Yasuaki Ishimatsu Wrote: >> Hi David and Wen, >> >> Thank you for reviewing my patch. >> >> 2012/06/27 17:47, Wen Congyang wrote: >>> At 06/27/2012 03:14 PM, Wen Congyang Wrote: >>>> At 06/27/2012 01:42 PM, Yasuaki Ishimatsu Wrote: >>>>> remove_memory() does not remove memory but just offlines memory. The patch >>>>> changes name of it to offline_memory(). >>>> >>>> There are 3 functions in the kernel: >>>> 1. add_memory() >>>> 2. online_pages() >>>> 3. remove_memory() >>>> >>>> So I think offline_pages() is better than offline_memory(). >>> >>> There is already a function named offline_pages(). So we >>> should call offline_pages() instead of remove_memory() in >>> memory_block_action(), and there is no need to rename >>> remove_memory(). >> >> As Wen says, Linux has 4 functions for memory hotplug already. >> In my recognition, these functions are prepared for following purpose. >> >> 1. add_memory : add physical memory >> 2. online_pages : online logical memory >> 3. remove_memory : offline logical memory >> 4. offline_pages : offline logical memory >> >> add_memory() is used for adding physical memory. I think remove_memory() >> would rather be used for removing physical memory than be used for removing >> logical memory. So I renamed remove_memory() to offline_memory(). >> How do you think? > > Hmm, remove_memory() will revert all things we do in add_memory(), so I think I think so too. add_memory() prepares to use physical memory. It prepares some structures (pgdat, page table, node, etc) for using the physical memory at the system. But it does not online the meomory. For onlining the memory, we use online_pages(). So I think that remove_memory() should remove these structures which are prepared by add_memory() not offline memory. But current remove_memory() code only calls offline_pages() and offlines memory. The patch series recreates remove_memory() for removing these structures after [RFC PATCH 3/12]. The reason to change the name of remove_memory() is a preparation to recreate it. Thanks, Yasuaki Ishimatsu > there is no need to rename it. If we rename it to offline_memory(), we should > also rename add_memory() to online_memory(). > > Thanks > Wen Congyang > >> >> Regards, >> Yasuaki Ishimatsu >> >>> >>> Thanks >>> Wen Congyang >>> >>>> >>>> Thanks >>>> Wen Congyang >>>>> From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yasuaki Ishimatsu Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages Date: Thu, 28 Jun 2012 14:06:14 +0900 Message-ID: <4FEBE646.5090801@jp.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> <4FEAC916.7030506@cn.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Return-path: Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:37774 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751123Ab2F1FGl (ORCPT ); Thu, 28 Jun 2012 01:06:41 -0400 In-Reply-To: <4FEAC916.7030506@cn.fujitsu.com> Sender: linux-acpi-owner@vger.kernel.org List-Id: linux-acpi@vger.kernel.org To: Wen Congyang Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com Hi Wen, 2012/06/27 17:49, Wen Congyang wrote: > At 06/27/2012 01:44 PM, Yasuaki Ishimatsu Wrote: >> When offline_pages() is called to offlined memory, the function fails since >> all memory has been offlined. In this case, the function should succeed. >> The patch adds the check function into offline_pages(). > > You miss such case: some pages are online, while some pages are offline. > offline_pages() will fail too in such case. You are right. But current code fails, when the function is called to offline memory. In this case, the function should succeed. So the patch confirms whether the memory was offlined or not. And if memory has already been offlined, offline_pages return 0. Thanks, Yasuaki Ishimatsu > > Thanks > Wen Congyang > >> >> CC: Len Brown >> CC: Benjamin Herrenschmidt >> CC: Paul Mackerras >> CC: Christoph Lameter >> Cc: Minchan Kim >> CC: Andrew Morton >> CC: KOSAKI Motohiro >> CC: Wen Congyang >> Signed-off-by: Yasuaki Ishimatsu >> >> --- >> drivers/base/memory.c | 20 ++++++++++++++++++++ >> include/linux/memory.h | 1 + >> mm/memory_hotplug.c | 5 +++++ >> 3 files changed, 26 insertions(+) >> >> Index: linux-3.5-rc4/drivers/base/memory.c >> =================================================================== >> --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-26 13:28:16.726211752 +0900 >> +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:34:22.423639904 +0900 >> @@ -70,6 +70,26 @@ void unregister_memory_isolate_notifier( >> } >> EXPORT_SYMBOL(unregister_memory_isolate_notifier); >> >> +bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn) >> +{ >> + struct memory_block *mem; >> + struct mem_section *section; >> + unsigned long pfn, section_nr; >> + >> + for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { >> + section_nr = pfn_to_section_nr(pfn); >> + section = __nr_to_section(section_nr); >> + mem = find_memory_block(section); >> + if (!mem) >> + continue; >> + if (mem->state == MEM_OFFLINE) >> + continue; >> + return false; >> + } >> + >> + return true; >> +} >> + >> /* >> * register_memory - Setup a sysfs device for a memory block >> */ >> Index: linux-3.5-rc4/include/linux/memory.h >> =================================================================== >> --- linux-3.5-rc4.orig/include/linux/memory.h 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/include/linux/memory.h 2012-06-26 13:34:22.424639891 +0900 >> @@ -120,6 +120,7 @@ extern int memory_isolate_notify(unsigne >> extern struct memory_block *find_memory_block_hinted(struct mem_section *, >> struct memory_block *); >> extern struct memory_block *find_memory_block(struct mem_section *); >> +extern bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn); >> #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION<> enum mem_add_context { BOOT, HOTPLUG }; >> #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ >> Index: linux-3.5-rc4/mm/memory_hotplug.c >> =================================================================== >> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:28:16.743211538 +0900 >> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:38.264940468 +0900 >> @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned >> >> lock_memory_hotplug(); >> >> + if (memory_is_offline(start_pfn, end_pfn)) { >> + ret = 0; >> + goto out; >> + } >> + >> zone = page_zone(pfn_to_page(start_pfn)); >> node = zone_to_nid(zone); >> nr_pages = end_pfn - start_pfn; >> >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >> Please read the FAQ at http://www.tux.org/lkml/ >> > > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ > From mboxrd@z Thu Jan 1 00:00:00 1970 From: KOSAKI Motohiro Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages Date: Thu, 28 Jun 2012 01:26:21 -0400 Message-ID: References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Return-path: Received: from mail-yx0-f174.google.com ([209.85.213.174]:48499 "EHLO mail-yx0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751315Ab2F1F0l convert rfc822-to-8bit (ORCPT ); Thu, 28 Jun 2012 01:26:41 -0400 In-Reply-To: <4FEA9DB1.7010303@jp.fujitsu.com> Sender: linux-acpi-owner@vger.kernel.org List-Id: linux-acpi@vger.kernel.org To: Yasuaki Ishimatsu Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, wency@cn.fujitsu.com On Wed, Jun 27, 2012 at 1:44 AM, Yasuaki Ishimatsu wrote: > When offline_pages() is called to offlined memory, the function fails= since > all memory has been offlined. In this case, the function should succe= ed. > The patch adds the check function into offline_pages(). I don't understand your point. I think following misoperation should fail. Otherwise administrator have no way to know their fault. $ echo offline > memoryN/state $ echo offline > memoryN/state In general, we don't like to ignore an error except the standard requir= e it. > > CC: Len Brown > CC: Benjamin Herrenschmidt > CC: Paul Mackerras > CC: Christoph Lameter > Cc: Minchan Kim > CC: Andrew Morton > CC: KOSAKI Motohiro > CC: Wen Congyang > Signed-off-by: Yasuaki Ishimatsu > > --- > =A0drivers/base/memory.c =A0| =A0 20 ++++++++++++++++++++ > =A0include/linux/memory.h | =A0 =A01 + > =A0mm/memory_hotplug.c =A0 =A0| =A0 =A05 +++++ > =A03 files changed, 26 insertions(+) > > Index: linux-3.5-rc4/drivers/base/memory.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- linux-3.5-rc4.orig/drivers/base/memory.c =A0 =A02012-06-26 13:28:= 16.726211752 +0900 > +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:34:22.423639904= +0900 > @@ -70,6 +70,26 @@ void unregister_memory_isolate_notifier( > =A0} > =A0EXPORT_SYMBOL(unregister_memory_isolate_notifier); > > +bool memory_is_offline(unsigned long start_pfn, unsigned long end_pf= n) I dislike this function name. 'memory' is too vague to me. > +{ > + =A0 =A0 =A0 struct memory_block *mem; > + =A0 =A0 =A0 struct mem_section *section; > + =A0 =A0 =A0 unsigned long pfn, section_nr; > + > + =A0 =A0 =A0 for (pfn =3D start_pfn; pfn < end_pfn; pfn +=3D PAGES_P= ER_SECTION) { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 section_nr =3D pfn_to_section_nr(pfn); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 section =3D __nr_to_section(section_nr)= ; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 mem =3D find_memory_block(section); This seems to have strong sparse dependency. Hm, I wonder why memory-hotplug.c can enable when X86_64_ACPI_NUMA. # eventually, we can have this option just 'select SPARSEMEM' config MEMORY_HOTPLUG bool "Allow for memory hot-add" depends on SPARSEMEM || X86_64_ACPI_NUMA > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!mem) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 continue; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (mem->state =3D=3D MEM_OFFLINE) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 continue; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return false; > + =A0 =A0 =A0 } > + > + =A0 =A0 =A0 return true; > +} > + > =A0/* > =A0* register_memory - Setup a sysfs device for a memory block > =A0*/ > Index: linux-3.5-rc4/include/linux/memory.h > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- linux-3.5-rc4.orig/include/linux/memory.h =A0 2012-06-25 04:53:04= =2E000000000 +0900 > +++ linux-3.5-rc4/include/linux/memory.h =A0 =A0 =A0 =A02012-06-26 13= :34:22.424639891 +0900 > @@ -120,6 +120,7 @@ extern int memory_isolate_notify(unsigne > =A0extern struct memory_block *find_memory_block_hinted(struct mem_se= ction *, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0struct memory_block *); > =A0extern struct memory_block *find_memory_block(struct mem_section *= ); > +extern bool memory_is_offline(unsigned long start_pfn, unsigned long= end_pfn); > =A0#define CONFIG_MEM_BLOCK_SIZE =A0(PAGES_PER_SECTION< =A0enum mem_add_context { BOOT, HOTPLUG }; > =A0#endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ > Index: linux-3.5-rc4/mm/memory_hotplug.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- linux-3.5-rc4.orig/mm/memory_hotplug.c =A0 =A0 =A02012-06-26 13:2= 8:16.743211538 +0900 > +++ linux-3.5-rc4/mm/memory_hotplug.c =A0 2012-06-26 13:48:38.2649404= 68 +0900 > @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned > > =A0 =A0 =A0 =A0lock_memory_hotplug(); > > + =A0 =A0 =A0 if (memory_is_offline(start_pfn, end_pfn)) { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D 0; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out; > + =A0 =A0 =A0 } > + > =A0 =A0 =A0 =A0zone =3D page_zone(pfn_to_page(start_pfn)); > =A0 =A0 =A0 =A0node =3D zone_to_nid(zone); > =A0 =A0 =A0 =A0nr_pages =3D end_pfn - start_pfn; > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. =A0For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: email@kvack.org -- To unsubscribe from this list: send the line "unsubscribe linux-acpi" i= n the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html From mboxrd@z Thu Jan 1 00:00:00 1970 From: KOSAKI Motohiro Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages Date: Thu, 28 Jun 2012 01:27:35 -0400 Message-ID: References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> <4FEAC916.7030506@cn.fujitsu.com> <4FEBE646.5090801@jp.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Return-path: Received: from mail-yx0-f174.google.com ([209.85.213.174]:40049 "EHLO mail-yx0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750789Ab2F1F14 (ORCPT ); Thu, 28 Jun 2012 01:27:56 -0400 In-Reply-To: <4FEBE646.5090801@jp.fujitsu.com> Sender: linux-acpi-owner@vger.kernel.org List-Id: linux-acpi@vger.kernel.org To: Yasuaki Ishimatsu Cc: Wen Congyang , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org On Thu, Jun 28, 2012 at 1:06 AM, Yasuaki Ishimatsu wrote: > Hi Wen, > > 2012/06/27 17:49, Wen Congyang wrote: >> At 06/27/2012 01:44 PM, Yasuaki Ishimatsu Wrote: >>> When offline_pages() is called to offlined memory, the function fails since >>> all memory has been offlined. In this case, the function should succeed. >>> The patch adds the check function into offline_pages(). >> >> You miss such case: some pages are online, while some pages are offline. >> offline_pages() will fail too in such case. > > You are right. But current code fails, when the function is called to offline > memory. In this case, the function should succeed. So the patch confirms > whether the memory was offlined or not. And if memory has already been > offlined, offline_pages return 0. Can you please explain why the caller can't check it? I hope to avoid an ignorance as far as we can. From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yasuaki Ishimatsu Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages Date: Thu, 28 Jun 2012 15:01:38 +0900 Message-ID: <4FEBF342.9030303@jp.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> <4FEAC916.7030506@cn.fujitsu.com> <4FEBE646.5090801@jp.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit Return-path: Received: from fgwmail5.fujitsu.co.jp ([192.51.44.35]:53882 "EHLO fgwmail5.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750789Ab2F1GCD (ORCPT ); Thu, 28 Jun 2012 02:02:03 -0400 In-Reply-To: Sender: linux-acpi-owner@vger.kernel.org List-Id: linux-acpi@vger.kernel.org To: KOSAKI Motohiro Cc: Wen Congyang , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org Hi Kosaki-san, 2012/06/28 14:27, KOSAKI Motohiro wrote: > On Thu, Jun 28, 2012 at 1:06 AM, Yasuaki Ishimatsu > wrote: >> Hi Wen, >> >> 2012/06/27 17:49, Wen Congyang wrote: >>> At 06/27/2012 01:44 PM, Yasuaki Ishimatsu Wrote: >>>> When offline_pages() is called to offlined memory, the function fails since >>>> all memory has been offlined. In this case, the function should succeed. >>>> The patch adds the check function into offline_pages(). >>> >>> You miss such case: some pages are online, while some pages are offline. >>> offline_pages() will fail too in such case. >> >> You are right. But current code fails, when the function is called to offline >> memory. In this case, the function should succeed. So the patch confirms >> whether the memory was offlined or not. And if memory has already been >> offlined, offline_pages return 0. > > Can you please explain why the caller can't check it? I hope to avoid > an ignorance > as far as we can. Of course, caller side can check it. But there is a possibility that offline_pages() is called by many functions. So I do not think that it is good that all functions which call offline_pages() check it. Thanks, Yasuaki Ishimatsu From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wen Congyang Subject: Re: [RFC PATCH 4/12] memory-hotplug : remove /sys/firmware/memmap/X sysfs Date: Thu, 28 Jun 2012 14:32:45 +0800 Message-ID: <4FEBFA8D.5040607@cn.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9E5F.4070205@jp.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <4FEA9E5F.4070205@jp.fujitsu.com> Sender: linux-kernel-owner@vger.kernel.org To: Yasuaki Ishimatsu Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com List-Id: linux-acpi@vger.kernel.org At 06/27/2012 01:47 PM, Yasuaki Ishimatsu Wrote: > When (hot)adding memory into system, /sys/firmware/memmap/X/{end, start, type} > sysfs files are created. But there is no code to remove these files. The patch > implements the function to remove them. > > Note : The code does not free firmware_map_entry since there is no way to free > memory which is allocated by bootmem. > > CC: Len Brown > CC: Benjamin Herrenschmidt > CC: Paul Mackerras > CC: Christoph Lameter > Cc: Minchan Kim > CC: Andrew Morton > CC: KOSAKI Motohiro > CC: Wen Congyang > Signed-off-by: Yasuaki Ishimatsu > > --- > drivers/firmware/memmap.c | 71 +++++++++++++++++++++++++++++++++++++++++++ > include/linux/firmware-map.h | 6 +++ > mm/memory_hotplug.c | 6 +++ > 3 files changed, 82 insertions(+), 1 deletion(-) > > Index: linux-3.5-rc4/mm/memory_hotplug.c > =================================================================== > --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:37:30.546288901 +0900 > +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:44:37.069955820 +0900 > @@ -661,7 +661,11 @@ EXPORT_SYMBOL_GPL(add_memory); > > int remove_memory(int nid, u64 start, u64 size) > { > - return -EBUSY; > + lock_memory_hotplug(); > + /* remove memmap entry */ > + firmware_map_remove(start, start + size, "System RAM"); > + unlock_memory_hotplug(); > + return 0; > > } > EXPORT_SYMBOL_GPL(remove_memory); > Index: linux-3.5-rc4/include/linux/firmware-map.h > =================================================================== > --- linux-3.5-rc4.orig/include/linux/firmware-map.h 2012-06-25 04:53:04.000000000 +0900 > +++ linux-3.5-rc4/include/linux/firmware-map.h 2012-06-26 13:44:37.070955807 +0900 > @@ -25,6 +25,7 @@ > > int firmware_map_add_early(u64 start, u64 end, const char *type); > int firmware_map_add_hotplug(u64 start, u64 end, const char *type); > +int firmware_map_remove(u64 start, u64 end, const char *type); > > #else /* CONFIG_FIRMWARE_MEMMAP */ > > @@ -38,6 +39,11 @@ static inline int firmware_map_add_hotpl > return 0; > } > > +static inline int firmware_map_remove(u64 start, u64 end, const char *type) > +{ > + return 0; > +} > + > #endif /* CONFIG_FIRMWARE_MEMMAP */ > > #endif /* _LINUX_FIRMWARE_MAP_H */ > Index: linux-3.5-rc4/drivers/firmware/memmap.c > =================================================================== > --- linux-3.5-rc4.orig/drivers/firmware/memmap.c 2012-06-25 04:53:04.000000000 +0900 > +++ linux-3.5-rc4/drivers/firmware/memmap.c 2012-06-26 13:47:17.606948898 +0900 > @@ -123,6 +123,16 @@ static int firmware_map_add_entry(u64 st > return 0; > } > > +/** > + * firmware_map_remove_entry() - Does the real work to remove a firmware > + * memmap entry. > + * @entry: removed entry. > + **/ > +static inline void firmware_map_remove_entry(struct firmware_map_entry *entry) > +{ > + list_del(&entry->list); > +} > + > /* > * Add memmap entry on sysfs > */ > @@ -144,6 +154,31 @@ static int add_sysfs_fw_map_entry(struct > return 0; > } > > +/* > + * Remove memmap entry on sysfs > + */ > +static inline void remove_sysfs_fw_map_entry(struct firmware_map_entry *entry) > +{ > + kobject_del(&entry->kobj); > +} > + > +/* > + * Search memmap entry > + */ > + > +struct firmware_map_entry * __meminit > +find_firmware_map_entry(u64 start, u64 end, const char *type) > +{ > + struct firmware_map_entry *entry; > + > + list_for_each_entry(entry, &map_entries, list) > + if ((entry->start == start) && (entry->end == end) && > + (!strcmp(entry->type, type))) > + return entry; > + > + return NULL; > +} > + > /** > * firmware_map_add_hotplug() - Adds a firmware mapping entry when we do > * memory hotplug. > @@ -196,6 +231,42 @@ int __init firmware_map_add_early(u64 st > return firmware_map_add_entry(start, end, type, entry); > } > > +void release_firmware_map_entry(struct firmware_map_entry *entry) > +{ > + /* > + * FIXME : There is no idea. > + * How to free the entry which allocated bootmem? > + */ > +} > + > +/** > + * firmware_map_remove() - remove a firmware mapping entry > + * @start: Start of the memory range. > + * @end: End of the memory range (inclusive). > + * @type: Type of the memory range. > + * > + * removes a firmware mapping entry. > + * > + * Returns 0 on success, or -EINVAL if no entry. > + **/ > +int __meminit firmware_map_remove(u64 start, u64 end, const char *type) > +{ > + struct firmware_map_entry *entry; > + > + entry = find_firmware_map_entry(start, end, type); Hmm, we cannot find the entry easily, because the end can be: 1. start + size 2. start + size - 1 So, We should fix this bug first. > + if (!entry) > + return -EINVAL; > + > + /* remove the memmap entry */ > + remove_sysfs_fw_map_entry(entry); > + > + firmware_map_remove_entry(entry); > + > + release_firmware_map_entry(entry); I guess you want to free the memory in the above function. But I think it is not a good idea to free it here. We should free it when the entry->kobj's kref is decreased to 0. Thanks Wen Congyang > + > + return 0; > +} > + > /* > * Sysfs functions ------------------------------------------------------------- > */ > > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ > From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yasuaki Ishimatsu Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages Date: Thu, 28 Jun 2012 15:51:52 +0900 Message-ID: <4FEBFF08.60502@jp.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: Sender: owner-linux-mm@kvack.org To: KOSAKI Motohiro Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, wency@cn.fujitsu.com List-Id: linux-acpi@vger.kernel.org Hi Kosaki-san, 2012/06/28 14:26, KOSAKI Motohiro wrote: > On Wed, Jun 27, 2012 at 1:44 AM, Yasuaki Ishimatsu > wrote: >> When offline_pages() is called to offlined memory, the function fails since >> all memory has been offlined. In this case, the function should succeed. >> The patch adds the check function into offline_pages(). > > I don't understand your point. I think following misoperation should > fail. Otherwise > administrator have no way to know their fault. > > $ echo offline > memoryN/state > $ echo offline > memoryN/state > > In general, we don't like to ignore an error except the standard require it. I understood the intention of previous mail (why the caller can't check it? ). I'll move memory_is_offline() to caller side. >> >> CC: Len Brown >> CC: Benjamin Herrenschmidt >> CC: Paul Mackerras >> CC: Christoph Lameter >> Cc: Minchan Kim >> CC: Andrew Morton >> CC: KOSAKI Motohiro >> CC: Wen Congyang >> Signed-off-by: Yasuaki Ishimatsu >> >> --- >> drivers/base/memory.c | 20 ++++++++++++++++++++ >> include/linux/memory.h | 1 + >> mm/memory_hotplug.c | 5 +++++ >> 3 files changed, 26 insertions(+) >> >> Index: linux-3.5-rc4/drivers/base/memory.c >> =================================================================== >> --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-26 13:28:16.726211752 +0900 >> +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:34:22.423639904 +0900 >> @@ -70,6 +70,26 @@ void unregister_memory_isolate_notifier( >> } >> EXPORT_SYMBOL(unregister_memory_isolate_notifier); >> >> +bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn) > > I dislike this function name. 'memory' is too vague to me. O.K. I retry to change the name of the function. > > >> +{ >> + struct memory_block *mem; >> + struct mem_section *section; >> + unsigned long pfn, section_nr; >> + >> + for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { >> + section_nr = pfn_to_section_nr(pfn); >> + section = __nr_to_section(section_nr); >> + mem = find_memory_block(section); > > This seems to have strong sparse dependency. Thanks. I will consider other CONFIG_. Thanks. Yasuaki Ishimatsu > Hm, I wonder why memory-hotplug.c can enable when X86_64_ACPI_NUMA. > > # eventually, we can have this option just 'select SPARSEMEM' > config MEMORY_HOTPLUG > bool "Allow for memory hot-add" > depends on SPARSEMEM || X86_64_ACPI_NUMA > > >> + if (!mem) >> + continue; >> + if (mem->state == MEM_OFFLINE) >> + continue; >> + return false; >> + } >> + >> + return true; >> +} >> + >> /* >> * register_memory - Setup a sysfs device for a memory block >> */ >> Index: linux-3.5-rc4/include/linux/memory.h >> =================================================================== >> --- linux-3.5-rc4.orig/include/linux/memory.h 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/include/linux/memory.h 2012-06-26 13:34:22.424639891 +0900 >> @@ -120,6 +120,7 @@ extern int memory_isolate_notify(unsigne >> extern struct memory_block *find_memory_block_hinted(struct mem_section *, >> struct memory_block *); >> extern struct memory_block *find_memory_block(struct mem_section *); >> +extern bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn); >> #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION<> enum mem_add_context { BOOT, HOTPLUG }; >> #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ >> Index: linux-3.5-rc4/mm/memory_hotplug.c >> =================================================================== >> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:28:16.743211538 +0900 >> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:38.264940468 +0900 >> @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned >> >> lock_memory_hotplug(); >> >> + if (memory_is_offline(start_pfn, end_pfn)) { >> + ret = 0; >> + goto out; >> + } >> + >> zone = page_zone(pfn_to_page(start_pfn)); >> node = zone_to_nid(zone); >> nr_pages = end_pfn - start_pfn; >> >> -- >> To unsubscribe, send a message with 'unsubscribe linux-mm' in >> the body to majordomo@kvack.org. For more info on Linux MM, >> see: http://www.linux-mm.org/ . >> Don't email: email@kvack.org -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yasuaki Ishimatsu Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages Date: Thu, 28 Jun 2012 16:01:02 +0900 Message-ID: <4FEC012E.5030209@jp.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: Sender: owner-linux-mm@kvack.org To: David Rientjes Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com List-Id: linux-acpi@vger.kernel.org Hi David, 2012/06/27 15:16, David Rientjes wrote: > On Wed, 27 Jun 2012, Yasuaki Ishimatsu wrote: > >> Index: linux-3.5-rc4/mm/memory_hotplug.c >> =================================================================== >> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:28:16.743211538 +0900 >> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:38.264940468 +0900 >> @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned >> >> lock_memory_hotplug(); >> >> + if (memory_is_offline(start_pfn, end_pfn)) { >> + ret = 0; >> + goto out; >> + } >> + >> zone = page_zone(pfn_to_page(start_pfn)); >> node = zone_to_nid(zone); >> nr_pages = end_pfn - start_pfn; > > Are there additional prerequisites for this patch? Otherwise it changes > the return value of offline_memory() which will now call > acpi_memory_powerdown_device() in the acpi memhotplug case when disabling. > Is that a problem? I have understood there is a person who expects "offline_pages()" to fail in this case by kosaki's comment. So I'll move memory_is_offline to caller side. Thanks, Yasuaki Ishimatsu > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: email@kvack.org > -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yasuaki Ishimatsu Subject: Re: [RFC PATCH 4/12] memory-hotplug : remove /sys/firmware/memmap/X sysfs Date: Thu, 28 Jun 2012 17:07:39 +0900 Message-ID: <4FEC10CB.3060403@jp.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9E5F.4070205@jp.fujitsu.com> <4FEBFA8D.5040607@cn.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <4FEBFA8D.5040607@cn.fujitsu.com> Sender: owner-linux-mm@kvack.org To: Wen Congyang Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com List-Id: linux-acpi@vger.kernel.org Hi Wen, 2012/06/28 15:32, Wen Congyang wrote: > At 06/27/2012 01:47 PM, Yasuaki Ishimatsu Wrote: >> When (hot)adding memory into system, /sys/firmware/memmap/X/{end, start, type} >> sysfs files are created. But there is no code to remove these files. The patch >> implements the function to remove them. >> >> Note : The code does not free firmware_map_entry since there is no way to free >> memory which is allocated by bootmem. >> >> CC: Len Brown >> CC: Benjamin Herrenschmidt >> CC: Paul Mackerras >> CC: Christoph Lameter >> Cc: Minchan Kim >> CC: Andrew Morton >> CC: KOSAKI Motohiro >> CC: Wen Congyang >> Signed-off-by: Yasuaki Ishimatsu >> >> --- >> drivers/firmware/memmap.c | 71 +++++++++++++++++++++++++++++++++++++++++++ >> include/linux/firmware-map.h | 6 +++ >> mm/memory_hotplug.c | 6 +++ >> 3 files changed, 82 insertions(+), 1 deletion(-) >> >> Index: linux-3.5-rc4/mm/memory_hotplug.c >> =================================================================== >> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:37:30.546288901 +0900 >> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:44:37.069955820 +0900 >> @@ -661,7 +661,11 @@ EXPORT_SYMBOL_GPL(add_memory); >> >> int remove_memory(int nid, u64 start, u64 size) >> { >> - return -EBUSY; >> + lock_memory_hotplug(); >> + /* remove memmap entry */ >> + firmware_map_remove(start, start + size, "System RAM"); >> + unlock_memory_hotplug(); >> + return 0; >> >> } >> EXPORT_SYMBOL_GPL(remove_memory); >> Index: linux-3.5-rc4/include/linux/firmware-map.h >> =================================================================== >> --- linux-3.5-rc4.orig/include/linux/firmware-map.h 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/include/linux/firmware-map.h 2012-06-26 13:44:37.070955807 +0900 >> @@ -25,6 +25,7 @@ >> >> int firmware_map_add_early(u64 start, u64 end, const char *type); >> int firmware_map_add_hotplug(u64 start, u64 end, const char *type); >> +int firmware_map_remove(u64 start, u64 end, const char *type); >> >> #else /* CONFIG_FIRMWARE_MEMMAP */ >> >> @@ -38,6 +39,11 @@ static inline int firmware_map_add_hotpl >> return 0; >> } >> >> +static inline int firmware_map_remove(u64 start, u64 end, const char *type) >> +{ >> + return 0; >> +} >> + >> #endif /* CONFIG_FIRMWARE_MEMMAP */ >> >> #endif /* _LINUX_FIRMWARE_MAP_H */ >> Index: linux-3.5-rc4/drivers/firmware/memmap.c >> =================================================================== >> --- linux-3.5-rc4.orig/drivers/firmware/memmap.c 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/drivers/firmware/memmap.c 2012-06-26 13:47:17.606948898 +0900 >> @@ -123,6 +123,16 @@ static int firmware_map_add_entry(u64 st >> return 0; >> } >> >> +/** >> + * firmware_map_remove_entry() - Does the real work to remove a firmware >> + * memmap entry. >> + * @entry: removed entry. >> + **/ >> +static inline void firmware_map_remove_entry(struct firmware_map_entry *entry) >> +{ >> + list_del(&entry->list); >> +} >> + >> /* >> * Add memmap entry on sysfs >> */ >> @@ -144,6 +154,31 @@ static int add_sysfs_fw_map_entry(struct >> return 0; >> } >> >> +/* >> + * Remove memmap entry on sysfs >> + */ >> +static inline void remove_sysfs_fw_map_entry(struct firmware_map_entry *entry) >> +{ >> + kobject_del(&entry->kobj); >> +} >> + >> +/* >> + * Search memmap entry >> + */ >> + >> +struct firmware_map_entry * __meminit >> +find_firmware_map_entry(u64 start, u64 end, const char *type) >> +{ >> + struct firmware_map_entry *entry; >> + >> + list_for_each_entry(entry, &map_entries, list) >> + if ((entry->start == start) && (entry->end == end) && >> + (!strcmp(entry->type, type))) >> + return entry; >> + >> + return NULL; >> +} >> + >> /** >> * firmware_map_add_hotplug() - Adds a firmware mapping entry when we do >> * memory hotplug. >> @@ -196,6 +231,42 @@ int __init firmware_map_add_early(u64 st >> return firmware_map_add_entry(start, end, type, entry); >> } >> >> +void release_firmware_map_entry(struct firmware_map_entry *entry) >> +{ >> + /* >> + * FIXME : There is no idea. >> + * How to free the entry which allocated bootmem? >> + */ >> +} >> + >> +/** >> + * firmware_map_remove() - remove a firmware mapping entry >> + * @start: Start of the memory range. >> + * @end: End of the memory range (inclusive). >> + * @type: Type of the memory range. >> + * >> + * removes a firmware mapping entry. >> + * >> + * Returns 0 on success, or -EINVAL if no entry. >> + **/ >> +int __meminit firmware_map_remove(u64 start, u64 end, const char *type) >> +{ >> + struct firmware_map_entry *entry; >> + >> + entry = find_firmware_map_entry(start, end, type); > > Hmm, we cannot find the entry easily, because the end can be: > 1. start + size > 2. start + size - 1 > > So, We should fix this bug first. This is not a bug. start and size arguments of firmware_map_remove() include acpi_memory_info->{start_addr, length}. And when creating a firmware_map_entry, the entry is created by acpi_memory_info->{start_addr, length}. So I don't think that we need care your comment. > >> + if (!entry) >> + return -EINVAL; >> + >> + /* remove the memmap entry */ >> + remove_sysfs_fw_map_entry(entry); >> + >> + firmware_map_remove_entry(entry); >> + >> + release_firmware_map_entry(entry); > > I guess you want to free the memory in the above function. But I think it is > not a good idea to free it here. We should free it when the entry->kobj's kref > is decreased to 0. Thanks. I'll update your comment at next version. Thanks, Yasuaki Ishimatsu > > Thanks > Wen Congyang > >> + >> + return 0; >> +} >> + >> /* >> * Sysfs functions ------------------------------------------------------------- >> */ >> >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >> Please read the FAQ at http://www.tux.org/lkml/ >> > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: email@kvack.org > -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wen Congyang Subject: Re: [RFC PATCH 4/12] memory-hotplug : remove /sys/firmware/memmap/X sysfs Date: Thu, 28 Jun 2012 16:38:16 +0800 Message-ID: <4FEC17F8.1000405@cn.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9E5F.4070205@jp.fujitsu.com> <4FEBFA8D.5040607@cn.fujitsu.com> <4FEC10CB.3060403@jp.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <4FEC10CB.3060403@jp.fujitsu.com> Sender: owner-linux-mm@kvack.org To: Yasuaki Ishimatsu Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com List-Id: linux-acpi@vger.kernel.org At 06/28/2012 04:07 PM, Yasuaki Ishimatsu Wrote: > Hi Wen, > > 2012/06/28 15:32, Wen Congyang wrote: >> At 06/27/2012 01:47 PM, Yasuaki Ishimatsu Wrote: >>> When (hot)adding memory into system, /sys/firmware/memmap/X/{end, >>> start, type} >>> sysfs files are created. But there is no code to remove these files. >>> The patch >>> implements the function to remove them. >>> >>> Note : The code does not free firmware_map_entry since there is no >>> way to free >>> memory which is allocated by bootmem. >>> >>> CC: Len Brown >>> CC: Benjamin Herrenschmidt >>> CC: Paul Mackerras >>> CC: Christoph Lameter >>> Cc: Minchan Kim >>> CC: Andrew Morton >>> CC: KOSAKI Motohiro >>> CC: Wen Congyang >>> Signed-off-by: Yasuaki Ishimatsu >>> >>> --- >>> drivers/firmware/memmap.c | 71 >>> +++++++++++++++++++++++++++++++++++++++++++ >>> include/linux/firmware-map.h | 6 +++ >>> mm/memory_hotplug.c | 6 +++ >>> 3 files changed, 82 insertions(+), 1 deletion(-) >>> >>> Index: linux-3.5-rc4/mm/memory_hotplug.c >>> =================================================================== >>> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 >>> 13:37:30.546288901 +0900 >>> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 >>> 13:44:37.069955820 +0900 >>> @@ -661,7 +661,11 @@ EXPORT_SYMBOL_GPL(add_memory); >>> >>> int remove_memory(int nid, u64 start, u64 size) >>> { >>> - return -EBUSY; >>> + lock_memory_hotplug(); >>> + /* remove memmap entry */ >>> + firmware_map_remove(start, start + size, "System RAM"); >>> + unlock_memory_hotplug(); >>> + return 0; >>> >>> } >>> EXPORT_SYMBOL_GPL(remove_memory); >>> Index: linux-3.5-rc4/include/linux/firmware-map.h >>> =================================================================== >>> --- linux-3.5-rc4.orig/include/linux/firmware-map.h 2012-06-25 >>> 04:53:04.000000000 +0900 >>> +++ linux-3.5-rc4/include/linux/firmware-map.h 2012-06-26 >>> 13:44:37.070955807 +0900 >>> @@ -25,6 +25,7 @@ >>> >>> int firmware_map_add_early(u64 start, u64 end, const char *type); >>> int firmware_map_add_hotplug(u64 start, u64 end, const char *type); >>> +int firmware_map_remove(u64 start, u64 end, const char *type); >>> >>> #else /* CONFIG_FIRMWARE_MEMMAP */ >>> >>> @@ -38,6 +39,11 @@ static inline int firmware_map_add_hotpl >>> return 0; >>> } >>> >>> +static inline int firmware_map_remove(u64 start, u64 end, const char >>> *type) >>> +{ >>> + return 0; >>> +} >>> + >>> #endif /* CONFIG_FIRMWARE_MEMMAP */ >>> >>> #endif /* _LINUX_FIRMWARE_MAP_H */ >>> Index: linux-3.5-rc4/drivers/firmware/memmap.c >>> =================================================================== >>> --- linux-3.5-rc4.orig/drivers/firmware/memmap.c 2012-06-25 >>> 04:53:04.000000000 +0900 >>> +++ linux-3.5-rc4/drivers/firmware/memmap.c 2012-06-26 >>> 13:47:17.606948898 +0900 >>> @@ -123,6 +123,16 @@ static int firmware_map_add_entry(u64 st >>> return 0; >>> } >>> >>> +/** >>> + * firmware_map_remove_entry() - Does the real work to remove a >>> firmware >>> + * memmap entry. >>> + * @entry: removed entry. >>> + **/ >>> +static inline void firmware_map_remove_entry(struct >>> firmware_map_entry *entry) >>> +{ >>> + list_del(&entry->list); >>> +} >>> + >>> /* >>> * Add memmap entry on sysfs >>> */ >>> @@ -144,6 +154,31 @@ static int add_sysfs_fw_map_entry(struct >>> return 0; >>> } >>> >>> +/* >>> + * Remove memmap entry on sysfs >>> + */ >>> +static inline void remove_sysfs_fw_map_entry(struct >>> firmware_map_entry *entry) >>> +{ >>> + kobject_del(&entry->kobj); >>> +} >>> + >>> +/* >>> + * Search memmap entry >>> + */ >>> + >>> +struct firmware_map_entry * __meminit >>> +find_firmware_map_entry(u64 start, u64 end, const char *type) >>> +{ >>> + struct firmware_map_entry *entry; >>> + >>> + list_for_each_entry(entry, &map_entries, list) >>> + if ((entry->start == start) && (entry->end == end) && >>> + (!strcmp(entry->type, type))) >>> + return entry; >>> + >>> + return NULL; >>> +} >>> + >>> /** >>> * firmware_map_add_hotplug() - Adds a firmware mapping entry when >>> we do >>> * memory hotplug. >>> @@ -196,6 +231,42 @@ int __init firmware_map_add_early(u64 st >>> return firmware_map_add_entry(start, end, type, entry); >>> } >>> >>> +void release_firmware_map_entry(struct firmware_map_entry *entry) >>> +{ >>> + /* >>> + * FIXME : There is no idea. >>> + * How to free the entry which allocated bootmem? >>> + */ >>> +} >>> + >>> +/** >>> + * firmware_map_remove() - remove a firmware mapping entry >>> + * @start: Start of the memory range. >>> + * @end: End of the memory range (inclusive). >>> + * @type: Type of the memory range. >>> + * >>> + * removes a firmware mapping entry. >>> + * >>> + * Returns 0 on success, or -EINVAL if no entry. >>> + **/ >>> +int __meminit firmware_map_remove(u64 start, u64 end, const char *type) >>> +{ >>> + struct firmware_map_entry *entry; >>> + >>> + entry = find_firmware_map_entry(start, end, type); >> >> Hmm, we cannot find the entry easily, because the end can be: >> 1. start + size >> 2. start + size - 1 >> >> So, We should fix this bug first. > > This is not a bug. > > start and size arguments of firmware_map_remove() include > acpi_memory_info->{start_addr, length}. And when creating a > firmware_map_entry, > the entry is created by acpi_memory_info->{start_addr, length}. So I don't > think that we need care your comment. If the memory device is hotpluged before the os starts, and the memory map is included in e820 map, the entry will be created by firmware_map_add_early(). The function firmware_map_add_early() is called by e820_reserve_resources(): ===================== for (i = 0; i < e820_saved.nr_map; i++) { struct e820entry *entry = &e820_saved.map[i]; firmware_map_add_early(entry->addr, entry->addr + entry->size - 1, e820_type_to_string(entry->type)); } ===================== Note: the end is addr + size - 1, not addr + size. In such case, you cannot find the entry. Thanks Wen Congyang > >> >>> + if (!entry) >>> + return -EINVAL; >>> + >>> + /* remove the memmap entry */ >>> + remove_sysfs_fw_map_entry(entry); >>> + >>> + firmware_map_remove_entry(entry); >>> + >>> + release_firmware_map_entry(entry); >> >> I guess you want to free the memory in the above function. But I think >> it is >> not a good idea to free it here. We should free it when the >> entry->kobj's kref >> is decreased to 0. > > Thanks. > I'll update your comment at next version. > > Thanks, > Yasuaki Ishimatsu > >> >> Thanks >> Wen Congyang >> >>> + >>> + return 0; >>> +} >>> + >>> /* >>> * Sysfs functions >>> ------------------------------------------------------------- >>> */ >>> >>> -- >>> To unsubscribe from this list: send the line "unsubscribe >>> linux-kernel" in >>> the body of a message to majordomo@vger.kernel.org >>> More majordomo info at http://vger.kernel.org/majordomo-info.html >>> Please read the FAQ at http://www.tux.org/lkml/ >>> >> >> -- >> To unsubscribe, send a message with 'unsubscribe linux-mm' in >> the body to majordomo@kvack.org. For more info on Linux MM, >> see: http://www.linux-mm.org/ . >> Don't email: email@kvack.org >> > > > > -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yasuaki Ishimatsu Subject: Re: [RFC PATCH 4/12] memory-hotplug : remove /sys/firmware/memmap/X sysfs Date: Fri, 29 Jun 2012 12:09:25 +0900 Message-ID: <4FED1C65.7010902@jp.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9E5F.4070205@jp.fujitsu.com> <4FEBFA8D.5040607@cn.fujitsu.com> <4FEC10CB.3060403@jp.fujitsu.com> <4FEC17F8.1000405@cn.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <4FEC17F8.1000405@cn.fujitsu.com> Sender: owner-linux-mm@kvack.org To: Wen Congyang Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com List-Id: linux-acpi@vger.kernel.org Hi Wen, 2012/06/28 17:38, Wen Congyang wrote: > At 06/28/2012 04:07 PM, Yasuaki Ishimatsu Wrote: >> Hi Wen, >> >> 2012/06/28 15:32, Wen Congyang wrote: >>> At 06/27/2012 01:47 PM, Yasuaki Ishimatsu Wrote: >>>> When (hot)adding memory into system, /sys/firmware/memmap/X/{end, >>>> start, type} >>>> sysfs files are created. But there is no code to remove these files. >>>> The patch >>>> implements the function to remove them. >>>> >>>> Note : The code does not free firmware_map_entry since there is no >>>> way to free >>>> memory which is allocated by bootmem. >>>> >>>> CC: Len Brown >>>> CC: Benjamin Herrenschmidt >>>> CC: Paul Mackerras >>>> CC: Christoph Lameter >>>> Cc: Minchan Kim >>>> CC: Andrew Morton >>>> CC: KOSAKI Motohiro >>>> CC: Wen Congyang >>>> Signed-off-by: Yasuaki Ishimatsu >>>> >>>> --- >>>> drivers/firmware/memmap.c | 71 >>>> +++++++++++++++++++++++++++++++++++++++++++ >>>> include/linux/firmware-map.h | 6 +++ >>>> mm/memory_hotplug.c | 6 +++ >>>> 3 files changed, 82 insertions(+), 1 deletion(-) >>>> >>>> Index: linux-3.5-rc4/mm/memory_hotplug.c >>>> =================================================================== >>>> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 >>>> 13:37:30.546288901 +0900 >>>> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 >>>> 13:44:37.069955820 +0900 >>>> @@ -661,7 +661,11 @@ EXPORT_SYMBOL_GPL(add_memory); >>>> >>>> int remove_memory(int nid, u64 start, u64 size) >>>> { >>>> - return -EBUSY; >>>> + lock_memory_hotplug(); >>>> + /* remove memmap entry */ >>>> + firmware_map_remove(start, start + size, "System RAM"); >>>> + unlock_memory_hotplug(); >>>> + return 0; >>>> >>>> } >>>> EXPORT_SYMBOL_GPL(remove_memory); >>>> Index: linux-3.5-rc4/include/linux/firmware-map.h >>>> =================================================================== >>>> --- linux-3.5-rc4.orig/include/linux/firmware-map.h 2012-06-25 >>>> 04:53:04.000000000 +0900 >>>> +++ linux-3.5-rc4/include/linux/firmware-map.h 2012-06-26 >>>> 13:44:37.070955807 +0900 >>>> @@ -25,6 +25,7 @@ >>>> >>>> int firmware_map_add_early(u64 start, u64 end, const char *type); >>>> int firmware_map_add_hotplug(u64 start, u64 end, const char *type); >>>> +int firmware_map_remove(u64 start, u64 end, const char *type); >>>> >>>> #else /* CONFIG_FIRMWARE_MEMMAP */ >>>> >>>> @@ -38,6 +39,11 @@ static inline int firmware_map_add_hotpl >>>> return 0; >>>> } >>>> >>>> +static inline int firmware_map_remove(u64 start, u64 end, const char >>>> *type) >>>> +{ >>>> + return 0; >>>> +} >>>> + >>>> #endif /* CONFIG_FIRMWARE_MEMMAP */ >>>> >>>> #endif /* _LINUX_FIRMWARE_MAP_H */ >>>> Index: linux-3.5-rc4/drivers/firmware/memmap.c >>>> =================================================================== >>>> --- linux-3.5-rc4.orig/drivers/firmware/memmap.c 2012-06-25 >>>> 04:53:04.000000000 +0900 >>>> +++ linux-3.5-rc4/drivers/firmware/memmap.c 2012-06-26 >>>> 13:47:17.606948898 +0900 >>>> @@ -123,6 +123,16 @@ static int firmware_map_add_entry(u64 st >>>> return 0; >>>> } >>>> >>>> +/** >>>> + * firmware_map_remove_entry() - Does the real work to remove a >>>> firmware >>>> + * memmap entry. >>>> + * @entry: removed entry. >>>> + **/ >>>> +static inline void firmware_map_remove_entry(struct >>>> firmware_map_entry *entry) >>>> +{ >>>> + list_del(&entry->list); >>>> +} >>>> + >>>> /* >>>> * Add memmap entry on sysfs >>>> */ >>>> @@ -144,6 +154,31 @@ static int add_sysfs_fw_map_entry(struct >>>> return 0; >>>> } >>>> >>>> +/* >>>> + * Remove memmap entry on sysfs >>>> + */ >>>> +static inline void remove_sysfs_fw_map_entry(struct >>>> firmware_map_entry *entry) >>>> +{ >>>> + kobject_del(&entry->kobj); >>>> +} >>>> + >>>> +/* >>>> + * Search memmap entry >>>> + */ >>>> + >>>> +struct firmware_map_entry * __meminit >>>> +find_firmware_map_entry(u64 start, u64 end, const char *type) >>>> +{ >>>> + struct firmware_map_entry *entry; >>>> + >>>> + list_for_each_entry(entry, &map_entries, list) >>>> + if ((entry->start == start) && (entry->end == end) && >>>> + (!strcmp(entry->type, type))) >>>> + return entry; >>>> + >>>> + return NULL; >>>> +} >>>> + >>>> /** >>>> * firmware_map_add_hotplug() - Adds a firmware mapping entry when >>>> we do >>>> * memory hotplug. >>>> @@ -196,6 +231,42 @@ int __init firmware_map_add_early(u64 st >>>> return firmware_map_add_entry(start, end, type, entry); >>>> } >>>> >>>> +void release_firmware_map_entry(struct firmware_map_entry *entry) >>>> +{ >>>> + /* >>>> + * FIXME : There is no idea. >>>> + * How to free the entry which allocated bootmem? >>>> + */ >>>> +} >>>> + >>>> +/** >>>> + * firmware_map_remove() - remove a firmware mapping entry >>>> + * @start: Start of the memory range. >>>> + * @end: End of the memory range (inclusive). >>>> + * @type: Type of the memory range. >>>> + * >>>> + * removes a firmware mapping entry. >>>> + * >>>> + * Returns 0 on success, or -EINVAL if no entry. >>>> + **/ >>>> +int __meminit firmware_map_remove(u64 start, u64 end, const char *type) >>>> +{ >>>> + struct firmware_map_entry *entry; >>>> + >>>> + entry = find_firmware_map_entry(start, end, type); >>> >>> Hmm, we cannot find the entry easily, because the end can be: >>> 1. start + size >>> 2. start + size - 1 >>> >>> So, We should fix this bug first. >> >> This is not a bug. >> >> start and size arguments of firmware_map_remove() include >> acpi_memory_info->{start_addr, length}. And when creating a >> firmware_map_entry, >> the entry is created by acpi_memory_info->{start_addr, length}. So I don't >> think that we need care your comment. > > If the memory device is hotpluged before the os starts, and the memory > map is included in e820 map, the entry will be created by firmware_map_add_early(). > > The function firmware_map_add_early() is called by e820_reserve_resources(): > ===================== > for (i = 0; i < e820_saved.nr_map; i++) { > struct e820entry *entry = &e820_saved.map[i]; > firmware_map_add_early(entry->addr, > entry->addr + entry->size - 1, > e820_type_to_string(entry->type)); > } > ===================== > > Note: the end is addr + size - 1, not addr + size. > > In such case, you cannot find the entry. Thank you for your explanation. I understood it. end argument of firmware_map_add_hotplug() has always "addr + size", not "addr + size - 1". I think that changing argument of firmware_map_add_early() is high risk since the function has been used since early times. So, I will unify to "addr + size - 1". Thanks, Yasuaki Ishimatsu > Thanks > Wen Congyang > >> >>> >>>> + if (!entry) >>>> + return -EINVAL; >>>> + >>>> + /* remove the memmap entry */ >>>> + remove_sysfs_fw_map_entry(entry); >>>> + >>>> + firmware_map_remove_entry(entry); >>>> + >>>> + release_firmware_map_entry(entry); >>> >>> I guess you want to free the memory in the above function. But I think >>> it is >>> not a good idea to free it here. We should free it when the >>> entry->kobj's kref >>> is decreased to 0. >> >> Thanks. >> I'll update your comment at next version. >> >> Thanks, >> Yasuaki Ishimatsu >> >>> >>> Thanks >>> Wen Congyang >>> >>>> + >>>> + return 0; >>>> +} >>>> + >>>> /* >>>> * Sysfs functions >>>> ------------------------------------------------------------- >>>> */ >>>> >>>> -- >>>> To unsubscribe from this list: send the line "unsubscribe >>>> linux-kernel" in >>>> the body of a message to majordomo@vger.kernel.org >>>> More majordomo info at http://vger.kernel.org/majordomo-info.html >>>> Please read the FAQ at http://www.tux.org/lkml/ >>>> >>> >>> -- >>> To unsubscribe, send a message with 'unsubscribe linux-mm' in >>> the body to majordomo@kvack.org. For more info on Linux MM, >>> see: http://www.linux-mm.org/ . >>> Don't email: email@kvack.org >>> >> >> >> >> > > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ > -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jiang Liu Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages Date: Sat, 30 Jun 2012 23:46:50 +0800 Message-ID: <4FEF1F6A.6090705@gmail.com> References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit Return-path: Received: from mail-pz0-f46.google.com ([209.85.210.46]:48423 "EHLO mail-pz0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751155Ab2F3PrI (ORCPT ); Sat, 30 Jun 2012 11:47:08 -0400 In-Reply-To: <4FEA9DB1.7010303@jp.fujitsu.com> Sender: linux-acpi-owner@vger.kernel.org List-Id: linux-acpi@vger.kernel.org To: Yasuaki Ishimatsu Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com On 06/27/2012 01:44 PM, Yasuaki Ishimatsu wrote: > When offline_pages() is called to offlined memory, the function fails since > all memory has been offlined. In this case, the function should succeed. > The patch adds the check function into offline_pages(). > > CC: Len Brown > CC: Benjamin Herrenschmidt > CC: Paul Mackerras > CC: Christoph Lameter > Cc: Minchan Kim > CC: Andrew Morton > CC: KOSAKI Motohiro > CC: Wen Congyang > Signed-off-by: Yasuaki Ishimatsu > > --- > drivers/base/memory.c | 20 ++++++++++++++++++++ > include/linux/memory.h | 1 + > mm/memory_hotplug.c | 5 +++++ > 3 files changed, 26 insertions(+) > > Index: linux-3.5-rc4/drivers/base/memory.c > =================================================================== > --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-26 13:28:16.726211752 +0900 > +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:34:22.423639904 +0900 > @@ -70,6 +70,26 @@ void unregister_memory_isolate_notifier( > } > EXPORT_SYMBOL(unregister_memory_isolate_notifier); > > +bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn) > +{ > + struct memory_block *mem; > + struct mem_section *section; > + unsigned long pfn, section_nr; > + > + for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { > + section_nr = pfn_to_section_nr(pfn); > + section = __nr_to_section(section_nr); Is it possible for __nr_to_section return NULL here? > + mem = find_memory_block(section); > + if (!mem) > + continue; > + if (mem->state == MEM_OFFLINE) > + continue; > + return false; > + } > + > + return true; > +} Need a put_dev(&mem->dev) for the last memory block device handled before return. > + > /* > * register_memory - Setup a sysfs device for a memory block > */ > Index: linux-3.5-rc4/include/linux/memory.h > =================================================================== > --- linux-3.5-rc4.orig/include/linux/memory.h 2012-06-25 04:53:04.000000000 +0900 > +++ linux-3.5-rc4/include/linux/memory.h 2012-06-26 13:34:22.424639891 +0900 > @@ -120,6 +120,7 @@ extern int memory_isolate_notify(unsigne > extern struct memory_block *find_memory_block_hinted(struct mem_section *, > struct memory_block *); > extern struct memory_block *find_memory_block(struct mem_section *); > +extern bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn); > #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION< enum mem_add_context { BOOT, HOTPLUG }; > #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ > Index: linux-3.5-rc4/mm/memory_hotplug.c > =================================================================== > --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:28:16.743211538 +0900 > +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:38.264940468 +0900 > @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned > > lock_memory_hotplug(); > > + if (memory_is_offline(start_pfn, end_pfn)) { > + ret = 0; > + goto out; > + } > + > zone = page_zone(pfn_to_page(start_pfn)); > node = zone_to_nid(zone); > nr_pages = end_pfn - start_pfn; > > -- > To unsubscribe from this list: send the line "unsubscribe linux-acpi" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jiang Liu Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages Date: Sat, 30 Jun 2012 23:51:17 +0800 Message-ID: <4FEF2075.2050603@gmail.com> References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit Return-path: Received: from mail-pz0-f46.google.com ([209.85.210.46]:57843 "EHLO mail-pz0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751155Ab2F3Pvb (ORCPT ); Sat, 30 Jun 2012 11:51:31 -0400 In-Reply-To: <4FEA9DB1.7010303@jp.fujitsu.com> Sender: linux-acpi-owner@vger.kernel.org List-Id: linux-acpi@vger.kernel.org To: Yasuaki Ishimatsu Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com On 06/27/2012 01:44 PM, Yasuaki Ishimatsu wrote: > When offline_pages() is called to offlined memory, the function fails since > all memory has been offlined. In this case, the function should succeed. > The patch adds the check function into offline_pages(). > > CC: Len Brown > CC: Benjamin Herrenschmidt > CC: Paul Mackerras > CC: Christoph Lameter > Cc: Minchan Kim > CC: Andrew Morton > CC: KOSAKI Motohiro > CC: Wen Congyang > Signed-off-by: Yasuaki Ishimatsu > > --- > drivers/base/memory.c | 20 ++++++++++++++++++++ > include/linux/memory.h | 1 + > mm/memory_hotplug.c | 5 +++++ > 3 files changed, 26 insertions(+) > > Index: linux-3.5-rc4/drivers/base/memory.c > =================================================================== > --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-26 13:28:16.726211752 +0900 > +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:34:22.423639904 +0900 > @@ -70,6 +70,26 @@ void unregister_memory_isolate_notifier( > } > EXPORT_SYMBOL(unregister_memory_isolate_notifier); > > +bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn) > +{ > + struct memory_block *mem; > + struct mem_section *section; > + unsigned long pfn, section_nr; > + > + for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { > + section_nr = pfn_to_section_nr(pfn); > + section = __nr_to_section(section_nr); > + mem = find_memory_block(section); Seems find_memory_block_hinted() is more efficient than find_memory_block() here. > + if (!mem) > + continue; > + if (mem->state == MEM_OFFLINE) > + continue; > + return false; > + } > + > + return true; > +} > + > /* > * register_memory - Setup a sysfs device for a memory block > */ > Index: linux-3.5-rc4/include/linux/memory.h > =================================================================== > --- linux-3.5-rc4.orig/include/linux/memory.h 2012-06-25 04:53:04.000000000 +0900 > +++ linux-3.5-rc4/include/linux/memory.h 2012-06-26 13:34:22.424639891 +0900 > @@ -120,6 +120,7 @@ extern int memory_isolate_notify(unsigne > extern struct memory_block *find_memory_block_hinted(struct mem_section *, > struct memory_block *); > extern struct memory_block *find_memory_block(struct mem_section *); > +extern bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn); > #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION< enum mem_add_context { BOOT, HOTPLUG }; > #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ > Index: linux-3.5-rc4/mm/memory_hotplug.c > =================================================================== > --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:28:16.743211538 +0900 > +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:38.264940468 +0900 > @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned > > lock_memory_hotplug(); > > + if (memory_is_offline(start_pfn, end_pfn)) { > + ret = 0; > + goto out; > + } > + > zone = page_zone(pfn_to_page(start_pfn)); > node = zone_to_nid(zone); > nr_pages = end_pfn - start_pfn; > > -- > To unsubscribe from this list: send the line "unsubscribe linux-acpi" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jiang Liu Subject: Re: [RFC PATCH 10/12] memory-hotplug : free memmap of sparse-vmemmap Date: Sat, 30 Jun 2012 23:58:12 +0800 Message-ID: <4FEF2214.4000205@gmail.com> References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEAA09F.5000907@jp.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <4FEAA09F.5000907@jp.fujitsu.com> Sender: owner-linux-mm@kvack.org To: Yasuaki Ishimatsu Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com List-Id: linux-acpi@vger.kernel.org On 06/27/2012 01:56 PM, Yasuaki Ishimatsu wrote: > I don't think that all pages of virtual mapping in removed memory can be > freed, since page which type is MIX_SECTION_INFO is difficult to free. > So, the patch only frees page which type is SECTION_INFO at first. > > CC: Len Brown > CC: Benjamin Herrenschmidt > CC: Paul Mackerras > CC: Christoph Lameter > Cc: Minchan Kim > CC: Andrew Morton > CC: KOSAKI Motohiro > CC: Wen Congyang > Signed-off-by: Yasuaki Ishimatsu > > --- > arch/x86/mm/init_64.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ > include/linux/mm.h | 2 + > mm/memory_hotplug.c | 5 ++ > mm/sparse.c | 5 +- > 4 files changed, 99 insertions(+), 2 deletions(-) > > Index: linux-3.5-rc4/include/linux/mm.h > =================================================================== > --- linux-3.5-rc4.orig/include/linux/mm.h 2012-06-27 09:11:13.790150442 +0900 > +++ linux-3.5-rc4/include/linux/mm.h 2012-06-27 09:11:16.433117400 +0900 > @@ -1588,6 +1588,8 @@ int vmemmap_populate(struct page *start_ > void vmemmap_populate_print_last(void); > void register_page_bootmem_memmap(unsigned long section_nr, struct page *map, > unsigned long size); > +void vmemmap_kfree(struct page *memmpa, unsigned long nr_pages); > +void vmemmap_free_bootmem(struct page *memmpa, unsigned long nr_pages); > > enum mf_flags { > MF_COUNT_INCREASED = 1 << 0, > Index: linux-3.5-rc4/mm/sparse.c > =================================================================== > --- linux-3.5-rc4.orig/mm/sparse.c 2012-06-27 09:06:35.317631878 +0900 > +++ linux-3.5-rc4/mm/sparse.c 2012-06-27 09:11:16.434117388 +0900 > @@ -614,12 +614,13 @@ static inline struct page *kmalloc_secti > /* This will make the necessary allocations eventually. */ > return sparse_mem_map_populate(pnum, nid); > } > -static void __kfree_section_memmap(struct page *memmap, unsigned long nr_pages) > +static void __kfree_section_memmap(struct page *page, unsigned long nr_pages) > { > - return; /* XXX: Not implemented yet */ > + vmemmap_kfree(page, nr_pages); > } > static void free_map_bootmem(struct page *page, unsigned long nr_pages) > { > + vmemmap_free_bootmem(page, nr_pages); > } > #else > static struct page *__kmalloc_section_memmap(unsigned long nr_pages) > Index: linux-3.5-rc4/arch/x86/mm/init_64.c > =================================================================== > --- linux-3.5-rc4.orig/arch/x86/mm/init_64.c 2012-06-27 09:11:13.791150430 +0900 > +++ linux-3.5-rc4/arch/x86/mm/init_64.c 2012-06-27 09:11:59.254581998 +0900 > @@ -978,6 +978,95 @@ vmemmap_populate(struct page *start_page > return 0; > } > > +unsigned long find_and_clear_pte_page(unsigned long addr, unsigned long end, > + struct page *page) I think the third parameter should be "struct page **pp" instead of "struct page *page". And "page = pte_page(*pte)" should be "*pp = pte_page(*pte)". Otherwise the found page pointer can't be returned to the caller and vmemmap_kfree() just sees random value in variable "page". > +{ > + pgd_t *pgd; > + pud_t *pud; > + pmd_t *pmd; > + pte_t *pte; > + unsigned long next; > + > + page = NULL; > + > + pgd = pgd_offset_k(addr); > + if (pgd_none(*pgd)) > + return PAGE_SIZE; > + > + pud = pud_offset(pgd, addr); > + if (pud_none(*pud)) > + return PAGE_SIZE; > + > + if (!cpu_has_pse) { > + next = (addr + PAGE_SIZE) & PAGE_MASK; > + pmd = pmd_offset(pud, addr); > + if (pmd_none(*pmd)) > + return next; > + > + pte = pte_offset_kernel(pmd, addr); > + if (pte_none(*pte)) > + return next; > + > + page = pte_page(*pte); > + pte_clear(&init_mm, addr, pte); > + } else { > + next = pmd_addr_end(addr, end); > + > + pmd = pmd_offset(pud, addr); > + if (pmd_none(*pmd)) > + return next; > + > + page = pmd_page(*pmd); > + pmd_clear(pmd); > + } > + > + return next; > +} > + > +void __meminit > +vmemmap_kfree(struct page *memmap, unsigned long nr_pages) > +{ > + unsigned long addr = (unsigned long)memmap; > + unsigned long end = (unsigned long)(memmap + nr_pages); > + unsigned long next; > + unsigned int order; > + struct page *page; > + > + for (; addr < end; addr = next) { > + next = find_and_clear_pte_page(addr, end, page); > + if (!page) > + continue; > + > + if (is_vmalloc_addr(page)) > + vfree(page); > + else { > + order = next - addr; > + free_pages((unsigned long)page, > + get_order(sizeof(struct page) * order)); > + } > + } > +} > + > +void __meminit > +vmemmap_free_bootmem(struct page *memmap, unsigned long nr_pages) > +{ > + unsigned long addr = (unsigned long)memmap; > + unsigned long end = (unsigned long)(memmap + nr_pages); > + unsigned long next; > + struct page *page; > + unsigned long magic; > + > + for (; addr < end; addr = next) { > + next = find_and_clear_pte_page(addr, end, page); > + if (!page) > + continue; > + > + magic = (unsigned long) page->lru.next; > + if (magic == SECTION_INFO) > + put_page_bootmem(page); > + } > +} > + > void __meminit > register_page_bootmem_memmap(unsigned long section_nr, struct page *start_page, > unsigned long size) > Index: linux-3.5-rc4/mm/memory_hotplug.c > =================================================================== > --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-27 09:11:13.789150454 +0900 > +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-27 09:11:16.436117363 +0900 > @@ -303,6 +303,8 @@ static int __meminit __add_section(int n > #ifdef CONFIG_SPARSEMEM_VMEMMAP > static int __remove_section(struct zone *zone, struct mem_section *ms) > { > + unsigned long flags; > + struct pglist_data *pgdat = zone->zone_pgdat; > int ret; > > if (!valid_section(ms)) > @@ -310,6 +312,9 @@ static int __remove_section(struct zone > > ret = unregister_memory_section(ms); > > + pgdat_resize_lock(pgdat, &flags); > + sparse_remove_one_section(zone, ms); > + pgdat_resize_unlock(pgdat, &flags); > return ret; > } > #else > > -- > To unsubscribe from this list: send the line "unsubscribe linux-acpi" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yasuaki Ishimatsu Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages Date: Mon, 2 Jul 2012 11:56:48 +0900 Message-ID: <4FF10DF0.7000508@jp.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> <4FEF2075.2050603@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <4FEF2075.2050603@gmail.com> Sender: owner-linux-mm@kvack.org To: Jiang Liu Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com List-Id: linux-acpi@vger.kernel.org Hi Jiang, 2012/07/01 0:51, Jiang Liu wrote: > On 06/27/2012 01:44 PM, Yasuaki Ishimatsu wrote: >> When offline_pages() is called to offlined memory, the function fails since >> all memory has been offlined. In this case, the function should succeed. >> The patch adds the check function into offline_pages(). >> >> CC: Len Brown >> CC: Benjamin Herrenschmidt >> CC: Paul Mackerras >> CC: Christoph Lameter >> Cc: Minchan Kim >> CC: Andrew Morton >> CC: KOSAKI Motohiro >> CC: Wen Congyang >> Signed-off-by: Yasuaki Ishimatsu >> >> --- >> drivers/base/memory.c | 20 ++++++++++++++++++++ >> include/linux/memory.h | 1 + >> mm/memory_hotplug.c | 5 +++++ >> 3 files changed, 26 insertions(+) >> >> Index: linux-3.5-rc4/drivers/base/memory.c >> =================================================================== >> --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-26 13:28:16.726211752 +0900 >> +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:34:22.423639904 +0900 >> @@ -70,6 +70,26 @@ void unregister_memory_isolate_notifier( >> } >> EXPORT_SYMBOL(unregister_memory_isolate_notifier); >> >> +bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn) >> +{ >> + struct memory_block *mem; >> + struct mem_section *section; >> + unsigned long pfn, section_nr; >> + >> + for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { >> + section_nr = pfn_to_section_nr(pfn); >> + section = __nr_to_section(section_nr); >> + mem = find_memory_block(section); > Seems find_memory_block_hinted() is more efficient than find_memory_block() here. Thanks. I'll update it. Thanks, Yasuaki Ishimatsu > >> + if (!mem) >> + continue; >> + if (mem->state == MEM_OFFLINE) >> + continue; >> + return false; >> + } >> + >> + return true; >> +} >> + >> /* >> * register_memory - Setup a sysfs device for a memory block >> */ >> Index: linux-3.5-rc4/include/linux/memory.h >> =================================================================== >> --- linux-3.5-rc4.orig/include/linux/memory.h 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/include/linux/memory.h 2012-06-26 13:34:22.424639891 +0900 >> @@ -120,6 +120,7 @@ extern int memory_isolate_notify(unsigne >> extern struct memory_block *find_memory_block_hinted(struct mem_section *, >> struct memory_block *); >> extern struct memory_block *find_memory_block(struct mem_section *); >> +extern bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn); >> #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION<> enum mem_add_context { BOOT, HOTPLUG }; >> #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ >> Index: linux-3.5-rc4/mm/memory_hotplug.c >> =================================================================== >> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:28:16.743211538 +0900 >> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:38.264940468 +0900 >> @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned >> >> lock_memory_hotplug(); >> >> + if (memory_is_offline(start_pfn, end_pfn)) { >> + ret = 0; >> + goto out; >> + } >> + >> zone = page_zone(pfn_to_page(start_pfn)); >> node = zone_to_nid(zone); >> nr_pages = end_pfn - start_pfn; >> >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >> > > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: email@kvack.org > -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yasuaki Ishimatsu Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages Date: Mon, 2 Jul 2012 11:53:16 +0900 Message-ID: <4FF10D1C.3060601@jp.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> <4FEF1F6A.6090705@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Return-path: Received: from fgwmail5.fujitsu.co.jp ([192.51.44.35]:48849 "EHLO fgwmail5.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932148Ab2GBC5T (ORCPT ); Sun, 1 Jul 2012 22:57:19 -0400 In-Reply-To: <4FEF1F6A.6090705@gmail.com> Sender: linux-acpi-owner@vger.kernel.org List-Id: linux-acpi@vger.kernel.org To: Jiang Liu Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com Hi Jiang, Thank you for your feedback. 2012/07/01 0:46, Jiang Liu wrote: > On 06/27/2012 01:44 PM, Yasuaki Ishimatsu wrote: >> When offline_pages() is called to offlined memory, the function fails since >> all memory has been offlined. In this case, the function should succeed. >> The patch adds the check function into offline_pages(). >> >> CC: Len Brown >> CC: Benjamin Herrenschmidt >> CC: Paul Mackerras >> CC: Christoph Lameter >> Cc: Minchan Kim >> CC: Andrew Morton >> CC: KOSAKI Motohiro >> CC: Wen Congyang >> Signed-off-by: Yasuaki Ishimatsu >> >> --- >> drivers/base/memory.c | 20 ++++++++++++++++++++ >> include/linux/memory.h | 1 + >> mm/memory_hotplug.c | 5 +++++ >> 3 files changed, 26 insertions(+) >> >> Index: linux-3.5-rc4/drivers/base/memory.c >> =================================================================== >> --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-26 13:28:16.726211752 +0900 >> +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:34:22.423639904 +0900 >> @@ -70,6 +70,26 @@ void unregister_memory_isolate_notifier( >> } >> EXPORT_SYMBOL(unregister_memory_isolate_notifier); >> >> +bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn) >> +{ >> + struct memory_block *mem; >> + struct mem_section *section; >> + unsigned long pfn, section_nr; >> + >> + for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { >> + section_nr = pfn_to_section_nr(pfn); >> + section = __nr_to_section(section_nr); > Is it possible for __nr_to_section return NULL here? Yes. I'll add NULL check. > >> + mem = find_memory_block(section); >> + if (!mem) >> + continue; >> + if (mem->state == MEM_OFFLINE) >> + continue; >> + return false; >> + } >> + >> + return true; >> +} > Need a put_dev(&mem->dev) for the last memory block device handled before return. Thanks. I think kobject_put(&mem->dev.kobj) should be handled for all memory block devices found by find_memory_block(). I'll update it. Thanks, Yasuaki Ishimatsu > >> + >> /* >> * register_memory - Setup a sysfs device for a memory block >> */ >> Index: linux-3.5-rc4/include/linux/memory.h >> =================================================================== >> --- linux-3.5-rc4.orig/include/linux/memory.h 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/include/linux/memory.h 2012-06-26 13:34:22.424639891 +0900 >> @@ -120,6 +120,7 @@ extern int memory_isolate_notify(unsigne >> extern struct memory_block *find_memory_block_hinted(struct mem_section *, >> struct memory_block *); >> extern struct memory_block *find_memory_block(struct mem_section *); >> +extern bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn); >> #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION<> enum mem_add_context { BOOT, HOTPLUG }; >> #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ >> Index: linux-3.5-rc4/mm/memory_hotplug.c >> =================================================================== >> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:28:16.743211538 +0900 >> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:38.264940468 +0900 >> @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned >> >> lock_memory_hotplug(); >> >> + if (memory_is_offline(start_pfn, end_pfn)) { >> + ret = 0; >> + goto out; >> + } >> + >> zone = page_zone(pfn_to_page(start_pfn)); >> node = zone_to_nid(zone); >> nr_pages = end_pfn - start_pfn; >> >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >> > > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: email@kvack.org > From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yasuaki Ishimatsu Subject: Re: [RFC PATCH 10/12] memory-hotplug : free memmap of sparse-vmemmap Date: Mon, 2 Jul 2012 12:01:19 +0900 Message-ID: <4FF10EFF.5050803@jp.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEAA09F.5000907@jp.fujitsu.com> <4FEF2214.4000205@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Return-path: Received: from fgwmail5.fujitsu.co.jp ([192.51.44.35]:36247 "EHLO fgwmail5.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754798Ab2GBDBn (ORCPT ); Sun, 1 Jul 2012 23:01:43 -0400 In-Reply-To: <4FEF2214.4000205@gmail.com> Sender: linux-acpi-owner@vger.kernel.org List-Id: linux-acpi@vger.kernel.org To: Jiang Liu Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com Hi Jiang, 2012/07/01 0:58, Jiang Liu wrote: > On 06/27/2012 01:56 PM, Yasuaki Ishimatsu wrote: >> I don't think that all pages of virtual mapping in removed memory can be >> freed, since page which type is MIX_SECTION_INFO is difficult to free. >> So, the patch only frees page which type is SECTION_INFO at first. >> >> CC: Len Brown >> CC: Benjamin Herrenschmidt >> CC: Paul Mackerras >> CC: Christoph Lameter >> Cc: Minchan Kim >> CC: Andrew Morton >> CC: KOSAKI Motohiro >> CC: Wen Congyang >> Signed-off-by: Yasuaki Ishimatsu >> >> --- >> arch/x86/mm/init_64.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ >> include/linux/mm.h | 2 + >> mm/memory_hotplug.c | 5 ++ >> mm/sparse.c | 5 +- >> 4 files changed, 99 insertions(+), 2 deletions(-) >> >> Index: linux-3.5-rc4/include/linux/mm.h >> =================================================================== >> --- linux-3.5-rc4.orig/include/linux/mm.h 2012-06-27 09:11:13.790150442 +0900 >> +++ linux-3.5-rc4/include/linux/mm.h 2012-06-27 09:11:16.433117400 +0900 >> @@ -1588,6 +1588,8 @@ int vmemmap_populate(struct page *start_ >> void vmemmap_populate_print_last(void); >> void register_page_bootmem_memmap(unsigned long section_nr, struct page *map, >> unsigned long size); >> +void vmemmap_kfree(struct page *memmpa, unsigned long nr_pages); >> +void vmemmap_free_bootmem(struct page *memmpa, unsigned long nr_pages); >> >> enum mf_flags { >> MF_COUNT_INCREASED = 1 << 0, >> Index: linux-3.5-rc4/mm/sparse.c >> =================================================================== >> --- linux-3.5-rc4.orig/mm/sparse.c 2012-06-27 09:06:35.317631878 +0900 >> +++ linux-3.5-rc4/mm/sparse.c 2012-06-27 09:11:16.434117388 +0900 >> @@ -614,12 +614,13 @@ static inline struct page *kmalloc_secti >> /* This will make the necessary allocations eventually. */ >> return sparse_mem_map_populate(pnum, nid); >> } >> -static void __kfree_section_memmap(struct page *memmap, unsigned long nr_pages) >> +static void __kfree_section_memmap(struct page *page, unsigned long nr_pages) >> { >> - return; /* XXX: Not implemented yet */ >> + vmemmap_kfree(page, nr_pages); >> } >> static void free_map_bootmem(struct page *page, unsigned long nr_pages) >> { >> + vmemmap_free_bootmem(page, nr_pages); >> } >> #else >> static struct page *__kmalloc_section_memmap(unsigned long nr_pages) >> Index: linux-3.5-rc4/arch/x86/mm/init_64.c >> =================================================================== >> --- linux-3.5-rc4.orig/arch/x86/mm/init_64.c 2012-06-27 09:11:13.791150430 +0900 >> +++ linux-3.5-rc4/arch/x86/mm/init_64.c 2012-06-27 09:11:59.254581998 +0900 >> @@ -978,6 +978,95 @@ vmemmap_populate(struct page *start_page >> return 0; >> } >> >> +unsigned long find_and_clear_pte_page(unsigned long addr, unsigned long end, >> + struct page *page) > I think the third parameter should be "struct page **pp" instead of "struct page *page". > And "page = pte_page(*pte)" should be "*pp = pte_page(*pte)". > Otherwise the found page pointer can't be returned to the caller and vmemmap_kfree() > just sees random value in variable "page". Oh, you are right. I'll update it. Thanks, Yasuaki Ishimatsu >> +{ >> + pgd_t *pgd; >> + pud_t *pud; >> + pmd_t *pmd; >> + pte_t *pte; >> + unsigned long next; >> + >> + page = NULL; >> + >> + pgd = pgd_offset_k(addr); >> + if (pgd_none(*pgd)) >> + return PAGE_SIZE; >> + >> + pud = pud_offset(pgd, addr); >> + if (pud_none(*pud)) >> + return PAGE_SIZE; >> + >> + if (!cpu_has_pse) { >> + next = (addr + PAGE_SIZE) & PAGE_MASK; >> + pmd = pmd_offset(pud, addr); >> + if (pmd_none(*pmd)) >> + return next; >> + >> + pte = pte_offset_kernel(pmd, addr); >> + if (pte_none(*pte)) >> + return next; >> + >> + page = pte_page(*pte); >> + pte_clear(&init_mm, addr, pte); >> + } else { >> + next = pmd_addr_end(addr, end); >> + >> + pmd = pmd_offset(pud, addr); >> + if (pmd_none(*pmd)) >> + return next; >> + >> + page = pmd_page(*pmd); >> + pmd_clear(pmd); >> + } >> + >> + return next; >> +} >> + >> +void __meminit >> +vmemmap_kfree(struct page *memmap, unsigned long nr_pages) >> +{ >> + unsigned long addr = (unsigned long)memmap; >> + unsigned long end = (unsigned long)(memmap + nr_pages); >> + unsigned long next; >> + unsigned int order; >> + struct page *page; >> + >> + for (; addr < end; addr = next) { >> + next = find_and_clear_pte_page(addr, end, page); >> + if (!page) >> + continue; >> + >> + if (is_vmalloc_addr(page)) >> + vfree(page); >> + else { >> + order = next - addr; >> + free_pages((unsigned long)page, >> + get_order(sizeof(struct page) * order)); >> + } >> + } >> +} >> + >> +void __meminit >> +vmemmap_free_bootmem(struct page *memmap, unsigned long nr_pages) >> +{ >> + unsigned long addr = (unsigned long)memmap; >> + unsigned long end = (unsigned long)(memmap + nr_pages); >> + unsigned long next; >> + struct page *page; >> + unsigned long magic; >> + >> + for (; addr < end; addr = next) { >> + next = find_and_clear_pte_page(addr, end, page); >> + if (!page) >> + continue; >> + >> + magic = (unsigned long) page->lru.next; >> + if (magic == SECTION_INFO) >> + put_page_bootmem(page); >> + } >> +} >> + >> void __meminit >> register_page_bootmem_memmap(unsigned long section_nr, struct page *start_page, >> unsigned long size) >> Index: linux-3.5-rc4/mm/memory_hotplug.c >> =================================================================== >> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-27 09:11:13.789150454 +0900 >> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-27 09:11:16.436117363 +0900 >> @@ -303,6 +303,8 @@ static int __meminit __add_section(int n >> #ifdef CONFIG_SPARSEMEM_VMEMMAP >> static int __remove_section(struct zone *zone, struct mem_section *ms) >> { >> + unsigned long flags; >> + struct pglist_data *pgdat = zone->zone_pgdat; >> int ret; >> >> if (!valid_section(ms)) >> @@ -310,6 +312,9 @@ static int __remove_section(struct zone >> >> ret = unregister_memory_section(ms); >> >> + pgdat_resize_lock(pgdat, &flags); >> + sparse_remove_one_section(zone, ms); >> + pgdat_resize_unlock(pgdat, &flags); >> return ret; >> } >> #else >> >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >> > > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: email@kvack.org > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pb0-f51.google.com (mail-pb0-f51.google.com [209.85.160.51]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 1F7D9B6FA7 for ; Wed, 27 Jun 2012 16:10:36 +1000 (EST) Received: by pbbrp16 with SMTP id rp16so1242809pbb.38 for ; Tue, 26 Jun 2012 23:10:34 -0700 (PDT) Date: Tue, 26 Jun 2012 23:10:32 -0700 (PDT) From: David Rientjes To: Yasuaki Ishimatsu Subject: Re: [RFC PATCH 1/12] memory-hotplug : rename remove_memory to offline_memory In-Reply-To: <4FEA9D5C.1080508@jp.fujitsu.com> Message-ID: References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9D5C.1080508@jp.fujitsu.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Cc: len.brown@intel.com, wency@cn.fujitsu.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, cl@linux.com, linuxppc-dev@lists.ozlabs.org, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , On Wed, 27 Jun 2012, Yasuaki Ishimatsu wrote: > remove_memory() does not remove memory but just offlines memory. The patch > changes name of it to offline_memory(). > The kernel is never going to physically remove the memory itself, so I don't see the big problem with calling it remove_memory(). If you're going to change it to offline_memory(), which is just as good but not better, then I'd suggest changing add_memory() to online_memory() for completeness. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pz0-f51.google.com (mail-pz0-f51.google.com [209.85.210.51]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 0CE94B6FBE for ; Wed, 27 Jun 2012 16:16:28 +1000 (EST) Received: by dajt11 with SMTP id t11so1058579daj.38 for ; Tue, 26 Jun 2012 23:16:26 -0700 (PDT) Date: Tue, 26 Jun 2012 23:16:24 -0700 (PDT) From: David Rientjes To: Yasuaki Ishimatsu Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages In-Reply-To: <4FEA9DB1.7010303@jp.fujitsu.com> Message-ID: References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Cc: len.brown@intel.com, wency@cn.fujitsu.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, cl@linux.com, linuxppc-dev@lists.ozlabs.org, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , On Wed, 27 Jun 2012, Yasuaki Ishimatsu wrote: > Index: linux-3.5-rc4/mm/memory_hotplug.c > =================================================================== > --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:28:16.743211538 +0900 > +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:38.264940468 +0900 > @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned > > lock_memory_hotplug(); > > + if (memory_is_offline(start_pfn, end_pfn)) { > + ret = 0; > + goto out; > + } > + > zone = page_zone(pfn_to_page(start_pfn)); > node = zone_to_nid(zone); > nr_pages = end_pfn - start_pfn; Are there additional prerequisites for this patch? Otherwise it changes the return value of offline_memory() which will now call acpi_memory_powerdown_device() in the acpi memhotplug case when disabling. Is that a problem? From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fgwmail5.fujitsu.co.jp (fgwmail5.fujitsu.co.jp [192.51.44.35]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5DE0FB6FA8 for ; Wed, 27 Jun 2012 15:46:09 +1000 (EST) Received: from m2.gw.fujitsu.co.jp (unknown [10.0.50.72]) by fgwmail5.fujitsu.co.jp (Postfix) with ESMTP id 68F493EE0C0 for ; Wed, 27 Jun 2012 14:46:06 +0900 (JST) Received: from smail (m2 [127.0.0.1]) by outgoing.m2.gw.fujitsu.co.jp (Postfix) with ESMTP id 4917245DE5E for ; Wed, 27 Jun 2012 14:46:06 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (s2.gw.fujitsu.co.jp [10.0.50.92]) by m2.gw.fujitsu.co.jp (Postfix) with ESMTP id F3A6845DE50 for ; Wed, 27 Jun 2012 14:46:05 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id E6D1D1DB803A for ; Wed, 27 Jun 2012 14:46:05 +0900 (JST) Received: from g01jpexchkw01.g01.fujitsu.local (g01jpexchkw01.g01.fujitsu.local [10.0.194.40]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id 9E3BCEF8005 for ; Wed, 27 Jun 2012 14:46:05 +0900 (JST) Message-ID: <4FEA9E0A.1040202@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:45:46 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 To: , , , Subject: [RFC PATCH 3/12] memory-hotplug : add physical memory hotplug code to acpi_memory_device_remove References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Cc: len.brown@intel.com, wency@cn.fujitsu.com, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, cl@linux.com, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , acpi_memory_device_remove() has been prepared to remove physical memory. But, the function only frees acpi_memory_device currentlry. The patch adds following functions into acpi_memory_device_remove(): - offline memory - remove physical memory (only return -EBUSY) - free acpi_memory_device CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- drivers/acpi/acpi_memhotplug.c | 23 ++++++++++++++++++++++- include/linux/memory_hotplug.h | 1 + mm/memory_hotplug.c | 8 ++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) Index: linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c =================================================================== --- linux-3.5-rc4.orig/drivers/acpi/acpi_memhotplug.c 2012-06-26 13:28:16.722211802 +0900 +++ linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c 2012-06-26 13:38:01.085906251 +0900 @@ -452,12 +452,33 @@ static int acpi_memory_device_add(struct static int acpi_memory_device_remove(struct acpi_device *device, int type) { struct acpi_memory_device *mem_device = NULL; - + struct acpi_memory_info *info, *tmp; + int result; + int node; if (!device || !acpi_driver_data(device)) return -EINVAL; mem_device = acpi_driver_data(device); + + node = acpi_get_node(mem_device->device->handle); + + list_for_each_entry_safe(info, tmp, &mem_device->res_list, list) { + if (!info->enabled) + continue; + + result = offline_memory(info->start_addr, info->length); + if (result) + return result; + + result = remove_memory(node, info->start_addr, info->length); + if (result) + return result; + + list_del(&info->list); + kfree(info); + } + kfree(mem_device); return 0; Index: linux-3.5-rc4/include/linux/memory_hotplug.h =================================================================== --- linux-3.5-rc4.orig/include/linux/memory_hotplug.h 2012-06-26 13:28:16.773211163 +0900 +++ linux-3.5-rc4/include/linux/memory_hotplug.h 2012-06-26 13:37:30.545288962 +0900 @@ -233,6 +233,7 @@ static inline int is_mem_section_removab extern int mem_online_node(int nid); extern int add_memory(int nid, u64 start, u64 size); extern int arch_add_memory(int nid, u64 start, u64 size); +extern int remove_memory(int nid, u64 start, u64 size); extern int offline_memory(u64 start, u64 size); extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn, int nr_pages); Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:34:22.425639879 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:30.096046767 +0900 @@ -659,6 +659,14 @@ out: } EXPORT_SYMBOL_GPL(add_memory); +int remove_memory(int nid, u64 start, u64 size) +{ + return -EBUSY; + +} +EXPORT_SYMBOL_GPL(remove_memory); + + #ifdef CONFIG_MEMORY_HOTREMOVE /* * A free page on the buddy free lists (not the per-cpu lists) has PageBuddy From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fgwmail5.fujitsu.co.jp (fgwmail5.fujitsu.co.jp [192.51.44.35]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2AC74B6FBB for ; Wed, 27 Jun 2012 15:47:29 +1000 (EST) Received: from m3.gw.fujitsu.co.jp (unknown [10.0.50.73]) by fgwmail5.fujitsu.co.jp (Postfix) with ESMTP id 640E23EE0BD for ; Wed, 27 Jun 2012 14:47:27 +0900 (JST) Received: from smail (m3 [127.0.0.1]) by outgoing.m3.gw.fujitsu.co.jp (Postfix) with ESMTP id 4688E45DEA6 for ; Wed, 27 Jun 2012 14:47:27 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (s3.gw.fujitsu.co.jp [10.0.50.93]) by m3.gw.fujitsu.co.jp (Postfix) with ESMTP id 2E4D845DE9E for ; Wed, 27 Jun 2012 14:47:27 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id 0D33A1DB8040 for ; Wed, 27 Jun 2012 14:47:27 +0900 (JST) Received: from g01jpexchkw07.g01.fujitsu.local (g01jpexchkw07.g01.fujitsu.local [10.0.194.46]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id BC8541DB803C for ; Wed, 27 Jun 2012 14:47:26 +0900 (JST) Message-ID: <4FEA9E5F.4070205@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:47:11 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 To: , , , Subject: [RFC PATCH 4/12] memory-hotplug : remove /sys/firmware/memmap/X sysfs References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Cc: len.brown@intel.com, wency@cn.fujitsu.com, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, cl@linux.com, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , When (hot)adding memory into system, /sys/firmware/memmap/X/{end, start, type} sysfs files are created. But there is no code to remove these files. The patch implements the function to remove them. Note : The code does not free firmware_map_entry since there is no way to free memory which is allocated by bootmem. CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- drivers/firmware/memmap.c | 71 +++++++++++++++++++++++++++++++++++++++++++ include/linux/firmware-map.h | 6 +++ mm/memory_hotplug.c | 6 +++ 3 files changed, 82 insertions(+), 1 deletion(-) Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:37:30.546288901 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:44:37.069955820 +0900 @@ -661,7 +661,11 @@ EXPORT_SYMBOL_GPL(add_memory); int remove_memory(int nid, u64 start, u64 size) { - return -EBUSY; + lock_memory_hotplug(); + /* remove memmap entry */ + firmware_map_remove(start, start + size, "System RAM"); + unlock_memory_hotplug(); + return 0; } EXPORT_SYMBOL_GPL(remove_memory); Index: linux-3.5-rc4/include/linux/firmware-map.h =================================================================== --- linux-3.5-rc4.orig/include/linux/firmware-map.h 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/include/linux/firmware-map.h 2012-06-26 13:44:37.070955807 +0900 @@ -25,6 +25,7 @@ int firmware_map_add_early(u64 start, u64 end, const char *type); int firmware_map_add_hotplug(u64 start, u64 end, const char *type); +int firmware_map_remove(u64 start, u64 end, const char *type); #else /* CONFIG_FIRMWARE_MEMMAP */ @@ -38,6 +39,11 @@ static inline int firmware_map_add_hotpl return 0; } +static inline int firmware_map_remove(u64 start, u64 end, const char *type) +{ + return 0; +} + #endif /* CONFIG_FIRMWARE_MEMMAP */ #endif /* _LINUX_FIRMWARE_MAP_H */ Index: linux-3.5-rc4/drivers/firmware/memmap.c =================================================================== --- linux-3.5-rc4.orig/drivers/firmware/memmap.c 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/drivers/firmware/memmap.c 2012-06-26 13:47:17.606948898 +0900 @@ -123,6 +123,16 @@ static int firmware_map_add_entry(u64 st return 0; } +/** + * firmware_map_remove_entry() - Does the real work to remove a firmware + * memmap entry. + * @entry: removed entry. + **/ +static inline void firmware_map_remove_entry(struct firmware_map_entry *entry) +{ + list_del(&entry->list); +} + /* * Add memmap entry on sysfs */ @@ -144,6 +154,31 @@ static int add_sysfs_fw_map_entry(struct return 0; } +/* + * Remove memmap entry on sysfs + */ +static inline void remove_sysfs_fw_map_entry(struct firmware_map_entry *entry) +{ + kobject_del(&entry->kobj); +} + +/* + * Search memmap entry + */ + +struct firmware_map_entry * __meminit +find_firmware_map_entry(u64 start, u64 end, const char *type) +{ + struct firmware_map_entry *entry; + + list_for_each_entry(entry, &map_entries, list) + if ((entry->start == start) && (entry->end == end) && + (!strcmp(entry->type, type))) + return entry; + + return NULL; +} + /** * firmware_map_add_hotplug() - Adds a firmware mapping entry when we do * memory hotplug. @@ -196,6 +231,42 @@ int __init firmware_map_add_early(u64 st return firmware_map_add_entry(start, end, type, entry); } +void release_firmware_map_entry(struct firmware_map_entry *entry) +{ + /* + * FIXME : There is no idea. + * How to free the entry which allocated bootmem? + */ +} + +/** + * firmware_map_remove() - remove a firmware mapping entry + * @start: Start of the memory range. + * @end: End of the memory range (inclusive). + * @type: Type of the memory range. + * + * removes a firmware mapping entry. + * + * Returns 0 on success, or -EINVAL if no entry. + **/ +int __meminit firmware_map_remove(u64 start, u64 end, const char *type) +{ + struct firmware_map_entry *entry; + + entry = find_firmware_map_entry(start, end, type); + if (!entry) + return -EINVAL; + + /* remove the memmap entry */ + remove_sysfs_fw_map_entry(entry); + + firmware_map_remove_entry(entry); + + release_firmware_map_entry(entry); + + return 0; +} + /* * Sysfs functions ------------------------------------------------------------- */ From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fgwmail5.fujitsu.co.jp (fgwmail5.fujitsu.co.jp [192.51.44.35]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6E875B6FA8 for ; Wed, 27 Jun 2012 15:48:50 +1000 (EST) Received: from m4.gw.fujitsu.co.jp (unknown [10.0.50.74]) by fgwmail5.fujitsu.co.jp (Postfix) with ESMTP id 881ED3EE0C0 for ; Wed, 27 Jun 2012 14:48:48 +0900 (JST) Received: from smail (m4 [127.0.0.1]) by outgoing.m4.gw.fujitsu.co.jp (Postfix) with ESMTP id 6D3CA45DE52 for ; Wed, 27 Jun 2012 14:48:48 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (s4.gw.fujitsu.co.jp [10.0.50.94]) by m4.gw.fujitsu.co.jp (Postfix) with ESMTP id 462D845DE4E for ; Wed, 27 Jun 2012 14:48:48 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id 328A91DB803E for ; Wed, 27 Jun 2012 14:48:48 +0900 (JST) Received: from g01jpexchkw04.g01.fujitsu.local (g01jpexchkw04.g01.fujitsu.local [10.0.194.43]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id DFFAE1DB8037 for ; Wed, 27 Jun 2012 14:48:47 +0900 (JST) Message-ID: <4FEA9EAF.1060608@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:48:31 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 To: , , , Subject: [RFC PATCH 5/12] memory-hotplug : does not release memory region in PAGES_PER_SECTION chunks References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Cc: len.brown@intel.com, wency@cn.fujitsu.com, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, cl@linux.com, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Since applying a patch(de7f0cba96786c), release_mem_region() has been changed as called in PAGES_PER_SECTION chunks because register_memory_resource() is called in PAGES_PER_SECTION chunks by add_memory(). But it seems firmware dependency. If CRS are written in the PAGES_PER_SECTION chunks in ACPI DSDT Table, register_memory_resource() is called in PAGES_PER_SECTION chunks. But if CRS are written in the DIMM unit in ACPI DSDT Table, register_memory_resource() is called in DIMM unit. So release_mem_region() should not be called in PAGES_PER_SECTION chunks. The patch fixes it. CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- arch/powerpc/platforms/pseries/hotplug-memory.c | 13 +++++++++---- mm/memory_hotplug.c | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:50:57.075205100 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:55:36.152716100 +0900 @@ -358,11 +358,11 @@ int __remove_pages(struct zone *zone, un BUG_ON(phys_start_pfn & ~PAGE_SECTION_MASK); BUG_ON(nr_pages % PAGES_PER_SECTION); + release_mem_region(phys_start_pfn << PAGE_SHIFT, nr_pages * PAGE_SIZE); + sections_to_remove = nr_pages / PAGES_PER_SECTION; for (i = 0; i < sections_to_remove; i++) { unsigned long pfn = phys_start_pfn + i*PAGES_PER_SECTION; - release_mem_region(pfn << PAGE_SHIFT, - PAGES_PER_SECTION << PAGE_SHIFT); ret = __remove_section(zone, __pfn_to_section(pfn)); if (ret) break; Index: linux-3.5-rc4/arch/powerpc/platforms/pseries/hotplug-memory.c =================================================================== --- linux-3.5-rc4.orig/arch/powerpc/platforms/pseries/hotplug-memory.c 2012-06-26 13:50:57.075205100 +0900 +++ linux-3.5-rc4/arch/powerpc/platforms/pseries/hotplug-memory.c 2012-06-26 13:55:36.153716088 +0900 @@ -77,7 +77,8 @@ static int pseries_remove_memblock(unsig { unsigned long start, start_pfn; struct zone *zone; - int ret; + int i, ret; + int sections_to_remove; start_pfn = base >> PAGE_SHIFT; @@ -97,9 +98,13 @@ static int pseries_remove_memblock(unsig * to sysfs "state" file and we can't remove sysfs entries * while writing to it. So we have to defer it to here. */ - ret = __remove_pages(zone, start_pfn, memblock_size >> PAGE_SHIFT); - if (ret) - return ret; + sections_to_remove = (memblock_size >> PAGE_SHIFT) / PAGES_PER_SECTION; + for (i = 0; i < sections_to_remove; i++) { + unsigned long pfn = start_pfn + i * PAGES_PER_SECTION; + ret = __remove_pages(zone, start_pfn, PAGES_PER_SECTION); + if (ret) + return ret; + } /* * Update memory regions for memory remove From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fgwmail7.fujitsu.co.jp (fgwmail7.fujitsu.co.jp [192.51.44.37]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E0C5FB6F13 for ; Wed, 27 Jun 2012 15:50:14 +1000 (EST) Received: from fgwmail6.fujitsu.co.jp (fgwmail6.fujitsu.co.jp [192.51.44.36]) by fgwmail7.fujitsu.co.jp (Postfix) with ESMTP id 27B8A1792DF2 for ; Wed, 27 Jun 2012 14:40:01 +0900 (JST) Received: from m3.gw.fujitsu.co.jp (unknown [10.0.50.73]) by fgwmail6.fujitsu.co.jp (Postfix) with ESMTP id 21F1E3EE0BC for ; Wed, 27 Jun 2012 14:39:57 +0900 (JST) Received: from smail (m3 [127.0.0.1]) by outgoing.m3.gw.fujitsu.co.jp (Postfix) with ESMTP id 03D9345DE9E for ; Wed, 27 Jun 2012 14:39:57 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (s3.gw.fujitsu.co.jp [10.0.50.93]) by m3.gw.fujitsu.co.jp (Postfix) with ESMTP id DFE7E45DEA6 for ; Wed, 27 Jun 2012 14:39:56 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id D43F71DB803F for ; Wed, 27 Jun 2012 14:39:56 +0900 (JST) Received: from g01jpexchkw04.g01.fujitsu.local (g01jpexchkw04.g01.fujitsu.local [10.0.194.43]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id 8EF011DB803C for ; Wed, 27 Jun 2012 14:39:56 +0900 (JST) Message-ID: <4FEA9C88.1070800@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:39:20 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 To: , , , Subject: [RFC PATCH 0/12] memory-hotplug : hot-remove physical memory Content-Type: text/plain; charset="ISO-2022-JP" Cc: len.brown@intel.com, wency@cn.fujitsu.com, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, cl@linux.com, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , This patch series aims to support physical memory hot-remove. [RFC PATCH 1/12] memory-hotplug : rename remove_memory to offline_memory [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages [RFC PATCH 3/12] memory-hotplug : add physical memory hotplug code to acpi_memory_device_remove [RFC PATCH 4/12] memory-hotplug : remove /sys/firmware/memmap/X sysfs [RFC PATCH 5/12] memory hotplug : does not release memory region in PAGES_PER_SECTION chunks [RFC PATCH 6/12] memory-hotplug : remove_memory calls __remove_pages [RFC PATCH 7/12] memory-hotplug : check page type in get_page_bootmem [RFC PATCH 8/12] memory-hotplug : move register_page_bootmem_info_node and put_page_bootmem for sparse-vmemmap [RFC PATCH 9/12] memory-hotplug : implement register_page_bootmem_info_section of sparse-vmemmap [RFC PATCH 10/12] memory-hotplug : free memmap of sparse-vmemmap [RFC PATCH 11/12] memory-hotplug : add node_device_release [RFC PATCH 12/12] memory-hotplug : remove sysfs file of node Even if you apply these patches, you cannot remove the physical memory completely since these patches are still under development. I want you to cooperate to improve the physical memory hot-remove. So please review these patches and give your comment/idea. The patches can free/remove following things: - acpi_memory_info : [RFC PATCH 3/12] - /sys/firmware/memmap/X/{end, start, type} : [RFC PATCH 4/12] - iomem_resource : [RFC PATCH 5/12] - mem_section and related sysfs files : [RFC PATCH 6-10/12] - node and related sysfs files : [RFC PATCH 11-12/12] The patches cannot do following things yet: - page table of removed memory If you find lack of function for physical memory hot-remove, please let me know. --- arch/powerpc/platforms/pseries/hotplug-memory.c | 16 +- arch/x86/mm/init_64.c | 142 ++++++++++++++++++++++++ drivers/acpi/acpi_memhotplug.c | 25 +++- drivers/base/memory.c | 24 +++- drivers/base/node.c | 7 + drivers/firmware/memmap.c | 71 ++++++++++++ include/linux/firmware-map.h | 6 + include/linux/memory.h | 1 include/linux/memory_hotplug.h | 17 -- include/linux/mm.h | 5 mm/memory_hotplug.c | 101 +++++++++++++---- mm/sparse.c | 5 12 files changed, 374 insertions(+), 46 deletions(-) From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fgwmail8.fujitsu.co.jp (fgwmail8.fujitsu.co.jp [192.51.44.38]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 59E3BB6FA8 for ; Wed, 27 Jun 2012 15:51:46 +1000 (EST) Received: from fgwmail6.fujitsu.co.jp (fgwmail6.fujitsu.co.jp [192.51.44.36]) by fgwmail8.fujitsu.co.jp (Postfix) with ESMTP id 3854F17930A0 for ; Wed, 27 Jun 2012 14:43:14 +0900 (JST) Received: from m2.gw.fujitsu.co.jp (unknown [10.0.50.72]) by fgwmail6.fujitsu.co.jp (Postfix) with ESMTP id 0059D3EE0BB for ; Wed, 27 Jun 2012 14:43:12 +0900 (JST) Received: from smail (m2 [127.0.0.1]) by outgoing.m2.gw.fujitsu.co.jp (Postfix) with ESMTP id CE72645DE58 for ; Wed, 27 Jun 2012 14:43:11 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (s2.gw.fujitsu.co.jp [10.0.50.92]) by m2.gw.fujitsu.co.jp (Postfix) with ESMTP id A8E7B45DE50 for ; Wed, 27 Jun 2012 14:43:11 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id 9ABCEE1800B for ; Wed, 27 Jun 2012 14:43:11 +0900 (JST) Received: from g01jpexchkw01.g01.fujitsu.local (g01jpexchkw01.g01.fujitsu.local [10.0.194.40]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id 55BE21DB803C for ; Wed, 27 Jun 2012 14:43:11 +0900 (JST) Message-ID: <4FEA9D5C.1080508@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:42:52 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 To: , , , Subject: [RFC PATCH 1/12] memory-hotplug : rename remove_memory to offline_memory References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Cc: len.brown@intel.com, wency@cn.fujitsu.com, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, cl@linux.com, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , remove_memory() does not remove memory but just offlines memory. The patch changes name of it to offline_memory(). CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- drivers/acpi/acpi_memhotplug.c | 2 +- drivers/base/memory.c | 4 ++-- include/linux/memory_hotplug.h | 2 +- mm/memory_hotplug.c | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) Index: linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c =================================================================== --- linux-3.5-rc4.orig/drivers/acpi/acpi_memhotplug.c 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c 2012-06-26 13:48:38.263940481 +0900 @@ -318,7 +318,7 @@ static int acpi_memory_disable_device(st */ list_for_each_entry_safe(info, n, &mem_device->res_list, list) { if (info->enabled) { - result = remove_memory(info->start_addr, info->length); + result = offline_memory(info->start_addr, info->length); if (result) return result; } Index: linux-3.5-rc4/drivers/base/memory.c =================================================================== --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:48:46.072842803 +0900 @@ -266,8 +266,8 @@ memory_block_action(unsigned long phys_i break; case MEM_OFFLINE: start_paddr = page_to_pfn(first_page) << PAGE_SHIFT; - ret = remove_memory(start_paddr, - nr_pages << PAGE_SHIFT); + ret = offline_memory(start_paddr, + nr_pages << PAGE_SHIFT); break; default: WARN(1, KERN_WARNING "%s(%ld, %ld) unknown action: " Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:46.072842803 +0900 @@ -990,7 +990,7 @@ out: return ret; } -int remove_memory(u64 start, u64 size) +int offline_memory(u64 start, u64 size) { unsigned long start_pfn, end_pfn; @@ -999,9 +999,9 @@ int remove_memory(u64 start, u64 size) return offline_pages(start_pfn, end_pfn, 120 * HZ); } #else -int remove_memory(u64 start, u64 size) +int offline_memory(u64 start, u64 size) { return -EINVAL; } #endif /* CONFIG_MEMORY_HOTREMOVE */ -EXPORT_SYMBOL_GPL(remove_memory); +EXPORT_SYMBOL_GPL(offline_memory); Index: linux-3.5-rc4/include/linux/memory_hotplug.h =================================================================== --- linux-3.5-rc4.orig/include/linux/memory_hotplug.h 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/include/linux/memory_hotplug.h 2012-06-26 13:48:38.264940468 +0900 @@ -233,7 +233,7 @@ static inline int is_mem_section_removab extern int mem_online_node(int nid); extern int add_memory(int nid, u64 start, u64 size); extern int arch_add_memory(int nid, u64 start, u64 size); -extern int remove_memory(u64 start, u64 size); +extern int offline_memory(u64 start, u64 size); extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn, int nr_pages); extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms); From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fgwmail8.fujitsu.co.jp (fgwmail8.fujitsu.co.jp [192.51.44.38]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9471DB6FBA for ; Wed, 27 Jun 2012 15:51:50 +1000 (EST) Received: from fgwmail6.fujitsu.co.jp (fgwmail6.fujitsu.co.jp [192.51.44.36]) by fgwmail8.fujitsu.co.jp (Postfix) with ESMTP id 0F0011793B54 for ; Wed, 27 Jun 2012 14:44:37 +0900 (JST) Received: from m2.gw.fujitsu.co.jp (unknown [10.0.50.72]) by fgwmail6.fujitsu.co.jp (Postfix) with ESMTP id E37A63EE0AE for ; Wed, 27 Jun 2012 14:44:34 +0900 (JST) Received: from smail (m2 [127.0.0.1]) by outgoing.m2.gw.fujitsu.co.jp (Postfix) with ESMTP id CD86045DD78 for ; Wed, 27 Jun 2012 14:44:34 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (s2.gw.fujitsu.co.jp [10.0.50.92]) by m2.gw.fujitsu.co.jp (Postfix) with ESMTP id AD2D245DD74 for ; Wed, 27 Jun 2012 14:44:34 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id 9F702E18004 for ; Wed, 27 Jun 2012 14:44:34 +0900 (JST) Received: from g01jpexchkw07.g01.fujitsu.local (g01jpexchkw07.g01.fujitsu.local [10.0.194.46]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id 5B5C21DB802C for ; Wed, 27 Jun 2012 14:44:34 +0900 (JST) Message-ID: <4FEA9DB1.7010303@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:44:17 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 To: , , , Subject: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Cc: len.brown@intel.com, wency@cn.fujitsu.com, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, cl@linux.com, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , When offline_pages() is called to offlined memory, the function fails since all memory has been offlined. In this case, the function should succeed. The patch adds the check function into offline_pages(). CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- drivers/base/memory.c | 20 ++++++++++++++++++++ include/linux/memory.h | 1 + mm/memory_hotplug.c | 5 +++++ 3 files changed, 26 insertions(+) Index: linux-3.5-rc4/drivers/base/memory.c =================================================================== --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-26 13:28:16.726211752 +0900 +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:34:22.423639904 +0900 @@ -70,6 +70,26 @@ void unregister_memory_isolate_notifier( } EXPORT_SYMBOL(unregister_memory_isolate_notifier); +bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn) +{ + struct memory_block *mem; + struct mem_section *section; + unsigned long pfn, section_nr; + + for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { + section_nr = pfn_to_section_nr(pfn); + section = __nr_to_section(section_nr); + mem = find_memory_block(section); + if (!mem) + continue; + if (mem->state == MEM_OFFLINE) + continue; + return false; + } + + return true; +} + /* * register_memory - Setup a sysfs device for a memory block */ Index: linux-3.5-rc4/include/linux/memory.h =================================================================== --- linux-3.5-rc4.orig/include/linux/memory.h 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/include/linux/memory.h 2012-06-26 13:34:22.424639891 +0900 @@ -120,6 +120,7 @@ extern int memory_isolate_notify(unsigne extern struct memory_block *find_memory_block_hinted(struct mem_section *, struct memory_block *); extern struct memory_block *find_memory_block(struct mem_section *); +extern bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn); #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION< Received: from fgwmail6.fujitsu.co.jp (fgwmail6.fujitsu.co.jp [192.51.44.36]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 77506B6FA8 for ; Wed, 27 Jun 2012 15:52:30 +1000 (EST) Received: from m2.gw.fujitsu.co.jp (unknown [10.0.50.72]) by fgwmail6.fujitsu.co.jp (Postfix) with ESMTP id BA9F83EE0BD for ; Wed, 27 Jun 2012 14:52:28 +0900 (JST) Received: from smail (m2 [127.0.0.1]) by outgoing.m2.gw.fujitsu.co.jp (Postfix) with ESMTP id 9C83345DE52 for ; Wed, 27 Jun 2012 14:52:28 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (s2.gw.fujitsu.co.jp [10.0.50.92]) by m2.gw.fujitsu.co.jp (Postfix) with ESMTP id 7CFB045DD78 for ; Wed, 27 Jun 2012 14:52:28 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id 6B6FBE78001 for ; Wed, 27 Jun 2012 14:52:28 +0900 (JST) Received: from g01jpexchkw02.g01.fujitsu.local (g01jpexchkw02.g01.fujitsu.local [10.0.194.41]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id 26983E18001 for ; Wed, 27 Jun 2012 14:52:28 +0900 (JST) Message-ID: <4FEA9F8B.30105@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:52:11 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 To: , , , Subject: [RFC PATCH 6/12] memory-hotplug : remove_memory calls __remove_pages References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Cc: len.brown@intel.com, wency@cn.fujitsu.com, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, cl@linux.com, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , The patch adds __remove_pages() to remove_memory(). Then the range of phys_start_pfn argument and nr_pages argument in __remove_pagse() may have different zone. So zone argument is removed from __remove_pages() and __remove_pages() caluculates zone in each section. When CONFIG_SPARSEMEM_VMEMMAP is defined, there is no way to remove a memmap. So __remove_section only calls unregister_memory_section(). CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- arch/powerpc/platforms/pseries/hotplug-memory.c | 5 +---- include/linux/memory_hotplug.h | 3 +-- mm/memory_hotplug.c | 20 +++++++++++++------- 3 files changed, 15 insertions(+), 13 deletions(-) Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-27 09:07:49.124709164 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-27 09:08:30.612190446 +0900 @@ -275,11 +275,14 @@ static int __meminit __add_section(int n #ifdef CONFIG_SPARSEMEM_VMEMMAP static int __remove_section(struct zone *zone, struct mem_section *ms) { - /* - * XXX: Freeing memmap with vmemmap is not implement yet. - * This should be removed later. - */ - return -EBUSY; + int ret; + + if (!valid_section(ms)) + return ret; + + ret = unregister_memory_section(ms); + + return ret; } #else static int __remove_section(struct zone *zone, struct mem_section *ms) @@ -346,11 +349,11 @@ EXPORT_SYMBOL_GPL(__add_pages); * sure that pages are marked reserved and zones are adjust properly by * calling offline_pages(). */ -int __remove_pages(struct zone *zone, unsigned long phys_start_pfn, - unsigned long nr_pages) +int __remove_pages(unsigned long phys_start_pfn, unsigned long nr_pages) { unsigned long i, ret = 0; int sections_to_remove; + struct zone *zone; /* * We can only remove entire sections @@ -363,6 +366,7 @@ int __remove_pages(struct zone *zone, un sections_to_remove = nr_pages / PAGES_PER_SECTION; for (i = 0; i < sections_to_remove; i++) { unsigned long pfn = phys_start_pfn + i*PAGES_PER_SECTION; + zone = page_zone(pfn_to_page(pfn)); ret = __remove_section(zone, __pfn_to_section(pfn)); if (ret) break; @@ -664,6 +668,8 @@ int remove_memory(int nid, u64 start, u6 lock_memory_hotplug(); /* remove memmap entry */ firmware_map_remove(start, start + size, "System RAM"); + + __remove_pages(start >> PAGE_SHIFT, size >> PAGE_SHIFT); unlock_memory_hotplug(); return 0; Index: linux-3.5-rc4/include/linux/memory_hotplug.h =================================================================== --- linux-3.5-rc4.orig/include/linux/memory_hotplug.h 2012-06-27 09:06:35.616628141 +0900 +++ linux-3.5-rc4/include/linux/memory_hotplug.h 2012-06-27 09:08:30.612190446 +0900 @@ -89,8 +89,7 @@ extern bool is_pageblock_removable_noloc /* reasonably generic interface to expand the physical pages in a zone */ extern int __add_pages(int nid, struct zone *zone, unsigned long start_pfn, unsigned long nr_pages); -extern int __remove_pages(struct zone *zone, unsigned long start_pfn, - unsigned long nr_pages); +extern int __remove_pages(unsigned long start_pfn, unsigned long nr_pages); #ifdef CONFIG_NUMA extern int memory_add_physaddr_to_nid(u64 start); Index: linux-3.5-rc4/arch/powerpc/platforms/pseries/hotplug-memory.c =================================================================== --- linux-3.5-rc4.orig/arch/powerpc/platforms/pseries/hotplug-memory.c 2012-06-27 09:08:25.737248748 +0900 +++ linux-3.5-rc4/arch/powerpc/platforms/pseries/hotplug-memory.c 2012-06-27 09:08:30.613190434 +0900 @@ -76,7 +76,6 @@ unsigned long memory_block_size_bytes(vo static int pseries_remove_memblock(unsigned long base, unsigned int memblock_size) { unsigned long start, start_pfn; - struct zone *zone; int i, ret; int sections_to_remove; @@ -87,8 +86,6 @@ static int pseries_remove_memblock(unsig return 0; } - zone = page_zone(pfn_to_page(start_pfn)); - /* * Remove section mappings and sysfs entries for the * section of the memory we are removing. @@ -101,7 +98,7 @@ static int pseries_remove_memblock(unsig sections_to_remove = (memblock_size >> PAGE_SHIFT) / PAGES_PER_SECTION; for (i = 0; i < sections_to_remove; i++) { unsigned long pfn = start_pfn + i * PAGES_PER_SECTION; - ret = __remove_pages(zone, start_pfn, PAGES_PER_SECTION); + ret = __remove_pages(start_pfn, PAGES_PER_SECTION); if (ret) return ret; } From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fgwmail6.fujitsu.co.jp (fgwmail6.fujitsu.co.jp [192.51.44.36]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 637AAB6FA8 for ; Wed, 27 Jun 2012 15:53:35 +1000 (EST) Received: from m2.gw.fujitsu.co.jp (unknown [10.0.50.72]) by fgwmail6.fujitsu.co.jp (Postfix) with ESMTP id 813AD3EE0C3 for ; Wed, 27 Jun 2012 14:53:33 +0900 (JST) Received: from smail (m2 [127.0.0.1]) by outgoing.m2.gw.fujitsu.co.jp (Postfix) with ESMTP id 687B945DE50 for ; Wed, 27 Jun 2012 14:53:33 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (s2.gw.fujitsu.co.jp [10.0.50.92]) by m2.gw.fujitsu.co.jp (Postfix) with ESMTP id 441EE45DD78 for ; Wed, 27 Jun 2012 14:53:33 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id 35759E18004 for ; Wed, 27 Jun 2012 14:53:33 +0900 (JST) Received: from g01jpexchkw07.g01.fujitsu.local (g01jpexchkw07.g01.fujitsu.local [10.0.194.46]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id E72371DB8038 for ; Wed, 27 Jun 2012 14:53:32 +0900 (JST) Message-ID: <4FEA9FCD.6020405@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:53:17 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 To: , , , Subject: [RFC PATCH 7/12] memory-hotplug : check page type in get_page_bootmem References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Cc: len.brown@intel.com, wency@cn.fujitsu.com, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, cl@linux.com, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , There is a possibility that get_page_bootmem() is called to the same page many times. So when get_page_bootmem is called to the same page, the function only increments page->_count. CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:56:34.371988312 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 14:03:37.564697621 +0900 @@ -95,10 +95,17 @@ static void release_memory_resource(stru static void get_page_bootmem(unsigned long info, struct page *page, unsigned long type) { - page->lru.next = (struct list_head *) type; - SetPagePrivate(page); - set_page_private(page, info); - atomic_inc(&page->_count); + unsigned long page_type; + + page_type = (unsigned long) page->lru.next; + if (type < MEMORY_HOTPLUG_MIN_BOOTMEM_TYPE || + type > MEMORY_HOTPLUG_MAX_BOOTMEM_TYPE){ + page->lru.next = (struct list_head *) type; + SetPagePrivate(page); + set_page_private(page, info); + atomic_inc(&page->_count); + } else + atomic_inc(&page->_count); } /* reference to __meminit __free_pages_bootmem is valid From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fgwmail6.fujitsu.co.jp (fgwmail6.fujitsu.co.jp [192.51.44.36]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9DF57B6FB6 for ; Wed, 27 Jun 2012 15:54:49 +1000 (EST) Received: from m4.gw.fujitsu.co.jp (unknown [10.0.50.74]) by fgwmail6.fujitsu.co.jp (Postfix) with ESMTP id D7E6C3EE0C5 for ; Wed, 27 Jun 2012 14:54:47 +0900 (JST) Received: from smail (m4 [127.0.0.1]) by outgoing.m4.gw.fujitsu.co.jp (Postfix) with ESMTP id BEA0D45DE4D for ; Wed, 27 Jun 2012 14:54:47 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (s4.gw.fujitsu.co.jp [10.0.50.94]) by m4.gw.fujitsu.co.jp (Postfix) with ESMTP id 9474645DE51 for ; Wed, 27 Jun 2012 14:54:47 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id 83867E18005 for ; Wed, 27 Jun 2012 14:54:47 +0900 (JST) Received: from g01jpexchkw06.g01.fujitsu.local (g01jpexchkw06.g01.fujitsu.local [10.0.194.45]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id 341AB1DB803B for ; Wed, 27 Jun 2012 14:54:47 +0900 (JST) Message-ID: <4FEAA019.7070302@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:54:33 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 To: , , , Subject: [RFC PATCH 8/12] memory-hotplug : move register_page_bootmem_info_node and put_page_bootmem for sparse-vmemmap References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Cc: len.brown@intel.com, wency@cn.fujitsu.com, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, cl@linux.com, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , For implementing register_page_bootmem_info_node of sparse-vmemmap, register_page_bootmem_info_node and put_page_bootmem are moved to memory_hotplug.c CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyan Signed-off-by: Yasuaki Ishimatsu --- include/linux/memory_hotplug.h | 9 --------- mm/memory_hotplug.c | 8 ++++++-- 2 files changed, 6 insertions(+), 11 deletions(-) Index: linux-3.5-rc4/include/linux/memory_hotplug.h =================================================================== --- linux-3.5-rc4.orig/include/linux/memory_hotplug.h 2012-06-26 13:56:34.372988299 +0900 +++ linux-3.5-rc4/include/linux/memory_hotplug.h 2012-06-26 14:05:16.603459518 +0900 @@ -160,17 +160,8 @@ static inline void arch_refresh_nodedata #endif /* CONFIG_NUMA */ #endif /* CONFIG_HAVE_ARCH_NODEDATA_EXTENSION */ -#ifdef CONFIG_SPARSEMEM_VMEMMAP -static inline void register_page_bootmem_info_node(struct pglist_data *pgdat) -{ -} -static inline void put_page_bootmem(struct page *page) -{ -} -#else extern void register_page_bootmem_info_node(struct pglist_data *pgdat); extern void put_page_bootmem(struct page *page); -#endif /* * Lock for memory hotplug guarantees 1) all callbacks for memory hotplug Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 14:03:37.564697621 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 14:05:16.604459506 +0900 @@ -91,7 +91,6 @@ static void release_memory_resource(stru } #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE -#ifndef CONFIG_SPARSEMEM_VMEMMAP static void get_page_bootmem(unsigned long info, struct page *page, unsigned long type) { @@ -127,6 +126,7 @@ void __ref put_page_bootmem(struct page } +#ifndef CONFIG_SPARSEMEM_VMEMMAP static void register_page_bootmem_info_section(unsigned long start_pfn) { unsigned long *usemap, mapsize, section_nr, i; @@ -163,6 +163,11 @@ static void register_page_bootmem_info_s get_page_bootmem(section_nr, page, MIX_SECTION_INFO); } +#else +static inline void register_page_bootmem_info_section(unsigned long start_pfn) +{ +} +#endif void register_page_bootmem_info_node(struct pglist_data *pgdat) { @@ -198,7 +203,6 @@ void register_page_bootmem_info_node(str register_page_bootmem_info_section(pfn); } -#endif /* !CONFIG_SPARSEMEM_VMEMMAP */ static void grow_zone_span(struct zone *zone, unsigned long start_pfn, unsigned long end_pfn) From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fgwmail5.fujitsu.co.jp (fgwmail5.fujitsu.co.jp [192.51.44.35]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4E153B6FBD for ; Wed, 27 Jun 2012 15:56:03 +1000 (EST) Received: from m1.gw.fujitsu.co.jp (unknown [10.0.50.71]) by fgwmail5.fujitsu.co.jp (Postfix) with ESMTP id 7DFB03EE0C1 for ; Wed, 27 Jun 2012 14:55:58 +0900 (JST) Received: from smail (m1 [127.0.0.1]) by outgoing.m1.gw.fujitsu.co.jp (Postfix) with ESMTP id 5E57845DE5A for ; Wed, 27 Jun 2012 14:55:58 +0900 (JST) Received: from s1.gw.fujitsu.co.jp (s1.gw.fujitsu.co.jp [10.0.50.91]) by m1.gw.fujitsu.co.jp (Postfix) with ESMTP id 42E9B45DE58 for ; Wed, 27 Jun 2012 14:55:58 +0900 (JST) Received: from s1.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s1.gw.fujitsu.co.jp (Postfix) with ESMTP id 34F771DB8053 for ; Wed, 27 Jun 2012 14:55:58 +0900 (JST) Received: from g01jpexchkw03.g01.fujitsu.local (g01jpexchkw03.g01.fujitsu.local [10.0.194.42]) by s1.gw.fujitsu.co.jp (Postfix) with ESMTP id E9C4E1DB8046 for ; Wed, 27 Jun 2012 14:55:57 +0900 (JST) Message-ID: <4FEAA05C.6090204@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:55:40 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 To: , , , Subject: [RFC PATCH 9/12] memory-hotplug : implement register_page_bootmem_info_section of sparse-vmemmap References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Cc: len.brown@intel.com, wency@cn.fujitsu.com, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, cl@linux.com, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , For removing memmap region of sparse-vmemmap which is allocated bootmem, memmap region of sparse-vmemmap needs to be registered by get_page_bootmem(). So the patch searches pages of virtual mapping and registers the pages by get_page_bootmem(). CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- arch/x86/mm/init_64.c | 53 +++++++++++++++++++++++++++++++++++++++++ include/linux/memory_hotplug.h | 2 + include/linux/mm.h | 3 +- mm/memory_hotplug.c | 23 +++++++++++++++-- 4 files changed, 77 insertions(+), 4 deletions(-) Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 14:05:16.604459506 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 14:27:19.850916817 +0900 @@ -91,8 +91,8 @@ static void release_memory_resource(stru } #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE -static void get_page_bootmem(unsigned long info, struct page *page, - unsigned long type) +void get_page_bootmem(unsigned long info, struct page *page, + unsigned long type) { unsigned long page_type; @@ -164,8 +164,25 @@ static void register_page_bootmem_info_s } #else -static inline void register_page_bootmem_info_section(unsigned long start_pfn) +static void register_page_bootmem_info_section(unsigned long start_pfn) { + unsigned long mapsize, section_nr; + struct mem_section *ms; + struct page *page, *memmap; + + if (!pfn_valid(start_pfn)) + return; + + section_nr = pfn_to_section_nr(start_pfn); + ms = __nr_to_section(section_nr); + + memmap = sparse_decode_mem_map(ms->section_mem_map, section_nr); + + page = virt_to_page(memmap); + mapsize = sizeof(struct page) * PAGES_PER_SECTION; + mapsize = PAGE_ALIGN(mapsize) >> PAGE_SHIFT; + + register_page_bootmem_memmap(section_nr, memmap, PAGES_PER_SECTION); } #endif Index: linux-3.5-rc4/include/linux/mm.h =================================================================== --- linux-3.5-rc4.orig/include/linux/mm.h 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/include/linux/mm.h 2012-06-26 14:26:17.481696320 +0900 @@ -1586,7 +1586,8 @@ int vmemmap_populate_basepages(struct pa unsigned long pages, int node); int vmemmap_populate(struct page *start_page, unsigned long pages, int node); void vmemmap_populate_print_last(void); - +void register_page_bootmem_memmap(unsigned long section_nr, struct page *map, + unsigned long size); enum mf_flags { MF_COUNT_INCREASED = 1 << 0, Index: linux-3.5-rc4/arch/x86/mm/init_64.c =================================================================== --- linux-3.5-rc4.orig/arch/x86/mm/init_64.c 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/arch/x86/mm/init_64.c 2012-06-26 14:26:17.481696320 +0900 @@ -978,6 +978,59 @@ vmemmap_populate(struct page *start_page return 0; } +void __meminit +register_page_bootmem_memmap(unsigned long section_nr, struct page *start_page, + unsigned long size) +{ + unsigned long addr = (unsigned long)start_page; + unsigned long end = (unsigned long)(start_page + size); + unsigned long next; + pgd_t *pgd; + pud_t *pud; + pmd_t *pmd; + + for (; addr < end; addr = next) { + pte_t *pte = NULL; + + pgd = pgd_offset_k(addr); + if (pgd_none(*pgd)) { + next = (addr + PAGE_SIZE) & PAGE_MASK; + continue; + } + get_page_bootmem(section_nr, pgd_page(*pgd), MIX_SECTION_INFO); + + pud = pud_offset(pgd, addr); + if (pud_none(*pud)) { + next = (addr + PAGE_SIZE) & PAGE_MASK; + continue; + } + get_page_bootmem(section_nr, pud_page(*pud), MIX_SECTION_INFO); + + if (!cpu_has_pse) { + next = (addr + PAGE_SIZE) & PAGE_MASK; + pmd = pmd_offset(pud, addr); + if (pmd_none(*pmd)) + continue; + get_page_bootmem(section_nr, pmd_page(*pmd), + MIX_SECTION_INFO); + + pte = pte_offset_kernel(pmd, addr); + if (pte_none(*pte)) + continue; + get_page_bootmem(section_nr, pte_page(*pte), + SECTION_INFO); + } else { + next = pmd_addr_end(addr, end); + + pmd = pmd_offset(pud, addr); + if (pmd_none(*pmd)) + continue; + get_page_bootmem(section_nr, pmd_page(*pmd), + SECTION_INFO); + } + } +} + void __meminit vmemmap_populate_print_last(void) { if (p_start) { Index: linux-3.5-rc4/include/linux/memory_hotplug.h =================================================================== --- linux-3.5-rc4.orig/include/linux/memory_hotplug.h 2012-06-26 14:05:16.603459518 +0900 +++ linux-3.5-rc4/include/linux/memory_hotplug.h 2012-06-26 14:11:14.175989381 +0900 @@ -162,6 +162,8 @@ static inline void arch_refresh_nodedata extern void register_page_bootmem_info_node(struct pglist_data *pgdat); extern void put_page_bootmem(struct page *page); +extern void get_page_bootmem(unsigned long ingo, struct page *page, + unsigned long type); /* * Lock for memory hotplug guarantees 1) all callbacks for memory hotplug From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fgwmail6.fujitsu.co.jp (fgwmail6.fujitsu.co.jp [192.51.44.36]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 07D3EB6FA9 for ; Wed, 27 Jun 2012 15:57:05 +1000 (EST) Received: from m1.gw.fujitsu.co.jp (unknown [10.0.50.71]) by fgwmail6.fujitsu.co.jp (Postfix) with ESMTP id 517DE3EE0BC for ; Wed, 27 Jun 2012 14:57:03 +0900 (JST) Received: from smail (m1 [127.0.0.1]) by outgoing.m1.gw.fujitsu.co.jp (Postfix) with ESMTP id 2112045DE5F for ; Wed, 27 Jun 2012 14:57:03 +0900 (JST) Received: from s1.gw.fujitsu.co.jp (s1.gw.fujitsu.co.jp [10.0.50.91]) by m1.gw.fujitsu.co.jp (Postfix) with ESMTP id DB4FD45DE58 for ; Wed, 27 Jun 2012 14:57:02 +0900 (JST) Received: from s1.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s1.gw.fujitsu.co.jp (Postfix) with ESMTP id CBA11E38004 for ; Wed, 27 Jun 2012 14:57:02 +0900 (JST) Received: from G01JPEXCHKW08.g01.fujitsu.local (G01JPEXCHKW08.g01.fujitsu.local [10.0.194.47]) by s1.gw.fujitsu.co.jp (Postfix) with ESMTP id 4A1B41DB8050 for ; Wed, 27 Jun 2012 14:57:02 +0900 (JST) Message-ID: <4FEAA09F.5000907@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:56:47 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 To: , , , Subject: [RFC PATCH 10/12] memory-hotplug : free memmap of sparse-vmemmap References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Cc: len.brown@intel.com, wency@cn.fujitsu.com, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, cl@linux.com, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , I don't think that all pages of virtual mapping in removed memory can be freed, since page which type is MIX_SECTION_INFO is difficult to free. So, the patch only frees page which type is SECTION_INFO at first. CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- arch/x86/mm/init_64.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/mm.h | 2 + mm/memory_hotplug.c | 5 ++ mm/sparse.c | 5 +- 4 files changed, 99 insertions(+), 2 deletions(-) Index: linux-3.5-rc4/include/linux/mm.h =================================================================== --- linux-3.5-rc4.orig/include/linux/mm.h 2012-06-27 09:11:13.790150442 +0900 +++ linux-3.5-rc4/include/linux/mm.h 2012-06-27 09:11:16.433117400 +0900 @@ -1588,6 +1588,8 @@ int vmemmap_populate(struct page *start_ void vmemmap_populate_print_last(void); void register_page_bootmem_memmap(unsigned long section_nr, struct page *map, unsigned long size); +void vmemmap_kfree(struct page *memmpa, unsigned long nr_pages); +void vmemmap_free_bootmem(struct page *memmpa, unsigned long nr_pages); enum mf_flags { MF_COUNT_INCREASED = 1 << 0, Index: linux-3.5-rc4/mm/sparse.c =================================================================== --- linux-3.5-rc4.orig/mm/sparse.c 2012-06-27 09:06:35.317631878 +0900 +++ linux-3.5-rc4/mm/sparse.c 2012-06-27 09:11:16.434117388 +0900 @@ -614,12 +614,13 @@ static inline struct page *kmalloc_secti /* This will make the necessary allocations eventually. */ return sparse_mem_map_populate(pnum, nid); } -static void __kfree_section_memmap(struct page *memmap, unsigned long nr_pages) +static void __kfree_section_memmap(struct page *page, unsigned long nr_pages) { - return; /* XXX: Not implemented yet */ + vmemmap_kfree(page, nr_pages); } static void free_map_bootmem(struct page *page, unsigned long nr_pages) { + vmemmap_free_bootmem(page, nr_pages); } #else static struct page *__kmalloc_section_memmap(unsigned long nr_pages) Index: linux-3.5-rc4/arch/x86/mm/init_64.c =================================================================== --- linux-3.5-rc4.orig/arch/x86/mm/init_64.c 2012-06-27 09:11:13.791150430 +0900 +++ linux-3.5-rc4/arch/x86/mm/init_64.c 2012-06-27 09:11:59.254581998 +0900 @@ -978,6 +978,95 @@ vmemmap_populate(struct page *start_page return 0; } +unsigned long find_and_clear_pte_page(unsigned long addr, unsigned long end, + struct page *page) +{ + pgd_t *pgd; + pud_t *pud; + pmd_t *pmd; + pte_t *pte; + unsigned long next; + + page = NULL; + + pgd = pgd_offset_k(addr); + if (pgd_none(*pgd)) + return PAGE_SIZE; + + pud = pud_offset(pgd, addr); + if (pud_none(*pud)) + return PAGE_SIZE; + + if (!cpu_has_pse) { + next = (addr + PAGE_SIZE) & PAGE_MASK; + pmd = pmd_offset(pud, addr); + if (pmd_none(*pmd)) + return next; + + pte = pte_offset_kernel(pmd, addr); + if (pte_none(*pte)) + return next; + + page = pte_page(*pte); + pte_clear(&init_mm, addr, pte); + } else { + next = pmd_addr_end(addr, end); + + pmd = pmd_offset(pud, addr); + if (pmd_none(*pmd)) + return next; + + page = pmd_page(*pmd); + pmd_clear(pmd); + } + + return next; +} + +void __meminit +vmemmap_kfree(struct page *memmap, unsigned long nr_pages) +{ + unsigned long addr = (unsigned long)memmap; + unsigned long end = (unsigned long)(memmap + nr_pages); + unsigned long next; + unsigned int order; + struct page *page; + + for (; addr < end; addr = next) { + next = find_and_clear_pte_page(addr, end, page); + if (!page) + continue; + + if (is_vmalloc_addr(page)) + vfree(page); + else { + order = next - addr; + free_pages((unsigned long)page, + get_order(sizeof(struct page) * order)); + } + } +} + +void __meminit +vmemmap_free_bootmem(struct page *memmap, unsigned long nr_pages) +{ + unsigned long addr = (unsigned long)memmap; + unsigned long end = (unsigned long)(memmap + nr_pages); + unsigned long next; + struct page *page; + unsigned long magic; + + for (; addr < end; addr = next) { + next = find_and_clear_pte_page(addr, end, page); + if (!page) + continue; + + magic = (unsigned long) page->lru.next; + if (magic == SECTION_INFO) + put_page_bootmem(page); + } +} + void __meminit register_page_bootmem_memmap(unsigned long section_nr, struct page *start_page, unsigned long size) Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-27 09:11:13.789150454 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-27 09:11:16.436117363 +0900 @@ -303,6 +303,8 @@ static int __meminit __add_section(int n #ifdef CONFIG_SPARSEMEM_VMEMMAP static int __remove_section(struct zone *zone, struct mem_section *ms) { + unsigned long flags; + struct pglist_data *pgdat = zone->zone_pgdat; int ret; if (!valid_section(ms)) @@ -310,6 +312,9 @@ static int __remove_section(struct zone ret = unregister_memory_section(ms); + pgdat_resize_lock(pgdat, &flags); + sparse_remove_one_section(zone, ms); + pgdat_resize_unlock(pgdat, &flags); return ret; } #else From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fgwmail5.fujitsu.co.jp (fgwmail5.fujitsu.co.jp [192.51.44.35]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2BC60B6FA9 for ; Wed, 27 Jun 2012 15:58:16 +1000 (EST) Received: from m4.gw.fujitsu.co.jp (unknown [10.0.50.74]) by fgwmail5.fujitsu.co.jp (Postfix) with ESMTP id 51DE83EE0C0 for ; Wed, 27 Jun 2012 14:58:15 +0900 (JST) Received: from smail (m4 [127.0.0.1]) by outgoing.m4.gw.fujitsu.co.jp (Postfix) with ESMTP id DEAB845DE58 for ; Wed, 27 Jun 2012 14:58:14 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (s4.gw.fujitsu.co.jp [10.0.50.94]) by m4.gw.fujitsu.co.jp (Postfix) with ESMTP id 06D0445DE56 for ; Wed, 27 Jun 2012 14:58:14 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id D6885E38006 for ; Wed, 27 Jun 2012 14:58:13 +0900 (JST) Received: from g01jpexchkw03.g01.fujitsu.local (g01jpexchkw03.g01.fujitsu.local [10.0.194.42]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id 8F9E61DB8045 for ; Wed, 27 Jun 2012 14:58:13 +0900 (JST) Message-ID: <4FEAA0E2.2080003@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:57:54 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 To: , , , Subject: [RFC PATCH 11/12] memory-hotplug : add node_device_release References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Cc: len.brown@intel.com, wency@cn.fujitsu.com, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, cl@linux.com, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , When calling unregister_node(), the function shows following message at device_release(). Device 'node2' does not have a release() function, it is broken and must be fixed. So the patch implements node_device_release() CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu Index: linux-3.5-rc1/drivers/base/node.c =================================================================== --- linux-3.5-rc1.orig/drivers/base/node.c 2012-06-14 09:09:53.000000000 +0900 +++ linux-3.5-rc1/drivers/base/node.c 2012-06-25 18:40:45.810261969 +0900 @@ -252,6 +252,12 @@ static inline void hugetlb_register_node static inline void hugetlb_unregister_node(struct node *node) {} #endif +static void node_device_release(struct device *dev) +{ + struct node *node_dev = to_node(dev); + + memset(node_dev, 0, sizeof(struct node)); +} /* * register_node - Setup a sysfs device for a node. @@ -265,6 +271,7 @@ int register_node(struct node *node, int node->dev.id = num; node->dev.bus = &node_subsys; + node->dev.release = node_device_release; error = device_register(&node->dev); if (!error){ From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fgwmail6.fujitsu.co.jp (fgwmail6.fujitsu.co.jp [192.51.44.36]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2D965B6FBB for ; Wed, 27 Jun 2012 15:59:28 +1000 (EST) Received: from m4.gw.fujitsu.co.jp (unknown [10.0.50.74]) by fgwmail6.fujitsu.co.jp (Postfix) with ESMTP id 83FC43EE0C7 for ; Wed, 27 Jun 2012 14:59:26 +0900 (JST) Received: from smail (m4 [127.0.0.1]) by outgoing.m4.gw.fujitsu.co.jp (Postfix) with ESMTP id 6AA0C45DE54 for ; Wed, 27 Jun 2012 14:59:26 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (s4.gw.fujitsu.co.jp [10.0.50.94]) by m4.gw.fujitsu.co.jp (Postfix) with ESMTP id 4F68645DE50 for ; Wed, 27 Jun 2012 14:59:26 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id 2FE23E38003 for ; Wed, 27 Jun 2012 14:59:26 +0900 (JST) Received: from g01jpexchkw06.g01.fujitsu.local (g01jpexchkw06.g01.fujitsu.local [10.0.194.45]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id D3F491DB803B for ; Wed, 27 Jun 2012 14:59:25 +0900 (JST) Message-ID: <4FEAA12B.6070906@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:59:07 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 To: , , , Subject: [RFC PATCH 12/12] memory-hotplug : remove sysfs file of node References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Cc: len.brown@intel.com, wency@cn.fujitsu.com, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, cl@linux.com, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , The patch adds node_set_offline() and unregister_one_node() to remove_memory() for removing sysfs file of node. CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- mm/memory_hotplug.c | 5 +++++ 1 file changed, 5 insertions(+) Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 14:32:03.630368866 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 14:39:58.090437374 +0900 @@ -702,6 +702,11 @@ int remove_memory(int nid, u64 start, u6 /* remove memmap entry */ firmware_map_remove(start, start + size, "System RAM"); + if (!node_present_pages(nid)) { + node_set_offline(nid); + unregister_one_node(nid); + } + __remove_pages(start >> PAGE_SHIFT, size >> PAGE_SHIFT); unlock_memory_hotplug(); return 0; From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from song.cn.fujitsu.com (unknown [222.73.24.84]) by ozlabs.org (Postfix) with ESMTP id C91EE10160B for ; Wed, 27 Jun 2012 17:20:41 +1000 (EST) Message-ID: <4FEAB2E1.3090200@cn.fujitsu.com> Date: Wed, 27 Jun 2012 15:14:41 +0800 From: Wen Congyang MIME-Version: 1.0 To: Yasuaki Ishimatsu Subject: Re: [RFC PATCH 1/12] memory-hotplug : rename remove_memory to offline_memory References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9D5C.1080508@jp.fujitsu.com> In-Reply-To: <4FEA9D5C.1080508@jp.fujitsu.com> Content-Type: text/plain; charset=ISO-2022-JP Cc: len.brown@intel.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, cl@linux.com, linuxppc-dev@lists.ozlabs.org, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , At 06/27/2012 01:42 PM, Yasuaki Ishimatsu Wrote: > remove_memory() does not remove memory but just offlines memory. The patch > changes name of it to offline_memory(). There are 3 functions in the kernel: 1. add_memory() 2. online_pages() 3. remove_memory() So I think offline_pages() is better than offline_memory(). Thanks Wen Congyang > > CC: Len Brown > CC: Benjamin Herrenschmidt > CC: Paul Mackerras > CC: Christoph Lameter > Cc: Minchan Kim > CC: Andrew Morton > CC: KOSAKI Motohiro > CC: Wen Congyang > Signed-off-by: Yasuaki Ishimatsu > > --- > drivers/acpi/acpi_memhotplug.c | 2 +- > drivers/base/memory.c | 4 ++-- > include/linux/memory_hotplug.h | 2 +- > mm/memory_hotplug.c | 6 +++--- > 4 files changed, 7 insertions(+), 7 deletions(-) > > Index: linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c > =================================================================== > --- linux-3.5-rc4.orig/drivers/acpi/acpi_memhotplug.c 2012-06-25 04:53:04.000000000 +0900 > +++ linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c 2012-06-26 13:48:38.263940481 +0900 > @@ -318,7 +318,7 @@ static int acpi_memory_disable_device(st > */ > list_for_each_entry_safe(info, n, &mem_device->res_list, list) { > if (info->enabled) { > - result = remove_memory(info->start_addr, info->length); > + result = offline_memory(info->start_addr, info->length); > if (result) > return result; > } > Index: linux-3.5-rc4/drivers/base/memory.c > =================================================================== > --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-25 04:53:04.000000000 +0900 > +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:48:46.072842803 +0900 > @@ -266,8 +266,8 @@ memory_block_action(unsigned long phys_i > break; > case MEM_OFFLINE: > start_paddr = page_to_pfn(first_page) << PAGE_SHIFT; > - ret = remove_memory(start_paddr, > - nr_pages << PAGE_SHIFT); > + ret = offline_memory(start_paddr, > + nr_pages << PAGE_SHIFT); > break; > default: > WARN(1, KERN_WARNING "%s(%ld, %ld) unknown action: " > Index: linux-3.5-rc4/mm/memory_hotplug.c > =================================================================== > --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-25 04:53:04.000000000 +0900 > +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:46.072842803 +0900 > @@ -990,7 +990,7 @@ out: > return ret; > } > > -int remove_memory(u64 start, u64 size) > +int offline_memory(u64 start, u64 size) > { > unsigned long start_pfn, end_pfn; > > @@ -999,9 +999,9 @@ int remove_memory(u64 start, u64 size) > return offline_pages(start_pfn, end_pfn, 120 * HZ); > } > #else > -int remove_memory(u64 start, u64 size) > +int offline_memory(u64 start, u64 size) > { > return -EINVAL; > } > #endif /* CONFIG_MEMORY_HOTREMOVE */ > -EXPORT_SYMBOL_GPL(remove_memory); > +EXPORT_SYMBOL_GPL(offline_memory); > Index: linux-3.5-rc4/include/linux/memory_hotplug.h > =================================================================== > --- linux-3.5-rc4.orig/include/linux/memory_hotplug.h 2012-06-25 04:53:04.000000000 +0900 > +++ linux-3.5-rc4/include/linux/memory_hotplug.h 2012-06-26 13:48:38.264940468 +0900 > @@ -233,7 +233,7 @@ static inline int is_mem_section_removab > extern int mem_online_node(int nid); > extern int add_memory(int nid, u64 start, u64 size); > extern int arch_add_memory(int nid, u64 start, u64 size); > -extern int remove_memory(u64 start, u64 size); > +extern int offline_memory(u64 start, u64 size); > extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn, > int nr_pages); > extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms); > > > > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from song.cn.fujitsu.com (unknown [222.73.24.84]) by ozlabs.org (Postfix) with ESMTP id 982241007DB for ; Wed, 27 Jun 2012 18:42:55 +1000 (EST) Message-ID: <4FEAC891.7030808@cn.fujitsu.com> Date: Wed, 27 Jun 2012 16:47:13 +0800 From: Wen Congyang MIME-Version: 1.0 To: Yasuaki Ishimatsu Subject: Re: [RFC PATCH 1/12] memory-hotplug : rename remove_memory to offline_memory References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9D5C.1080508@jp.fujitsu.com> <4FEAB2E1.3090200@cn.fujitsu.com> In-Reply-To: <4FEAB2E1.3090200@cn.fujitsu.com> Content-Type: text/plain; charset=ISO-2022-JP Cc: len.brown@intel.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, cl@linux.com, linuxppc-dev@lists.ozlabs.org, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , At 06/27/2012 03:14 PM, Wen Congyang Wrote: > At 06/27/2012 01:42 PM, Yasuaki Ishimatsu Wrote: >> remove_memory() does not remove memory but just offlines memory. The patch >> changes name of it to offline_memory(). > > There are 3 functions in the kernel: > 1. add_memory() > 2. online_pages() > 3. remove_memory() > > So I think offline_pages() is better than offline_memory(). There is already a function named offline_pages(). So we should call offline_pages() instead of remove_memory() in memory_block_action(), and there is no need to rename remove_memory(). Thanks Wen Congyang > > Thanks > Wen Congyang >> >> CC: Len Brown >> CC: Benjamin Herrenschmidt >> CC: Paul Mackerras >> CC: Christoph Lameter >> Cc: Minchan Kim >> CC: Andrew Morton >> CC: KOSAKI Motohiro >> CC: Wen Congyang >> Signed-off-by: Yasuaki Ishimatsu >> >> --- >> drivers/acpi/acpi_memhotplug.c | 2 +- >> drivers/base/memory.c | 4 ++-- >> include/linux/memory_hotplug.h | 2 +- >> mm/memory_hotplug.c | 6 +++--- >> 4 files changed, 7 insertions(+), 7 deletions(-) >> >> Index: linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c >> =================================================================== >> --- linux-3.5-rc4.orig/drivers/acpi/acpi_memhotplug.c 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c 2012-06-26 13:48:38.263940481 +0900 >> @@ -318,7 +318,7 @@ static int acpi_memory_disable_device(st >> */ >> list_for_each_entry_safe(info, n, &mem_device->res_list, list) { >> if (info->enabled) { >> - result = remove_memory(info->start_addr, info->length); >> + result = offline_memory(info->start_addr, info->length); >> if (result) >> return result; >> } >> Index: linux-3.5-rc4/drivers/base/memory.c >> =================================================================== >> --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:48:46.072842803 +0900 >> @@ -266,8 +266,8 @@ memory_block_action(unsigned long phys_i >> break; >> case MEM_OFFLINE: >> start_paddr = page_to_pfn(first_page) << PAGE_SHIFT; >> - ret = remove_memory(start_paddr, >> - nr_pages << PAGE_SHIFT); >> + ret = offline_memory(start_paddr, >> + nr_pages << PAGE_SHIFT); >> break; >> default: >> WARN(1, KERN_WARNING "%s(%ld, %ld) unknown action: " >> Index: linux-3.5-rc4/mm/memory_hotplug.c >> =================================================================== >> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:46.072842803 +0900 >> @@ -990,7 +990,7 @@ out: >> return ret; >> } >> >> -int remove_memory(u64 start, u64 size) >> +int offline_memory(u64 start, u64 size) >> { >> unsigned long start_pfn, end_pfn; >> >> @@ -999,9 +999,9 @@ int remove_memory(u64 start, u64 size) >> return offline_pages(start_pfn, end_pfn, 120 * HZ); >> } >> #else >> -int remove_memory(u64 start, u64 size) >> +int offline_memory(u64 start, u64 size) >> { >> return -EINVAL; >> } >> #endif /* CONFIG_MEMORY_HOTREMOVE */ >> -EXPORT_SYMBOL_GPL(remove_memory); >> +EXPORT_SYMBOL_GPL(offline_memory); >> Index: linux-3.5-rc4/include/linux/memory_hotplug.h >> =================================================================== >> --- linux-3.5-rc4.orig/include/linux/memory_hotplug.h 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/include/linux/memory_hotplug.h 2012-06-26 13:48:38.264940468 +0900 >> @@ -233,7 +233,7 @@ static inline int is_mem_section_removab >> extern int mem_online_node(int nid); >> extern int add_memory(int nid, u64 start, u64 size); >> extern int arch_add_memory(int nid, u64 start, u64 size); >> -extern int remove_memory(u64 start, u64 size); >> +extern int offline_memory(u64 start, u64 size); >> extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn, >> int nr_pages); >> extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms); >> >> >> >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >> Please read the FAQ at http://www.tux.org/lkml/ >> > > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from song.cn.fujitsu.com (unknown [222.73.24.84]) by ozlabs.org (Postfix) with ESMTP id A32EEB6FD4 for ; Wed, 27 Jun 2012 18:45:04 +1000 (EST) Message-ID: <4FEAC916.7030506@cn.fujitsu.com> Date: Wed, 27 Jun 2012 16:49:26 +0800 From: Wen Congyang MIME-Version: 1.0 To: Yasuaki Ishimatsu Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> In-Reply-To: <4FEA9DB1.7010303@jp.fujitsu.com> Content-Type: text/plain; charset=ISO-2022-JP Cc: len.brown@intel.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, cl@linux.com, linuxppc-dev@lists.ozlabs.org, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , At 06/27/2012 01:44 PM, Yasuaki Ishimatsu Wrote: > When offline_pages() is called to offlined memory, the function fails since > all memory has been offlined. In this case, the function should succeed. > The patch adds the check function into offline_pages(). You miss such case: some pages are online, while some pages are offline. offline_pages() will fail too in such case. Thanks Wen Congyang > > CC: Len Brown > CC: Benjamin Herrenschmidt > CC: Paul Mackerras > CC: Christoph Lameter > Cc: Minchan Kim > CC: Andrew Morton > CC: KOSAKI Motohiro > CC: Wen Congyang > Signed-off-by: Yasuaki Ishimatsu > > --- > drivers/base/memory.c | 20 ++++++++++++++++++++ > include/linux/memory.h | 1 + > mm/memory_hotplug.c | 5 +++++ > 3 files changed, 26 insertions(+) > > Index: linux-3.5-rc4/drivers/base/memory.c > =================================================================== > --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-26 13:28:16.726211752 +0900 > +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:34:22.423639904 +0900 > @@ -70,6 +70,26 @@ void unregister_memory_isolate_notifier( > } > EXPORT_SYMBOL(unregister_memory_isolate_notifier); > > +bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn) > +{ > + struct memory_block *mem; > + struct mem_section *section; > + unsigned long pfn, section_nr; > + > + for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { > + section_nr = pfn_to_section_nr(pfn); > + section = __nr_to_section(section_nr); > + mem = find_memory_block(section); > + if (!mem) > + continue; > + if (mem->state == MEM_OFFLINE) > + continue; > + return false; > + } > + > + return true; > +} > + > /* > * register_memory - Setup a sysfs device for a memory block > */ > Index: linux-3.5-rc4/include/linux/memory.h > =================================================================== > --- linux-3.5-rc4.orig/include/linux/memory.h 2012-06-25 04:53:04.000000000 +0900 > +++ linux-3.5-rc4/include/linux/memory.h 2012-06-26 13:34:22.424639891 +0900 > @@ -120,6 +120,7 @@ extern int memory_isolate_notify(unsigne > extern struct memory_block *find_memory_block_hinted(struct mem_section *, > struct memory_block *); > extern struct memory_block *find_memory_block(struct mem_section *); > +extern bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn); > #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION< enum mem_add_context { BOOT, HOTPLUG }; > #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ > Index: linux-3.5-rc4/mm/memory_hotplug.c > =================================================================== > --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:28:16.743211538 +0900 > +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:38.264940468 +0900 > @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned > > lock_memory_hotplug(); > > + if (memory_is_offline(start_pfn, end_pfn)) { > + ret = 0; > + goto out; > + } > + > zone = page_zone(pfn_to_page(start_pfn)); > node = zone_to_nid(zone); > nr_pages = end_pfn - start_pfn; > > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fgwmail6.fujitsu.co.jp (fgwmail6.fujitsu.co.jp [192.51.44.36]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2A3BDB6FA0 for ; Thu, 28 Jun 2012 13:01:26 +1000 (EST) Received: from m2.gw.fujitsu.co.jp (unknown [10.0.50.72]) by fgwmail6.fujitsu.co.jp (Postfix) with ESMTP id D76AB3EE0C8 for ; Thu, 28 Jun 2012 12:01:22 +0900 (JST) Received: from smail (m2 [127.0.0.1]) by outgoing.m2.gw.fujitsu.co.jp (Postfix) with ESMTP id BD2FA45DE53 for ; Thu, 28 Jun 2012 12:01:22 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (s2.gw.fujitsu.co.jp [10.0.50.92]) by m2.gw.fujitsu.co.jp (Postfix) with ESMTP id 9F2C945DE4D for ; Thu, 28 Jun 2012 12:01:22 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id 92C8F1DB802C for ; Thu, 28 Jun 2012 12:01:22 +0900 (JST) Received: from g01jpexchkw03.g01.fujitsu.local (g01jpexchkw03.g01.fujitsu.local [10.0.194.42]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id 0969C1DB8040 for ; Thu, 28 Jun 2012 12:01:22 +0900 (JST) Message-ID: <4FEBC8EE.7040207@jp.fujitsu.com> Date: Thu, 28 Jun 2012 12:01:02 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 To: Wen Congyang , Subject: Re: [RFC PATCH 1/12] memory-hotplug : rename remove_memory to offline_memory References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9D5C.1080508@jp.fujitsu.com> <4FEAB2E1.3090200@cn.fujitsu.com> <4FEAC891.7030808@cn.fujitsu.com> In-Reply-To: <4FEAC891.7030808@cn.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Cc: len.brown@intel.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, cl@linux.com, linuxppc-dev@lists.ozlabs.org, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Hi David and Wen, Thank you for reviewing my patch. 2012/06/27 17:47, Wen Congyang wrote: > At 06/27/2012 03:14 PM, Wen Congyang Wrote: >> At 06/27/2012 01:42 PM, Yasuaki Ishimatsu Wrote: >>> remove_memory() does not remove memory but just offlines memory. The patch >>> changes name of it to offline_memory(). >> >> There are 3 functions in the kernel: >> 1. add_memory() >> 2. online_pages() >> 3. remove_memory() >> >> So I think offline_pages() is better than offline_memory(). > > There is already a function named offline_pages(). So we > should call offline_pages() instead of remove_memory() in > memory_block_action(), and there is no need to rename > remove_memory(). As Wen says, Linux has 4 functions for memory hotplug already. In my recognition, these functions are prepared for following purpose. 1. add_memory : add physical memory 2. online_pages : online logical memory 3. remove_memory : offline logical memory 4. offline_pages : offline logical memory add_memory() is used for adding physical memory. I think remove_memory() would rather be used for removing physical memory than be used for removing logical memory. So I renamed remove_memory() to offline_memory(). How do you think? Regards, Yasuaki Ishimatsu > > Thanks > Wen Congyang > >> >> Thanks >> Wen Congyang >>> >>> CC: Len Brown >>> CC: Benjamin Herrenschmidt >>> CC: Paul Mackerras >>> CC: Christoph Lameter >>> Cc: Minchan Kim >>> CC: Andrew Morton >>> CC: KOSAKI Motohiro >>> CC: Wen Congyang >>> Signed-off-by: Yasuaki Ishimatsu >>> >>> --- >>> drivers/acpi/acpi_memhotplug.c | 2 +- >>> drivers/base/memory.c | 4 ++-- >>> include/linux/memory_hotplug.h | 2 +- >>> mm/memory_hotplug.c | 6 +++--- >>> 4 files changed, 7 insertions(+), 7 deletions(-) >>> >>> Index: linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c >>> =================================================================== >>> --- linux-3.5-rc4.orig/drivers/acpi/acpi_memhotplug.c 2012-06-25 04:53:04.000000000 +0900 >>> +++ linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c 2012-06-26 13:48:38.263940481 +0900 >>> @@ -318,7 +318,7 @@ static int acpi_memory_disable_device(st >>> */ >>> list_for_each_entry_safe(info, n, &mem_device->res_list, list) { >>> if (info->enabled) { >>> - result = remove_memory(info->start_addr, info->length); >>> + result = offline_memory(info->start_addr, info->length); >>> if (result) >>> return result; >>> } >>> Index: linux-3.5-rc4/drivers/base/memory.c >>> =================================================================== >>> --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-25 04:53:04.000000000 +0900 >>> +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:48:46.072842803 +0900 >>> @@ -266,8 +266,8 @@ memory_block_action(unsigned long phys_i >>> break; >>> case MEM_OFFLINE: >>> start_paddr = page_to_pfn(first_page) << PAGE_SHIFT; >>> - ret = remove_memory(start_paddr, >>> - nr_pages << PAGE_SHIFT); >>> + ret = offline_memory(start_paddr, >>> + nr_pages << PAGE_SHIFT); >>> break; >>> default: >>> WARN(1, KERN_WARNING "%s(%ld, %ld) unknown action: " >>> Index: linux-3.5-rc4/mm/memory_hotplug.c >>> =================================================================== >>> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-25 04:53:04.000000000 +0900 >>> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:46.072842803 +0900 >>> @@ -990,7 +990,7 @@ out: >>> return ret; >>> } >>> >>> -int remove_memory(u64 start, u64 size) >>> +int offline_memory(u64 start, u64 size) >>> { >>> unsigned long start_pfn, end_pfn; >>> >>> @@ -999,9 +999,9 @@ int remove_memory(u64 start, u64 size) >>> return offline_pages(start_pfn, end_pfn, 120 * HZ); >>> } >>> #else >>> -int remove_memory(u64 start, u64 size) >>> +int offline_memory(u64 start, u64 size) >>> { >>> return -EINVAL; >>> } >>> #endif /* CONFIG_MEMORY_HOTREMOVE */ >>> -EXPORT_SYMBOL_GPL(remove_memory); >>> +EXPORT_SYMBOL_GPL(offline_memory); >>> Index: linux-3.5-rc4/include/linux/memory_hotplug.h >>> =================================================================== >>> --- linux-3.5-rc4.orig/include/linux/memory_hotplug.h 2012-06-25 04:53:04.000000000 +0900 >>> +++ linux-3.5-rc4/include/linux/memory_hotplug.h 2012-06-26 13:48:38.264940468 +0900 >>> @@ -233,7 +233,7 @@ static inline int is_mem_section_removab >>> extern int mem_online_node(int nid); >>> extern int add_memory(int nid, u64 start, u64 size); >>> extern int arch_add_memory(int nid, u64 start, u64 size); >>> -extern int remove_memory(u64 start, u64 size); >>> +extern int offline_memory(u64 start, u64 size); >>> extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn, >>> int nr_pages); >>> extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms); >>> >>> >>> >>> -- >>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in >>> the body of a message to majordomo@vger.kernel.org >>> More majordomo info at http://vger.kernel.org/majordomo-info.html >>> Please read the FAQ at http://www.tux.org/lkml/ >>> >> >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >> Please read the FAQ at http://www.tux.org/lkml/ >> > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: email@kvack.org > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from song.cn.fujitsu.com (unknown [222.73.24.84]) by ozlabs.org (Postfix) with ESMTP id A8076B6EF1 for ; Thu, 28 Jun 2012 13:20:51 +1000 (EST) Message-ID: <4FEBCE9C.7030904@cn.fujitsu.com> Date: Thu, 28 Jun 2012 11:25:16 +0800 From: Wen Congyang MIME-Version: 1.0 To: Yasuaki Ishimatsu Subject: Re: [RFC PATCH 1/12] memory-hotplug : rename remove_memory to offline_memory References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9D5C.1080508@jp.fujitsu.com> <4FEAB2E1.3090200@cn.fujitsu.com> <4FEAC891.7030808@cn.fujitsu.com> <4FEBC8EE.7040207@jp.fujitsu.com> In-Reply-To: <4FEBC8EE.7040207@jp.fujitsu.com> Content-Type: text/plain; charset=ISO-2022-JP Cc: len.brown@intel.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, rientjes@google.com, cl@linux.com, linuxppc-dev@lists.ozlabs.org, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , At 06/28/2012 11:01 AM, Yasuaki Ishimatsu Wrote: > Hi David and Wen, > > Thank you for reviewing my patch. > > 2012/06/27 17:47, Wen Congyang wrote: >> At 06/27/2012 03:14 PM, Wen Congyang Wrote: >>> At 06/27/2012 01:42 PM, Yasuaki Ishimatsu Wrote: >>>> remove_memory() does not remove memory but just offlines memory. The patch >>>> changes name of it to offline_memory(). >>> >>> There are 3 functions in the kernel: >>> 1. add_memory() >>> 2. online_pages() >>> 3. remove_memory() >>> >>> So I think offline_pages() is better than offline_memory(). >> >> There is already a function named offline_pages(). So we >> should call offline_pages() instead of remove_memory() in >> memory_block_action(), and there is no need to rename >> remove_memory(). > > As Wen says, Linux has 4 functions for memory hotplug already. > In my recognition, these functions are prepared for following purpose. > > 1. add_memory : add physical memory > 2. online_pages : online logical memory > 3. remove_memory : offline logical memory > 4. offline_pages : offline logical memory > > add_memory() is used for adding physical memory. I think remove_memory() > would rather be used for removing physical memory than be used for removing > logical memory. So I renamed remove_memory() to offline_memory(). > How do you think? Hmm, remove_memory() will revert all things we do in add_memory(), so I think there is no need to rename it. If we rename it to offline_memory(), we should also rename add_memory() to online_memory(). Thanks Wen Congyang > > Regards, > Yasuaki Ishimatsu > >> >> Thanks >> Wen Congyang >> >>> >>> Thanks >>> Wen Congyang >>>> From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fgwmail5.fujitsu.co.jp (fgwmail5.fujitsu.co.jp [192.51.44.35]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4BD08B7004 for ; Thu, 28 Jun 2012 14:50:46 +1000 (EST) Received: from m2.gw.fujitsu.co.jp (unknown [10.0.50.72]) by fgwmail5.fujitsu.co.jp (Postfix) with ESMTP id DA25D3EE0C0 for ; Thu, 28 Jun 2012 13:50:41 +0900 (JST) Received: from smail (m2 [127.0.0.1]) by outgoing.m2.gw.fujitsu.co.jp (Postfix) with ESMTP id BD49A45DE53 for ; Thu, 28 Jun 2012 13:50:41 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (s2.gw.fujitsu.co.jp [10.0.50.92]) by m2.gw.fujitsu.co.jp (Postfix) with ESMTP id 9AAF645DE50 for ; Thu, 28 Jun 2012 13:50:41 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id 8CD321DB8040 for ; Thu, 28 Jun 2012 13:50:41 +0900 (JST) Received: from g01jpexchyt07.g01.fujitsu.local (g01jpexchyt07.g01.fujitsu.local [10.128.194.46]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id 35E591DB803C for ; Thu, 28 Jun 2012 13:50:41 +0900 (JST) Message-ID: <4FEBE280.4060107@jp.fujitsu.com> Date: Thu, 28 Jun 2012 13:50:08 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 To: Wen Congyang Subject: Re: [RFC PATCH 1/12] memory-hotplug : rename remove_memory to offline_memory References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9D5C.1080508@jp.fujitsu.com> <4FEAB2E1.3090200@cn.fujitsu.com> <4FEAC891.7030808@cn.fujitsu.com> <4FEBC8EE.7040207@jp.fujitsu.com> <4FEBCE9C.7030904@cn.fujitsu.com> In-Reply-To: <4FEBCE9C.7030904@cn.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Cc: len.brown@intel.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, rientjes@google.com, cl@linux.com, linuxppc-dev@lists.ozlabs.org, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Hi Wen, 2012/06/28 12:25, Wen Congyang wrote: > At 06/28/2012 11:01 AM, Yasuaki Ishimatsu Wrote: >> Hi David and Wen, >> >> Thank you for reviewing my patch. >> >> 2012/06/27 17:47, Wen Congyang wrote: >>> At 06/27/2012 03:14 PM, Wen Congyang Wrote: >>>> At 06/27/2012 01:42 PM, Yasuaki Ishimatsu Wrote: >>>>> remove_memory() does not remove memory but just offlines memory. The patch >>>>> changes name of it to offline_memory(). >>>> >>>> There are 3 functions in the kernel: >>>> 1. add_memory() >>>> 2. online_pages() >>>> 3. remove_memory() >>>> >>>> So I think offline_pages() is better than offline_memory(). >>> >>> There is already a function named offline_pages(). So we >>> should call offline_pages() instead of remove_memory() in >>> memory_block_action(), and there is no need to rename >>> remove_memory(). >> >> As Wen says, Linux has 4 functions for memory hotplug already. >> In my recognition, these functions are prepared for following purpose. >> >> 1. add_memory : add physical memory >> 2. online_pages : online logical memory >> 3. remove_memory : offline logical memory >> 4. offline_pages : offline logical memory >> >> add_memory() is used for adding physical memory. I think remove_memory() >> would rather be used for removing physical memory than be used for removing >> logical memory. So I renamed remove_memory() to offline_memory(). >> How do you think? > > Hmm, remove_memory() will revert all things we do in add_memory(), so I think I think so too. add_memory() prepares to use physical memory. It prepares some structures (pgdat, page table, node, etc) for using the physical memory at the system. But it does not online the meomory. For onlining the memory, we use online_pages(). So I think that remove_memory() should remove these structures which are prepared by add_memory() not offline memory. But current remove_memory() code only calls offline_pages() and offlines memory. The patch series recreates remove_memory() for removing these structures after [RFC PATCH 3/12]. The reason to change the name of remove_memory() is a preparation to recreate it. Thanks, Yasuaki Ishimatsu > there is no need to rename it. If we rename it to offline_memory(), we should > also rename add_memory() to online_memory(). > > Thanks > Wen Congyang > >> >> Regards, >> Yasuaki Ishimatsu >> >>> >>> Thanks >>> Wen Congyang >>> >>>> >>>> Thanks >>>> Wen Congyang >>>>> From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fgwmail5.fujitsu.co.jp (fgwmail5.fujitsu.co.jp [192.51.44.35]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BB28CB7004 for ; Thu, 28 Jun 2012 15:06:42 +1000 (EST) Received: from m4.gw.fujitsu.co.jp (unknown [10.0.50.74]) by fgwmail5.fujitsu.co.jp (Postfix) with ESMTP id A553E3EE0BD for ; Thu, 28 Jun 2012 14:06:40 +0900 (JST) Received: from smail (m4 [127.0.0.1]) by outgoing.m4.gw.fujitsu.co.jp (Postfix) with ESMTP id 8C55E45DE53 for ; Thu, 28 Jun 2012 14:06:40 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (s4.gw.fujitsu.co.jp [10.0.50.94]) by m4.gw.fujitsu.co.jp (Postfix) with ESMTP id 6489545DE50 for ; Thu, 28 Jun 2012 14:06:40 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id 56A10E08002 for ; Thu, 28 Jun 2012 14:06:40 +0900 (JST) Received: from g01jpexchyt01.g01.fujitsu.local (g01jpexchyt01.g01.fujitsu.local [10.128.194.40]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id E76781DB803B for ; Thu, 28 Jun 2012 14:06:39 +0900 (JST) Message-ID: <4FEBE646.5090801@jp.fujitsu.com> Date: Thu, 28 Jun 2012 14:06:14 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 To: Wen Congyang Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> <4FEAC916.7030506@cn.fujitsu.com> In-Reply-To: <4FEAC916.7030506@cn.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Cc: len.brown@intel.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, cl@linux.com, linuxppc-dev@lists.ozlabs.org, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Hi Wen, 2012/06/27 17:49, Wen Congyang wrote: > At 06/27/2012 01:44 PM, Yasuaki Ishimatsu Wrote: >> When offline_pages() is called to offlined memory, the function fails since >> all memory has been offlined. In this case, the function should succeed. >> The patch adds the check function into offline_pages(). > > You miss such case: some pages are online, while some pages are offline. > offline_pages() will fail too in such case. You are right. But current code fails, when the function is called to offline memory. In this case, the function should succeed. So the patch confirms whether the memory was offlined or not. And if memory has already been offlined, offline_pages return 0. Thanks, Yasuaki Ishimatsu > > Thanks > Wen Congyang > >> >> CC: Len Brown >> CC: Benjamin Herrenschmidt >> CC: Paul Mackerras >> CC: Christoph Lameter >> Cc: Minchan Kim >> CC: Andrew Morton >> CC: KOSAKI Motohiro >> CC: Wen Congyang >> Signed-off-by: Yasuaki Ishimatsu >> >> --- >> drivers/base/memory.c | 20 ++++++++++++++++++++ >> include/linux/memory.h | 1 + >> mm/memory_hotplug.c | 5 +++++ >> 3 files changed, 26 insertions(+) >> >> Index: linux-3.5-rc4/drivers/base/memory.c >> =================================================================== >> --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-26 13:28:16.726211752 +0900 >> +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:34:22.423639904 +0900 >> @@ -70,6 +70,26 @@ void unregister_memory_isolate_notifier( >> } >> EXPORT_SYMBOL(unregister_memory_isolate_notifier); >> >> +bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn) >> +{ >> + struct memory_block *mem; >> + struct mem_section *section; >> + unsigned long pfn, section_nr; >> + >> + for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { >> + section_nr = pfn_to_section_nr(pfn); >> + section = __nr_to_section(section_nr); >> + mem = find_memory_block(section); >> + if (!mem) >> + continue; >> + if (mem->state == MEM_OFFLINE) >> + continue; >> + return false; >> + } >> + >> + return true; >> +} >> + >> /* >> * register_memory - Setup a sysfs device for a memory block >> */ >> Index: linux-3.5-rc4/include/linux/memory.h >> =================================================================== >> --- linux-3.5-rc4.orig/include/linux/memory.h 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/include/linux/memory.h 2012-06-26 13:34:22.424639891 +0900 >> @@ -120,6 +120,7 @@ extern int memory_isolate_notify(unsigne >> extern struct memory_block *find_memory_block_hinted(struct mem_section *, >> struct memory_block *); >> extern struct memory_block *find_memory_block(struct mem_section *); >> +extern bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn); >> #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION<> enum mem_add_context { BOOT, HOTPLUG }; >> #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ >> Index: linux-3.5-rc4/mm/memory_hotplug.c >> =================================================================== >> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:28:16.743211538 +0900 >> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:38.264940468 +0900 >> @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned >> >> lock_memory_hotplug(); >> >> + if (memory_is_offline(start_pfn, end_pfn)) { >> + ret = 0; >> + goto out; >> + } >> + >> zone = page_zone(pfn_to_page(start_pfn)); >> node = zone_to_nid(zone); >> nr_pages = end_pfn - start_pfn; >> >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >> Please read the FAQ at http://www.tux.org/lkml/ >> > > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yx0-f179.google.com (mail-yx0-f179.google.com [209.85.213.179]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 4426DB6FFC for ; Thu, 28 Jun 2012 15:26:44 +1000 (EST) Received: by yenr13 with SMTP id r13so1529256yen.38 for ; Wed, 27 Jun 2012 22:26:41 -0700 (PDT) MIME-Version: 1.0 Sender: kosaki.motohiro@gmail.com In-Reply-To: <4FEA9DB1.7010303@jp.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> From: KOSAKI Motohiro Date: Thu, 28 Jun 2012 01:26:21 -0400 Message-ID: Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages To: Yasuaki Ishimatsu Content-Type: text/plain; charset=ISO-8859-1 Cc: len.brown@intel.com, wency@cn.fujitsu.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, paulus@samba.org, minchan.kim@gmail.com, cl@linux.com, linuxppc-dev@lists.ozlabs.org, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , On Wed, Jun 27, 2012 at 1:44 AM, Yasuaki Ishimatsu wrote: > When offline_pages() is called to offlined memory, the function fails sin= ce > all memory has been offlined. In this case, the function should succeed. > The patch adds the check function into offline_pages(). I don't understand your point. I think following misoperation should fail. Otherwise administrator have no way to know their fault. $ echo offline > memoryN/state $ echo offline > memoryN/state In general, we don't like to ignore an error except the standard require it= . > > CC: Len Brown > CC: Benjamin Herrenschmidt > CC: Paul Mackerras > CC: Christoph Lameter > Cc: Minchan Kim > CC: Andrew Morton > CC: KOSAKI Motohiro > CC: Wen Congyang > Signed-off-by: Yasuaki Ishimatsu > > --- > =A0drivers/base/memory.c =A0| =A0 20 ++++++++++++++++++++ > =A0include/linux/memory.h | =A0 =A01 + > =A0mm/memory_hotplug.c =A0 =A0| =A0 =A05 +++++ > =A03 files changed, 26 insertions(+) > > Index: linux-3.5-rc4/drivers/base/memory.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- linux-3.5-rc4.orig/drivers/base/memory.c =A0 =A02012-06-26 13:28:16.7= 26211752 +0900 > +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:34:22.423639904 +09= 00 > @@ -70,6 +70,26 @@ void unregister_memory_isolate_notifier( > =A0} > =A0EXPORT_SYMBOL(unregister_memory_isolate_notifier); > > +bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn) I dislike this function name. 'memory' is too vague to me. > +{ > + =A0 =A0 =A0 struct memory_block *mem; > + =A0 =A0 =A0 struct mem_section *section; > + =A0 =A0 =A0 unsigned long pfn, section_nr; > + > + =A0 =A0 =A0 for (pfn =3D start_pfn; pfn < end_pfn; pfn +=3D PAGES_PER_S= ECTION) { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 section_nr =3D pfn_to_section_nr(pfn); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 section =3D __nr_to_section(section_nr); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 mem =3D find_memory_block(section); This seems to have strong sparse dependency. Hm, I wonder why memory-hotplug.c can enable when X86_64_ACPI_NUMA. # eventually, we can have this option just 'select SPARSEMEM' config MEMORY_HOTPLUG bool "Allow for memory hot-add" depends on SPARSEMEM || X86_64_ACPI_NUMA > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!mem) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 continue; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (mem->state =3D=3D MEM_OFFLINE) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 continue; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return false; > + =A0 =A0 =A0 } > + > + =A0 =A0 =A0 return true; > +} > + > =A0/* > =A0* register_memory - Setup a sysfs device for a memory block > =A0*/ > Index: linux-3.5-rc4/include/linux/memory.h > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- linux-3.5-rc4.orig/include/linux/memory.h =A0 2012-06-25 04:53:04.000= 000000 +0900 > +++ linux-3.5-rc4/include/linux/memory.h =A0 =A0 =A0 =A02012-06-26 13:34:= 22.424639891 +0900 > @@ -120,6 +120,7 @@ extern int memory_isolate_notify(unsigne > =A0extern struct memory_block *find_memory_block_hinted(struct mem_sectio= n *, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0struct memory_block *); > =A0extern struct memory_block *find_memory_block(struct mem_section *); > +extern bool memory_is_offline(unsigned long start_pfn, unsigned long end= _pfn); > =A0#define CONFIG_MEM_BLOCK_SIZE =A0(PAGES_PER_SECTION< =A0enum mem_add_context { BOOT, HOTPLUG }; > =A0#endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ > Index: linux-3.5-rc4/mm/memory_hotplug.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- linux-3.5-rc4.orig/mm/memory_hotplug.c =A0 =A0 =A02012-06-26 13:28:16= .743211538 +0900 > +++ linux-3.5-rc4/mm/memory_hotplug.c =A0 2012-06-26 13:48:38.264940468 += 0900 > @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned > > =A0 =A0 =A0 =A0lock_memory_hotplug(); > > + =A0 =A0 =A0 if (memory_is_offline(start_pfn, end_pfn)) { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D 0; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out; > + =A0 =A0 =A0 } > + > =A0 =A0 =A0 =A0zone =3D page_zone(pfn_to_page(start_pfn)); > =A0 =A0 =A0 =A0node =3D zone_to_nid(zone); > =A0 =A0 =A0 =A0nr_pages =3D end_pfn - start_pfn; > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. =A0For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yw0-f44.google.com (mail-yw0-f44.google.com [209.85.213.44]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 276CB10083A for ; Thu, 28 Jun 2012 15:27:58 +1000 (EST) Received: by yhq56 with SMTP id 56so2060424yhq.17 for ; Wed, 27 Jun 2012 22:27:56 -0700 (PDT) MIME-Version: 1.0 Sender: kosaki.motohiro@gmail.com In-Reply-To: <4FEBE646.5090801@jp.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> <4FEAC916.7030506@cn.fujitsu.com> <4FEBE646.5090801@jp.fujitsu.com> From: KOSAKI Motohiro Date: Thu, 28 Jun 2012 01:27:35 -0400 Message-ID: Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages To: Yasuaki Ishimatsu Content-Type: text/plain; charset=ISO-8859-1 Cc: len.brown@intel.com, Wen Congyang , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, paulus@samba.org, minchan.kim@gmail.com, cl@linux.com, linuxppc-dev@lists.ozlabs.org, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , On Thu, Jun 28, 2012 at 1:06 AM, Yasuaki Ishimatsu wrote: > Hi Wen, > > 2012/06/27 17:49, Wen Congyang wrote: >> At 06/27/2012 01:44 PM, Yasuaki Ishimatsu Wrote: >>> When offline_pages() is called to offlined memory, the function fails since >>> all memory has been offlined. In this case, the function should succeed. >>> The patch adds the check function into offline_pages(). >> >> You miss such case: some pages are online, while some pages are offline. >> offline_pages() will fail too in such case. > > You are right. But current code fails, when the function is called to offline > memory. In this case, the function should succeed. So the patch confirms > whether the memory was offlined or not. And if memory has already been > offlined, offline_pages return 0. Can you please explain why the caller can't check it? I hope to avoid an ignorance as far as we can. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fgwmail5.fujitsu.co.jp (fgwmail5.fujitsu.co.jp [192.51.44.35]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 46570B6F77 for ; Thu, 28 Jun 2012 16:02:06 +1000 (EST) Received: from m3.gw.fujitsu.co.jp (unknown [10.0.50.73]) by fgwmail5.fujitsu.co.jp (Postfix) with ESMTP id 7CBE43EE081 for ; Thu, 28 Jun 2012 15:02:01 +0900 (JST) Received: from smail (m3 [127.0.0.1]) by outgoing.m3.gw.fujitsu.co.jp (Postfix) with ESMTP id 65A4845DEAD for ; Thu, 28 Jun 2012 15:02:01 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (s3.gw.fujitsu.co.jp [10.0.50.93]) by m3.gw.fujitsu.co.jp (Postfix) with ESMTP id 5009345DEA6 for ; Thu, 28 Jun 2012 15:02:01 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id 4497E1DB803E for ; Thu, 28 Jun 2012 15:02:01 +0900 (JST) Received: from g01jpexchyt05.g01.fujitsu.local (g01jpexchyt05.g01.fujitsu.local [10.128.194.44]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id DF6611DB8038 for ; Thu, 28 Jun 2012 15:02:00 +0900 (JST) Message-ID: <4FEBF342.9030303@jp.fujitsu.com> Date: Thu, 28 Jun 2012 15:01:38 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 To: KOSAKI Motohiro Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> <4FEAC916.7030506@cn.fujitsu.com> <4FEBE646.5090801@jp.fujitsu.com> In-Reply-To: Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Cc: len.brown@intel.com, Wen Congyang , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, paulus@samba.org, minchan.kim@gmail.com, cl@linux.com, linuxppc-dev@lists.ozlabs.org, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Hi Kosaki-san, 2012/06/28 14:27, KOSAKI Motohiro wrote: > On Thu, Jun 28, 2012 at 1:06 AM, Yasuaki Ishimatsu > wrote: >> Hi Wen, >> >> 2012/06/27 17:49, Wen Congyang wrote: >>> At 06/27/2012 01:44 PM, Yasuaki Ishimatsu Wrote: >>>> When offline_pages() is called to offlined memory, the function fails since >>>> all memory has been offlined. In this case, the function should succeed. >>>> The patch adds the check function into offline_pages(). >>> >>> You miss such case: some pages are online, while some pages are offline. >>> offline_pages() will fail too in such case. >> >> You are right. But current code fails, when the function is called to offline >> memory. In this case, the function should succeed. So the patch confirms >> whether the memory was offlined or not. And if memory has already been >> offlined, offline_pages return 0. > > Can you please explain why the caller can't check it? I hope to avoid > an ignorance > as far as we can. Of course, caller side can check it. But there is a possibility that offline_pages() is called by many functions. So I do not think that it is good that all functions which call offline_pages() check it. Thanks, Yasuaki Ishimatsu From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from song.cn.fujitsu.com (unknown [222.73.24.84]) by ozlabs.org (Postfix) with ESMTP id 54E03B7004 for ; Thu, 28 Jun 2012 16:28:21 +1000 (EST) Message-ID: <4FEBFA8D.5040607@cn.fujitsu.com> Date: Thu, 28 Jun 2012 14:32:45 +0800 From: Wen Congyang MIME-Version: 1.0 To: Yasuaki Ishimatsu Subject: Re: [RFC PATCH 4/12] memory-hotplug : remove /sys/firmware/memmap/X sysfs References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9E5F.4070205@jp.fujitsu.com> In-Reply-To: <4FEA9E5F.4070205@jp.fujitsu.com> Content-Type: text/plain; charset=ISO-8859-1 Cc: len.brown@intel.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, cl@linux.com, linuxppc-dev@lists.ozlabs.org, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , At 06/27/2012 01:47 PM, Yasuaki Ishimatsu Wrote: > When (hot)adding memory into system, /sys/firmware/memmap/X/{end, start, type} > sysfs files are created. But there is no code to remove these files. The patch > implements the function to remove them. > > Note : The code does not free firmware_map_entry since there is no way to free > memory which is allocated by bootmem. > > CC: Len Brown > CC: Benjamin Herrenschmidt > CC: Paul Mackerras > CC: Christoph Lameter > Cc: Minchan Kim > CC: Andrew Morton > CC: KOSAKI Motohiro > CC: Wen Congyang > Signed-off-by: Yasuaki Ishimatsu > > --- > drivers/firmware/memmap.c | 71 +++++++++++++++++++++++++++++++++++++++++++ > include/linux/firmware-map.h | 6 +++ > mm/memory_hotplug.c | 6 +++ > 3 files changed, 82 insertions(+), 1 deletion(-) > > Index: linux-3.5-rc4/mm/memory_hotplug.c > =================================================================== > --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:37:30.546288901 +0900 > +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:44:37.069955820 +0900 > @@ -661,7 +661,11 @@ EXPORT_SYMBOL_GPL(add_memory); > > int remove_memory(int nid, u64 start, u64 size) > { > - return -EBUSY; > + lock_memory_hotplug(); > + /* remove memmap entry */ > + firmware_map_remove(start, start + size, "System RAM"); > + unlock_memory_hotplug(); > + return 0; > > } > EXPORT_SYMBOL_GPL(remove_memory); > Index: linux-3.5-rc4/include/linux/firmware-map.h > =================================================================== > --- linux-3.5-rc4.orig/include/linux/firmware-map.h 2012-06-25 04:53:04.000000000 +0900 > +++ linux-3.5-rc4/include/linux/firmware-map.h 2012-06-26 13:44:37.070955807 +0900 > @@ -25,6 +25,7 @@ > > int firmware_map_add_early(u64 start, u64 end, const char *type); > int firmware_map_add_hotplug(u64 start, u64 end, const char *type); > +int firmware_map_remove(u64 start, u64 end, const char *type); > > #else /* CONFIG_FIRMWARE_MEMMAP */ > > @@ -38,6 +39,11 @@ static inline int firmware_map_add_hotpl > return 0; > } > > +static inline int firmware_map_remove(u64 start, u64 end, const char *type) > +{ > + return 0; > +} > + > #endif /* CONFIG_FIRMWARE_MEMMAP */ > > #endif /* _LINUX_FIRMWARE_MAP_H */ > Index: linux-3.5-rc4/drivers/firmware/memmap.c > =================================================================== > --- linux-3.5-rc4.orig/drivers/firmware/memmap.c 2012-06-25 04:53:04.000000000 +0900 > +++ linux-3.5-rc4/drivers/firmware/memmap.c 2012-06-26 13:47:17.606948898 +0900 > @@ -123,6 +123,16 @@ static int firmware_map_add_entry(u64 st > return 0; > } > > +/** > + * firmware_map_remove_entry() - Does the real work to remove a firmware > + * memmap entry. > + * @entry: removed entry. > + **/ > +static inline void firmware_map_remove_entry(struct firmware_map_entry *entry) > +{ > + list_del(&entry->list); > +} > + > /* > * Add memmap entry on sysfs > */ > @@ -144,6 +154,31 @@ static int add_sysfs_fw_map_entry(struct > return 0; > } > > +/* > + * Remove memmap entry on sysfs > + */ > +static inline void remove_sysfs_fw_map_entry(struct firmware_map_entry *entry) > +{ > + kobject_del(&entry->kobj); > +} > + > +/* > + * Search memmap entry > + */ > + > +struct firmware_map_entry * __meminit > +find_firmware_map_entry(u64 start, u64 end, const char *type) > +{ > + struct firmware_map_entry *entry; > + > + list_for_each_entry(entry, &map_entries, list) > + if ((entry->start == start) && (entry->end == end) && > + (!strcmp(entry->type, type))) > + return entry; > + > + return NULL; > +} > + > /** > * firmware_map_add_hotplug() - Adds a firmware mapping entry when we do > * memory hotplug. > @@ -196,6 +231,42 @@ int __init firmware_map_add_early(u64 st > return firmware_map_add_entry(start, end, type, entry); > } > > +void release_firmware_map_entry(struct firmware_map_entry *entry) > +{ > + /* > + * FIXME : There is no idea. > + * How to free the entry which allocated bootmem? > + */ > +} > + > +/** > + * firmware_map_remove() - remove a firmware mapping entry > + * @start: Start of the memory range. > + * @end: End of the memory range (inclusive). > + * @type: Type of the memory range. > + * > + * removes a firmware mapping entry. > + * > + * Returns 0 on success, or -EINVAL if no entry. > + **/ > +int __meminit firmware_map_remove(u64 start, u64 end, const char *type) > +{ > + struct firmware_map_entry *entry; > + > + entry = find_firmware_map_entry(start, end, type); Hmm, we cannot find the entry easily, because the end can be: 1. start + size 2. start + size - 1 So, We should fix this bug first. > + if (!entry) > + return -EINVAL; > + > + /* remove the memmap entry */ > + remove_sysfs_fw_map_entry(entry); > + > + firmware_map_remove_entry(entry); > + > + release_firmware_map_entry(entry); I guess you want to free the memory in the above function. But I think it is not a good idea to free it here. We should free it when the entry->kobj's kref is decreased to 0. Thanks Wen Congyang > + > + return 0; > +} > + > /* > * Sysfs functions ------------------------------------------------------------- > */ > > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fgwmail5.fujitsu.co.jp (fgwmail5.fujitsu.co.jp [192.51.44.35]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 0058BB6EEB for ; Thu, 28 Jun 2012 16:52:14 +1000 (EST) Received: from m3.gw.fujitsu.co.jp (unknown [10.0.50.73]) by fgwmail5.fujitsu.co.jp (Postfix) with ESMTP id E3B5B3EE0BD for ; Thu, 28 Jun 2012 15:52:12 +0900 (JST) Received: from smail (m3 [127.0.0.1]) by outgoing.m3.gw.fujitsu.co.jp (Postfix) with ESMTP id C630C45DEB4 for ; Thu, 28 Jun 2012 15:52:12 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (s3.gw.fujitsu.co.jp [10.0.50.93]) by m3.gw.fujitsu.co.jp (Postfix) with ESMTP id AB71345DE9E for ; Thu, 28 Jun 2012 15:52:12 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id 9436CE08009 for ; Thu, 28 Jun 2012 15:52:12 +0900 (JST) Received: from g01jpexchkw06.g01.fujitsu.local (g01jpexchkw06.g01.fujitsu.local [10.0.194.45]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id 46AB1E08002 for ; Thu, 28 Jun 2012 15:52:12 +0900 (JST) Message-ID: <4FEBFF08.60502@jp.fujitsu.com> Date: Thu, 28 Jun 2012 15:51:52 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 To: KOSAKI Motohiro Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> In-Reply-To: Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Cc: len.brown@intel.com, wency@cn.fujitsu.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, paulus@samba.org, minchan.kim@gmail.com, cl@linux.com, linuxppc-dev@lists.ozlabs.org, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Hi Kosaki-san, 2012/06/28 14:26, KOSAKI Motohiro wrote: > On Wed, Jun 27, 2012 at 1:44 AM, Yasuaki Ishimatsu > wrote: >> When offline_pages() is called to offlined memory, the function fails since >> all memory has been offlined. In this case, the function should succeed. >> The patch adds the check function into offline_pages(). > > I don't understand your point. I think following misoperation should > fail. Otherwise > administrator have no way to know their fault. > > $ echo offline > memoryN/state > $ echo offline > memoryN/state > > In general, we don't like to ignore an error except the standard require it. I understood the intention of previous mail (why the caller can't check it? ). I'll move memory_is_offline() to caller side. >> >> CC: Len Brown >> CC: Benjamin Herrenschmidt >> CC: Paul Mackerras >> CC: Christoph Lameter >> Cc: Minchan Kim >> CC: Andrew Morton >> CC: KOSAKI Motohiro >> CC: Wen Congyang >> Signed-off-by: Yasuaki Ishimatsu >> >> --- >> drivers/base/memory.c | 20 ++++++++++++++++++++ >> include/linux/memory.h | 1 + >> mm/memory_hotplug.c | 5 +++++ >> 3 files changed, 26 insertions(+) >> >> Index: linux-3.5-rc4/drivers/base/memory.c >> =================================================================== >> --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-26 13:28:16.726211752 +0900 >> +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:34:22.423639904 +0900 >> @@ -70,6 +70,26 @@ void unregister_memory_isolate_notifier( >> } >> EXPORT_SYMBOL(unregister_memory_isolate_notifier); >> >> +bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn) > > I dislike this function name. 'memory' is too vague to me. O.K. I retry to change the name of the function. > > >> +{ >> + struct memory_block *mem; >> + struct mem_section *section; >> + unsigned long pfn, section_nr; >> + >> + for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { >> + section_nr = pfn_to_section_nr(pfn); >> + section = __nr_to_section(section_nr); >> + mem = find_memory_block(section); > > This seems to have strong sparse dependency. Thanks. I will consider other CONFIG_. Thanks. Yasuaki Ishimatsu > Hm, I wonder why memory-hotplug.c can enable when X86_64_ACPI_NUMA. > > # eventually, we can have this option just 'select SPARSEMEM' > config MEMORY_HOTPLUG > bool "Allow for memory hot-add" > depends on SPARSEMEM || X86_64_ACPI_NUMA > > >> + if (!mem) >> + continue; >> + if (mem->state == MEM_OFFLINE) >> + continue; >> + return false; >> + } >> + >> + return true; >> +} >> + >> /* >> * register_memory - Setup a sysfs device for a memory block >> */ >> Index: linux-3.5-rc4/include/linux/memory.h >> =================================================================== >> --- linux-3.5-rc4.orig/include/linux/memory.h 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/include/linux/memory.h 2012-06-26 13:34:22.424639891 +0900 >> @@ -120,6 +120,7 @@ extern int memory_isolate_notify(unsigne >> extern struct memory_block *find_memory_block_hinted(struct mem_section *, >> struct memory_block *); >> extern struct memory_block *find_memory_block(struct mem_section *); >> +extern bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn); >> #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION<> enum mem_add_context { BOOT, HOTPLUG }; >> #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ >> Index: linux-3.5-rc4/mm/memory_hotplug.c >> =================================================================== >> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:28:16.743211538 +0900 >> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:38.264940468 +0900 >> @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned >> >> lock_memory_hotplug(); >> >> + if (memory_is_offline(start_pfn, end_pfn)) { >> + ret = 0; >> + goto out; >> + } >> + >> zone = page_zone(pfn_to_page(start_pfn)); >> node = zone_to_nid(zone); >> nr_pages = end_pfn - start_pfn; >> >> -- >> To unsubscribe, send a message with 'unsubscribe linux-mm' in >> the body to majordomo@kvack.org. For more info on Linux MM, >> see: http://www.linux-mm.org/ . >> Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fgwmail5.fujitsu.co.jp (fgwmail5.fujitsu.co.jp [192.51.44.35]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 35BB5B6FBC for ; Thu, 28 Jun 2012 17:01:24 +1000 (EST) Received: from m1.gw.fujitsu.co.jp (unknown [10.0.50.71]) by fgwmail5.fujitsu.co.jp (Postfix) with ESMTP id 461A83EE0BC for ; Thu, 28 Jun 2012 16:01:23 +0900 (JST) Received: from smail (m1 [127.0.0.1]) by outgoing.m1.gw.fujitsu.co.jp (Postfix) with ESMTP id 3071D45DE59 for ; Thu, 28 Jun 2012 16:01:23 +0900 (JST) Received: from s1.gw.fujitsu.co.jp (s1.gw.fujitsu.co.jp [10.0.50.91]) by m1.gw.fujitsu.co.jp (Postfix) with ESMTP id 057D845DE5A for ; Thu, 28 Jun 2012 16:01:23 +0900 (JST) Received: from s1.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s1.gw.fujitsu.co.jp (Postfix) with ESMTP id ECF231DB804D for ; Thu, 28 Jun 2012 16:01:22 +0900 (JST) Received: from g01jpexchkw02.g01.fujitsu.local (g01jpexchkw02.g01.fujitsu.local [10.0.194.41]) by s1.gw.fujitsu.co.jp (Postfix) with ESMTP id ABAF31DB8046 for ; Thu, 28 Jun 2012 16:01:22 +0900 (JST) Message-ID: <4FEC012E.5030209@jp.fujitsu.com> Date: Thu, 28 Jun 2012 16:01:02 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 To: David Rientjes Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> In-Reply-To: Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Cc: len.brown@intel.com, wency@cn.fujitsu.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, cl@linux.com, linuxppc-dev@lists.ozlabs.org, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Hi David, 2012/06/27 15:16, David Rientjes wrote: > On Wed, 27 Jun 2012, Yasuaki Ishimatsu wrote: > >> Index: linux-3.5-rc4/mm/memory_hotplug.c >> =================================================================== >> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:28:16.743211538 +0900 >> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:38.264940468 +0900 >> @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned >> >> lock_memory_hotplug(); >> >> + if (memory_is_offline(start_pfn, end_pfn)) { >> + ret = 0; >> + goto out; >> + } >> + >> zone = page_zone(pfn_to_page(start_pfn)); >> node = zone_to_nid(zone); >> nr_pages = end_pfn - start_pfn; > > Are there additional prerequisites for this patch? Otherwise it changes > the return value of offline_memory() which will now call > acpi_memory_powerdown_device() in the acpi memhotplug case when disabling. > Is that a problem? I have understood there is a person who expects "offline_pages()" to fail in this case by kosaki's comment. So I'll move memory_is_offline to caller side. Thanks, Yasuaki Ishimatsu > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: email@kvack.org > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fgwmail6.fujitsu.co.jp (fgwmail6.fujitsu.co.jp [192.51.44.36]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id DEED2B6FF8 for ; Thu, 28 Jun 2012 18:08:09 +1000 (EST) Received: from m3.gw.fujitsu.co.jp (unknown [10.0.50.73]) by fgwmail6.fujitsu.co.jp (Postfix) with ESMTP id 8929C3EE0C2 for ; Thu, 28 Jun 2012 17:08:05 +0900 (JST) Received: from smail (m3 [127.0.0.1]) by outgoing.m3.gw.fujitsu.co.jp (Postfix) with ESMTP id 6E82645DE9E for ; Thu, 28 Jun 2012 17:08:05 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (s3.gw.fujitsu.co.jp [10.0.50.93]) by m3.gw.fujitsu.co.jp (Postfix) with ESMTP id 4B4F645DEBB for ; Thu, 28 Jun 2012 17:08:05 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id 3B6FBE08001 for ; Thu, 28 Jun 2012 17:08:05 +0900 (JST) Received: from G01JPEXCHKW08.g01.fujitsu.local (G01JPEXCHKW08.g01.fujitsu.local [10.0.194.47]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id A25F7E08003 for ; Thu, 28 Jun 2012 17:08:04 +0900 (JST) Message-ID: <4FEC10CB.3060403@jp.fujitsu.com> Date: Thu, 28 Jun 2012 17:07:39 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 To: Wen Congyang Subject: Re: [RFC PATCH 4/12] memory-hotplug : remove /sys/firmware/memmap/X sysfs References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9E5F.4070205@jp.fujitsu.com> <4FEBFA8D.5040607@cn.fujitsu.com> In-Reply-To: <4FEBFA8D.5040607@cn.fujitsu.com> Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Cc: len.brown@intel.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, cl@linux.com, linuxppc-dev@lists.ozlabs.org, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Hi Wen, 2012/06/28 15:32, Wen Congyang wrote: > At 06/27/2012 01:47 PM, Yasuaki Ishimatsu Wrote: >> When (hot)adding memory into system, /sys/firmware/memmap/X/{end, start, type} >> sysfs files are created. But there is no code to remove these files. The patch >> implements the function to remove them. >> >> Note : The code does not free firmware_map_entry since there is no way to free >> memory which is allocated by bootmem. >> >> CC: Len Brown >> CC: Benjamin Herrenschmidt >> CC: Paul Mackerras >> CC: Christoph Lameter >> Cc: Minchan Kim >> CC: Andrew Morton >> CC: KOSAKI Motohiro >> CC: Wen Congyang >> Signed-off-by: Yasuaki Ishimatsu >> >> --- >> drivers/firmware/memmap.c | 71 +++++++++++++++++++++++++++++++++++++++++++ >> include/linux/firmware-map.h | 6 +++ >> mm/memory_hotplug.c | 6 +++ >> 3 files changed, 82 insertions(+), 1 deletion(-) >> >> Index: linux-3.5-rc4/mm/memory_hotplug.c >> =================================================================== >> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:37:30.546288901 +0900 >> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:44:37.069955820 +0900 >> @@ -661,7 +661,11 @@ EXPORT_SYMBOL_GPL(add_memory); >> >> int remove_memory(int nid, u64 start, u64 size) >> { >> - return -EBUSY; >> + lock_memory_hotplug(); >> + /* remove memmap entry */ >> + firmware_map_remove(start, start + size, "System RAM"); >> + unlock_memory_hotplug(); >> + return 0; >> >> } >> EXPORT_SYMBOL_GPL(remove_memory); >> Index: linux-3.5-rc4/include/linux/firmware-map.h >> =================================================================== >> --- linux-3.5-rc4.orig/include/linux/firmware-map.h 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/include/linux/firmware-map.h 2012-06-26 13:44:37.070955807 +0900 >> @@ -25,6 +25,7 @@ >> >> int firmware_map_add_early(u64 start, u64 end, const char *type); >> int firmware_map_add_hotplug(u64 start, u64 end, const char *type); >> +int firmware_map_remove(u64 start, u64 end, const char *type); >> >> #else /* CONFIG_FIRMWARE_MEMMAP */ >> >> @@ -38,6 +39,11 @@ static inline int firmware_map_add_hotpl >> return 0; >> } >> >> +static inline int firmware_map_remove(u64 start, u64 end, const char *type) >> +{ >> + return 0; >> +} >> + >> #endif /* CONFIG_FIRMWARE_MEMMAP */ >> >> #endif /* _LINUX_FIRMWARE_MAP_H */ >> Index: linux-3.5-rc4/drivers/firmware/memmap.c >> =================================================================== >> --- linux-3.5-rc4.orig/drivers/firmware/memmap.c 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/drivers/firmware/memmap.c 2012-06-26 13:47:17.606948898 +0900 >> @@ -123,6 +123,16 @@ static int firmware_map_add_entry(u64 st >> return 0; >> } >> >> +/** >> + * firmware_map_remove_entry() - Does the real work to remove a firmware >> + * memmap entry. >> + * @entry: removed entry. >> + **/ >> +static inline void firmware_map_remove_entry(struct firmware_map_entry *entry) >> +{ >> + list_del(&entry->list); >> +} >> + >> /* >> * Add memmap entry on sysfs >> */ >> @@ -144,6 +154,31 @@ static int add_sysfs_fw_map_entry(struct >> return 0; >> } >> >> +/* >> + * Remove memmap entry on sysfs >> + */ >> +static inline void remove_sysfs_fw_map_entry(struct firmware_map_entry *entry) >> +{ >> + kobject_del(&entry->kobj); >> +} >> + >> +/* >> + * Search memmap entry >> + */ >> + >> +struct firmware_map_entry * __meminit >> +find_firmware_map_entry(u64 start, u64 end, const char *type) >> +{ >> + struct firmware_map_entry *entry; >> + >> + list_for_each_entry(entry, &map_entries, list) >> + if ((entry->start == start) && (entry->end == end) && >> + (!strcmp(entry->type, type))) >> + return entry; >> + >> + return NULL; >> +} >> + >> /** >> * firmware_map_add_hotplug() - Adds a firmware mapping entry when we do >> * memory hotplug. >> @@ -196,6 +231,42 @@ int __init firmware_map_add_early(u64 st >> return firmware_map_add_entry(start, end, type, entry); >> } >> >> +void release_firmware_map_entry(struct firmware_map_entry *entry) >> +{ >> + /* >> + * FIXME : There is no idea. >> + * How to free the entry which allocated bootmem? >> + */ >> +} >> + >> +/** >> + * firmware_map_remove() - remove a firmware mapping entry >> + * @start: Start of the memory range. >> + * @end: End of the memory range (inclusive). >> + * @type: Type of the memory range. >> + * >> + * removes a firmware mapping entry. >> + * >> + * Returns 0 on success, or -EINVAL if no entry. >> + **/ >> +int __meminit firmware_map_remove(u64 start, u64 end, const char *type) >> +{ >> + struct firmware_map_entry *entry; >> + >> + entry = find_firmware_map_entry(start, end, type); > > Hmm, we cannot find the entry easily, because the end can be: > 1. start + size > 2. start + size - 1 > > So, We should fix this bug first. This is not a bug. start and size arguments of firmware_map_remove() include acpi_memory_info->{start_addr, length}. And when creating a firmware_map_entry, the entry is created by acpi_memory_info->{start_addr, length}. So I don't think that we need care your comment. > >> + if (!entry) >> + return -EINVAL; >> + >> + /* remove the memmap entry */ >> + remove_sysfs_fw_map_entry(entry); >> + >> + firmware_map_remove_entry(entry); >> + >> + release_firmware_map_entry(entry); > > I guess you want to free the memory in the above function. But I think it is > not a good idea to free it here. We should free it when the entry->kobj's kref > is decreased to 0. Thanks. I'll update your comment at next version. Thanks, Yasuaki Ishimatsu > > Thanks > Wen Congyang > >> + >> + return 0; >> +} >> + >> /* >> * Sysfs functions ------------------------------------------------------------- >> */ >> >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >> Please read the FAQ at http://www.tux.org/lkml/ >> > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: email@kvack.org > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from song.cn.fujitsu.com (unknown [222.73.24.84]) by ozlabs.org (Postfix) with ESMTP id EE8961007D4 for ; Thu, 28 Jun 2012 18:33:58 +1000 (EST) Message-ID: <4FEC17F8.1000405@cn.fujitsu.com> Date: Thu, 28 Jun 2012 16:38:16 +0800 From: Wen Congyang MIME-Version: 1.0 To: Yasuaki Ishimatsu Subject: Re: [RFC PATCH 4/12] memory-hotplug : remove /sys/firmware/memmap/X sysfs References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9E5F.4070205@jp.fujitsu.com> <4FEBFA8D.5040607@cn.fujitsu.com> <4FEC10CB.3060403@jp.fujitsu.com> In-Reply-To: <4FEC10CB.3060403@jp.fujitsu.com> Content-Type: text/plain; charset=ISO-8859-1 Cc: len.brown@intel.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, cl@linux.com, linuxppc-dev@lists.ozlabs.org, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , At 06/28/2012 04:07 PM, Yasuaki Ishimatsu Wrote: > Hi Wen, > > 2012/06/28 15:32, Wen Congyang wrote: >> At 06/27/2012 01:47 PM, Yasuaki Ishimatsu Wrote: >>> When (hot)adding memory into system, /sys/firmware/memmap/X/{end, >>> start, type} >>> sysfs files are created. But there is no code to remove these files. >>> The patch >>> implements the function to remove them. >>> >>> Note : The code does not free firmware_map_entry since there is no >>> way to free >>> memory which is allocated by bootmem. >>> >>> CC: Len Brown >>> CC: Benjamin Herrenschmidt >>> CC: Paul Mackerras >>> CC: Christoph Lameter >>> Cc: Minchan Kim >>> CC: Andrew Morton >>> CC: KOSAKI Motohiro >>> CC: Wen Congyang >>> Signed-off-by: Yasuaki Ishimatsu >>> >>> --- >>> drivers/firmware/memmap.c | 71 >>> +++++++++++++++++++++++++++++++++++++++++++ >>> include/linux/firmware-map.h | 6 +++ >>> mm/memory_hotplug.c | 6 +++ >>> 3 files changed, 82 insertions(+), 1 deletion(-) >>> >>> Index: linux-3.5-rc4/mm/memory_hotplug.c >>> =================================================================== >>> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 >>> 13:37:30.546288901 +0900 >>> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 >>> 13:44:37.069955820 +0900 >>> @@ -661,7 +661,11 @@ EXPORT_SYMBOL_GPL(add_memory); >>> >>> int remove_memory(int nid, u64 start, u64 size) >>> { >>> - return -EBUSY; >>> + lock_memory_hotplug(); >>> + /* remove memmap entry */ >>> + firmware_map_remove(start, start + size, "System RAM"); >>> + unlock_memory_hotplug(); >>> + return 0; >>> >>> } >>> EXPORT_SYMBOL_GPL(remove_memory); >>> Index: linux-3.5-rc4/include/linux/firmware-map.h >>> =================================================================== >>> --- linux-3.5-rc4.orig/include/linux/firmware-map.h 2012-06-25 >>> 04:53:04.000000000 +0900 >>> +++ linux-3.5-rc4/include/linux/firmware-map.h 2012-06-26 >>> 13:44:37.070955807 +0900 >>> @@ -25,6 +25,7 @@ >>> >>> int firmware_map_add_early(u64 start, u64 end, const char *type); >>> int firmware_map_add_hotplug(u64 start, u64 end, const char *type); >>> +int firmware_map_remove(u64 start, u64 end, const char *type); >>> >>> #else /* CONFIG_FIRMWARE_MEMMAP */ >>> >>> @@ -38,6 +39,11 @@ static inline int firmware_map_add_hotpl >>> return 0; >>> } >>> >>> +static inline int firmware_map_remove(u64 start, u64 end, const char >>> *type) >>> +{ >>> + return 0; >>> +} >>> + >>> #endif /* CONFIG_FIRMWARE_MEMMAP */ >>> >>> #endif /* _LINUX_FIRMWARE_MAP_H */ >>> Index: linux-3.5-rc4/drivers/firmware/memmap.c >>> =================================================================== >>> --- linux-3.5-rc4.orig/drivers/firmware/memmap.c 2012-06-25 >>> 04:53:04.000000000 +0900 >>> +++ linux-3.5-rc4/drivers/firmware/memmap.c 2012-06-26 >>> 13:47:17.606948898 +0900 >>> @@ -123,6 +123,16 @@ static int firmware_map_add_entry(u64 st >>> return 0; >>> } >>> >>> +/** >>> + * firmware_map_remove_entry() - Does the real work to remove a >>> firmware >>> + * memmap entry. >>> + * @entry: removed entry. >>> + **/ >>> +static inline void firmware_map_remove_entry(struct >>> firmware_map_entry *entry) >>> +{ >>> + list_del(&entry->list); >>> +} >>> + >>> /* >>> * Add memmap entry on sysfs >>> */ >>> @@ -144,6 +154,31 @@ static int add_sysfs_fw_map_entry(struct >>> return 0; >>> } >>> >>> +/* >>> + * Remove memmap entry on sysfs >>> + */ >>> +static inline void remove_sysfs_fw_map_entry(struct >>> firmware_map_entry *entry) >>> +{ >>> + kobject_del(&entry->kobj); >>> +} >>> + >>> +/* >>> + * Search memmap entry >>> + */ >>> + >>> +struct firmware_map_entry * __meminit >>> +find_firmware_map_entry(u64 start, u64 end, const char *type) >>> +{ >>> + struct firmware_map_entry *entry; >>> + >>> + list_for_each_entry(entry, &map_entries, list) >>> + if ((entry->start == start) && (entry->end == end) && >>> + (!strcmp(entry->type, type))) >>> + return entry; >>> + >>> + return NULL; >>> +} >>> + >>> /** >>> * firmware_map_add_hotplug() - Adds a firmware mapping entry when >>> we do >>> * memory hotplug. >>> @@ -196,6 +231,42 @@ int __init firmware_map_add_early(u64 st >>> return firmware_map_add_entry(start, end, type, entry); >>> } >>> >>> +void release_firmware_map_entry(struct firmware_map_entry *entry) >>> +{ >>> + /* >>> + * FIXME : There is no idea. >>> + * How to free the entry which allocated bootmem? >>> + */ >>> +} >>> + >>> +/** >>> + * firmware_map_remove() - remove a firmware mapping entry >>> + * @start: Start of the memory range. >>> + * @end: End of the memory range (inclusive). >>> + * @type: Type of the memory range. >>> + * >>> + * removes a firmware mapping entry. >>> + * >>> + * Returns 0 on success, or -EINVAL if no entry. >>> + **/ >>> +int __meminit firmware_map_remove(u64 start, u64 end, const char *type) >>> +{ >>> + struct firmware_map_entry *entry; >>> + >>> + entry = find_firmware_map_entry(start, end, type); >> >> Hmm, we cannot find the entry easily, because the end can be: >> 1. start + size >> 2. start + size - 1 >> >> So, We should fix this bug first. > > This is not a bug. > > start and size arguments of firmware_map_remove() include > acpi_memory_info->{start_addr, length}. And when creating a > firmware_map_entry, > the entry is created by acpi_memory_info->{start_addr, length}. So I don't > think that we need care your comment. If the memory device is hotpluged before the os starts, and the memory map is included in e820 map, the entry will be created by firmware_map_add_early(). The function firmware_map_add_early() is called by e820_reserve_resources(): ===================== for (i = 0; i < e820_saved.nr_map; i++) { struct e820entry *entry = &e820_saved.map[i]; firmware_map_add_early(entry->addr, entry->addr + entry->size - 1, e820_type_to_string(entry->type)); } ===================== Note: the end is addr + size - 1, not addr + size. In such case, you cannot find the entry. Thanks Wen Congyang > >> >>> + if (!entry) >>> + return -EINVAL; >>> + >>> + /* remove the memmap entry */ >>> + remove_sysfs_fw_map_entry(entry); >>> + >>> + firmware_map_remove_entry(entry); >>> + >>> + release_firmware_map_entry(entry); >> >> I guess you want to free the memory in the above function. But I think >> it is >> not a good idea to free it here. We should free it when the >> entry->kobj's kref >> is decreased to 0. > > Thanks. > I'll update your comment at next version. > > Thanks, > Yasuaki Ishimatsu > >> >> Thanks >> Wen Congyang >> >>> + >>> + return 0; >>> +} >>> + >>> /* >>> * Sysfs functions >>> ------------------------------------------------------------- >>> */ >>> >>> -- >>> To unsubscribe from this list: send the line "unsubscribe >>> linux-kernel" in >>> the body of a message to majordomo@vger.kernel.org >>> More majordomo info at http://vger.kernel.org/majordomo-info.html >>> Please read the FAQ at http://www.tux.org/lkml/ >>> >> >> -- >> To unsubscribe, send a message with 'unsubscribe linux-mm' in >> the body to majordomo@kvack.org. For more info on Linux MM, >> see: http://www.linux-mm.org/ . >> Don't email: email@kvack.org >> > > > > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fgwmail6.fujitsu.co.jp (fgwmail6.fujitsu.co.jp [192.51.44.36]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id EDDDAB7006 for ; Fri, 29 Jun 2012 13:09:58 +1000 (EST) Received: from m1.gw.fujitsu.co.jp (unknown [10.0.50.71]) by fgwmail6.fujitsu.co.jp (Postfix) with ESMTP id 05B403EE0B6 for ; Fri, 29 Jun 2012 12:09:54 +0900 (JST) Received: from smail (m1 [127.0.0.1]) by outgoing.m1.gw.fujitsu.co.jp (Postfix) with ESMTP id D9FAE45DE54 for ; Fri, 29 Jun 2012 12:09:53 +0900 (JST) Received: from s1.gw.fujitsu.co.jp (s1.gw.fujitsu.co.jp [10.0.50.91]) by m1.gw.fujitsu.co.jp (Postfix) with ESMTP id C084445DE55 for ; Fri, 29 Jun 2012 12:09:53 +0900 (JST) Received: from s1.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s1.gw.fujitsu.co.jp (Postfix) with ESMTP id B16FF1DB8053 for ; Fri, 29 Jun 2012 12:09:53 +0900 (JST) Received: from g01jpexchyt04.g01.fujitsu.local (g01jpexchyt04.g01.fujitsu.local [10.128.194.43]) by s1.gw.fujitsu.co.jp (Postfix) with ESMTP id 5AEDD1DB8050 for ; Fri, 29 Jun 2012 12:09:53 +0900 (JST) Message-ID: <4FED1C65.7010902@jp.fujitsu.com> Date: Fri, 29 Jun 2012 12:09:25 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 To: Wen Congyang Subject: Re: [RFC PATCH 4/12] memory-hotplug : remove /sys/firmware/memmap/X sysfs References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9E5F.4070205@jp.fujitsu.com> <4FEBFA8D.5040607@cn.fujitsu.com> <4FEC10CB.3060403@jp.fujitsu.com> <4FEC17F8.1000405@cn.fujitsu.com> In-Reply-To: <4FEC17F8.1000405@cn.fujitsu.com> Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Cc: len.brown@intel.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, cl@linux.com, linuxppc-dev@lists.ozlabs.org, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Hi Wen, 2012/06/28 17:38, Wen Congyang wrote: > At 06/28/2012 04:07 PM, Yasuaki Ishimatsu Wrote: >> Hi Wen, >> >> 2012/06/28 15:32, Wen Congyang wrote: >>> At 06/27/2012 01:47 PM, Yasuaki Ishimatsu Wrote: >>>> When (hot)adding memory into system, /sys/firmware/memmap/X/{end, >>>> start, type} >>>> sysfs files are created. But there is no code to remove these files. >>>> The patch >>>> implements the function to remove them. >>>> >>>> Note : The code does not free firmware_map_entry since there is no >>>> way to free >>>> memory which is allocated by bootmem. >>>> >>>> CC: Len Brown >>>> CC: Benjamin Herrenschmidt >>>> CC: Paul Mackerras >>>> CC: Christoph Lameter >>>> Cc: Minchan Kim >>>> CC: Andrew Morton >>>> CC: KOSAKI Motohiro >>>> CC: Wen Congyang >>>> Signed-off-by: Yasuaki Ishimatsu >>>> >>>> --- >>>> drivers/firmware/memmap.c | 71 >>>> +++++++++++++++++++++++++++++++++++++++++++ >>>> include/linux/firmware-map.h | 6 +++ >>>> mm/memory_hotplug.c | 6 +++ >>>> 3 files changed, 82 insertions(+), 1 deletion(-) >>>> >>>> Index: linux-3.5-rc4/mm/memory_hotplug.c >>>> =================================================================== >>>> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 >>>> 13:37:30.546288901 +0900 >>>> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 >>>> 13:44:37.069955820 +0900 >>>> @@ -661,7 +661,11 @@ EXPORT_SYMBOL_GPL(add_memory); >>>> >>>> int remove_memory(int nid, u64 start, u64 size) >>>> { >>>> - return -EBUSY; >>>> + lock_memory_hotplug(); >>>> + /* remove memmap entry */ >>>> + firmware_map_remove(start, start + size, "System RAM"); >>>> + unlock_memory_hotplug(); >>>> + return 0; >>>> >>>> } >>>> EXPORT_SYMBOL_GPL(remove_memory); >>>> Index: linux-3.5-rc4/include/linux/firmware-map.h >>>> =================================================================== >>>> --- linux-3.5-rc4.orig/include/linux/firmware-map.h 2012-06-25 >>>> 04:53:04.000000000 +0900 >>>> +++ linux-3.5-rc4/include/linux/firmware-map.h 2012-06-26 >>>> 13:44:37.070955807 +0900 >>>> @@ -25,6 +25,7 @@ >>>> >>>> int firmware_map_add_early(u64 start, u64 end, const char *type); >>>> int firmware_map_add_hotplug(u64 start, u64 end, const char *type); >>>> +int firmware_map_remove(u64 start, u64 end, const char *type); >>>> >>>> #else /* CONFIG_FIRMWARE_MEMMAP */ >>>> >>>> @@ -38,6 +39,11 @@ static inline int firmware_map_add_hotpl >>>> return 0; >>>> } >>>> >>>> +static inline int firmware_map_remove(u64 start, u64 end, const char >>>> *type) >>>> +{ >>>> + return 0; >>>> +} >>>> + >>>> #endif /* CONFIG_FIRMWARE_MEMMAP */ >>>> >>>> #endif /* _LINUX_FIRMWARE_MAP_H */ >>>> Index: linux-3.5-rc4/drivers/firmware/memmap.c >>>> =================================================================== >>>> --- linux-3.5-rc4.orig/drivers/firmware/memmap.c 2012-06-25 >>>> 04:53:04.000000000 +0900 >>>> +++ linux-3.5-rc4/drivers/firmware/memmap.c 2012-06-26 >>>> 13:47:17.606948898 +0900 >>>> @@ -123,6 +123,16 @@ static int firmware_map_add_entry(u64 st >>>> return 0; >>>> } >>>> >>>> +/** >>>> + * firmware_map_remove_entry() - Does the real work to remove a >>>> firmware >>>> + * memmap entry. >>>> + * @entry: removed entry. >>>> + **/ >>>> +static inline void firmware_map_remove_entry(struct >>>> firmware_map_entry *entry) >>>> +{ >>>> + list_del(&entry->list); >>>> +} >>>> + >>>> /* >>>> * Add memmap entry on sysfs >>>> */ >>>> @@ -144,6 +154,31 @@ static int add_sysfs_fw_map_entry(struct >>>> return 0; >>>> } >>>> >>>> +/* >>>> + * Remove memmap entry on sysfs >>>> + */ >>>> +static inline void remove_sysfs_fw_map_entry(struct >>>> firmware_map_entry *entry) >>>> +{ >>>> + kobject_del(&entry->kobj); >>>> +} >>>> + >>>> +/* >>>> + * Search memmap entry >>>> + */ >>>> + >>>> +struct firmware_map_entry * __meminit >>>> +find_firmware_map_entry(u64 start, u64 end, const char *type) >>>> +{ >>>> + struct firmware_map_entry *entry; >>>> + >>>> + list_for_each_entry(entry, &map_entries, list) >>>> + if ((entry->start == start) && (entry->end == end) && >>>> + (!strcmp(entry->type, type))) >>>> + return entry; >>>> + >>>> + return NULL; >>>> +} >>>> + >>>> /** >>>> * firmware_map_add_hotplug() - Adds a firmware mapping entry when >>>> we do >>>> * memory hotplug. >>>> @@ -196,6 +231,42 @@ int __init firmware_map_add_early(u64 st >>>> return firmware_map_add_entry(start, end, type, entry); >>>> } >>>> >>>> +void release_firmware_map_entry(struct firmware_map_entry *entry) >>>> +{ >>>> + /* >>>> + * FIXME : There is no idea. >>>> + * How to free the entry which allocated bootmem? >>>> + */ >>>> +} >>>> + >>>> +/** >>>> + * firmware_map_remove() - remove a firmware mapping entry >>>> + * @start: Start of the memory range. >>>> + * @end: End of the memory range (inclusive). >>>> + * @type: Type of the memory range. >>>> + * >>>> + * removes a firmware mapping entry. >>>> + * >>>> + * Returns 0 on success, or -EINVAL if no entry. >>>> + **/ >>>> +int __meminit firmware_map_remove(u64 start, u64 end, const char *type) >>>> +{ >>>> + struct firmware_map_entry *entry; >>>> + >>>> + entry = find_firmware_map_entry(start, end, type); >>> >>> Hmm, we cannot find the entry easily, because the end can be: >>> 1. start + size >>> 2. start + size - 1 >>> >>> So, We should fix this bug first. >> >> This is not a bug. >> >> start and size arguments of firmware_map_remove() include >> acpi_memory_info->{start_addr, length}. And when creating a >> firmware_map_entry, >> the entry is created by acpi_memory_info->{start_addr, length}. So I don't >> think that we need care your comment. > > If the memory device is hotpluged before the os starts, and the memory > map is included in e820 map, the entry will be created by firmware_map_add_early(). > > The function firmware_map_add_early() is called by e820_reserve_resources(): > ===================== > for (i = 0; i < e820_saved.nr_map; i++) { > struct e820entry *entry = &e820_saved.map[i]; > firmware_map_add_early(entry->addr, > entry->addr + entry->size - 1, > e820_type_to_string(entry->type)); > } > ===================== > > Note: the end is addr + size - 1, not addr + size. > > In such case, you cannot find the entry. Thank you for your explanation. I understood it. end argument of firmware_map_add_hotplug() has always "addr + size", not "addr + size - 1". I think that changing argument of firmware_map_add_early() is high risk since the function has been used since early times. So, I will unify to "addr + size - 1". Thanks, Yasuaki Ishimatsu > Thanks > Wen Congyang > >> >>> >>>> + if (!entry) >>>> + return -EINVAL; >>>> + >>>> + /* remove the memmap entry */ >>>> + remove_sysfs_fw_map_entry(entry); >>>> + >>>> + firmware_map_remove_entry(entry); >>>> + >>>> + release_firmware_map_entry(entry); >>> >>> I guess you want to free the memory in the above function. But I think >>> it is >>> not a good idea to free it here. We should free it when the >>> entry->kobj's kref >>> is decreased to 0. >> >> Thanks. >> I'll update your comment at next version. >> >> Thanks, >> Yasuaki Ishimatsu >> >>> >>> Thanks >>> Wen Congyang >>> >>>> + >>>> + return 0; >>>> +} >>>> + >>>> /* >>>> * Sysfs functions >>>> ------------------------------------------------------------- >>>> */ >>>> >>>> -- >>>> To unsubscribe from this list: send the line "unsubscribe >>>> linux-kernel" in >>>> the body of a message to majordomo@vger.kernel.org >>>> More majordomo info at http://vger.kernel.org/majordomo-info.html >>>> Please read the FAQ at http://www.tux.org/lkml/ >>>> >>> >>> -- >>> To unsubscribe, send a message with 'unsubscribe linux-mm' in >>> the body to majordomo@kvack.org. For more info on Linux MM, >>> see: http://www.linux-mm.org/ . >>> Don't email: email@kvack.org >>> >> >> >> >> > > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pb0-f51.google.com (mail-pb0-f51.google.com [209.85.160.51]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 26D062C007B for ; Sun, 1 Jul 2012 01:47:09 +1000 (EST) Received: by pbbrp16 with SMTP id rp16so6714190pbb.38 for ; Sat, 30 Jun 2012 08:47:07 -0700 (PDT) Message-ID: <4FEF1F6A.6090705@gmail.com> Date: Sat, 30 Jun 2012 23:46:50 +0800 From: Jiang Liu MIME-Version: 1.0 To: Yasuaki Ishimatsu Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> In-Reply-To: <4FEA9DB1.7010303@jp.fujitsu.com> Content-Type: text/plain; charset=ISO-2022-JP Cc: len.brown@intel.com, wency@cn.fujitsu.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, cl@linux.com, linuxppc-dev@lists.ozlabs.org, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , On 06/27/2012 01:44 PM, Yasuaki Ishimatsu wrote: > When offline_pages() is called to offlined memory, the function fails since > all memory has been offlined. In this case, the function should succeed. > The patch adds the check function into offline_pages(). > > CC: Len Brown > CC: Benjamin Herrenschmidt > CC: Paul Mackerras > CC: Christoph Lameter > Cc: Minchan Kim > CC: Andrew Morton > CC: KOSAKI Motohiro > CC: Wen Congyang > Signed-off-by: Yasuaki Ishimatsu > > --- > drivers/base/memory.c | 20 ++++++++++++++++++++ > include/linux/memory.h | 1 + > mm/memory_hotplug.c | 5 +++++ > 3 files changed, 26 insertions(+) > > Index: linux-3.5-rc4/drivers/base/memory.c > =================================================================== > --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-26 13:28:16.726211752 +0900 > +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:34:22.423639904 +0900 > @@ -70,6 +70,26 @@ void unregister_memory_isolate_notifier( > } > EXPORT_SYMBOL(unregister_memory_isolate_notifier); > > +bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn) > +{ > + struct memory_block *mem; > + struct mem_section *section; > + unsigned long pfn, section_nr; > + > + for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { > + section_nr = pfn_to_section_nr(pfn); > + section = __nr_to_section(section_nr); Is it possible for __nr_to_section return NULL here? > + mem = find_memory_block(section); > + if (!mem) > + continue; > + if (mem->state == MEM_OFFLINE) > + continue; > + return false; > + } > + > + return true; > +} Need a put_dev(&mem->dev) for the last memory block device handled before return. > + > /* > * register_memory - Setup a sysfs device for a memory block > */ > Index: linux-3.5-rc4/include/linux/memory.h > =================================================================== > --- linux-3.5-rc4.orig/include/linux/memory.h 2012-06-25 04:53:04.000000000 +0900 > +++ linux-3.5-rc4/include/linux/memory.h 2012-06-26 13:34:22.424639891 +0900 > @@ -120,6 +120,7 @@ extern int memory_isolate_notify(unsigne > extern struct memory_block *find_memory_block_hinted(struct mem_section *, > struct memory_block *); > extern struct memory_block *find_memory_block(struct mem_section *); > +extern bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn); > #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION< enum mem_add_context { BOOT, HOTPLUG }; > #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ > Index: linux-3.5-rc4/mm/memory_hotplug.c > =================================================================== > --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:28:16.743211538 +0900 > +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:38.264940468 +0900 > @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned > > lock_memory_hotplug(); > > + if (memory_is_offline(start_pfn, end_pfn)) { > + ret = 0; > + goto out; > + } > + > zone = page_zone(pfn_to_page(start_pfn)); > node = zone_to_nid(zone); > nr_pages = end_pfn - start_pfn; > > -- > To unsubscribe from this list: send the line "unsubscribe linux-acpi" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pz0-f51.google.com (mail-pz0-f51.google.com [209.85.210.51]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 0CE1C2C007B for ; Sun, 1 Jul 2012 01:51:33 +1000 (EST) Received: by dajt11 with SMTP id t11so6541484daj.38 for ; Sat, 30 Jun 2012 08:51:31 -0700 (PDT) Message-ID: <4FEF2075.2050603@gmail.com> Date: Sat, 30 Jun 2012 23:51:17 +0800 From: Jiang Liu MIME-Version: 1.0 To: Yasuaki Ishimatsu Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> In-Reply-To: <4FEA9DB1.7010303@jp.fujitsu.com> Content-Type: text/plain; charset=ISO-2022-JP Cc: len.brown@intel.com, wency@cn.fujitsu.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, cl@linux.com, linuxppc-dev@lists.ozlabs.org, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , On 06/27/2012 01:44 PM, Yasuaki Ishimatsu wrote: > When offline_pages() is called to offlined memory, the function fails since > all memory has been offlined. In this case, the function should succeed. > The patch adds the check function into offline_pages(). > > CC: Len Brown > CC: Benjamin Herrenschmidt > CC: Paul Mackerras > CC: Christoph Lameter > Cc: Minchan Kim > CC: Andrew Morton > CC: KOSAKI Motohiro > CC: Wen Congyang > Signed-off-by: Yasuaki Ishimatsu > > --- > drivers/base/memory.c | 20 ++++++++++++++++++++ > include/linux/memory.h | 1 + > mm/memory_hotplug.c | 5 +++++ > 3 files changed, 26 insertions(+) > > Index: linux-3.5-rc4/drivers/base/memory.c > =================================================================== > --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-26 13:28:16.726211752 +0900 > +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:34:22.423639904 +0900 > @@ -70,6 +70,26 @@ void unregister_memory_isolate_notifier( > } > EXPORT_SYMBOL(unregister_memory_isolate_notifier); > > +bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn) > +{ > + struct memory_block *mem; > + struct mem_section *section; > + unsigned long pfn, section_nr; > + > + for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { > + section_nr = pfn_to_section_nr(pfn); > + section = __nr_to_section(section_nr); > + mem = find_memory_block(section); Seems find_memory_block_hinted() is more efficient than find_memory_block() here. > + if (!mem) > + continue; > + if (mem->state == MEM_OFFLINE) > + continue; > + return false; > + } > + > + return true; > +} > + > /* > * register_memory - Setup a sysfs device for a memory block > */ > Index: linux-3.5-rc4/include/linux/memory.h > =================================================================== > --- linux-3.5-rc4.orig/include/linux/memory.h 2012-06-25 04:53:04.000000000 +0900 > +++ linux-3.5-rc4/include/linux/memory.h 2012-06-26 13:34:22.424639891 +0900 > @@ -120,6 +120,7 @@ extern int memory_isolate_notify(unsigne > extern struct memory_block *find_memory_block_hinted(struct mem_section *, > struct memory_block *); > extern struct memory_block *find_memory_block(struct mem_section *); > +extern bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn); > #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION< enum mem_add_context { BOOT, HOTPLUG }; > #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ > Index: linux-3.5-rc4/mm/memory_hotplug.c > =================================================================== > --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:28:16.743211538 +0900 > +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:38.264940468 +0900 > @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned > > lock_memory_hotplug(); > > + if (memory_is_offline(start_pfn, end_pfn)) { > + ret = 0; > + goto out; > + } > + > zone = page_zone(pfn_to_page(start_pfn)); > node = zone_to_nid(zone); > nr_pages = end_pfn - start_pfn; > > -- > To unsubscribe from this list: send the line "unsubscribe linux-acpi" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pb0-f51.google.com (mail-pb0-f51.google.com [209.85.160.51]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 4352F2C01B8 for ; Sun, 1 Jul 2012 01:58:26 +1000 (EST) Received: by pbbrp16 with SMTP id rp16so6724170pbb.38 for ; Sat, 30 Jun 2012 08:58:24 -0700 (PDT) Message-ID: <4FEF2214.4000205@gmail.com> Date: Sat, 30 Jun 2012 23:58:12 +0800 From: Jiang Liu MIME-Version: 1.0 To: Yasuaki Ishimatsu Subject: Re: [RFC PATCH 10/12] memory-hotplug : free memmap of sparse-vmemmap References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEAA09F.5000907@jp.fujitsu.com> In-Reply-To: <4FEAA09F.5000907@jp.fujitsu.com> Content-Type: text/plain; charset=ISO-2022-JP Cc: len.brown@intel.com, wency@cn.fujitsu.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, cl@linux.com, linuxppc-dev@lists.ozlabs.org, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , On 06/27/2012 01:56 PM, Yasuaki Ishimatsu wrote: > I don't think that all pages of virtual mapping in removed memory can be > freed, since page which type is MIX_SECTION_INFO is difficult to free. > So, the patch only frees page which type is SECTION_INFO at first. > > CC: Len Brown > CC: Benjamin Herrenschmidt > CC: Paul Mackerras > CC: Christoph Lameter > Cc: Minchan Kim > CC: Andrew Morton > CC: KOSAKI Motohiro > CC: Wen Congyang > Signed-off-by: Yasuaki Ishimatsu > > --- > arch/x86/mm/init_64.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ > include/linux/mm.h | 2 + > mm/memory_hotplug.c | 5 ++ > mm/sparse.c | 5 +- > 4 files changed, 99 insertions(+), 2 deletions(-) > > Index: linux-3.5-rc4/include/linux/mm.h > =================================================================== > --- linux-3.5-rc4.orig/include/linux/mm.h 2012-06-27 09:11:13.790150442 +0900 > +++ linux-3.5-rc4/include/linux/mm.h 2012-06-27 09:11:16.433117400 +0900 > @@ -1588,6 +1588,8 @@ int vmemmap_populate(struct page *start_ > void vmemmap_populate_print_last(void); > void register_page_bootmem_memmap(unsigned long section_nr, struct page *map, > unsigned long size); > +void vmemmap_kfree(struct page *memmpa, unsigned long nr_pages); > +void vmemmap_free_bootmem(struct page *memmpa, unsigned long nr_pages); > > enum mf_flags { > MF_COUNT_INCREASED = 1 << 0, > Index: linux-3.5-rc4/mm/sparse.c > =================================================================== > --- linux-3.5-rc4.orig/mm/sparse.c 2012-06-27 09:06:35.317631878 +0900 > +++ linux-3.5-rc4/mm/sparse.c 2012-06-27 09:11:16.434117388 +0900 > @@ -614,12 +614,13 @@ static inline struct page *kmalloc_secti > /* This will make the necessary allocations eventually. */ > return sparse_mem_map_populate(pnum, nid); > } > -static void __kfree_section_memmap(struct page *memmap, unsigned long nr_pages) > +static void __kfree_section_memmap(struct page *page, unsigned long nr_pages) > { > - return; /* XXX: Not implemented yet */ > + vmemmap_kfree(page, nr_pages); > } > static void free_map_bootmem(struct page *page, unsigned long nr_pages) > { > + vmemmap_free_bootmem(page, nr_pages); > } > #else > static struct page *__kmalloc_section_memmap(unsigned long nr_pages) > Index: linux-3.5-rc4/arch/x86/mm/init_64.c > =================================================================== > --- linux-3.5-rc4.orig/arch/x86/mm/init_64.c 2012-06-27 09:11:13.791150430 +0900 > +++ linux-3.5-rc4/arch/x86/mm/init_64.c 2012-06-27 09:11:59.254581998 +0900 > @@ -978,6 +978,95 @@ vmemmap_populate(struct page *start_page > return 0; > } > > +unsigned long find_and_clear_pte_page(unsigned long addr, unsigned long end, > + struct page *page) I think the third parameter should be "struct page **pp" instead of "struct page *page". And "page = pte_page(*pte)" should be "*pp = pte_page(*pte)". Otherwise the found page pointer can't be returned to the caller and vmemmap_kfree() just sees random value in variable "page". > +{ > + pgd_t *pgd; > + pud_t *pud; > + pmd_t *pmd; > + pte_t *pte; > + unsigned long next; > + > + page = NULL; > + > + pgd = pgd_offset_k(addr); > + if (pgd_none(*pgd)) > + return PAGE_SIZE; > + > + pud = pud_offset(pgd, addr); > + if (pud_none(*pud)) > + return PAGE_SIZE; > + > + if (!cpu_has_pse) { > + next = (addr + PAGE_SIZE) & PAGE_MASK; > + pmd = pmd_offset(pud, addr); > + if (pmd_none(*pmd)) > + return next; > + > + pte = pte_offset_kernel(pmd, addr); > + if (pte_none(*pte)) > + return next; > + > + page = pte_page(*pte); > + pte_clear(&init_mm, addr, pte); > + } else { > + next = pmd_addr_end(addr, end); > + > + pmd = pmd_offset(pud, addr); > + if (pmd_none(*pmd)) > + return next; > + > + page = pmd_page(*pmd); > + pmd_clear(pmd); > + } > + > + return next; > +} > + > +void __meminit > +vmemmap_kfree(struct page *memmap, unsigned long nr_pages) > +{ > + unsigned long addr = (unsigned long)memmap; > + unsigned long end = (unsigned long)(memmap + nr_pages); > + unsigned long next; > + unsigned int order; > + struct page *page; > + > + for (; addr < end; addr = next) { > + next = find_and_clear_pte_page(addr, end, page); > + if (!page) > + continue; > + > + if (is_vmalloc_addr(page)) > + vfree(page); > + else { > + order = next - addr; > + free_pages((unsigned long)page, > + get_order(sizeof(struct page) * order)); > + } > + } > +} > + > +void __meminit > +vmemmap_free_bootmem(struct page *memmap, unsigned long nr_pages) > +{ > + unsigned long addr = (unsigned long)memmap; > + unsigned long end = (unsigned long)(memmap + nr_pages); > + unsigned long next; > + struct page *page; > + unsigned long magic; > + > + for (; addr < end; addr = next) { > + next = find_and_clear_pte_page(addr, end, page); > + if (!page) > + continue; > + > + magic = (unsigned long) page->lru.next; > + if (magic == SECTION_INFO) > + put_page_bootmem(page); > + } > +} > + > void __meminit > register_page_bootmem_memmap(unsigned long section_nr, struct page *start_page, > unsigned long size) > Index: linux-3.5-rc4/mm/memory_hotplug.c > =================================================================== > --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-27 09:11:13.789150454 +0900 > +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-27 09:11:16.436117363 +0900 > @@ -303,6 +303,8 @@ static int __meminit __add_section(int n > #ifdef CONFIG_SPARSEMEM_VMEMMAP > static int __remove_section(struct zone *zone, struct mem_section *ms) > { > + unsigned long flags; > + struct pglist_data *pgdat = zone->zone_pgdat; > int ret; > > if (!valid_section(ms)) > @@ -310,6 +312,9 @@ static int __remove_section(struct zone > > ret = unregister_memory_section(ms); > > + pgdat_resize_lock(pgdat, &flags); > + sparse_remove_one_section(zone, ms); > + pgdat_resize_unlock(pgdat, &flags); > return ret; > } > #else > > -- > To unsubscribe from this list: send the line "unsubscribe linux-acpi" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fgwmail5.fujitsu.co.jp (fgwmail5.fujitsu.co.jp [192.51.44.35]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A39F02C01C7 for ; Mon, 2 Jul 2012 12:57:21 +1000 (EST) Received: from m2.gw.fujitsu.co.jp (unknown [10.0.50.72]) by fgwmail5.fujitsu.co.jp (Postfix) with ESMTP id 4F02F3EE0C0 for ; Mon, 2 Jul 2012 11:57:17 +0900 (JST) Received: from smail (m2 [127.0.0.1]) by outgoing.m2.gw.fujitsu.co.jp (Postfix) with ESMTP id 3524E45DE5A for ; Mon, 2 Jul 2012 11:57:17 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (s2.gw.fujitsu.co.jp [10.0.50.92]) by m2.gw.fujitsu.co.jp (Postfix) with ESMTP id 1B41F45DE4E for ; Mon, 2 Jul 2012 11:57:17 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id 08DA51DB8043 for ; Mon, 2 Jul 2012 11:57:17 +0900 (JST) Received: from g01jpexchyt03.g01.fujitsu.local (g01jpexchyt03.g01.fujitsu.local [10.128.194.42]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id A911F1DB803C for ; Mon, 2 Jul 2012 11:57:16 +0900 (JST) Message-ID: <4FF10D1C.3060601@jp.fujitsu.com> Date: Mon, 2 Jul 2012 11:53:16 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 To: Jiang Liu Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> <4FEF1F6A.6090705@gmail.com> In-Reply-To: <4FEF1F6A.6090705@gmail.com> Content-Type: text/plain; charset="ISO-2022-JP" Cc: len.brown@intel.com, wency@cn.fujitsu.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, cl@linux.com, linuxppc-dev@lists.ozlabs.org, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Hi Jiang, Thank you for your feedback. 2012/07/01 0:46, Jiang Liu wrote: > On 06/27/2012 01:44 PM, Yasuaki Ishimatsu wrote: >> When offline_pages() is called to offlined memory, the function fails since >> all memory has been offlined. In this case, the function should succeed. >> The patch adds the check function into offline_pages(). >> >> CC: Len Brown >> CC: Benjamin Herrenschmidt >> CC: Paul Mackerras >> CC: Christoph Lameter >> Cc: Minchan Kim >> CC: Andrew Morton >> CC: KOSAKI Motohiro >> CC: Wen Congyang >> Signed-off-by: Yasuaki Ishimatsu >> >> --- >> drivers/base/memory.c | 20 ++++++++++++++++++++ >> include/linux/memory.h | 1 + >> mm/memory_hotplug.c | 5 +++++ >> 3 files changed, 26 insertions(+) >> >> Index: linux-3.5-rc4/drivers/base/memory.c >> =================================================================== >> --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-26 13:28:16.726211752 +0900 >> +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:34:22.423639904 +0900 >> @@ -70,6 +70,26 @@ void unregister_memory_isolate_notifier( >> } >> EXPORT_SYMBOL(unregister_memory_isolate_notifier); >> >> +bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn) >> +{ >> + struct memory_block *mem; >> + struct mem_section *section; >> + unsigned long pfn, section_nr; >> + >> + for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { >> + section_nr = pfn_to_section_nr(pfn); >> + section = __nr_to_section(section_nr); > Is it possible for __nr_to_section return NULL here? Yes. I'll add NULL check. > >> + mem = find_memory_block(section); >> + if (!mem) >> + continue; >> + if (mem->state == MEM_OFFLINE) >> + continue; >> + return false; >> + } >> + >> + return true; >> +} > Need a put_dev(&mem->dev) for the last memory block device handled before return. Thanks. I think kobject_put(&mem->dev.kobj) should be handled for all memory block devices found by find_memory_block(). I'll update it. Thanks, Yasuaki Ishimatsu > >> + >> /* >> * register_memory - Setup a sysfs device for a memory block >> */ >> Index: linux-3.5-rc4/include/linux/memory.h >> =================================================================== >> --- linux-3.5-rc4.orig/include/linux/memory.h 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/include/linux/memory.h 2012-06-26 13:34:22.424639891 +0900 >> @@ -120,6 +120,7 @@ extern int memory_isolate_notify(unsigne >> extern struct memory_block *find_memory_block_hinted(struct mem_section *, >> struct memory_block *); >> extern struct memory_block *find_memory_block(struct mem_section *); >> +extern bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn); >> #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION<> enum mem_add_context { BOOT, HOTPLUG }; >> #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ >> Index: linux-3.5-rc4/mm/memory_hotplug.c >> =================================================================== >> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:28:16.743211538 +0900 >> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:38.264940468 +0900 >> @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned >> >> lock_memory_hotplug(); >> >> + if (memory_is_offline(start_pfn, end_pfn)) { >> + ret = 0; >> + goto out; >> + } >> + >> zone = page_zone(pfn_to_page(start_pfn)); >> node = zone_to_nid(zone); >> nr_pages = end_pfn - start_pfn; >> >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >> > > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: email@kvack.org > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fgwmail5.fujitsu.co.jp (fgwmail5.fujitsu.co.jp [192.51.44.35]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 98A0C2C0315 for ; Mon, 2 Jul 2012 12:57:27 +1000 (EST) Received: from m1.gw.fujitsu.co.jp (unknown [10.0.50.71]) by fgwmail5.fujitsu.co.jp (Postfix) with ESMTP id C8ABE3EE0BD for ; Mon, 2 Jul 2012 11:57:25 +0900 (JST) Received: from smail (m1 [127.0.0.1]) by outgoing.m1.gw.fujitsu.co.jp (Postfix) with ESMTP id AEF7F45DE5F for ; Mon, 2 Jul 2012 11:57:25 +0900 (JST) Received: from s1.gw.fujitsu.co.jp (s1.gw.fujitsu.co.jp [10.0.50.91]) by m1.gw.fujitsu.co.jp (Postfix) with ESMTP id 8976045DE5D for ; Mon, 2 Jul 2012 11:57:25 +0900 (JST) Received: from s1.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s1.gw.fujitsu.co.jp (Postfix) with ESMTP id 706AE1DB8048 for ; Mon, 2 Jul 2012 11:57:25 +0900 (JST) Received: from g01jpexchyt11.g01.fujitsu.local (g01jpexchyt11.g01.fujitsu.local [10.128.194.50]) by s1.gw.fujitsu.co.jp (Postfix) with ESMTP id 1FE12E08001 for ; Mon, 2 Jul 2012 11:57:25 +0900 (JST) Message-ID: <4FF10DF0.7000508@jp.fujitsu.com> Date: Mon, 2 Jul 2012 11:56:48 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 To: Jiang Liu Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> <4FEF2075.2050603@gmail.com> In-Reply-To: <4FEF2075.2050603@gmail.com> Content-Type: text/plain; charset="ISO-2022-JP" Cc: len.brown@intel.com, wency@cn.fujitsu.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, cl@linux.com, linuxppc-dev@lists.ozlabs.org, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Hi Jiang, 2012/07/01 0:51, Jiang Liu wrote: > On 06/27/2012 01:44 PM, Yasuaki Ishimatsu wrote: >> When offline_pages() is called to offlined memory, the function fails since >> all memory has been offlined. In this case, the function should succeed. >> The patch adds the check function into offline_pages(). >> >> CC: Len Brown >> CC: Benjamin Herrenschmidt >> CC: Paul Mackerras >> CC: Christoph Lameter >> Cc: Minchan Kim >> CC: Andrew Morton >> CC: KOSAKI Motohiro >> CC: Wen Congyang >> Signed-off-by: Yasuaki Ishimatsu >> >> --- >> drivers/base/memory.c | 20 ++++++++++++++++++++ >> include/linux/memory.h | 1 + >> mm/memory_hotplug.c | 5 +++++ >> 3 files changed, 26 insertions(+) >> >> Index: linux-3.5-rc4/drivers/base/memory.c >> =================================================================== >> --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-26 13:28:16.726211752 +0900 >> +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:34:22.423639904 +0900 >> @@ -70,6 +70,26 @@ void unregister_memory_isolate_notifier( >> } >> EXPORT_SYMBOL(unregister_memory_isolate_notifier); >> >> +bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn) >> +{ >> + struct memory_block *mem; >> + struct mem_section *section; >> + unsigned long pfn, section_nr; >> + >> + for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { >> + section_nr = pfn_to_section_nr(pfn); >> + section = __nr_to_section(section_nr); >> + mem = find_memory_block(section); > Seems find_memory_block_hinted() is more efficient than find_memory_block() here. Thanks. I'll update it. Thanks, Yasuaki Ishimatsu > >> + if (!mem) >> + continue; >> + if (mem->state == MEM_OFFLINE) >> + continue; >> + return false; >> + } >> + >> + return true; >> +} >> + >> /* >> * register_memory - Setup a sysfs device for a memory block >> */ >> Index: linux-3.5-rc4/include/linux/memory.h >> =================================================================== >> --- linux-3.5-rc4.orig/include/linux/memory.h 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/include/linux/memory.h 2012-06-26 13:34:22.424639891 +0900 >> @@ -120,6 +120,7 @@ extern int memory_isolate_notify(unsigne >> extern struct memory_block *find_memory_block_hinted(struct mem_section *, >> struct memory_block *); >> extern struct memory_block *find_memory_block(struct mem_section *); >> +extern bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn); >> #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION<> enum mem_add_context { BOOT, HOTPLUG }; >> #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ >> Index: linux-3.5-rc4/mm/memory_hotplug.c >> =================================================================== >> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:28:16.743211538 +0900 >> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:38.264940468 +0900 >> @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned >> >> lock_memory_hotplug(); >> >> + if (memory_is_offline(start_pfn, end_pfn)) { >> + ret = 0; >> + goto out; >> + } >> + >> zone = page_zone(pfn_to_page(start_pfn)); >> node = zone_to_nid(zone); >> nr_pages = end_pfn - start_pfn; >> >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >> > > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: email@kvack.org > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fgwmail5.fujitsu.co.jp (fgwmail5.fujitsu.co.jp [192.51.44.35]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 47DE32C01C7 for ; Mon, 2 Jul 2012 13:01:44 +1000 (EST) Received: from m2.gw.fujitsu.co.jp (unknown [10.0.50.72]) by fgwmail5.fujitsu.co.jp (Postfix) with ESMTP id 00FEF3EE081 for ; Mon, 2 Jul 2012 12:01:42 +0900 (JST) Received: from smail (m2 [127.0.0.1]) by outgoing.m2.gw.fujitsu.co.jp (Postfix) with ESMTP id CD11245DE50 for ; Mon, 2 Jul 2012 12:01:41 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (s2.gw.fujitsu.co.jp [10.0.50.92]) by m2.gw.fujitsu.co.jp (Postfix) with ESMTP id B1A1C45DE4E for ; Mon, 2 Jul 2012 12:01:41 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id 835931DB803A for ; Mon, 2 Jul 2012 12:01:41 +0900 (JST) Received: from g01jpexchyt07.g01.fujitsu.local (g01jpexchyt07.g01.fujitsu.local [10.128.194.46]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id 2D2C51DB8038 for ; Mon, 2 Jul 2012 12:01:41 +0900 (JST) Message-ID: <4FF10EFF.5050803@jp.fujitsu.com> Date: Mon, 2 Jul 2012 12:01:19 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 To: Jiang Liu Subject: Re: [RFC PATCH 10/12] memory-hotplug : free memmap of sparse-vmemmap References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEAA09F.5000907@jp.fujitsu.com> <4FEF2214.4000205@gmail.com> In-Reply-To: <4FEF2214.4000205@gmail.com> Content-Type: text/plain; charset="ISO-2022-JP" Cc: len.brown@intel.com, wency@cn.fujitsu.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, paulus@samba.org, minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, cl@linux.com, linuxppc-dev@lists.ozlabs.org, akpm@linux-foundation.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Hi Jiang, 2012/07/01 0:58, Jiang Liu wrote: > On 06/27/2012 01:56 PM, Yasuaki Ishimatsu wrote: >> I don't think that all pages of virtual mapping in removed memory can be >> freed, since page which type is MIX_SECTION_INFO is difficult to free. >> So, the patch only frees page which type is SECTION_INFO at first. >> >> CC: Len Brown >> CC: Benjamin Herrenschmidt >> CC: Paul Mackerras >> CC: Christoph Lameter >> Cc: Minchan Kim >> CC: Andrew Morton >> CC: KOSAKI Motohiro >> CC: Wen Congyang >> Signed-off-by: Yasuaki Ishimatsu >> >> --- >> arch/x86/mm/init_64.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ >> include/linux/mm.h | 2 + >> mm/memory_hotplug.c | 5 ++ >> mm/sparse.c | 5 +- >> 4 files changed, 99 insertions(+), 2 deletions(-) >> >> Index: linux-3.5-rc4/include/linux/mm.h >> =================================================================== >> --- linux-3.5-rc4.orig/include/linux/mm.h 2012-06-27 09:11:13.790150442 +0900 >> +++ linux-3.5-rc4/include/linux/mm.h 2012-06-27 09:11:16.433117400 +0900 >> @@ -1588,6 +1588,8 @@ int vmemmap_populate(struct page *start_ >> void vmemmap_populate_print_last(void); >> void register_page_bootmem_memmap(unsigned long section_nr, struct page *map, >> unsigned long size); >> +void vmemmap_kfree(struct page *memmpa, unsigned long nr_pages); >> +void vmemmap_free_bootmem(struct page *memmpa, unsigned long nr_pages); >> >> enum mf_flags { >> MF_COUNT_INCREASED = 1 << 0, >> Index: linux-3.5-rc4/mm/sparse.c >> =================================================================== >> --- linux-3.5-rc4.orig/mm/sparse.c 2012-06-27 09:06:35.317631878 +0900 >> +++ linux-3.5-rc4/mm/sparse.c 2012-06-27 09:11:16.434117388 +0900 >> @@ -614,12 +614,13 @@ static inline struct page *kmalloc_secti >> /* This will make the necessary allocations eventually. */ >> return sparse_mem_map_populate(pnum, nid); >> } >> -static void __kfree_section_memmap(struct page *memmap, unsigned long nr_pages) >> +static void __kfree_section_memmap(struct page *page, unsigned long nr_pages) >> { >> - return; /* XXX: Not implemented yet */ >> + vmemmap_kfree(page, nr_pages); >> } >> static void free_map_bootmem(struct page *page, unsigned long nr_pages) >> { >> + vmemmap_free_bootmem(page, nr_pages); >> } >> #else >> static struct page *__kmalloc_section_memmap(unsigned long nr_pages) >> Index: linux-3.5-rc4/arch/x86/mm/init_64.c >> =================================================================== >> --- linux-3.5-rc4.orig/arch/x86/mm/init_64.c 2012-06-27 09:11:13.791150430 +0900 >> +++ linux-3.5-rc4/arch/x86/mm/init_64.c 2012-06-27 09:11:59.254581998 +0900 >> @@ -978,6 +978,95 @@ vmemmap_populate(struct page *start_page >> return 0; >> } >> >> +unsigned long find_and_clear_pte_page(unsigned long addr, unsigned long end, >> + struct page *page) > I think the third parameter should be "struct page **pp" instead of "struct page *page". > And "page = pte_page(*pte)" should be "*pp = pte_page(*pte)". > Otherwise the found page pointer can't be returned to the caller and vmemmap_kfree() > just sees random value in variable "page". Oh, you are right. I'll update it. Thanks, Yasuaki Ishimatsu >> +{ >> + pgd_t *pgd; >> + pud_t *pud; >> + pmd_t *pmd; >> + pte_t *pte; >> + unsigned long next; >> + >> + page = NULL; >> + >> + pgd = pgd_offset_k(addr); >> + if (pgd_none(*pgd)) >> + return PAGE_SIZE; >> + >> + pud = pud_offset(pgd, addr); >> + if (pud_none(*pud)) >> + return PAGE_SIZE; >> + >> + if (!cpu_has_pse) { >> + next = (addr + PAGE_SIZE) & PAGE_MASK; >> + pmd = pmd_offset(pud, addr); >> + if (pmd_none(*pmd)) >> + return next; >> + >> + pte = pte_offset_kernel(pmd, addr); >> + if (pte_none(*pte)) >> + return next; >> + >> + page = pte_page(*pte); >> + pte_clear(&init_mm, addr, pte); >> + } else { >> + next = pmd_addr_end(addr, end); >> + >> + pmd = pmd_offset(pud, addr); >> + if (pmd_none(*pmd)) >> + return next; >> + >> + page = pmd_page(*pmd); >> + pmd_clear(pmd); >> + } >> + >> + return next; >> +} >> + >> +void __meminit >> +vmemmap_kfree(struct page *memmap, unsigned long nr_pages) >> +{ >> + unsigned long addr = (unsigned long)memmap; >> + unsigned long end = (unsigned long)(memmap + nr_pages); >> + unsigned long next; >> + unsigned int order; >> + struct page *page; >> + >> + for (; addr < end; addr = next) { >> + next = find_and_clear_pte_page(addr, end, page); >> + if (!page) >> + continue; >> + >> + if (is_vmalloc_addr(page)) >> + vfree(page); >> + else { >> + order = next - addr; >> + free_pages((unsigned long)page, >> + get_order(sizeof(struct page) * order)); >> + } >> + } >> +} >> + >> +void __meminit >> +vmemmap_free_bootmem(struct page *memmap, unsigned long nr_pages) >> +{ >> + unsigned long addr = (unsigned long)memmap; >> + unsigned long end = (unsigned long)(memmap + nr_pages); >> + unsigned long next; >> + struct page *page; >> + unsigned long magic; >> + >> + for (; addr < end; addr = next) { >> + next = find_and_clear_pte_page(addr, end, page); >> + if (!page) >> + continue; >> + >> + magic = (unsigned long) page->lru.next; >> + if (magic == SECTION_INFO) >> + put_page_bootmem(page); >> + } >> +} >> + >> void __meminit >> register_page_bootmem_memmap(unsigned long section_nr, struct page *start_page, >> unsigned long size) >> Index: linux-3.5-rc4/mm/memory_hotplug.c >> =================================================================== >> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-27 09:11:13.789150454 +0900 >> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-27 09:11:16.436117363 +0900 >> @@ -303,6 +303,8 @@ static int __meminit __add_section(int n >> #ifdef CONFIG_SPARSEMEM_VMEMMAP >> static int __remove_section(struct zone *zone, struct mem_section *ms) >> { >> + unsigned long flags; >> + struct pglist_data *pgdat = zone->zone_pgdat; >> int ret; >> >> if (!valid_section(ms)) >> @@ -310,6 +312,9 @@ static int __remove_section(struct zone >> >> ret = unregister_memory_section(ms); >> >> + pgdat_resize_lock(pgdat, &flags); >> + sparse_remove_one_section(zone, ms); >> + pgdat_resize_unlock(pgdat, &flags); >> return ret; >> } >> #else >> >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >> > > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: email@kvack.org > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx193.postini.com [74.125.245.193]) by kanga.kvack.org (Postfix) with SMTP id 2A21F6B005A for ; Wed, 27 Jun 2012 01:43:14 -0400 (EDT) Received: from m2.gw.fujitsu.co.jp (unknown [10.0.50.72]) by fgwmail6.fujitsu.co.jp (Postfix) with ESMTP id F29A53EE0B6 for ; Wed, 27 Jun 2012 14:43:11 +0900 (JST) Received: from smail (m2 [127.0.0.1]) by outgoing.m2.gw.fujitsu.co.jp (Postfix) with ESMTP id CD88D45DE54 for ; Wed, 27 Jun 2012 14:43:11 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (s2.gw.fujitsu.co.jp [10.0.50.92]) by m2.gw.fujitsu.co.jp (Postfix) with ESMTP id A261845DE4D for ; Wed, 27 Jun 2012 14:43:11 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id 91F31E18005 for ; Wed, 27 Jun 2012 14:43:11 +0900 (JST) Received: from g01jpexchkw01.g01.fujitsu.local (g01jpexchkw01.g01.fujitsu.local [10.0.194.40]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id 4C8381DB803A for ; Wed, 27 Jun 2012 14:43:11 +0900 (JST) Message-ID: <4FEA9D5C.1080508@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:42:52 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 Subject: [RFC PATCH 1/12] memory-hotplug : rename remove_memory to offline_memory References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org Cc: len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com remove_memory() does not remove memory but just offlines memory. The patch changes name of it to offline_memory(). CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- drivers/acpi/acpi_memhotplug.c | 2 +- drivers/base/memory.c | 4 ++-- include/linux/memory_hotplug.h | 2 +- mm/memory_hotplug.c | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) Index: linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c =================================================================== --- linux-3.5-rc4.orig/drivers/acpi/acpi_memhotplug.c 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c 2012-06-26 13:48:38.263940481 +0900 @@ -318,7 +318,7 @@ static int acpi_memory_disable_device(st */ list_for_each_entry_safe(info, n, &mem_device->res_list, list) { if (info->enabled) { - result = remove_memory(info->start_addr, info->length); + result = offline_memory(info->start_addr, info->length); if (result) return result; } Index: linux-3.5-rc4/drivers/base/memory.c =================================================================== --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:48:46.072842803 +0900 @@ -266,8 +266,8 @@ memory_block_action(unsigned long phys_i break; case MEM_OFFLINE: start_paddr = page_to_pfn(first_page) << PAGE_SHIFT; - ret = remove_memory(start_paddr, - nr_pages << PAGE_SHIFT); + ret = offline_memory(start_paddr, + nr_pages << PAGE_SHIFT); break; default: WARN(1, KERN_WARNING "%s(%ld, %ld) unknown action: " Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:46.072842803 +0900 @@ -990,7 +990,7 @@ out: return ret; } -int remove_memory(u64 start, u64 size) +int offline_memory(u64 start, u64 size) { unsigned long start_pfn, end_pfn; @@ -999,9 +999,9 @@ int remove_memory(u64 start, u64 size) return offline_pages(start_pfn, end_pfn, 120 * HZ); } #else -int remove_memory(u64 start, u64 size) +int offline_memory(u64 start, u64 size) { return -EINVAL; } #endif /* CONFIG_MEMORY_HOTREMOVE */ -EXPORT_SYMBOL_GPL(remove_memory); +EXPORT_SYMBOL_GPL(offline_memory); Index: linux-3.5-rc4/include/linux/memory_hotplug.h =================================================================== --- linux-3.5-rc4.orig/include/linux/memory_hotplug.h 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/include/linux/memory_hotplug.h 2012-06-26 13:48:38.264940468 +0900 @@ -233,7 +233,7 @@ static inline int is_mem_section_removab extern int mem_online_node(int nid); extern int add_memory(int nid, u64 start, u64 size); extern int arch_add_memory(int nid, u64 start, u64 size); -extern int remove_memory(u64 start, u64 size); +extern int offline_memory(u64 start, u64 size); extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn, int nr_pages); extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms); -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx205.postini.com [74.125.245.205]) by kanga.kvack.org (Postfix) with SMTP id B1E786B005A for ; Wed, 27 Jun 2012 01:44:36 -0400 (EDT) Received: from m3.gw.fujitsu.co.jp (unknown [10.0.50.73]) by fgwmail5.fujitsu.co.jp (Postfix) with ESMTP id F24763EE0BD for ; Wed, 27 Jun 2012 14:44:34 +0900 (JST) Received: from smail (m3 [127.0.0.1]) by outgoing.m3.gw.fujitsu.co.jp (Postfix) with ESMTP id D850F45DEB2 for ; Wed, 27 Jun 2012 14:44:34 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (s3.gw.fujitsu.co.jp [10.0.50.93]) by m3.gw.fujitsu.co.jp (Postfix) with ESMTP id B2A7045DE9E for ; Wed, 27 Jun 2012 14:44:34 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id A5BEC1DB803E for ; Wed, 27 Jun 2012 14:44:34 +0900 (JST) Received: from g01jpexchkw07.g01.fujitsu.local (g01jpexchkw07.g01.fujitsu.local [10.0.194.46]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id 560E51DB803B for ; Wed, 27 Jun 2012 14:44:34 +0900 (JST) Message-ID: <4FEA9DB1.7010303@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:44:17 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 Subject: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org Cc: len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com When offline_pages() is called to offlined memory, the function fails since all memory has been offlined. In this case, the function should succeed. The patch adds the check function into offline_pages(). CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- drivers/base/memory.c | 20 ++++++++++++++++++++ include/linux/memory.h | 1 + mm/memory_hotplug.c | 5 +++++ 3 files changed, 26 insertions(+) Index: linux-3.5-rc4/drivers/base/memory.c =================================================================== --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-26 13:28:16.726211752 +0900 +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:34:22.423639904 +0900 @@ -70,6 +70,26 @@ void unregister_memory_isolate_notifier( } EXPORT_SYMBOL(unregister_memory_isolate_notifier); +bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn) +{ + struct memory_block *mem; + struct mem_section *section; + unsigned long pfn, section_nr; + + for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { + section_nr = pfn_to_section_nr(pfn); + section = __nr_to_section(section_nr); + mem = find_memory_block(section); + if (!mem) + continue; + if (mem->state == MEM_OFFLINE) + continue; + return false; + } + + return true; +} + /* * register_memory - Setup a sysfs device for a memory block */ Index: linux-3.5-rc4/include/linux/memory.h =================================================================== --- linux-3.5-rc4.orig/include/linux/memory.h 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/include/linux/memory.h 2012-06-26 13:34:22.424639891 +0900 @@ -120,6 +120,7 @@ extern int memory_isolate_notify(unsigne extern struct memory_block *find_memory_block_hinted(struct mem_section *, struct memory_block *); extern struct memory_block *find_memory_block(struct mem_section *); +extern bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn); #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION< email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx138.postini.com [74.125.245.138]) by kanga.kvack.org (Postfix) with SMTP id 28C696B005A for ; Wed, 27 Jun 2012 01:46:08 -0400 (EDT) Received: from m1.gw.fujitsu.co.jp (unknown [10.0.50.71]) by fgwmail5.fujitsu.co.jp (Postfix) with ESMTP id 6EFCE3EE0C5 for ; Wed, 27 Jun 2012 14:46:06 +0900 (JST) Received: from smail (m1 [127.0.0.1]) by outgoing.m1.gw.fujitsu.co.jp (Postfix) with ESMTP id 4FFEF45DE58 for ; Wed, 27 Jun 2012 14:46:06 +0900 (JST) Received: from s1.gw.fujitsu.co.jp (s1.gw.fujitsu.co.jp [10.0.50.91]) by m1.gw.fujitsu.co.jp (Postfix) with ESMTP id 279A445DE5A for ; Wed, 27 Jun 2012 14:46:06 +0900 (JST) Received: from s1.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s1.gw.fujitsu.co.jp (Postfix) with ESMTP id 14A2F1DB804D for ; Wed, 27 Jun 2012 14:46:06 +0900 (JST) Received: from g01jpexchkw01.g01.fujitsu.local (g01jpexchkw01.g01.fujitsu.local [10.0.194.40]) by s1.gw.fujitsu.co.jp (Postfix) with ESMTP id A0F201DB8054 for ; Wed, 27 Jun 2012 14:46:05 +0900 (JST) Message-ID: <4FEA9E0A.1040202@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:45:46 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 Subject: [RFC PATCH 3/12] memory-hotplug : add physical memory hotplug code to acpi_memory_device_remove References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org Cc: len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com acpi_memory_device_remove() has been prepared to remove physical memory. But, the function only frees acpi_memory_device currentlry. The patch adds following functions into acpi_memory_device_remove(): - offline memory - remove physical memory (only return -EBUSY) - free acpi_memory_device CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- drivers/acpi/acpi_memhotplug.c | 23 ++++++++++++++++++++++- include/linux/memory_hotplug.h | 1 + mm/memory_hotplug.c | 8 ++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) Index: linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c =================================================================== --- linux-3.5-rc4.orig/drivers/acpi/acpi_memhotplug.c 2012-06-26 13:28:16.722211802 +0900 +++ linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c 2012-06-26 13:38:01.085906251 +0900 @@ -452,12 +452,33 @@ static int acpi_memory_device_add(struct static int acpi_memory_device_remove(struct acpi_device *device, int type) { struct acpi_memory_device *mem_device = NULL; - + struct acpi_memory_info *info, *tmp; + int result; + int node; if (!device || !acpi_driver_data(device)) return -EINVAL; mem_device = acpi_driver_data(device); + + node = acpi_get_node(mem_device->device->handle); + + list_for_each_entry_safe(info, tmp, &mem_device->res_list, list) { + if (!info->enabled) + continue; + + result = offline_memory(info->start_addr, info->length); + if (result) + return result; + + result = remove_memory(node, info->start_addr, info->length); + if (result) + return result; + + list_del(&info->list); + kfree(info); + } + kfree(mem_device); return 0; Index: linux-3.5-rc4/include/linux/memory_hotplug.h =================================================================== --- linux-3.5-rc4.orig/include/linux/memory_hotplug.h 2012-06-26 13:28:16.773211163 +0900 +++ linux-3.5-rc4/include/linux/memory_hotplug.h 2012-06-26 13:37:30.545288962 +0900 @@ -233,6 +233,7 @@ static inline int is_mem_section_removab extern int mem_online_node(int nid); extern int add_memory(int nid, u64 start, u64 size); extern int arch_add_memory(int nid, u64 start, u64 size); +extern int remove_memory(int nid, u64 start, u64 size); extern int offline_memory(u64 start, u64 size); extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn, int nr_pages); Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:34:22.425639879 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:30.096046767 +0900 @@ -659,6 +659,14 @@ out: } EXPORT_SYMBOL_GPL(add_memory); +int remove_memory(int nid, u64 start, u64 size) +{ + return -EBUSY; + +} +EXPORT_SYMBOL_GPL(remove_memory); + + #ifdef CONFIG_MEMORY_HOTREMOVE /* * A free page on the buddy free lists (not the per-cpu lists) has PageBuddy -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx192.postini.com [74.125.245.192]) by kanga.kvack.org (Postfix) with SMTP id 800526B005A for ; Wed, 27 Jun 2012 01:47:29 -0400 (EDT) Received: from m4.gw.fujitsu.co.jp (unknown [10.0.50.74]) by fgwmail5.fujitsu.co.jp (Postfix) with ESMTP id ADD923EE0C1 for ; Wed, 27 Jun 2012 14:47:27 +0900 (JST) Received: from smail (m4 [127.0.0.1]) by outgoing.m4.gw.fujitsu.co.jp (Postfix) with ESMTP id 9633645DE4E for ; Wed, 27 Jun 2012 14:47:27 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (s4.gw.fujitsu.co.jp [10.0.50.94]) by m4.gw.fujitsu.co.jp (Postfix) with ESMTP id 7FBA745DE4D for ; Wed, 27 Jun 2012 14:47:27 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id 7206D1DB802F for ; Wed, 27 Jun 2012 14:47:27 +0900 (JST) Received: from g01jpexchkw07.g01.fujitsu.local (g01jpexchkw07.g01.fujitsu.local [10.0.194.46]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id BC130E18002 for ; Wed, 27 Jun 2012 14:47:26 +0900 (JST) Message-ID: <4FEA9E5F.4070205@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:47:11 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 Subject: [RFC PATCH 4/12] memory-hotplug : remove /sys/firmware/memmap/X sysfs References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org Cc: len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com When (hot)adding memory into system, /sys/firmware/memmap/X/{end, start, type} sysfs files are created. But there is no code to remove these files. The patch implements the function to remove them. Note : The code does not free firmware_map_entry since there is no way to free memory which is allocated by bootmem. CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- drivers/firmware/memmap.c | 71 +++++++++++++++++++++++++++++++++++++++++++ include/linux/firmware-map.h | 6 +++ mm/memory_hotplug.c | 6 +++ 3 files changed, 82 insertions(+), 1 deletion(-) Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:37:30.546288901 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:44:37.069955820 +0900 @@ -661,7 +661,11 @@ EXPORT_SYMBOL_GPL(add_memory); int remove_memory(int nid, u64 start, u64 size) { - return -EBUSY; + lock_memory_hotplug(); + /* remove memmap entry */ + firmware_map_remove(start, start + size, "System RAM"); + unlock_memory_hotplug(); + return 0; } EXPORT_SYMBOL_GPL(remove_memory); Index: linux-3.5-rc4/include/linux/firmware-map.h =================================================================== --- linux-3.5-rc4.orig/include/linux/firmware-map.h 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/include/linux/firmware-map.h 2012-06-26 13:44:37.070955807 +0900 @@ -25,6 +25,7 @@ int firmware_map_add_early(u64 start, u64 end, const char *type); int firmware_map_add_hotplug(u64 start, u64 end, const char *type); +int firmware_map_remove(u64 start, u64 end, const char *type); #else /* CONFIG_FIRMWARE_MEMMAP */ @@ -38,6 +39,11 @@ static inline int firmware_map_add_hotpl return 0; } +static inline int firmware_map_remove(u64 start, u64 end, const char *type) +{ + return 0; +} + #endif /* CONFIG_FIRMWARE_MEMMAP */ #endif /* _LINUX_FIRMWARE_MAP_H */ Index: linux-3.5-rc4/drivers/firmware/memmap.c =================================================================== --- linux-3.5-rc4.orig/drivers/firmware/memmap.c 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/drivers/firmware/memmap.c 2012-06-26 13:47:17.606948898 +0900 @@ -123,6 +123,16 @@ static int firmware_map_add_entry(u64 st return 0; } +/** + * firmware_map_remove_entry() - Does the real work to remove a firmware + * memmap entry. + * @entry: removed entry. + **/ +static inline void firmware_map_remove_entry(struct firmware_map_entry *entry) +{ + list_del(&entry->list); +} + /* * Add memmap entry on sysfs */ @@ -144,6 +154,31 @@ static int add_sysfs_fw_map_entry(struct return 0; } +/* + * Remove memmap entry on sysfs + */ +static inline void remove_sysfs_fw_map_entry(struct firmware_map_entry *entry) +{ + kobject_del(&entry->kobj); +} + +/* + * Search memmap entry + */ + +struct firmware_map_entry * __meminit +find_firmware_map_entry(u64 start, u64 end, const char *type) +{ + struct firmware_map_entry *entry; + + list_for_each_entry(entry, &map_entries, list) + if ((entry->start == start) && (entry->end == end) && + (!strcmp(entry->type, type))) + return entry; + + return NULL; +} + /** * firmware_map_add_hotplug() - Adds a firmware mapping entry when we do * memory hotplug. @@ -196,6 +231,42 @@ int __init firmware_map_add_early(u64 st return firmware_map_add_entry(start, end, type, entry); } +void release_firmware_map_entry(struct firmware_map_entry *entry) +{ + /* + * FIXME : There is no idea. + * How to free the entry which allocated bootmem? + */ +} + +/** + * firmware_map_remove() - remove a firmware mapping entry + * @start: Start of the memory range. + * @end: End of the memory range (inclusive). + * @type: Type of the memory range. + * + * removes a firmware mapping entry. + * + * Returns 0 on success, or -EINVAL if no entry. + **/ +int __meminit firmware_map_remove(u64 start, u64 end, const char *type) +{ + struct firmware_map_entry *entry; + + entry = find_firmware_map_entry(start, end, type); + if (!entry) + return -EINVAL; + + /* remove the memmap entry */ + remove_sysfs_fw_map_entry(entry); + + firmware_map_remove_entry(entry); + + release_firmware_map_entry(entry); + + return 0; +} + /* * Sysfs functions ------------------------------------------------------------- */ -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx150.postini.com [74.125.245.150]) by kanga.kvack.org (Postfix) with SMTP id 181E46B005A for ; Wed, 27 Jun 2012 01:52:30 -0400 (EDT) Received: from m4.gw.fujitsu.co.jp (unknown [10.0.50.74]) by fgwmail5.fujitsu.co.jp (Postfix) with ESMTP id 623D93EE0C5 for ; Wed, 27 Jun 2012 14:52:29 +0900 (JST) Received: from smail (m4 [127.0.0.1]) by outgoing.m4.gw.fujitsu.co.jp (Postfix) with ESMTP id 488EE45DE50 for ; Wed, 27 Jun 2012 14:52:29 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (s4.gw.fujitsu.co.jp [10.0.50.94]) by m4.gw.fujitsu.co.jp (Postfix) with ESMTP id E32D445DE4D for ; Wed, 27 Jun 2012 14:52:28 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id CD6951DB8037 for ; Wed, 27 Jun 2012 14:52:28 +0900 (JST) Received: from g01jpexchkw02.g01.fujitsu.local (g01jpexchkw02.g01.fujitsu.local [10.0.194.41]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id 26993E18001 for ; Wed, 27 Jun 2012 14:52:28 +0900 (JST) Message-ID: <4FEA9F8B.30105@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:52:11 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 Subject: [RFC PATCH 6/12] memory-hotplug : remove_memory calls __remove_pages References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org Cc: len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com The patch adds __remove_pages() to remove_memory(). Then the range of phys_start_pfn argument and nr_pages argument in __remove_pagse() may have different zone. So zone argument is removed from __remove_pages() and __remove_pages() caluculates zone in each section. When CONFIG_SPARSEMEM_VMEMMAP is defined, there is no way to remove a memmap. So __remove_section only calls unregister_memory_section(). CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- arch/powerpc/platforms/pseries/hotplug-memory.c | 5 +---- include/linux/memory_hotplug.h | 3 +-- mm/memory_hotplug.c | 20 +++++++++++++------- 3 files changed, 15 insertions(+), 13 deletions(-) Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-27 09:07:49.124709164 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-27 09:08:30.612190446 +0900 @@ -275,11 +275,14 @@ static int __meminit __add_section(int n #ifdef CONFIG_SPARSEMEM_VMEMMAP static int __remove_section(struct zone *zone, struct mem_section *ms) { - /* - * XXX: Freeing memmap with vmemmap is not implement yet. - * This should be removed later. - */ - return -EBUSY; + int ret; + + if (!valid_section(ms)) + return ret; + + ret = unregister_memory_section(ms); + + return ret; } #else static int __remove_section(struct zone *zone, struct mem_section *ms) @@ -346,11 +349,11 @@ EXPORT_SYMBOL_GPL(__add_pages); * sure that pages are marked reserved and zones are adjust properly by * calling offline_pages(). */ -int __remove_pages(struct zone *zone, unsigned long phys_start_pfn, - unsigned long nr_pages) +int __remove_pages(unsigned long phys_start_pfn, unsigned long nr_pages) { unsigned long i, ret = 0; int sections_to_remove; + struct zone *zone; /* * We can only remove entire sections @@ -363,6 +366,7 @@ int __remove_pages(struct zone *zone, un sections_to_remove = nr_pages / PAGES_PER_SECTION; for (i = 0; i < sections_to_remove; i++) { unsigned long pfn = phys_start_pfn + i*PAGES_PER_SECTION; + zone = page_zone(pfn_to_page(pfn)); ret = __remove_section(zone, __pfn_to_section(pfn)); if (ret) break; @@ -664,6 +668,8 @@ int remove_memory(int nid, u64 start, u6 lock_memory_hotplug(); /* remove memmap entry */ firmware_map_remove(start, start + size, "System RAM"); + + __remove_pages(start >> PAGE_SHIFT, size >> PAGE_SHIFT); unlock_memory_hotplug(); return 0; Index: linux-3.5-rc4/include/linux/memory_hotplug.h =================================================================== --- linux-3.5-rc4.orig/include/linux/memory_hotplug.h 2012-06-27 09:06:35.616628141 +0900 +++ linux-3.5-rc4/include/linux/memory_hotplug.h 2012-06-27 09:08:30.612190446 +0900 @@ -89,8 +89,7 @@ extern bool is_pageblock_removable_noloc /* reasonably generic interface to expand the physical pages in a zone */ extern int __add_pages(int nid, struct zone *zone, unsigned long start_pfn, unsigned long nr_pages); -extern int __remove_pages(struct zone *zone, unsigned long start_pfn, - unsigned long nr_pages); +extern int __remove_pages(unsigned long start_pfn, unsigned long nr_pages); #ifdef CONFIG_NUMA extern int memory_add_physaddr_to_nid(u64 start); Index: linux-3.5-rc4/arch/powerpc/platforms/pseries/hotplug-memory.c =================================================================== --- linux-3.5-rc4.orig/arch/powerpc/platforms/pseries/hotplug-memory.c 2012-06-27 09:08:25.737248748 +0900 +++ linux-3.5-rc4/arch/powerpc/platforms/pseries/hotplug-memory.c 2012-06-27 09:08:30.613190434 +0900 @@ -76,7 +76,6 @@ unsigned long memory_block_size_bytes(vo static int pseries_remove_memblock(unsigned long base, unsigned int memblock_size) { unsigned long start, start_pfn; - struct zone *zone; int i, ret; int sections_to_remove; @@ -87,8 +86,6 @@ static int pseries_remove_memblock(unsig return 0; } - zone = page_zone(pfn_to_page(start_pfn)); - /* * Remove section mappings and sysfs entries for the * section of the memory we are removing. @@ -101,7 +98,7 @@ static int pseries_remove_memblock(unsig sections_to_remove = (memblock_size >> PAGE_SHIFT) / PAGES_PER_SECTION; for (i = 0; i < sections_to_remove; i++) { unsigned long pfn = start_pfn + i * PAGES_PER_SECTION; - ret = __remove_pages(zone, start_pfn, PAGES_PER_SECTION); + ret = __remove_pages(start_pfn, PAGES_PER_SECTION); if (ret) return ret; } -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx173.postini.com [74.125.245.173]) by kanga.kvack.org (Postfix) with SMTP id 9D4006B005C for ; Wed, 27 Jun 2012 01:54:49 -0400 (EDT) Received: from m2.gw.fujitsu.co.jp (unknown [10.0.50.72]) by fgwmail6.fujitsu.co.jp (Postfix) with ESMTP id E30343EE0C7 for ; Wed, 27 Jun 2012 14:54:47 +0900 (JST) Received: from smail (m2 [127.0.0.1]) by outgoing.m2.gw.fujitsu.co.jp (Postfix) with ESMTP id CAD3A45DE53 for ; Wed, 27 Jun 2012 14:54:47 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (s2.gw.fujitsu.co.jp [10.0.50.92]) by m2.gw.fujitsu.co.jp (Postfix) with ESMTP id A885A45DE4E for ; Wed, 27 Jun 2012 14:54:47 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id 9B8651DB8038 for ; Wed, 27 Jun 2012 14:54:47 +0900 (JST) Received: from g01jpexchkw06.g01.fujitsu.local (g01jpexchkw06.g01.fujitsu.local [10.0.194.45]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id 3CDD11DB803F for ; Wed, 27 Jun 2012 14:54:47 +0900 (JST) Message-ID: <4FEAA019.7070302@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:54:33 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 Subject: [RFC PATCH 8/12] memory-hotplug : move register_page_bootmem_info_node and put_page_bootmem for sparse-vmemmap References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org Cc: len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com For implementing register_page_bootmem_info_node of sparse-vmemmap, register_page_bootmem_info_node and put_page_bootmem are moved to memory_hotplug.c CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyan Signed-off-by: Yasuaki Ishimatsu --- include/linux/memory_hotplug.h | 9 --------- mm/memory_hotplug.c | 8 ++++++-- 2 files changed, 6 insertions(+), 11 deletions(-) Index: linux-3.5-rc4/include/linux/memory_hotplug.h =================================================================== --- linux-3.5-rc4.orig/include/linux/memory_hotplug.h 2012-06-26 13:56:34.372988299 +0900 +++ linux-3.5-rc4/include/linux/memory_hotplug.h 2012-06-26 14:05:16.603459518 +0900 @@ -160,17 +160,8 @@ static inline void arch_refresh_nodedata #endif /* CONFIG_NUMA */ #endif /* CONFIG_HAVE_ARCH_NODEDATA_EXTENSION */ -#ifdef CONFIG_SPARSEMEM_VMEMMAP -static inline void register_page_bootmem_info_node(struct pglist_data *pgdat) -{ -} -static inline void put_page_bootmem(struct page *page) -{ -} -#else extern void register_page_bootmem_info_node(struct pglist_data *pgdat); extern void put_page_bootmem(struct page *page); -#endif /* * Lock for memory hotplug guarantees 1) all callbacks for memory hotplug Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 14:03:37.564697621 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 14:05:16.604459506 +0900 @@ -91,7 +91,6 @@ static void release_memory_resource(stru } #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE -#ifndef CONFIG_SPARSEMEM_VMEMMAP static void get_page_bootmem(unsigned long info, struct page *page, unsigned long type) { @@ -127,6 +126,7 @@ void __ref put_page_bootmem(struct page } +#ifndef CONFIG_SPARSEMEM_VMEMMAP static void register_page_bootmem_info_section(unsigned long start_pfn) { unsigned long *usemap, mapsize, section_nr, i; @@ -163,6 +163,11 @@ static void register_page_bootmem_info_s get_page_bootmem(section_nr, page, MIX_SECTION_INFO); } +#else +static inline void register_page_bootmem_info_section(unsigned long start_pfn) +{ +} +#endif void register_page_bootmem_info_node(struct pglist_data *pgdat) { @@ -198,7 +203,6 @@ void register_page_bootmem_info_node(str register_page_bootmem_info_section(pfn); } -#endif /* !CONFIG_SPARSEMEM_VMEMMAP */ static void grow_zone_span(struct zone *zone, unsigned long start_pfn, unsigned long end_pfn) -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx137.postini.com [74.125.245.137]) by kanga.kvack.org (Postfix) with SMTP id C47A06B005A for ; Wed, 27 Jun 2012 01:56:00 -0400 (EDT) Received: from m3.gw.fujitsu.co.jp (unknown [10.0.50.73]) by fgwmail5.fujitsu.co.jp (Postfix) with ESMTP id 81AC93EE0C3 for ; Wed, 27 Jun 2012 14:55:58 +0900 (JST) Received: from smail (m3 [127.0.0.1]) by outgoing.m3.gw.fujitsu.co.jp (Postfix) with ESMTP id 5DBFB45DEB5 for ; Wed, 27 Jun 2012 14:55:58 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (s3.gw.fujitsu.co.jp [10.0.50.93]) by m3.gw.fujitsu.co.jp (Postfix) with ESMTP id 3F02045DE7E for ; Wed, 27 Jun 2012 14:55:58 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id 31FE21DB8042 for ; Wed, 27 Jun 2012 14:55:58 +0900 (JST) Received: from g01jpexchkw03.g01.fujitsu.local (g01jpexchkw03.g01.fujitsu.local [10.0.194.42]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id E07CC1DB803E for ; Wed, 27 Jun 2012 14:55:57 +0900 (JST) Message-ID: <4FEAA05C.6090204@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:55:40 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 Subject: [RFC PATCH 9/12] memory-hotplug : implement register_page_bootmem_info_section of sparse-vmemmap References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org Cc: len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com For removing memmap region of sparse-vmemmap which is allocated bootmem, memmap region of sparse-vmemmap needs to be registered by get_page_bootmem(). So the patch searches pages of virtual mapping and registers the pages by get_page_bootmem(). CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- arch/x86/mm/init_64.c | 53 +++++++++++++++++++++++++++++++++++++++++ include/linux/memory_hotplug.h | 2 + include/linux/mm.h | 3 +- mm/memory_hotplug.c | 23 +++++++++++++++-- 4 files changed, 77 insertions(+), 4 deletions(-) Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 14:05:16.604459506 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 14:27:19.850916817 +0900 @@ -91,8 +91,8 @@ static void release_memory_resource(stru } #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE -static void get_page_bootmem(unsigned long info, struct page *page, - unsigned long type) +void get_page_bootmem(unsigned long info, struct page *page, + unsigned long type) { unsigned long page_type; @@ -164,8 +164,25 @@ static void register_page_bootmem_info_s } #else -static inline void register_page_bootmem_info_section(unsigned long start_pfn) +static void register_page_bootmem_info_section(unsigned long start_pfn) { + unsigned long mapsize, section_nr; + struct mem_section *ms; + struct page *page, *memmap; + + if (!pfn_valid(start_pfn)) + return; + + section_nr = pfn_to_section_nr(start_pfn); + ms = __nr_to_section(section_nr); + + memmap = sparse_decode_mem_map(ms->section_mem_map, section_nr); + + page = virt_to_page(memmap); + mapsize = sizeof(struct page) * PAGES_PER_SECTION; + mapsize = PAGE_ALIGN(mapsize) >> PAGE_SHIFT; + + register_page_bootmem_memmap(section_nr, memmap, PAGES_PER_SECTION); } #endif Index: linux-3.5-rc4/include/linux/mm.h =================================================================== --- linux-3.5-rc4.orig/include/linux/mm.h 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/include/linux/mm.h 2012-06-26 14:26:17.481696320 +0900 @@ -1586,7 +1586,8 @@ int vmemmap_populate_basepages(struct pa unsigned long pages, int node); int vmemmap_populate(struct page *start_page, unsigned long pages, int node); void vmemmap_populate_print_last(void); - +void register_page_bootmem_memmap(unsigned long section_nr, struct page *map, + unsigned long size); enum mf_flags { MF_COUNT_INCREASED = 1 << 0, Index: linux-3.5-rc4/arch/x86/mm/init_64.c =================================================================== --- linux-3.5-rc4.orig/arch/x86/mm/init_64.c 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/arch/x86/mm/init_64.c 2012-06-26 14:26:17.481696320 +0900 @@ -978,6 +978,59 @@ vmemmap_populate(struct page *start_page return 0; } +void __meminit +register_page_bootmem_memmap(unsigned long section_nr, struct page *start_page, + unsigned long size) +{ + unsigned long addr = (unsigned long)start_page; + unsigned long end = (unsigned long)(start_page + size); + unsigned long next; + pgd_t *pgd; + pud_t *pud; + pmd_t *pmd; + + for (; addr < end; addr = next) { + pte_t *pte = NULL; + + pgd = pgd_offset_k(addr); + if (pgd_none(*pgd)) { + next = (addr + PAGE_SIZE) & PAGE_MASK; + continue; + } + get_page_bootmem(section_nr, pgd_page(*pgd), MIX_SECTION_INFO); + + pud = pud_offset(pgd, addr); + if (pud_none(*pud)) { + next = (addr + PAGE_SIZE) & PAGE_MASK; + continue; + } + get_page_bootmem(section_nr, pud_page(*pud), MIX_SECTION_INFO); + + if (!cpu_has_pse) { + next = (addr + PAGE_SIZE) & PAGE_MASK; + pmd = pmd_offset(pud, addr); + if (pmd_none(*pmd)) + continue; + get_page_bootmem(section_nr, pmd_page(*pmd), + MIX_SECTION_INFO); + + pte = pte_offset_kernel(pmd, addr); + if (pte_none(*pte)) + continue; + get_page_bootmem(section_nr, pte_page(*pte), + SECTION_INFO); + } else { + next = pmd_addr_end(addr, end); + + pmd = pmd_offset(pud, addr); + if (pmd_none(*pmd)) + continue; + get_page_bootmem(section_nr, pmd_page(*pmd), + SECTION_INFO); + } + } +} + void __meminit vmemmap_populate_print_last(void) { if (p_start) { Index: linux-3.5-rc4/include/linux/memory_hotplug.h =================================================================== --- linux-3.5-rc4.orig/include/linux/memory_hotplug.h 2012-06-26 14:05:16.603459518 +0900 +++ linux-3.5-rc4/include/linux/memory_hotplug.h 2012-06-26 14:11:14.175989381 +0900 @@ -162,6 +162,8 @@ static inline void arch_refresh_nodedata extern void register_page_bootmem_info_node(struct pglist_data *pgdat); extern void put_page_bootmem(struct page *page); +extern void get_page_bootmem(unsigned long ingo, struct page *page, + unsigned long type); /* * Lock for memory hotplug guarantees 1) all callbacks for memory hotplug -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx199.postini.com [74.125.245.199]) by kanga.kvack.org (Postfix) with SMTP id EC1A96B005A for ; Wed, 27 Jun 2012 01:58:15 -0400 (EDT) Received: from m2.gw.fujitsu.co.jp (unknown [10.0.50.72]) by fgwmail5.fujitsu.co.jp (Postfix) with ESMTP id 371203EE081 for ; Wed, 27 Jun 2012 14:58:14 +0900 (JST) Received: from smail (m2 [127.0.0.1]) by outgoing.m2.gw.fujitsu.co.jp (Postfix) with ESMTP id 0F03C45DE5A for ; Wed, 27 Jun 2012 14:58:14 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (s2.gw.fujitsu.co.jp [10.0.50.92]) by m2.gw.fujitsu.co.jp (Postfix) with ESMTP id E683C45DE52 for ; Wed, 27 Jun 2012 14:58:13 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id D5F301DB8041 for ; Wed, 27 Jun 2012 14:58:13 +0900 (JST) Received: from g01jpexchkw03.g01.fujitsu.local (g01jpexchkw03.g01.fujitsu.local [10.0.194.42]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id 8E6B01DB803A for ; Wed, 27 Jun 2012 14:58:13 +0900 (JST) Message-ID: <4FEAA0E2.2080003@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:57:54 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 Subject: [RFC PATCH 11/12] memory-hotplug : add node_device_release References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org Cc: len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com When calling unregister_node(), the function shows following message at device_release(). Device 'node2' does not have a release() function, it is broken and must be fixed. So the patch implements node_device_release() CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu Index: linux-3.5-rc1/drivers/base/node.c =================================================================== --- linux-3.5-rc1.orig/drivers/base/node.c 2012-06-14 09:09:53.000000000 +0900 +++ linux-3.5-rc1/drivers/base/node.c 2012-06-25 18:40:45.810261969 +0900 @@ -252,6 +252,12 @@ static inline void hugetlb_register_node static inline void hugetlb_unregister_node(struct node *node) {} #endif +static void node_device_release(struct device *dev) +{ + struct node *node_dev = to_node(dev); + + memset(node_dev, 0, sizeof(struct node)); +} /* * register_node - Setup a sysfs device for a node. @@ -265,6 +271,7 @@ int register_node(struct node *node, int node->dev.id = num; node->dev.bus = &node_subsys; + node->dev.release = node_device_release; error = device_register(&node->dev); if (!error){ -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx107.postini.com [74.125.245.107]) by kanga.kvack.org (Postfix) with SMTP id 26BB26B005A for ; Wed, 27 Jun 2012 01:59:28 -0400 (EDT) Received: from m2.gw.fujitsu.co.jp (unknown [10.0.50.72]) by fgwmail6.fujitsu.co.jp (Postfix) with ESMTP id 7BFFE3EE0C2 for ; Wed, 27 Jun 2012 14:59:26 +0900 (JST) Received: from smail (m2 [127.0.0.1]) by outgoing.m2.gw.fujitsu.co.jp (Postfix) with ESMTP id 5992145DE59 for ; Wed, 27 Jun 2012 14:59:26 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (s2.gw.fujitsu.co.jp [10.0.50.92]) by m2.gw.fujitsu.co.jp (Postfix) with ESMTP id 3FA3F45DE50 for ; Wed, 27 Jun 2012 14:59:26 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id 25C64E18005 for ; Wed, 27 Jun 2012 14:59:26 +0900 (JST) Received: from g01jpexchkw06.g01.fujitsu.local (g01jpexchkw06.g01.fujitsu.local [10.0.194.45]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id D370B1DB803A for ; Wed, 27 Jun 2012 14:59:25 +0900 (JST) Message-ID: <4FEAA12B.6070906@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:59:07 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 Subject: [RFC PATCH 12/12] memory-hotplug : remove sysfs file of node References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org Cc: len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com The patch adds node_set_offline() and unregister_one_node() to remove_memory() for removing sysfs file of node. CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- mm/memory_hotplug.c | 5 +++++ 1 file changed, 5 insertions(+) Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 14:32:03.630368866 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 14:39:58.090437374 +0900 @@ -702,6 +702,11 @@ int remove_memory(int nid, u64 start, u6 /* remove memmap entry */ firmware_map_remove(start, start + size, "System RAM"); + if (!node_present_pages(nid)) { + node_set_offline(nid); + unregister_one_node(nid); + } + __remove_pages(start >> PAGE_SHIFT, size >> PAGE_SHIFT); unlock_memory_hotplug(); return 0; -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx140.postini.com [74.125.245.140]) by kanga.kvack.org (Postfix) with SMTP id 4C9266B005A for ; Wed, 27 Jun 2012 02:16:27 -0400 (EDT) Received: by pbbrp2 with SMTP id rp2so1313621pbb.14 for ; Tue, 26 Jun 2012 23:16:26 -0700 (PDT) Date: Tue, 26 Jun 2012 23:16:24 -0700 (PDT) From: David Rientjes Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages In-Reply-To: <4FEA9DB1.7010303@jp.fujitsu.com> Message-ID: References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-linux-mm@kvack.org List-ID: To: Yasuaki Ishimatsu Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com On Wed, 27 Jun 2012, Yasuaki Ishimatsu wrote: > Index: linux-3.5-rc4/mm/memory_hotplug.c > =================================================================== > --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:28:16.743211538 +0900 > +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:38.264940468 +0900 > @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned > > lock_memory_hotplug(); > > + if (memory_is_offline(start_pfn, end_pfn)) { > + ret = 0; > + goto out; > + } > + > zone = page_zone(pfn_to_page(start_pfn)); > node = zone_to_nid(zone); > nr_pages = end_pfn - start_pfn; Are there additional prerequisites for this patch? Otherwise it changes the return value of offline_memory() which will now call acpi_memory_powerdown_device() in the acpi memhotplug case when disabling. Is that a problem? -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx191.postini.com [74.125.245.191]) by kanga.kvack.org (Postfix) with SMTP id 2B2426B005A for ; Wed, 27 Jun 2012 23:20:51 -0400 (EDT) Message-ID: <4FEBCE9C.7030904@cn.fujitsu.com> Date: Thu, 28 Jun 2012 11:25:16 +0800 From: Wen Congyang MIME-Version: 1.0 Subject: Re: [RFC PATCH 1/12] memory-hotplug : rename remove_memory to offline_memory References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9D5C.1080508@jp.fujitsu.com> <4FEAB2E1.3090200@cn.fujitsu.com> <4FEAC891.7030808@cn.fujitsu.com> <4FEBC8EE.7040207@jp.fujitsu.com> In-Reply-To: <4FEBC8EE.7040207@jp.fujitsu.com> Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=ISO-2022-JP Sender: owner-linux-mm@kvack.org List-ID: To: Yasuaki Ishimatsu Cc: rientjes@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com At 06/28/2012 11:01 AM, Yasuaki Ishimatsu Wrote: > Hi David and Wen, > > Thank you for reviewing my patch. > > 2012/06/27 17:47, Wen Congyang wrote: >> At 06/27/2012 03:14 PM, Wen Congyang Wrote: >>> At 06/27/2012 01:42 PM, Yasuaki Ishimatsu Wrote: >>>> remove_memory() does not remove memory but just offlines memory. The patch >>>> changes name of it to offline_memory(). >>> >>> There are 3 functions in the kernel: >>> 1. add_memory() >>> 2. online_pages() >>> 3. remove_memory() >>> >>> So I think offline_pages() is better than offline_memory(). >> >> There is already a function named offline_pages(). So we >> should call offline_pages() instead of remove_memory() in >> memory_block_action(), and there is no need to rename >> remove_memory(). > > As Wen says, Linux has 4 functions for memory hotplug already. > In my recognition, these functions are prepared for following purpose. > > 1. add_memory : add physical memory > 2. online_pages : online logical memory > 3. remove_memory : offline logical memory > 4. offline_pages : offline logical memory > > add_memory() is used for adding physical memory. I think remove_memory() > would rather be used for removing physical memory than be used for removing > logical memory. So I renamed remove_memory() to offline_memory(). > How do you think? Hmm, remove_memory() will revert all things we do in add_memory(), so I think there is no need to rename it. If we rename it to offline_memory(), we should also rename add_memory() to online_memory(). Thanks Wen Congyang > > Regards, > Yasuaki Ishimatsu > >> >> Thanks >> Wen Congyang >> >>> >>> Thanks >>> Wen Congyang >>>> -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx180.postini.com [74.125.245.180]) by kanga.kvack.org (Postfix) with SMTP id D6EC16B005A for ; Thu, 28 Jun 2012 00:50:43 -0400 (EDT) Received: from m2.gw.fujitsu.co.jp (unknown [10.0.50.72]) by fgwmail6.fujitsu.co.jp (Postfix) with ESMTP id DE66A3EE0C0 for ; Thu, 28 Jun 2012 13:50:41 +0900 (JST) Received: from smail (m2 [127.0.0.1]) by outgoing.m2.gw.fujitsu.co.jp (Postfix) with ESMTP id BCDB245DD74 for ; Thu, 28 Jun 2012 13:50:41 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (s2.gw.fujitsu.co.jp [10.0.50.92]) by m2.gw.fujitsu.co.jp (Postfix) with ESMTP id 9AAAF45DE4E for ; Thu, 28 Jun 2012 13:50:41 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id 8B0EB1DB803F for ; Thu, 28 Jun 2012 13:50:41 +0900 (JST) Received: from g01jpexchyt07.g01.fujitsu.local (g01jpexchyt07.g01.fujitsu.local [10.128.194.46]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id 358321DB803A for ; Thu, 28 Jun 2012 13:50:41 +0900 (JST) Message-ID: <4FEBE280.4060107@jp.fujitsu.com> Date: Thu, 28 Jun 2012 13:50:08 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 Subject: Re: [RFC PATCH 1/12] memory-hotplug : rename remove_memory to offline_memory References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9D5C.1080508@jp.fujitsu.com> <4FEAB2E1.3090200@cn.fujitsu.com> <4FEAC891.7030808@cn.fujitsu.com> <4FEBC8EE.7040207@jp.fujitsu.com> <4FEBCE9C.7030904@cn.fujitsu.com> In-Reply-To: <4FEBCE9C.7030904@cn.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: Wen Congyang Cc: rientjes@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com Hi Wen, 2012/06/28 12:25, Wen Congyang wrote: > At 06/28/2012 11:01 AM, Yasuaki Ishimatsu Wrote: >> Hi David and Wen, >> >> Thank you for reviewing my patch. >> >> 2012/06/27 17:47, Wen Congyang wrote: >>> At 06/27/2012 03:14 PM, Wen Congyang Wrote: >>>> At 06/27/2012 01:42 PM, Yasuaki Ishimatsu Wrote: >>>>> remove_memory() does not remove memory but just offlines memory. The patch >>>>> changes name of it to offline_memory(). >>>> >>>> There are 3 functions in the kernel: >>>> 1. add_memory() >>>> 2. online_pages() >>>> 3. remove_memory() >>>> >>>> So I think offline_pages() is better than offline_memory(). >>> >>> There is already a function named offline_pages(). So we >>> should call offline_pages() instead of remove_memory() in >>> memory_block_action(), and there is no need to rename >>> remove_memory(). >> >> As Wen says, Linux has 4 functions for memory hotplug already. >> In my recognition, these functions are prepared for following purpose. >> >> 1. add_memory : add physical memory >> 2. online_pages : online logical memory >> 3. remove_memory : offline logical memory >> 4. offline_pages : offline logical memory >> >> add_memory() is used for adding physical memory. I think remove_memory() >> would rather be used for removing physical memory than be used for removing >> logical memory. So I renamed remove_memory() to offline_memory(). >> How do you think? > > Hmm, remove_memory() will revert all things we do in add_memory(), so I think I think so too. add_memory() prepares to use physical memory. It prepares some structures (pgdat, page table, node, etc) for using the physical memory at the system. But it does not online the meomory. For onlining the memory, we use online_pages(). So I think that remove_memory() should remove these structures which are prepared by add_memory() not offline memory. But current remove_memory() code only calls offline_pages() and offlines memory. The patch series recreates remove_memory() for removing these structures after [RFC PATCH 3/12]. The reason to change the name of remove_memory() is a preparation to recreate it. Thanks, Yasuaki Ishimatsu > there is no need to rename it. If we rename it to offline_memory(), we should > also rename add_memory() to online_memory(). > > Thanks > Wen Congyang > >> >> Regards, >> Yasuaki Ishimatsu >> >>> >>> Thanks >>> Wen Congyang >>> >>>> >>>> Thanks >>>> Wen Congyang >>>>> -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx145.postini.com [74.125.245.145]) by kanga.kvack.org (Postfix) with SMTP id 78E726B005A for ; Thu, 28 Jun 2012 01:06:45 -0400 (EDT) Received: from m2.gw.fujitsu.co.jp (unknown [10.0.50.72]) by fgwmail6.fujitsu.co.jp (Postfix) with ESMTP id DFE5B3EE0C0 for ; Thu, 28 Jun 2012 14:06:40 +0900 (JST) Received: from smail (m2 [127.0.0.1]) by outgoing.m2.gw.fujitsu.co.jp (Postfix) with ESMTP id C189345DE5C for ; Thu, 28 Jun 2012 14:06:40 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (s2.gw.fujitsu.co.jp [10.0.50.92]) by m2.gw.fujitsu.co.jp (Postfix) with ESMTP id 581FA45DE53 for ; Thu, 28 Jun 2012 14:06:40 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id 4BC331DB803F for ; Thu, 28 Jun 2012 14:06:40 +0900 (JST) Received: from g01jpexchyt01.g01.fujitsu.local (g01jpexchyt01.g01.fujitsu.local [10.128.194.40]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id E7BF01DB803E for ; Thu, 28 Jun 2012 14:06:39 +0900 (JST) Message-ID: <4FEBE646.5090801@jp.fujitsu.com> Date: Thu, 28 Jun 2012 14:06:14 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> <4FEAC916.7030506@cn.fujitsu.com> In-Reply-To: <4FEAC916.7030506@cn.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: Wen Congyang Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com Hi Wen, 2012/06/27 17:49, Wen Congyang wrote: > At 06/27/2012 01:44 PM, Yasuaki Ishimatsu Wrote: >> When offline_pages() is called to offlined memory, the function fails since >> all memory has been offlined. In this case, the function should succeed. >> The patch adds the check function into offline_pages(). > > You miss such case: some pages are online, while some pages are offline. > offline_pages() will fail too in such case. You are right. But current code fails, when the function is called to offline memory. In this case, the function should succeed. So the patch confirms whether the memory was offlined or not. And if memory has already been offlined, offline_pages return 0. Thanks, Yasuaki Ishimatsu > > Thanks > Wen Congyang > >> >> CC: Len Brown >> CC: Benjamin Herrenschmidt >> CC: Paul Mackerras >> CC: Christoph Lameter >> Cc: Minchan Kim >> CC: Andrew Morton >> CC: KOSAKI Motohiro >> CC: Wen Congyang >> Signed-off-by: Yasuaki Ishimatsu >> >> --- >> drivers/base/memory.c | 20 ++++++++++++++++++++ >> include/linux/memory.h | 1 + >> mm/memory_hotplug.c | 5 +++++ >> 3 files changed, 26 insertions(+) >> >> Index: linux-3.5-rc4/drivers/base/memory.c >> =================================================================== >> --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-26 13:28:16.726211752 +0900 >> +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:34:22.423639904 +0900 >> @@ -70,6 +70,26 @@ void unregister_memory_isolate_notifier( >> } >> EXPORT_SYMBOL(unregister_memory_isolate_notifier); >> >> +bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn) >> +{ >> + struct memory_block *mem; >> + struct mem_section *section; >> + unsigned long pfn, section_nr; >> + >> + for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { >> + section_nr = pfn_to_section_nr(pfn); >> + section = __nr_to_section(section_nr); >> + mem = find_memory_block(section); >> + if (!mem) >> + continue; >> + if (mem->state == MEM_OFFLINE) >> + continue; >> + return false; >> + } >> + >> + return true; >> +} >> + >> /* >> * register_memory - Setup a sysfs device for a memory block >> */ >> Index: linux-3.5-rc4/include/linux/memory.h >> =================================================================== >> --- linux-3.5-rc4.orig/include/linux/memory.h 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/include/linux/memory.h 2012-06-26 13:34:22.424639891 +0900 >> @@ -120,6 +120,7 @@ extern int memory_isolate_notify(unsigne >> extern struct memory_block *find_memory_block_hinted(struct mem_section *, >> struct memory_block *); >> extern struct memory_block *find_memory_block(struct mem_section *); >> +extern bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn); >> #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION<> enum mem_add_context { BOOT, HOTPLUG }; >> #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ >> Index: linux-3.5-rc4/mm/memory_hotplug.c >> =================================================================== >> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:28:16.743211538 +0900 >> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:38.264940468 +0900 >> @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned >> >> lock_memory_hotplug(); >> >> + if (memory_is_offline(start_pfn, end_pfn)) { >> + ret = 0; >> + goto out; >> + } >> + >> zone = page_zone(pfn_to_page(start_pfn)); >> node = zone_to_nid(zone); >> nr_pages = end_pfn - start_pfn; >> >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >> Please read the FAQ at http://www.tux.org/lkml/ >> > > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ > -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx157.postini.com [74.125.245.157]) by kanga.kvack.org (Postfix) with SMTP id 79C766B005C for ; Thu, 28 Jun 2012 01:26:42 -0400 (EDT) Received: by yenr5 with SMTP id r5so1918609yen.14 for ; Wed, 27 Jun 2012 22:26:41 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <4FEA9DB1.7010303@jp.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> From: KOSAKI Motohiro Date: Thu, 28 Jun 2012 01:26:21 -0400 Message-ID: Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Sender: owner-linux-mm@kvack.org List-ID: To: Yasuaki Ishimatsu Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, wency@cn.fujitsu.com On Wed, Jun 27, 2012 at 1:44 AM, Yasuaki Ishimatsu wrote: > When offline_pages() is called to offlined memory, the function fails sin= ce > all memory has been offlined. In this case, the function should succeed. > The patch adds the check function into offline_pages(). I don't understand your point. I think following misoperation should fail. Otherwise administrator have no way to know their fault. $ echo offline > memoryN/state $ echo offline > memoryN/state In general, we don't like to ignore an error except the standard require it= . > > CC: Len Brown > CC: Benjamin Herrenschmidt > CC: Paul Mackerras > CC: Christoph Lameter > Cc: Minchan Kim > CC: Andrew Morton > CC: KOSAKI Motohiro > CC: Wen Congyang > Signed-off-by: Yasuaki Ishimatsu > > --- > =A0drivers/base/memory.c =A0| =A0 20 ++++++++++++++++++++ > =A0include/linux/memory.h | =A0 =A01 + > =A0mm/memory_hotplug.c =A0 =A0| =A0 =A05 +++++ > =A03 files changed, 26 insertions(+) > > Index: linux-3.5-rc4/drivers/base/memory.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- linux-3.5-rc4.orig/drivers/base/memory.c =A0 =A02012-06-26 13:28:16.7= 26211752 +0900 > +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:34:22.423639904 +09= 00 > @@ -70,6 +70,26 @@ void unregister_memory_isolate_notifier( > =A0} > =A0EXPORT_SYMBOL(unregister_memory_isolate_notifier); > > +bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn) I dislike this function name. 'memory' is too vague to me. > +{ > + =A0 =A0 =A0 struct memory_block *mem; > + =A0 =A0 =A0 struct mem_section *section; > + =A0 =A0 =A0 unsigned long pfn, section_nr; > + > + =A0 =A0 =A0 for (pfn =3D start_pfn; pfn < end_pfn; pfn +=3D PAGES_PER_S= ECTION) { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 section_nr =3D pfn_to_section_nr(pfn); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 section =3D __nr_to_section(section_nr); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 mem =3D find_memory_block(section); This seems to have strong sparse dependency. Hm, I wonder why memory-hotplug.c can enable when X86_64_ACPI_NUMA. # eventually, we can have this option just 'select SPARSEMEM' config MEMORY_HOTPLUG bool "Allow for memory hot-add" depends on SPARSEMEM || X86_64_ACPI_NUMA > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!mem) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 continue; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (mem->state =3D=3D MEM_OFFLINE) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 continue; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return false; > + =A0 =A0 =A0 } > + > + =A0 =A0 =A0 return true; > +} > + > =A0/* > =A0* register_memory - Setup a sysfs device for a memory block > =A0*/ > Index: linux-3.5-rc4/include/linux/memory.h > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- linux-3.5-rc4.orig/include/linux/memory.h =A0 2012-06-25 04:53:04.000= 000000 +0900 > +++ linux-3.5-rc4/include/linux/memory.h =A0 =A0 =A0 =A02012-06-26 13:34:= 22.424639891 +0900 > @@ -120,6 +120,7 @@ extern int memory_isolate_notify(unsigne > =A0extern struct memory_block *find_memory_block_hinted(struct mem_sectio= n *, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0struct memory_block *); > =A0extern struct memory_block *find_memory_block(struct mem_section *); > +extern bool memory_is_offline(unsigned long start_pfn, unsigned long end= _pfn); > =A0#define CONFIG_MEM_BLOCK_SIZE =A0(PAGES_PER_SECTION< =A0enum mem_add_context { BOOT, HOTPLUG }; > =A0#endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ > Index: linux-3.5-rc4/mm/memory_hotplug.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- linux-3.5-rc4.orig/mm/memory_hotplug.c =A0 =A0 =A02012-06-26 13:28:16= .743211538 +0900 > +++ linux-3.5-rc4/mm/memory_hotplug.c =A0 2012-06-26 13:48:38.264940468 += 0900 > @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned > > =A0 =A0 =A0 =A0lock_memory_hotplug(); > > + =A0 =A0 =A0 if (memory_is_offline(start_pfn, end_pfn)) { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D 0; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out; > + =A0 =A0 =A0 } > + > =A0 =A0 =A0 =A0zone =3D page_zone(pfn_to_page(start_pfn)); > =A0 =A0 =A0 =A0node =3D zone_to_nid(zone); > =A0 =A0 =A0 =A0nr_pages =3D end_pfn - start_pfn; > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. =A0For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: email@kvack.org -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx130.postini.com [74.125.245.130]) by kanga.kvack.org (Postfix) with SMTP id EC9BC6B005A for ; Thu, 28 Jun 2012 01:27:56 -0400 (EDT) Received: by ghrr18 with SMTP id r18so1933771ghr.14 for ; Wed, 27 Jun 2012 22:27:56 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <4FEBE646.5090801@jp.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> <4FEAC916.7030506@cn.fujitsu.com> <4FEBE646.5090801@jp.fujitsu.com> From: KOSAKI Motohiro Date: Thu, 28 Jun 2012 01:27:35 -0400 Message-ID: Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages Content-Type: text/plain; charset=ISO-8859-1 Sender: owner-linux-mm@kvack.org List-ID: To: Yasuaki Ishimatsu Cc: Wen Congyang , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org On Thu, Jun 28, 2012 at 1:06 AM, Yasuaki Ishimatsu wrote: > Hi Wen, > > 2012/06/27 17:49, Wen Congyang wrote: >> At 06/27/2012 01:44 PM, Yasuaki Ishimatsu Wrote: >>> When offline_pages() is called to offlined memory, the function fails since >>> all memory has been offlined. In this case, the function should succeed. >>> The patch adds the check function into offline_pages(). >> >> You miss such case: some pages are online, while some pages are offline. >> offline_pages() will fail too in such case. > > You are right. But current code fails, when the function is called to offline > memory. In this case, the function should succeed. So the patch confirms > whether the memory was offlined or not. And if memory has already been > offlined, offline_pages return 0. Can you please explain why the caller can't check it? I hope to avoid an ignorance as far as we can. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx146.postini.com [74.125.245.146]) by kanga.kvack.org (Postfix) with SMTP id C9CEC6B005A for ; Thu, 28 Jun 2012 02:02:03 -0400 (EDT) Received: from m4.gw.fujitsu.co.jp (unknown [10.0.50.74]) by fgwmail6.fujitsu.co.jp (Postfix) with ESMTP id A76C83EE0C1 for ; Thu, 28 Jun 2012 15:02:01 +0900 (JST) Received: from smail (m4 [127.0.0.1]) by outgoing.m4.gw.fujitsu.co.jp (Postfix) with ESMTP id 831DA45DE54 for ; Thu, 28 Jun 2012 15:02:01 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (s4.gw.fujitsu.co.jp [10.0.50.94]) by m4.gw.fujitsu.co.jp (Postfix) with ESMTP id 5A38445DE4F for ; Thu, 28 Jun 2012 15:02:01 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id 44070E08002 for ; Thu, 28 Jun 2012 15:02:01 +0900 (JST) Received: from g01jpexchyt05.g01.fujitsu.local (g01jpexchyt05.g01.fujitsu.local [10.128.194.44]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id DE0AAE08006 for ; Thu, 28 Jun 2012 15:02:00 +0900 (JST) Message-ID: <4FEBF342.9030303@jp.fujitsu.com> Date: Thu, 28 Jun 2012 15:01:38 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> <4FEAC916.7030506@cn.fujitsu.com> <4FEBE646.5090801@jp.fujitsu.com> In-Reply-To: Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: KOSAKI Motohiro Cc: Wen Congyang , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org Hi Kosaki-san, 2012/06/28 14:27, KOSAKI Motohiro wrote: > On Thu, Jun 28, 2012 at 1:06 AM, Yasuaki Ishimatsu > wrote: >> Hi Wen, >> >> 2012/06/27 17:49, Wen Congyang wrote: >>> At 06/27/2012 01:44 PM, Yasuaki Ishimatsu Wrote: >>>> When offline_pages() is called to offlined memory, the function fails since >>>> all memory has been offlined. In this case, the function should succeed. >>>> The patch adds the check function into offline_pages(). >>> >>> You miss such case: some pages are online, while some pages are offline. >>> offline_pages() will fail too in such case. >> >> You are right. But current code fails, when the function is called to offline >> memory. In this case, the function should succeed. So the patch confirms >> whether the memory was offlined or not. And if memory has already been >> offlined, offline_pages return 0. > > Can you please explain why the caller can't check it? I hope to avoid > an ignorance > as far as we can. Of course, caller side can check it. But there is a possibility that offline_pages() is called by many functions. So I do not think that it is good that all functions which call offline_pages() check it. Thanks, Yasuaki Ishimatsu -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx175.postini.com [74.125.245.175]) by kanga.kvack.org (Postfix) with SMTP id C726C6B005A for ; Thu, 28 Jun 2012 02:28:19 -0400 (EDT) Message-ID: <4FEBFA8D.5040607@cn.fujitsu.com> Date: Thu, 28 Jun 2012 14:32:45 +0800 From: Wen Congyang MIME-Version: 1.0 Subject: Re: [RFC PATCH 4/12] memory-hotplug : remove /sys/firmware/memmap/X sysfs References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9E5F.4070205@jp.fujitsu.com> In-Reply-To: <4FEA9E5F.4070205@jp.fujitsu.com> Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=ISO-8859-1 Sender: owner-linux-mm@kvack.org List-ID: To: Yasuaki Ishimatsu Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com At 06/27/2012 01:47 PM, Yasuaki Ishimatsu Wrote: > When (hot)adding memory into system, /sys/firmware/memmap/X/{end, start, type} > sysfs files are created. But there is no code to remove these files. The patch > implements the function to remove them. > > Note : The code does not free firmware_map_entry since there is no way to free > memory which is allocated by bootmem. > > CC: Len Brown > CC: Benjamin Herrenschmidt > CC: Paul Mackerras > CC: Christoph Lameter > Cc: Minchan Kim > CC: Andrew Morton > CC: KOSAKI Motohiro > CC: Wen Congyang > Signed-off-by: Yasuaki Ishimatsu > > --- > drivers/firmware/memmap.c | 71 +++++++++++++++++++++++++++++++++++++++++++ > include/linux/firmware-map.h | 6 +++ > mm/memory_hotplug.c | 6 +++ > 3 files changed, 82 insertions(+), 1 deletion(-) > > Index: linux-3.5-rc4/mm/memory_hotplug.c > =================================================================== > --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:37:30.546288901 +0900 > +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:44:37.069955820 +0900 > @@ -661,7 +661,11 @@ EXPORT_SYMBOL_GPL(add_memory); > > int remove_memory(int nid, u64 start, u64 size) > { > - return -EBUSY; > + lock_memory_hotplug(); > + /* remove memmap entry */ > + firmware_map_remove(start, start + size, "System RAM"); > + unlock_memory_hotplug(); > + return 0; > > } > EXPORT_SYMBOL_GPL(remove_memory); > Index: linux-3.5-rc4/include/linux/firmware-map.h > =================================================================== > --- linux-3.5-rc4.orig/include/linux/firmware-map.h 2012-06-25 04:53:04.000000000 +0900 > +++ linux-3.5-rc4/include/linux/firmware-map.h 2012-06-26 13:44:37.070955807 +0900 > @@ -25,6 +25,7 @@ > > int firmware_map_add_early(u64 start, u64 end, const char *type); > int firmware_map_add_hotplug(u64 start, u64 end, const char *type); > +int firmware_map_remove(u64 start, u64 end, const char *type); > > #else /* CONFIG_FIRMWARE_MEMMAP */ > > @@ -38,6 +39,11 @@ static inline int firmware_map_add_hotpl > return 0; > } > > +static inline int firmware_map_remove(u64 start, u64 end, const char *type) > +{ > + return 0; > +} > + > #endif /* CONFIG_FIRMWARE_MEMMAP */ > > #endif /* _LINUX_FIRMWARE_MAP_H */ > Index: linux-3.5-rc4/drivers/firmware/memmap.c > =================================================================== > --- linux-3.5-rc4.orig/drivers/firmware/memmap.c 2012-06-25 04:53:04.000000000 +0900 > +++ linux-3.5-rc4/drivers/firmware/memmap.c 2012-06-26 13:47:17.606948898 +0900 > @@ -123,6 +123,16 @@ static int firmware_map_add_entry(u64 st > return 0; > } > > +/** > + * firmware_map_remove_entry() - Does the real work to remove a firmware > + * memmap entry. > + * @entry: removed entry. > + **/ > +static inline void firmware_map_remove_entry(struct firmware_map_entry *entry) > +{ > + list_del(&entry->list); > +} > + > /* > * Add memmap entry on sysfs > */ > @@ -144,6 +154,31 @@ static int add_sysfs_fw_map_entry(struct > return 0; > } > > +/* > + * Remove memmap entry on sysfs > + */ > +static inline void remove_sysfs_fw_map_entry(struct firmware_map_entry *entry) > +{ > + kobject_del(&entry->kobj); > +} > + > +/* > + * Search memmap entry > + */ > + > +struct firmware_map_entry * __meminit > +find_firmware_map_entry(u64 start, u64 end, const char *type) > +{ > + struct firmware_map_entry *entry; > + > + list_for_each_entry(entry, &map_entries, list) > + if ((entry->start == start) && (entry->end == end) && > + (!strcmp(entry->type, type))) > + return entry; > + > + return NULL; > +} > + > /** > * firmware_map_add_hotplug() - Adds a firmware mapping entry when we do > * memory hotplug. > @@ -196,6 +231,42 @@ int __init firmware_map_add_early(u64 st > return firmware_map_add_entry(start, end, type, entry); > } > > +void release_firmware_map_entry(struct firmware_map_entry *entry) > +{ > + /* > + * FIXME : There is no idea. > + * How to free the entry which allocated bootmem? > + */ > +} > + > +/** > + * firmware_map_remove() - remove a firmware mapping entry > + * @start: Start of the memory range. > + * @end: End of the memory range (inclusive). > + * @type: Type of the memory range. > + * > + * removes a firmware mapping entry. > + * > + * Returns 0 on success, or -EINVAL if no entry. > + **/ > +int __meminit firmware_map_remove(u64 start, u64 end, const char *type) > +{ > + struct firmware_map_entry *entry; > + > + entry = find_firmware_map_entry(start, end, type); Hmm, we cannot find the entry easily, because the end can be: 1. start + size 2. start + size - 1 So, We should fix this bug first. > + if (!entry) > + return -EINVAL; > + > + /* remove the memmap entry */ > + remove_sysfs_fw_map_entry(entry); > + > + firmware_map_remove_entry(entry); > + > + release_firmware_map_entry(entry); I guess you want to free the memory in the above function. But I think it is not a good idea to free it here. We should free it when the entry->kobj's kref is decreased to 0. Thanks Wen Congyang > + > + return 0; > +} > + > /* > * Sysfs functions ------------------------------------------------------------- > */ > > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ > -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx187.postini.com [74.125.245.187]) by kanga.kvack.org (Postfix) with SMTP id 68F756B00AB for ; Sat, 30 Jun 2012 11:47:08 -0400 (EDT) Received: by pbbrp2 with SMTP id rp2so7105296pbb.14 for ; Sat, 30 Jun 2012 08:47:07 -0700 (PDT) Message-ID: <4FEF1F6A.6090705@gmail.com> Date: Sat, 30 Jun 2012 23:46:50 +0800 From: Jiang Liu MIME-Version: 1.0 Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> In-Reply-To: <4FEA9DB1.7010303@jp.fujitsu.com> Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: Yasuaki Ishimatsu Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com On 06/27/2012 01:44 PM, Yasuaki Ishimatsu wrote: > When offline_pages() is called to offlined memory, the function fails since > all memory has been offlined. In this case, the function should succeed. > The patch adds the check function into offline_pages(). > > CC: Len Brown > CC: Benjamin Herrenschmidt > CC: Paul Mackerras > CC: Christoph Lameter > Cc: Minchan Kim > CC: Andrew Morton > CC: KOSAKI Motohiro > CC: Wen Congyang > Signed-off-by: Yasuaki Ishimatsu > > --- > drivers/base/memory.c | 20 ++++++++++++++++++++ > include/linux/memory.h | 1 + > mm/memory_hotplug.c | 5 +++++ > 3 files changed, 26 insertions(+) > > Index: linux-3.5-rc4/drivers/base/memory.c > =================================================================== > --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-26 13:28:16.726211752 +0900 > +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:34:22.423639904 +0900 > @@ -70,6 +70,26 @@ void unregister_memory_isolate_notifier( > } > EXPORT_SYMBOL(unregister_memory_isolate_notifier); > > +bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn) > +{ > + struct memory_block *mem; > + struct mem_section *section; > + unsigned long pfn, section_nr; > + > + for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { > + section_nr = pfn_to_section_nr(pfn); > + section = __nr_to_section(section_nr); Is it possible for __nr_to_section return NULL here? > + mem = find_memory_block(section); > + if (!mem) > + continue; > + if (mem->state == MEM_OFFLINE) > + continue; > + return false; > + } > + > + return true; > +} Need a put_dev(&mem->dev) for the last memory block device handled before return. > + > /* > * register_memory - Setup a sysfs device for a memory block > */ > Index: linux-3.5-rc4/include/linux/memory.h > =================================================================== > --- linux-3.5-rc4.orig/include/linux/memory.h 2012-06-25 04:53:04.000000000 +0900 > +++ linux-3.5-rc4/include/linux/memory.h 2012-06-26 13:34:22.424639891 +0900 > @@ -120,6 +120,7 @@ extern int memory_isolate_notify(unsigne > extern struct memory_block *find_memory_block_hinted(struct mem_section *, > struct memory_block *); > extern struct memory_block *find_memory_block(struct mem_section *); > +extern bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn); > #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION< enum mem_add_context { BOOT, HOTPLUG }; > #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ > Index: linux-3.5-rc4/mm/memory_hotplug.c > =================================================================== > --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:28:16.743211538 +0900 > +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:38.264940468 +0900 > @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned > > lock_memory_hotplug(); > > + if (memory_is_offline(start_pfn, end_pfn)) { > + ret = 0; > + goto out; > + } > + > zone = page_zone(pfn_to_page(start_pfn)); > node = zone_to_nid(zone); > nr_pages = end_pfn - start_pfn; > > -- > To unsubscribe from this list: send the line "unsubscribe linux-acpi" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx172.postini.com [74.125.245.172]) by kanga.kvack.org (Postfix) with SMTP id 13E2A6B00AD for ; Sat, 30 Jun 2012 11:51:32 -0400 (EDT) Received: by dakp5 with SMTP id p5so6902176dak.14 for ; Sat, 30 Jun 2012 08:51:31 -0700 (PDT) Message-ID: <4FEF2075.2050603@gmail.com> Date: Sat, 30 Jun 2012 23:51:17 +0800 From: Jiang Liu MIME-Version: 1.0 Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> In-Reply-To: <4FEA9DB1.7010303@jp.fujitsu.com> Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: Yasuaki Ishimatsu Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com On 06/27/2012 01:44 PM, Yasuaki Ishimatsu wrote: > When offline_pages() is called to offlined memory, the function fails since > all memory has been offlined. In this case, the function should succeed. > The patch adds the check function into offline_pages(). > > CC: Len Brown > CC: Benjamin Herrenschmidt > CC: Paul Mackerras > CC: Christoph Lameter > Cc: Minchan Kim > CC: Andrew Morton > CC: KOSAKI Motohiro > CC: Wen Congyang > Signed-off-by: Yasuaki Ishimatsu > > --- > drivers/base/memory.c | 20 ++++++++++++++++++++ > include/linux/memory.h | 1 + > mm/memory_hotplug.c | 5 +++++ > 3 files changed, 26 insertions(+) > > Index: linux-3.5-rc4/drivers/base/memory.c > =================================================================== > --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-26 13:28:16.726211752 +0900 > +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:34:22.423639904 +0900 > @@ -70,6 +70,26 @@ void unregister_memory_isolate_notifier( > } > EXPORT_SYMBOL(unregister_memory_isolate_notifier); > > +bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn) > +{ > + struct memory_block *mem; > + struct mem_section *section; > + unsigned long pfn, section_nr; > + > + for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { > + section_nr = pfn_to_section_nr(pfn); > + section = __nr_to_section(section_nr); > + mem = find_memory_block(section); Seems find_memory_block_hinted() is more efficient than find_memory_block() here. > + if (!mem) > + continue; > + if (mem->state == MEM_OFFLINE) > + continue; > + return false; > + } > + > + return true; > +} > + > /* > * register_memory - Setup a sysfs device for a memory block > */ > Index: linux-3.5-rc4/include/linux/memory.h > =================================================================== > --- linux-3.5-rc4.orig/include/linux/memory.h 2012-06-25 04:53:04.000000000 +0900 > +++ linux-3.5-rc4/include/linux/memory.h 2012-06-26 13:34:22.424639891 +0900 > @@ -120,6 +120,7 @@ extern int memory_isolate_notify(unsigne > extern struct memory_block *find_memory_block_hinted(struct mem_section *, > struct memory_block *); > extern struct memory_block *find_memory_block(struct mem_section *); > +extern bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn); > #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION< enum mem_add_context { BOOT, HOTPLUG }; > #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ > Index: linux-3.5-rc4/mm/memory_hotplug.c > =================================================================== > --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:28:16.743211538 +0900 > +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:38.264940468 +0900 > @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned > > lock_memory_hotplug(); > > + if (memory_is_offline(start_pfn, end_pfn)) { > + ret = 0; > + goto out; > + } > + > zone = page_zone(pfn_to_page(start_pfn)); > node = zone_to_nid(zone); > nr_pages = end_pfn - start_pfn; > > -- > To unsubscribe from this list: send the line "unsubscribe linux-acpi" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx134.postini.com [74.125.245.134]) by kanga.kvack.org (Postfix) with SMTP id 2E9046B0068 for ; Sun, 1 Jul 2012 22:57:20 -0400 (EDT) Received: from m3.gw.fujitsu.co.jp (unknown [10.0.50.73]) by fgwmail6.fujitsu.co.jp (Postfix) with ESMTP id 25E363EE0BC for ; Mon, 2 Jul 2012 11:57:18 +0900 (JST) Received: from smail (m3 [127.0.0.1]) by outgoing.m3.gw.fujitsu.co.jp (Postfix) with ESMTP id F2A4445DEB5 for ; Mon, 2 Jul 2012 11:57:17 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (s3.gw.fujitsu.co.jp [10.0.50.93]) by m3.gw.fujitsu.co.jp (Postfix) with ESMTP id D9B9F45DEB2 for ; Mon, 2 Jul 2012 11:57:17 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id 8BB4F1DB8042 for ; Mon, 2 Jul 2012 11:57:17 +0900 (JST) Received: from g01jpexchyt03.g01.fujitsu.local (g01jpexchyt03.g01.fujitsu.local [10.128.194.42]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id A8CFF1DB803F for ; Mon, 2 Jul 2012 11:57:16 +0900 (JST) Message-ID: <4FF10D1C.3060601@jp.fujitsu.com> Date: Mon, 2 Jul 2012 11:53:16 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> <4FEF1F6A.6090705@gmail.com> In-Reply-To: <4FEF1F6A.6090705@gmail.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: Jiang Liu Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com Hi Jiang, Thank you for your feedback. 2012/07/01 0:46, Jiang Liu wrote: > On 06/27/2012 01:44 PM, Yasuaki Ishimatsu wrote: >> When offline_pages() is called to offlined memory, the function fails since >> all memory has been offlined. In this case, the function should succeed. >> The patch adds the check function into offline_pages(). >> >> CC: Len Brown >> CC: Benjamin Herrenschmidt >> CC: Paul Mackerras >> CC: Christoph Lameter >> Cc: Minchan Kim >> CC: Andrew Morton >> CC: KOSAKI Motohiro >> CC: Wen Congyang >> Signed-off-by: Yasuaki Ishimatsu >> >> --- >> drivers/base/memory.c | 20 ++++++++++++++++++++ >> include/linux/memory.h | 1 + >> mm/memory_hotplug.c | 5 +++++ >> 3 files changed, 26 insertions(+) >> >> Index: linux-3.5-rc4/drivers/base/memory.c >> =================================================================== >> --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-26 13:28:16.726211752 +0900 >> +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:34:22.423639904 +0900 >> @@ -70,6 +70,26 @@ void unregister_memory_isolate_notifier( >> } >> EXPORT_SYMBOL(unregister_memory_isolate_notifier); >> >> +bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn) >> +{ >> + struct memory_block *mem; >> + struct mem_section *section; >> + unsigned long pfn, section_nr; >> + >> + for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { >> + section_nr = pfn_to_section_nr(pfn); >> + section = __nr_to_section(section_nr); > Is it possible for __nr_to_section return NULL here? Yes. I'll add NULL check. > >> + mem = find_memory_block(section); >> + if (!mem) >> + continue; >> + if (mem->state == MEM_OFFLINE) >> + continue; >> + return false; >> + } >> + >> + return true; >> +} > Need a put_dev(&mem->dev) for the last memory block device handled before return. Thanks. I think kobject_put(&mem->dev.kobj) should be handled for all memory block devices found by find_memory_block(). I'll update it. Thanks, Yasuaki Ishimatsu > >> + >> /* >> * register_memory - Setup a sysfs device for a memory block >> */ >> Index: linux-3.5-rc4/include/linux/memory.h >> =================================================================== >> --- linux-3.5-rc4.orig/include/linux/memory.h 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/include/linux/memory.h 2012-06-26 13:34:22.424639891 +0900 >> @@ -120,6 +120,7 @@ extern int memory_isolate_notify(unsigne >> extern struct memory_block *find_memory_block_hinted(struct mem_section *, >> struct memory_block *); >> extern struct memory_block *find_memory_block(struct mem_section *); >> +extern bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn); >> #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION<> enum mem_add_context { BOOT, HOTPLUG }; >> #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ >> Index: linux-3.5-rc4/mm/memory_hotplug.c >> =================================================================== >> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:28:16.743211538 +0900 >> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:38.264940468 +0900 >> @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned >> >> lock_memory_hotplug(); >> >> + if (memory_is_offline(start_pfn, end_pfn)) { >> + ret = 0; >> + goto out; >> + } >> + >> zone = page_zone(pfn_to_page(start_pfn)); >> node = zone_to_nid(zone); >> nr_pages = end_pfn - start_pfn; >> >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >> > > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: email@kvack.org > -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx128.postini.com [74.125.245.128]) by kanga.kvack.org (Postfix) with SMTP id D52836B0062 for ; Sun, 1 Jul 2012 23:01:44 -0400 (EDT) Received: from m3.gw.fujitsu.co.jp (unknown [10.0.50.73]) by fgwmail5.fujitsu.co.jp (Postfix) with ESMTP id 766A03EE0C1 for ; Mon, 2 Jul 2012 12:01:42 +0900 (JST) Received: from smail (m3 [127.0.0.1]) by outgoing.m3.gw.fujitsu.co.jp (Postfix) with ESMTP id 467A245DEBD for ; Mon, 2 Jul 2012 12:01:42 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (s3.gw.fujitsu.co.jp [10.0.50.93]) by m3.gw.fujitsu.co.jp (Postfix) with ESMTP id 0D09845DEC3 for ; Mon, 2 Jul 2012 12:01:42 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id 00CE51DB803F for ; Mon, 2 Jul 2012 12:01:42 +0900 (JST) Received: from g01jpexchyt07.g01.fujitsu.local (g01jpexchyt07.g01.fujitsu.local [10.128.194.46]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id 313D91DB8046 for ; Mon, 2 Jul 2012 12:01:41 +0900 (JST) Message-ID: <4FF10EFF.5050803@jp.fujitsu.com> Date: Mon, 2 Jul 2012 12:01:19 +0900 From: Yasuaki Ishimatsu MIME-Version: 1.0 Subject: Re: [RFC PATCH 10/12] memory-hotplug : free memmap of sparse-vmemmap References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEAA09F.5000907@jp.fujitsu.com> <4FEF2214.4000205@gmail.com> In-Reply-To: <4FEF2214.4000205@gmail.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: Jiang Liu Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com Hi Jiang, 2012/07/01 0:58, Jiang Liu wrote: > On 06/27/2012 01:56 PM, Yasuaki Ishimatsu wrote: >> I don't think that all pages of virtual mapping in removed memory can be >> freed, since page which type is MIX_SECTION_INFO is difficult to free. >> So, the patch only frees page which type is SECTION_INFO at first. >> >> CC: Len Brown >> CC: Benjamin Herrenschmidt >> CC: Paul Mackerras >> CC: Christoph Lameter >> Cc: Minchan Kim >> CC: Andrew Morton >> CC: KOSAKI Motohiro >> CC: Wen Congyang >> Signed-off-by: Yasuaki Ishimatsu >> >> --- >> arch/x86/mm/init_64.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ >> include/linux/mm.h | 2 + >> mm/memory_hotplug.c | 5 ++ >> mm/sparse.c | 5 +- >> 4 files changed, 99 insertions(+), 2 deletions(-) >> >> Index: linux-3.5-rc4/include/linux/mm.h >> =================================================================== >> --- linux-3.5-rc4.orig/include/linux/mm.h 2012-06-27 09:11:13.790150442 +0900 >> +++ linux-3.5-rc4/include/linux/mm.h 2012-06-27 09:11:16.433117400 +0900 >> @@ -1588,6 +1588,8 @@ int vmemmap_populate(struct page *start_ >> void vmemmap_populate_print_last(void); >> void register_page_bootmem_memmap(unsigned long section_nr, struct page *map, >> unsigned long size); >> +void vmemmap_kfree(struct page *memmpa, unsigned long nr_pages); >> +void vmemmap_free_bootmem(struct page *memmpa, unsigned long nr_pages); >> >> enum mf_flags { >> MF_COUNT_INCREASED = 1 << 0, >> Index: linux-3.5-rc4/mm/sparse.c >> =================================================================== >> --- linux-3.5-rc4.orig/mm/sparse.c 2012-06-27 09:06:35.317631878 +0900 >> +++ linux-3.5-rc4/mm/sparse.c 2012-06-27 09:11:16.434117388 +0900 >> @@ -614,12 +614,13 @@ static inline struct page *kmalloc_secti >> /* This will make the necessary allocations eventually. */ >> return sparse_mem_map_populate(pnum, nid); >> } >> -static void __kfree_section_memmap(struct page *memmap, unsigned long nr_pages) >> +static void __kfree_section_memmap(struct page *page, unsigned long nr_pages) >> { >> - return; /* XXX: Not implemented yet */ >> + vmemmap_kfree(page, nr_pages); >> } >> static void free_map_bootmem(struct page *page, unsigned long nr_pages) >> { >> + vmemmap_free_bootmem(page, nr_pages); >> } >> #else >> static struct page *__kmalloc_section_memmap(unsigned long nr_pages) >> Index: linux-3.5-rc4/arch/x86/mm/init_64.c >> =================================================================== >> --- linux-3.5-rc4.orig/arch/x86/mm/init_64.c 2012-06-27 09:11:13.791150430 +0900 >> +++ linux-3.5-rc4/arch/x86/mm/init_64.c 2012-06-27 09:11:59.254581998 +0900 >> @@ -978,6 +978,95 @@ vmemmap_populate(struct page *start_page >> return 0; >> } >> >> +unsigned long find_and_clear_pte_page(unsigned long addr, unsigned long end, >> + struct page *page) > I think the third parameter should be "struct page **pp" instead of "struct page *page". > And "page = pte_page(*pte)" should be "*pp = pte_page(*pte)". > Otherwise the found page pointer can't be returned to the caller and vmemmap_kfree() > just sees random value in variable "page". Oh, you are right. I'll update it. Thanks, Yasuaki Ishimatsu >> +{ >> + pgd_t *pgd; >> + pud_t *pud; >> + pmd_t *pmd; >> + pte_t *pte; >> + unsigned long next; >> + >> + page = NULL; >> + >> + pgd = pgd_offset_k(addr); >> + if (pgd_none(*pgd)) >> + return PAGE_SIZE; >> + >> + pud = pud_offset(pgd, addr); >> + if (pud_none(*pud)) >> + return PAGE_SIZE; >> + >> + if (!cpu_has_pse) { >> + next = (addr + PAGE_SIZE) & PAGE_MASK; >> + pmd = pmd_offset(pud, addr); >> + if (pmd_none(*pmd)) >> + return next; >> + >> + pte = pte_offset_kernel(pmd, addr); >> + if (pte_none(*pte)) >> + return next; >> + >> + page = pte_page(*pte); >> + pte_clear(&init_mm, addr, pte); >> + } else { >> + next = pmd_addr_end(addr, end); >> + >> + pmd = pmd_offset(pud, addr); >> + if (pmd_none(*pmd)) >> + return next; >> + >> + page = pmd_page(*pmd); >> + pmd_clear(pmd); >> + } >> + >> + return next; >> +} >> + >> +void __meminit >> +vmemmap_kfree(struct page *memmap, unsigned long nr_pages) >> +{ >> + unsigned long addr = (unsigned long)memmap; >> + unsigned long end = (unsigned long)(memmap + nr_pages); >> + unsigned long next; >> + unsigned int order; >> + struct page *page; >> + >> + for (; addr < end; addr = next) { >> + next = find_and_clear_pte_page(addr, end, page); >> + if (!page) >> + continue; >> + >> + if (is_vmalloc_addr(page)) >> + vfree(page); >> + else { >> + order = next - addr; >> + free_pages((unsigned long)page, >> + get_order(sizeof(struct page) * order)); >> + } >> + } >> +} >> + >> +void __meminit >> +vmemmap_free_bootmem(struct page *memmap, unsigned long nr_pages) >> +{ >> + unsigned long addr = (unsigned long)memmap; >> + unsigned long end = (unsigned long)(memmap + nr_pages); >> + unsigned long next; >> + struct page *page; >> + unsigned long magic; >> + >> + for (; addr < end; addr = next) { >> + next = find_and_clear_pte_page(addr, end, page); >> + if (!page) >> + continue; >> + >> + magic = (unsigned long) page->lru.next; >> + if (magic == SECTION_INFO) >> + put_page_bootmem(page); >> + } >> +} >> + >> void __meminit >> register_page_bootmem_memmap(unsigned long section_nr, struct page *start_page, >> unsigned long size) >> Index: linux-3.5-rc4/mm/memory_hotplug.c >> =================================================================== >> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-27 09:11:13.789150454 +0900 >> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-27 09:11:16.436117363 +0900 >> @@ -303,6 +303,8 @@ static int __meminit __add_section(int n >> #ifdef CONFIG_SPARSEMEM_VMEMMAP >> static int __remove_section(struct zone *zone, struct mem_section *ms) >> { >> + unsigned long flags; >> + struct pglist_data *pgdat = zone->zone_pgdat; >> int ret; >> >> if (!valid_section(ms)) >> @@ -310,6 +312,9 @@ static int __remove_section(struct zone >> >> ret = unregister_memory_section(ms); >> >> + pgdat_resize_lock(pgdat, &flags); >> + sparse_remove_one_section(zone, ms); >> + pgdat_resize_unlock(pgdat, &flags); >> return ret; >> } >> #else >> >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >> > > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: email@kvack.org > -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755958Ab2F0FkB (ORCPT ); Wed, 27 Jun 2012 01:40:01 -0400 Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:40162 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750929Ab2F0Fj6 (ORCPT ); Wed, 27 Jun 2012 01:39:58 -0400 X-SecurityPolicyCheck: OK by SHieldMailChecker v1.7.4 Message-ID: <4FEA9C88.1070800@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:39:20 +0900 From: Yasuaki Ishimatsu User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: , , , CC: , , , , , , , Subject: [RFC PATCH 0/12] memory-hotplug : hot-remove physical memory Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch series aims to support physical memory hot-remove. [RFC PATCH 1/12] memory-hotplug : rename remove_memory to offline_memory [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages [RFC PATCH 3/12] memory-hotplug : add physical memory hotplug code to acpi_memory_device_remove [RFC PATCH 4/12] memory-hotplug : remove /sys/firmware/memmap/X sysfs [RFC PATCH 5/12] memory hotplug : does not release memory region in PAGES_PER_SECTION chunks [RFC PATCH 6/12] memory-hotplug : remove_memory calls __remove_pages [RFC PATCH 7/12] memory-hotplug : check page type in get_page_bootmem [RFC PATCH 8/12] memory-hotplug : move register_page_bootmem_info_node and put_page_bootmem for sparse-vmemmap [RFC PATCH 9/12] memory-hotplug : implement register_page_bootmem_info_section of sparse-vmemmap [RFC PATCH 10/12] memory-hotplug : free memmap of sparse-vmemmap [RFC PATCH 11/12] memory-hotplug : add node_device_release [RFC PATCH 12/12] memory-hotplug : remove sysfs file of node Even if you apply these patches, you cannot remove the physical memory completely since these patches are still under development. I want you to cooperate to improve the physical memory hot-remove. So please review these patches and give your comment/idea. The patches can free/remove following things: - acpi_memory_info : [RFC PATCH 3/12] - /sys/firmware/memmap/X/{end, start, type} : [RFC PATCH 4/12] - iomem_resource : [RFC PATCH 5/12] - mem_section and related sysfs files : [RFC PATCH 6-10/12] - node and related sysfs files : [RFC PATCH 11-12/12] The patches cannot do following things yet: - page table of removed memory If you find lack of function for physical memory hot-remove, please let me know. --- arch/powerpc/platforms/pseries/hotplug-memory.c | 16 +- arch/x86/mm/init_64.c | 142 ++++++++++++++++++++++++ drivers/acpi/acpi_memhotplug.c | 25 +++- drivers/base/memory.c | 24 +++- drivers/base/node.c | 7 + drivers/firmware/memmap.c | 71 ++++++++++++ include/linux/firmware-map.h | 6 + include/linux/memory.h | 1 include/linux/memory_hotplug.h | 17 -- include/linux/mm.h | 5 mm/memory_hotplug.c | 101 +++++++++++++---- mm/sparse.c | 5 12 files changed, 374 insertions(+), 46 deletions(-) From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756029Ab2F0FnO (ORCPT ); Wed, 27 Jun 2012 01:43:14 -0400 Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:39691 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750994Ab2F0FnN (ORCPT ); Wed, 27 Jun 2012 01:43:13 -0400 X-SecurityPolicyCheck: OK by SHieldMailChecker v1.7.4 Message-ID: <4FEA9D5C.1080508@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:42:52 +0900 From: Yasuaki Ishimatsu User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: , , , CC: , , , , , , , Subject: [RFC PATCH 1/12] memory-hotplug : rename remove_memory to offline_memory References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org remove_memory() does not remove memory but just offlines memory. The patch changes name of it to offline_memory(). CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- drivers/acpi/acpi_memhotplug.c | 2 +- drivers/base/memory.c | 4 ++-- include/linux/memory_hotplug.h | 2 +- mm/memory_hotplug.c | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) Index: linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c =================================================================== --- linux-3.5-rc4.orig/drivers/acpi/acpi_memhotplug.c 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c 2012-06-26 13:48:38.263940481 +0900 @@ -318,7 +318,7 @@ static int acpi_memory_disable_device(st */ list_for_each_entry_safe(info, n, &mem_device->res_list, list) { if (info->enabled) { - result = remove_memory(info->start_addr, info->length); + result = offline_memory(info->start_addr, info->length); if (result) return result; } Index: linux-3.5-rc4/drivers/base/memory.c =================================================================== --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:48:46.072842803 +0900 @@ -266,8 +266,8 @@ memory_block_action(unsigned long phys_i break; case MEM_OFFLINE: start_paddr = page_to_pfn(first_page) << PAGE_SHIFT; - ret = remove_memory(start_paddr, - nr_pages << PAGE_SHIFT); + ret = offline_memory(start_paddr, + nr_pages << PAGE_SHIFT); break; default: WARN(1, KERN_WARNING "%s(%ld, %ld) unknown action: " Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:46.072842803 +0900 @@ -990,7 +990,7 @@ out: return ret; } -int remove_memory(u64 start, u64 size) +int offline_memory(u64 start, u64 size) { unsigned long start_pfn, end_pfn; @@ -999,9 +999,9 @@ int remove_memory(u64 start, u64 size) return offline_pages(start_pfn, end_pfn, 120 * HZ); } #else -int remove_memory(u64 start, u64 size) +int offline_memory(u64 start, u64 size) { return -EINVAL; } #endif /* CONFIG_MEMORY_HOTREMOVE */ -EXPORT_SYMBOL_GPL(remove_memory); +EXPORT_SYMBOL_GPL(offline_memory); Index: linux-3.5-rc4/include/linux/memory_hotplug.h =================================================================== --- linux-3.5-rc4.orig/include/linux/memory_hotplug.h 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/include/linux/memory_hotplug.h 2012-06-26 13:48:38.264940468 +0900 @@ -233,7 +233,7 @@ static inline int is_mem_section_removab extern int mem_online_node(int nid); extern int add_memory(int nid, u64 start, u64 size); extern int arch_add_memory(int nid, u64 start, u64 size); -extern int remove_memory(u64 start, u64 size); +extern int offline_memory(u64 start, u64 size); extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn, int nr_pages); extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms); From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755689Ab2F0Foi (ORCPT ); Wed, 27 Jun 2012 01:44:38 -0400 Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:39736 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750708Ab2F0Fof (ORCPT ); Wed, 27 Jun 2012 01:44:35 -0400 X-SecurityPolicyCheck: OK by SHieldMailChecker v1.7.4 Message-ID: <4FEA9DB1.7010303@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:44:17 +0900 From: Yasuaki Ishimatsu User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: , , , CC: , , , , , , , Subject: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When offline_pages() is called to offlined memory, the function fails since all memory has been offlined. In this case, the function should succeed. The patch adds the check function into offline_pages(). CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- drivers/base/memory.c | 20 ++++++++++++++++++++ include/linux/memory.h | 1 + mm/memory_hotplug.c | 5 +++++ 3 files changed, 26 insertions(+) Index: linux-3.5-rc4/drivers/base/memory.c =================================================================== --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-26 13:28:16.726211752 +0900 +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:34:22.423639904 +0900 @@ -70,6 +70,26 @@ void unregister_memory_isolate_notifier( } EXPORT_SYMBOL(unregister_memory_isolate_notifier); +bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn) +{ + struct memory_block *mem; + struct mem_section *section; + unsigned long pfn, section_nr; + + for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { + section_nr = pfn_to_section_nr(pfn); + section = __nr_to_section(section_nr); + mem = find_memory_block(section); + if (!mem) + continue; + if (mem->state == MEM_OFFLINE) + continue; + return false; + } + + return true; +} + /* * register_memory - Setup a sysfs device for a memory block */ Index: linux-3.5-rc4/include/linux/memory.h =================================================================== --- linux-3.5-rc4.orig/include/linux/memory.h 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/include/linux/memory.h 2012-06-26 13:34:22.424639891 +0900 @@ -120,6 +120,7 @@ extern int memory_isolate_notify(unsigne extern struct memory_block *find_memory_block_hinted(struct mem_section *, struct memory_block *); extern struct memory_block *find_memory_block(struct mem_section *); +extern bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn); #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION< Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756001Ab2F0FqL (ORCPT ); Wed, 27 Jun 2012 01:46:11 -0400 Received: from fgwmail5.fujitsu.co.jp ([192.51.44.35]:38677 "EHLO fgwmail5.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750805Ab2F0FqJ (ORCPT ); Wed, 27 Jun 2012 01:46:09 -0400 X-SecurityPolicyCheck: OK by SHieldMailChecker v1.7.4 Message-ID: <4FEA9E0A.1040202@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:45:46 +0900 From: Yasuaki Ishimatsu User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: , , , CC: , , , , , , , Subject: [RFC PATCH 3/12] memory-hotplug : add physical memory hotplug code to acpi_memory_device_remove References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org acpi_memory_device_remove() has been prepared to remove physical memory. But, the function only frees acpi_memory_device currentlry. The patch adds following functions into acpi_memory_device_remove(): - offline memory - remove physical memory (only return -EBUSY) - free acpi_memory_device CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- drivers/acpi/acpi_memhotplug.c | 23 ++++++++++++++++++++++- include/linux/memory_hotplug.h | 1 + mm/memory_hotplug.c | 8 ++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) Index: linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c =================================================================== --- linux-3.5-rc4.orig/drivers/acpi/acpi_memhotplug.c 2012-06-26 13:28:16.722211802 +0900 +++ linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c 2012-06-26 13:38:01.085906251 +0900 @@ -452,12 +452,33 @@ static int acpi_memory_device_add(struct static int acpi_memory_device_remove(struct acpi_device *device, int type) { struct acpi_memory_device *mem_device = NULL; - + struct acpi_memory_info *info, *tmp; + int result; + int node; if (!device || !acpi_driver_data(device)) return -EINVAL; mem_device = acpi_driver_data(device); + + node = acpi_get_node(mem_device->device->handle); + + list_for_each_entry_safe(info, tmp, &mem_device->res_list, list) { + if (!info->enabled) + continue; + + result = offline_memory(info->start_addr, info->length); + if (result) + return result; + + result = remove_memory(node, info->start_addr, info->length); + if (result) + return result; + + list_del(&info->list); + kfree(info); + } + kfree(mem_device); return 0; Index: linux-3.5-rc4/include/linux/memory_hotplug.h =================================================================== --- linux-3.5-rc4.orig/include/linux/memory_hotplug.h 2012-06-26 13:28:16.773211163 +0900 +++ linux-3.5-rc4/include/linux/memory_hotplug.h 2012-06-26 13:37:30.545288962 +0900 @@ -233,6 +233,7 @@ static inline int is_mem_section_removab extern int mem_online_node(int nid); extern int add_memory(int nid, u64 start, u64 size); extern int arch_add_memory(int nid, u64 start, u64 size); +extern int remove_memory(int nid, u64 start, u64 size); extern int offline_memory(u64 start, u64 size); extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn, int nr_pages); Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:34:22.425639879 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:30.096046767 +0900 @@ -659,6 +659,14 @@ out: } EXPORT_SYMBOL_GPL(add_memory); +int remove_memory(int nid, u64 start, u64 size) +{ + return -EBUSY; + +} +EXPORT_SYMBOL_GPL(remove_memory); + + #ifdef CONFIG_MEMORY_HOTREMOVE /* * A free page on the buddy free lists (not the per-cpu lists) has PageBuddy From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756061Ab2F0Fr3 (ORCPT ); Wed, 27 Jun 2012 01:47:29 -0400 Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:41064 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752676Ab2F0Fr2 (ORCPT ); Wed, 27 Jun 2012 01:47:28 -0400 X-SecurityPolicyCheck: OK by SHieldMailChecker v1.7.4 Message-ID: <4FEA9E5F.4070205@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:47:11 +0900 From: Yasuaki Ishimatsu User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: , , , CC: , , , , , , , Subject: [RFC PATCH 4/12] memory-hotplug : remove /sys/firmware/memmap/X sysfs References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When (hot)adding memory into system, /sys/firmware/memmap/X/{end, start, type} sysfs files are created. But there is no code to remove these files. The patch implements the function to remove them. Note : The code does not free firmware_map_entry since there is no way to free memory which is allocated by bootmem. CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- drivers/firmware/memmap.c | 71 +++++++++++++++++++++++++++++++++++++++++++ include/linux/firmware-map.h | 6 +++ mm/memory_hotplug.c | 6 +++ 3 files changed, 82 insertions(+), 1 deletion(-) Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:37:30.546288901 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:44:37.069955820 +0900 @@ -661,7 +661,11 @@ EXPORT_SYMBOL_GPL(add_memory); int remove_memory(int nid, u64 start, u64 size) { - return -EBUSY; + lock_memory_hotplug(); + /* remove memmap entry */ + firmware_map_remove(start, start + size, "System RAM"); + unlock_memory_hotplug(); + return 0; } EXPORT_SYMBOL_GPL(remove_memory); Index: linux-3.5-rc4/include/linux/firmware-map.h =================================================================== --- linux-3.5-rc4.orig/include/linux/firmware-map.h 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/include/linux/firmware-map.h 2012-06-26 13:44:37.070955807 +0900 @@ -25,6 +25,7 @@ int firmware_map_add_early(u64 start, u64 end, const char *type); int firmware_map_add_hotplug(u64 start, u64 end, const char *type); +int firmware_map_remove(u64 start, u64 end, const char *type); #else /* CONFIG_FIRMWARE_MEMMAP */ @@ -38,6 +39,11 @@ static inline int firmware_map_add_hotpl return 0; } +static inline int firmware_map_remove(u64 start, u64 end, const char *type) +{ + return 0; +} + #endif /* CONFIG_FIRMWARE_MEMMAP */ #endif /* _LINUX_FIRMWARE_MAP_H */ Index: linux-3.5-rc4/drivers/firmware/memmap.c =================================================================== --- linux-3.5-rc4.orig/drivers/firmware/memmap.c 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/drivers/firmware/memmap.c 2012-06-26 13:47:17.606948898 +0900 @@ -123,6 +123,16 @@ static int firmware_map_add_entry(u64 st return 0; } +/** + * firmware_map_remove_entry() - Does the real work to remove a firmware + * memmap entry. + * @entry: removed entry. + **/ +static inline void firmware_map_remove_entry(struct firmware_map_entry *entry) +{ + list_del(&entry->list); +} + /* * Add memmap entry on sysfs */ @@ -144,6 +154,31 @@ static int add_sysfs_fw_map_entry(struct return 0; } +/* + * Remove memmap entry on sysfs + */ +static inline void remove_sysfs_fw_map_entry(struct firmware_map_entry *entry) +{ + kobject_del(&entry->kobj); +} + +/* + * Search memmap entry + */ + +struct firmware_map_entry * __meminit +find_firmware_map_entry(u64 start, u64 end, const char *type) +{ + struct firmware_map_entry *entry; + + list_for_each_entry(entry, &map_entries, list) + if ((entry->start == start) && (entry->end == end) && + (!strcmp(entry->type, type))) + return entry; + + return NULL; +} + /** * firmware_map_add_hotplug() - Adds a firmware mapping entry when we do * memory hotplug. @@ -196,6 +231,42 @@ int __init firmware_map_add_early(u64 st return firmware_map_add_entry(start, end, type, entry); } +void release_firmware_map_entry(struct firmware_map_entry *entry) +{ + /* + * FIXME : There is no idea. + * How to free the entry which allocated bootmem? + */ +} + +/** + * firmware_map_remove() - remove a firmware mapping entry + * @start: Start of the memory range. + * @end: End of the memory range (inclusive). + * @type: Type of the memory range. + * + * removes a firmware mapping entry. + * + * Returns 0 on success, or -EINVAL if no entry. + **/ +int __meminit firmware_map_remove(u64 start, u64 end, const char *type) +{ + struct firmware_map_entry *entry; + + entry = find_firmware_map_entry(start, end, type); + if (!entry) + return -EINVAL; + + /* remove the memmap entry */ + remove_sysfs_fw_map_entry(entry); + + firmware_map_remove_entry(entry); + + release_firmware_map_entry(entry); + + return 0; +} + /* * Sysfs functions ------------------------------------------------------------- */ From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756127Ab2F0Fsv (ORCPT ); Wed, 27 Jun 2012 01:48:51 -0400 Received: from fgwmail5.fujitsu.co.jp ([192.51.44.35]:38762 "EHLO fgwmail5.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756075Ab2F0Fst (ORCPT ); Wed, 27 Jun 2012 01:48:49 -0400 X-SecurityPolicyCheck: OK by SHieldMailChecker v1.7.4 Message-ID: <4FEA9EAF.1060608@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:48:31 +0900 From: Yasuaki Ishimatsu User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: , , , CC: , , , , , , , Subject: [RFC PATCH 5/12] memory-hotplug : does not release memory region in PAGES_PER_SECTION chunks References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since applying a patch(de7f0cba96786c), release_mem_region() has been changed as called in PAGES_PER_SECTION chunks because register_memory_resource() is called in PAGES_PER_SECTION chunks by add_memory(). But it seems firmware dependency. If CRS are written in the PAGES_PER_SECTION chunks in ACPI DSDT Table, register_memory_resource() is called in PAGES_PER_SECTION chunks. But if CRS are written in the DIMM unit in ACPI DSDT Table, register_memory_resource() is called in DIMM unit. So release_mem_region() should not be called in PAGES_PER_SECTION chunks. The patch fixes it. CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- arch/powerpc/platforms/pseries/hotplug-memory.c | 13 +++++++++---- mm/memory_hotplug.c | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:50:57.075205100 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:55:36.152716100 +0900 @@ -358,11 +358,11 @@ int __remove_pages(struct zone *zone, un BUG_ON(phys_start_pfn & ~PAGE_SECTION_MASK); BUG_ON(nr_pages % PAGES_PER_SECTION); + release_mem_region(phys_start_pfn << PAGE_SHIFT, nr_pages * PAGE_SIZE); + sections_to_remove = nr_pages / PAGES_PER_SECTION; for (i = 0; i < sections_to_remove; i++) { unsigned long pfn = phys_start_pfn + i*PAGES_PER_SECTION; - release_mem_region(pfn << PAGE_SHIFT, - PAGES_PER_SECTION << PAGE_SHIFT); ret = __remove_section(zone, __pfn_to_section(pfn)); if (ret) break; Index: linux-3.5-rc4/arch/powerpc/platforms/pseries/hotplug-memory.c =================================================================== --- linux-3.5-rc4.orig/arch/powerpc/platforms/pseries/hotplug-memory.c 2012-06-26 13:50:57.075205100 +0900 +++ linux-3.5-rc4/arch/powerpc/platforms/pseries/hotplug-memory.c 2012-06-26 13:55:36.153716088 +0900 @@ -77,7 +77,8 @@ static int pseries_remove_memblock(unsig { unsigned long start, start_pfn; struct zone *zone; - int ret; + int i, ret; + int sections_to_remove; start_pfn = base >> PAGE_SHIFT; @@ -97,9 +98,13 @@ static int pseries_remove_memblock(unsig * to sysfs "state" file and we can't remove sysfs entries * while writing to it. So we have to defer it to here. */ - ret = __remove_pages(zone, start_pfn, memblock_size >> PAGE_SHIFT); - if (ret) - return ret; + sections_to_remove = (memblock_size >> PAGE_SHIFT) / PAGES_PER_SECTION; + for (i = 0; i < sections_to_remove; i++) { + unsigned long pfn = start_pfn + i * PAGES_PER_SECTION; + ret = __remove_pages(zone, start_pfn, PAGES_PER_SECTION); + if (ret) + return ret; + } /* * Update memory regions for memory remove From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756013Ab2F0Fwb (ORCPT ); Wed, 27 Jun 2012 01:52:31 -0400 Received: from fgwmail5.fujitsu.co.jp ([192.51.44.35]:38761 "EHLO fgwmail5.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750780Ab2F0Fw3 (ORCPT ); Wed, 27 Jun 2012 01:52:29 -0400 X-SecurityPolicyCheck: OK by SHieldMailChecker v1.7.4 Message-ID: <4FEA9F8B.30105@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:52:11 +0900 From: Yasuaki Ishimatsu User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: , , , CC: , , , , , , , Subject: [RFC PATCH 6/12] memory-hotplug : remove_memory calls __remove_pages References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The patch adds __remove_pages() to remove_memory(). Then the range of phys_start_pfn argument and nr_pages argument in __remove_pagse() may have different zone. So zone argument is removed from __remove_pages() and __remove_pages() caluculates zone in each section. When CONFIG_SPARSEMEM_VMEMMAP is defined, there is no way to remove a memmap. So __remove_section only calls unregister_memory_section(). CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- arch/powerpc/platforms/pseries/hotplug-memory.c | 5 +---- include/linux/memory_hotplug.h | 3 +-- mm/memory_hotplug.c | 20 +++++++++++++------- 3 files changed, 15 insertions(+), 13 deletions(-) Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-27 09:07:49.124709164 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-27 09:08:30.612190446 +0900 @@ -275,11 +275,14 @@ static int __meminit __add_section(int n #ifdef CONFIG_SPARSEMEM_VMEMMAP static int __remove_section(struct zone *zone, struct mem_section *ms) { - /* - * XXX: Freeing memmap with vmemmap is not implement yet. - * This should be removed later. - */ - return -EBUSY; + int ret; + + if (!valid_section(ms)) + return ret; + + ret = unregister_memory_section(ms); + + return ret; } #else static int __remove_section(struct zone *zone, struct mem_section *ms) @@ -346,11 +349,11 @@ EXPORT_SYMBOL_GPL(__add_pages); * sure that pages are marked reserved and zones are adjust properly by * calling offline_pages(). */ -int __remove_pages(struct zone *zone, unsigned long phys_start_pfn, - unsigned long nr_pages) +int __remove_pages(unsigned long phys_start_pfn, unsigned long nr_pages) { unsigned long i, ret = 0; int sections_to_remove; + struct zone *zone; /* * We can only remove entire sections @@ -363,6 +366,7 @@ int __remove_pages(struct zone *zone, un sections_to_remove = nr_pages / PAGES_PER_SECTION; for (i = 0; i < sections_to_remove; i++) { unsigned long pfn = phys_start_pfn + i*PAGES_PER_SECTION; + zone = page_zone(pfn_to_page(pfn)); ret = __remove_section(zone, __pfn_to_section(pfn)); if (ret) break; @@ -664,6 +668,8 @@ int remove_memory(int nid, u64 start, u6 lock_memory_hotplug(); /* remove memmap entry */ firmware_map_remove(start, start + size, "System RAM"); + + __remove_pages(start >> PAGE_SHIFT, size >> PAGE_SHIFT); unlock_memory_hotplug(); return 0; Index: linux-3.5-rc4/include/linux/memory_hotplug.h =================================================================== --- linux-3.5-rc4.orig/include/linux/memory_hotplug.h 2012-06-27 09:06:35.616628141 +0900 +++ linux-3.5-rc4/include/linux/memory_hotplug.h 2012-06-27 09:08:30.612190446 +0900 @@ -89,8 +89,7 @@ extern bool is_pageblock_removable_noloc /* reasonably generic interface to expand the physical pages in a zone */ extern int __add_pages(int nid, struct zone *zone, unsigned long start_pfn, unsigned long nr_pages); -extern int __remove_pages(struct zone *zone, unsigned long start_pfn, - unsigned long nr_pages); +extern int __remove_pages(unsigned long start_pfn, unsigned long nr_pages); #ifdef CONFIG_NUMA extern int memory_add_physaddr_to_nid(u64 start); Index: linux-3.5-rc4/arch/powerpc/platforms/pseries/hotplug-memory.c =================================================================== --- linux-3.5-rc4.orig/arch/powerpc/platforms/pseries/hotplug-memory.c 2012-06-27 09:08:25.737248748 +0900 +++ linux-3.5-rc4/arch/powerpc/platforms/pseries/hotplug-memory.c 2012-06-27 09:08:30.613190434 +0900 @@ -76,7 +76,6 @@ unsigned long memory_block_size_bytes(vo static int pseries_remove_memblock(unsigned long base, unsigned int memblock_size) { unsigned long start, start_pfn; - struct zone *zone; int i, ret; int sections_to_remove; @@ -87,8 +86,6 @@ static int pseries_remove_memblock(unsig return 0; } - zone = page_zone(pfn_to_page(start_pfn)); - /* * Remove section mappings and sysfs entries for the * section of the memory we are removing. @@ -101,7 +98,7 @@ static int pseries_remove_memblock(unsig sections_to_remove = (memblock_size >> PAGE_SHIFT) / PAGES_PER_SECTION; for (i = 0; i < sections_to_remove; i++) { unsigned long pfn = start_pfn + i * PAGES_PER_SECTION; - ret = __remove_pages(zone, start_pfn, PAGES_PER_SECTION); + ret = __remove_pages(start_pfn, PAGES_PER_SECTION); if (ret) return ret; } From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756150Ab2F0Fxg (ORCPT ); Wed, 27 Jun 2012 01:53:36 -0400 Received: from fgwmail5.fujitsu.co.jp ([192.51.44.35]:38814 "EHLO fgwmail5.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755274Ab2F0Fxe (ORCPT ); Wed, 27 Jun 2012 01:53:34 -0400 X-SecurityPolicyCheck: OK by SHieldMailChecker v1.7.4 Message-ID: <4FEA9FCD.6020405@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:53:17 +0900 From: Yasuaki Ishimatsu User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: , , , CC: , , , , , , , Subject: [RFC PATCH 7/12] memory-hotplug : check page type in get_page_bootmem References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is a possibility that get_page_bootmem() is called to the same page many times. So when get_page_bootmem is called to the same page, the function only increments page->_count. CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:56:34.371988312 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 14:03:37.564697621 +0900 @@ -95,10 +95,17 @@ static void release_memory_resource(stru static void get_page_bootmem(unsigned long info, struct page *page, unsigned long type) { - page->lru.next = (struct list_head *) type; - SetPagePrivate(page); - set_page_private(page, info); - atomic_inc(&page->_count); + unsigned long page_type; + + page_type = (unsigned long) page->lru.next; + if (type < MEMORY_HOTPLUG_MIN_BOOTMEM_TYPE || + type > MEMORY_HOTPLUG_MAX_BOOTMEM_TYPE){ + page->lru.next = (struct list_head *) type; + SetPagePrivate(page); + set_page_private(page, info); + atomic_inc(&page->_count); + } else + atomic_inc(&page->_count); } /* reference to __meminit __free_pages_bootmem is valid From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756145Ab2F0F5F (ORCPT ); Wed, 27 Jun 2012 01:57:05 -0400 Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:58284 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750994Ab2F0F5D (ORCPT ); Wed, 27 Jun 2012 01:57:03 -0400 X-SecurityPolicyCheck: OK by SHieldMailChecker v1.7.4 Message-ID: <4FEAA09F.5000907@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:56:47 +0900 From: Yasuaki Ishimatsu User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: , , , CC: , , , , , , , Subject: [RFC PATCH 10/12] memory-hotplug : free memmap of sparse-vmemmap References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I don't think that all pages of virtual mapping in removed memory can be freed, since page which type is MIX_SECTION_INFO is difficult to free. So, the patch only frees page which type is SECTION_INFO at first. CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- arch/x86/mm/init_64.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/mm.h | 2 + mm/memory_hotplug.c | 5 ++ mm/sparse.c | 5 +- 4 files changed, 99 insertions(+), 2 deletions(-) Index: linux-3.5-rc4/include/linux/mm.h =================================================================== --- linux-3.5-rc4.orig/include/linux/mm.h 2012-06-27 09:11:13.790150442 +0900 +++ linux-3.5-rc4/include/linux/mm.h 2012-06-27 09:11:16.433117400 +0900 @@ -1588,6 +1588,8 @@ int vmemmap_populate(struct page *start_ void vmemmap_populate_print_last(void); void register_page_bootmem_memmap(unsigned long section_nr, struct page *map, unsigned long size); +void vmemmap_kfree(struct page *memmpa, unsigned long nr_pages); +void vmemmap_free_bootmem(struct page *memmpa, unsigned long nr_pages); enum mf_flags { MF_COUNT_INCREASED = 1 << 0, Index: linux-3.5-rc4/mm/sparse.c =================================================================== --- linux-3.5-rc4.orig/mm/sparse.c 2012-06-27 09:06:35.317631878 +0900 +++ linux-3.5-rc4/mm/sparse.c 2012-06-27 09:11:16.434117388 +0900 @@ -614,12 +614,13 @@ static inline struct page *kmalloc_secti /* This will make the necessary allocations eventually. */ return sparse_mem_map_populate(pnum, nid); } -static void __kfree_section_memmap(struct page *memmap, unsigned long nr_pages) +static void __kfree_section_memmap(struct page *page, unsigned long nr_pages) { - return; /* XXX: Not implemented yet */ + vmemmap_kfree(page, nr_pages); } static void free_map_bootmem(struct page *page, unsigned long nr_pages) { + vmemmap_free_bootmem(page, nr_pages); } #else static struct page *__kmalloc_section_memmap(unsigned long nr_pages) Index: linux-3.5-rc4/arch/x86/mm/init_64.c =================================================================== --- linux-3.5-rc4.orig/arch/x86/mm/init_64.c 2012-06-27 09:11:13.791150430 +0900 +++ linux-3.5-rc4/arch/x86/mm/init_64.c 2012-06-27 09:11:59.254581998 +0900 @@ -978,6 +978,95 @@ vmemmap_populate(struct page *start_page return 0; } +unsigned long find_and_clear_pte_page(unsigned long addr, unsigned long end, + struct page *page) +{ + pgd_t *pgd; + pud_t *pud; + pmd_t *pmd; + pte_t *pte; + unsigned long next; + + page = NULL; + + pgd = pgd_offset_k(addr); + if (pgd_none(*pgd)) + return PAGE_SIZE; + + pud = pud_offset(pgd, addr); + if (pud_none(*pud)) + return PAGE_SIZE; + + if (!cpu_has_pse) { + next = (addr + PAGE_SIZE) & PAGE_MASK; + pmd = pmd_offset(pud, addr); + if (pmd_none(*pmd)) + return next; + + pte = pte_offset_kernel(pmd, addr); + if (pte_none(*pte)) + return next; + + page = pte_page(*pte); + pte_clear(&init_mm, addr, pte); + } else { + next = pmd_addr_end(addr, end); + + pmd = pmd_offset(pud, addr); + if (pmd_none(*pmd)) + return next; + + page = pmd_page(*pmd); + pmd_clear(pmd); + } + + return next; +} + +void __meminit +vmemmap_kfree(struct page *memmap, unsigned long nr_pages) +{ + unsigned long addr = (unsigned long)memmap; + unsigned long end = (unsigned long)(memmap + nr_pages); + unsigned long next; + unsigned int order; + struct page *page; + + for (; addr < end; addr = next) { + next = find_and_clear_pte_page(addr, end, page); + if (!page) + continue; + + if (is_vmalloc_addr(page)) + vfree(page); + else { + order = next - addr; + free_pages((unsigned long)page, + get_order(sizeof(struct page) * order)); + } + } +} + +void __meminit +vmemmap_free_bootmem(struct page *memmap, unsigned long nr_pages) +{ + unsigned long addr = (unsigned long)memmap; + unsigned long end = (unsigned long)(memmap + nr_pages); + unsigned long next; + struct page *page; + unsigned long magic; + + for (; addr < end; addr = next) { + next = find_and_clear_pte_page(addr, end, page); + if (!page) + continue; + + magic = (unsigned long) page->lru.next; + if (magic == SECTION_INFO) + put_page_bootmem(page); + } +} + void __meminit register_page_bootmem_memmap(unsigned long section_nr, struct page *start_page, unsigned long size) Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-27 09:11:13.789150454 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-27 09:11:16.436117363 +0900 @@ -303,6 +303,8 @@ static int __meminit __add_section(int n #ifdef CONFIG_SPARSEMEM_VMEMMAP static int __remove_section(struct zone *zone, struct mem_section *ms) { + unsigned long flags; + struct pglist_data *pgdat = zone->zone_pgdat; int ret; if (!valid_section(ms)) @@ -310,6 +312,9 @@ static int __remove_section(struct zone ret = unregister_memory_section(ms); + pgdat_resize_lock(pgdat, &flags); + sparse_remove_one_section(zone, ms); + pgdat_resize_unlock(pgdat, &flags); return ret; } #else From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756094Ab2F0Fyu (ORCPT ); Wed, 27 Jun 2012 01:54:50 -0400 Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:58189 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751420Ab2F0Fyt (ORCPT ); Wed, 27 Jun 2012 01:54:49 -0400 X-SecurityPolicyCheck: OK by SHieldMailChecker v1.7.4 Message-ID: <4FEAA019.7070302@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:54:33 +0900 From: Yasuaki Ishimatsu User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: , , , CC: , , , , , , , Subject: [RFC PATCH 8/12] memory-hotplug : move register_page_bootmem_info_node and put_page_bootmem for sparse-vmemmap References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For implementing register_page_bootmem_info_node of sparse-vmemmap, register_page_bootmem_info_node and put_page_bootmem are moved to memory_hotplug.c CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyan Signed-off-by: Yasuaki Ishimatsu --- include/linux/memory_hotplug.h | 9 --------- mm/memory_hotplug.c | 8 ++++++-- 2 files changed, 6 insertions(+), 11 deletions(-) Index: linux-3.5-rc4/include/linux/memory_hotplug.h =================================================================== --- linux-3.5-rc4.orig/include/linux/memory_hotplug.h 2012-06-26 13:56:34.372988299 +0900 +++ linux-3.5-rc4/include/linux/memory_hotplug.h 2012-06-26 14:05:16.603459518 +0900 @@ -160,17 +160,8 @@ static inline void arch_refresh_nodedata #endif /* CONFIG_NUMA */ #endif /* CONFIG_HAVE_ARCH_NODEDATA_EXTENSION */ -#ifdef CONFIG_SPARSEMEM_VMEMMAP -static inline void register_page_bootmem_info_node(struct pglist_data *pgdat) -{ -} -static inline void put_page_bootmem(struct page *page) -{ -} -#else extern void register_page_bootmem_info_node(struct pglist_data *pgdat); extern void put_page_bootmem(struct page *page); -#endif /* * Lock for memory hotplug guarantees 1) all callbacks for memory hotplug Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 14:03:37.564697621 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 14:05:16.604459506 +0900 @@ -91,7 +91,6 @@ static void release_memory_resource(stru } #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE -#ifndef CONFIG_SPARSEMEM_VMEMMAP static void get_page_bootmem(unsigned long info, struct page *page, unsigned long type) { @@ -127,6 +126,7 @@ void __ref put_page_bootmem(struct page } +#ifndef CONFIG_SPARSEMEM_VMEMMAP static void register_page_bootmem_info_section(unsigned long start_pfn) { unsigned long *usemap, mapsize, section_nr, i; @@ -163,6 +163,11 @@ static void register_page_bootmem_info_s get_page_bootmem(section_nr, page, MIX_SECTION_INFO); } +#else +static inline void register_page_bootmem_info_section(unsigned long start_pfn) +{ +} +#endif void register_page_bootmem_info_node(struct pglist_data *pgdat) { @@ -198,7 +203,6 @@ void register_page_bootmem_info_node(str register_page_bootmem_info_section(pfn); } -#endif /* !CONFIG_SPARSEMEM_VMEMMAP */ static void grow_zone_span(struct zone *zone, unsigned long start_pfn, unsigned long end_pfn) From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756088Ab2F0F4B (ORCPT ); Wed, 27 Jun 2012 01:56:01 -0400 Received: from fgwmail5.fujitsu.co.jp ([192.51.44.35]:53753 "EHLO fgwmail5.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750780Ab2F0Fz7 (ORCPT ); Wed, 27 Jun 2012 01:55:59 -0400 X-SecurityPolicyCheck: OK by SHieldMailChecker v1.7.4 Message-ID: <4FEAA05C.6090204@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:55:40 +0900 From: Yasuaki Ishimatsu User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: , , , CC: , , , , , , , Subject: [RFC PATCH 9/12] memory-hotplug : implement register_page_bootmem_info_section of sparse-vmemmap References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For removing memmap region of sparse-vmemmap which is allocated bootmem, memmap region of sparse-vmemmap needs to be registered by get_page_bootmem(). So the patch searches pages of virtual mapping and registers the pages by get_page_bootmem(). CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- arch/x86/mm/init_64.c | 53 +++++++++++++++++++++++++++++++++++++++++ include/linux/memory_hotplug.h | 2 + include/linux/mm.h | 3 +- mm/memory_hotplug.c | 23 +++++++++++++++-- 4 files changed, 77 insertions(+), 4 deletions(-) Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 14:05:16.604459506 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 14:27:19.850916817 +0900 @@ -91,8 +91,8 @@ static void release_memory_resource(stru } #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE -static void get_page_bootmem(unsigned long info, struct page *page, - unsigned long type) +void get_page_bootmem(unsigned long info, struct page *page, + unsigned long type) { unsigned long page_type; @@ -164,8 +164,25 @@ static void register_page_bootmem_info_s } #else -static inline void register_page_bootmem_info_section(unsigned long start_pfn) +static void register_page_bootmem_info_section(unsigned long start_pfn) { + unsigned long mapsize, section_nr; + struct mem_section *ms; + struct page *page, *memmap; + + if (!pfn_valid(start_pfn)) + return; + + section_nr = pfn_to_section_nr(start_pfn); + ms = __nr_to_section(section_nr); + + memmap = sparse_decode_mem_map(ms->section_mem_map, section_nr); + + page = virt_to_page(memmap); + mapsize = sizeof(struct page) * PAGES_PER_SECTION; + mapsize = PAGE_ALIGN(mapsize) >> PAGE_SHIFT; + + register_page_bootmem_memmap(section_nr, memmap, PAGES_PER_SECTION); } #endif Index: linux-3.5-rc4/include/linux/mm.h =================================================================== --- linux-3.5-rc4.orig/include/linux/mm.h 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/include/linux/mm.h 2012-06-26 14:26:17.481696320 +0900 @@ -1586,7 +1586,8 @@ int vmemmap_populate_basepages(struct pa unsigned long pages, int node); int vmemmap_populate(struct page *start_page, unsigned long pages, int node); void vmemmap_populate_print_last(void); - +void register_page_bootmem_memmap(unsigned long section_nr, struct page *map, + unsigned long size); enum mf_flags { MF_COUNT_INCREASED = 1 << 0, Index: linux-3.5-rc4/arch/x86/mm/init_64.c =================================================================== --- linux-3.5-rc4.orig/arch/x86/mm/init_64.c 2012-06-25 04:53:04.000000000 +0900 +++ linux-3.5-rc4/arch/x86/mm/init_64.c 2012-06-26 14:26:17.481696320 +0900 @@ -978,6 +978,59 @@ vmemmap_populate(struct page *start_page return 0; } +void __meminit +register_page_bootmem_memmap(unsigned long section_nr, struct page *start_page, + unsigned long size) +{ + unsigned long addr = (unsigned long)start_page; + unsigned long end = (unsigned long)(start_page + size); + unsigned long next; + pgd_t *pgd; + pud_t *pud; + pmd_t *pmd; + + for (; addr < end; addr = next) { + pte_t *pte = NULL; + + pgd = pgd_offset_k(addr); + if (pgd_none(*pgd)) { + next = (addr + PAGE_SIZE) & PAGE_MASK; + continue; + } + get_page_bootmem(section_nr, pgd_page(*pgd), MIX_SECTION_INFO); + + pud = pud_offset(pgd, addr); + if (pud_none(*pud)) { + next = (addr + PAGE_SIZE) & PAGE_MASK; + continue; + } + get_page_bootmem(section_nr, pud_page(*pud), MIX_SECTION_INFO); + + if (!cpu_has_pse) { + next = (addr + PAGE_SIZE) & PAGE_MASK; + pmd = pmd_offset(pud, addr); + if (pmd_none(*pmd)) + continue; + get_page_bootmem(section_nr, pmd_page(*pmd), + MIX_SECTION_INFO); + + pte = pte_offset_kernel(pmd, addr); + if (pte_none(*pte)) + continue; + get_page_bootmem(section_nr, pte_page(*pte), + SECTION_INFO); + } else { + next = pmd_addr_end(addr, end); + + pmd = pmd_offset(pud, addr); + if (pmd_none(*pmd)) + continue; + get_page_bootmem(section_nr, pmd_page(*pmd), + SECTION_INFO); + } + } +} + void __meminit vmemmap_populate_print_last(void) { if (p_start) { Index: linux-3.5-rc4/include/linux/memory_hotplug.h =================================================================== --- linux-3.5-rc4.orig/include/linux/memory_hotplug.h 2012-06-26 14:05:16.603459518 +0900 +++ linux-3.5-rc4/include/linux/memory_hotplug.h 2012-06-26 14:11:14.175989381 +0900 @@ -162,6 +162,8 @@ static inline void arch_refresh_nodedata extern void register_page_bootmem_info_node(struct pglist_data *pgdat); extern void put_page_bootmem(struct page *page); +extern void get_page_bootmem(unsigned long ingo, struct page *page, + unsigned long type); /* * Lock for memory hotplug guarantees 1) all callbacks for memory hotplug From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756213Ab2F0F6S (ORCPT ); Wed, 27 Jun 2012 01:58:18 -0400 Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:36122 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750994Ab2F0F6Q (ORCPT ); Wed, 27 Jun 2012 01:58:16 -0400 X-SecurityPolicyCheck: OK by SHieldMailChecker v1.7.4 Message-ID: <4FEAA0E2.2080003@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:57:54 +0900 From: Yasuaki Ishimatsu User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: , , , CC: , , , , , , , Subject: [RFC PATCH 11/12] memory-hotplug : add node_device_release References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When calling unregister_node(), the function shows following message at device_release(). Device 'node2' does not have a release() function, it is broken and must be fixed. So the patch implements node_device_release() CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu Index: linux-3.5-rc1/drivers/base/node.c =================================================================== --- linux-3.5-rc1.orig/drivers/base/node.c 2012-06-14 09:09:53.000000000 +0900 +++ linux-3.5-rc1/drivers/base/node.c 2012-06-25 18:40:45.810261969 +0900 @@ -252,6 +252,12 @@ static inline void hugetlb_register_node static inline void hugetlb_unregister_node(struct node *node) {} #endif +static void node_device_release(struct device *dev) +{ + struct node *node_dev = to_node(dev); + + memset(node_dev, 0, sizeof(struct node)); +} /* * register_node - Setup a sysfs device for a node. @@ -265,6 +271,7 @@ int register_node(struct node *node, int node->dev.id = num; node->dev.bus = &node_subsys; + node->dev.release = node_device_release; error = device_register(&node->dev); if (!error){ From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756176Ab2F0F72 (ORCPT ); Wed, 27 Jun 2012 01:59:28 -0400 Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:36174 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750994Ab2F0F71 (ORCPT ); Wed, 27 Jun 2012 01:59:27 -0400 X-SecurityPolicyCheck: OK by SHieldMailChecker v1.7.4 Message-ID: <4FEAA12B.6070906@jp.fujitsu.com> Date: Wed, 27 Jun 2012 14:59:07 +0900 From: Yasuaki Ishimatsu User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: , , , CC: , , , , , , , Subject: [RFC PATCH 12/12] memory-hotplug : remove sysfs file of node References: <4FEA9C88.1070800@jp.fujitsu.com> In-Reply-To: <4FEA9C88.1070800@jp.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The patch adds node_set_offline() and unregister_one_node() to remove_memory() for removing sysfs file of node. CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- mm/memory_hotplug.c | 5 +++++ 1 file changed, 5 insertions(+) Index: linux-3.5-rc4/mm/memory_hotplug.c =================================================================== --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 14:32:03.630368866 +0900 +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 14:39:58.090437374 +0900 @@ -702,6 +702,11 @@ int remove_memory(int nid, u64 start, u6 /* remove memmap entry */ firmware_map_remove(start, start + size, "System RAM"); + if (!node_present_pages(nid)) { + node_set_offline(nid); + unregister_one_node(nid); + } + __remove_pages(start >> PAGE_SHIFT, size >> PAGE_SHIFT); unlock_memory_hotplug(); return 0; From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756204Ab2F0GKi (ORCPT ); Wed, 27 Jun 2012 02:10:38 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:36717 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753290Ab2F0GKe (ORCPT ); Wed, 27 Jun 2012 02:10:34 -0400 Date: Tue, 26 Jun 2012 23:10:32 -0700 (PDT) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: Yasuaki Ishimatsu cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com Subject: Re: [RFC PATCH 1/12] memory-hotplug : rename remove_memory to offline_memory In-Reply-To: <4FEA9D5C.1080508@jp.fujitsu.com> Message-ID: References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9D5C.1080508@jp.fujitsu.com> User-Agent: Alpine 2.00 (DEB 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 27 Jun 2012, Yasuaki Ishimatsu wrote: > remove_memory() does not remove memory but just offlines memory. The patch > changes name of it to offline_memory(). > The kernel is never going to physically remove the memory itself, so I don't see the big problem with calling it remove_memory(). If you're going to change it to offline_memory(), which is just as good but not better, then I'd suggest changing add_memory() to online_memory() for completeness. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756339Ab2F0HKT (ORCPT ); Wed, 27 Jun 2012 03:10:19 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:29686 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1756264Ab2F0HKR (ORCPT ); Wed, 27 Jun 2012 03:10:17 -0400 X-IronPort-AV: E=Sophos;i="4.77,483,1336320000"; d="scan'208";a="5272590" Message-ID: <4FEAB2E1.3090200@cn.fujitsu.com> Date: Wed, 27 Jun 2012 15:14:41 +0800 From: Wen Congyang User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100413 Fedora/3.0.4-2.fc13 Thunderbird/3.0.4 MIME-Version: 1.0 To: Yasuaki Ishimatsu CC: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com Subject: Re: [RFC PATCH 1/12] memory-hotplug : rename remove_memory to offline_memory References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9D5C.1080508@jp.fujitsu.com> In-Reply-To: <4FEA9D5C.1080508@jp.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2012/06/27 15:10:25, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2012/06/27 15:10:27, Serialize complete at 2012/06/27 15:10:27 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=ISO-2022-JP Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org At 06/27/2012 01:42 PM, Yasuaki Ishimatsu Wrote: > remove_memory() does not remove memory but just offlines memory. The patch > changes name of it to offline_memory(). There are 3 functions in the kernel: 1. add_memory() 2. online_pages() 3. remove_memory() So I think offline_pages() is better than offline_memory(). Thanks Wen Congyang > > CC: Len Brown > CC: Benjamin Herrenschmidt > CC: Paul Mackerras > CC: Christoph Lameter > Cc: Minchan Kim > CC: Andrew Morton > CC: KOSAKI Motohiro > CC: Wen Congyang > Signed-off-by: Yasuaki Ishimatsu > > --- > drivers/acpi/acpi_memhotplug.c | 2 +- > drivers/base/memory.c | 4 ++-- > include/linux/memory_hotplug.h | 2 +- > mm/memory_hotplug.c | 6 +++--- > 4 files changed, 7 insertions(+), 7 deletions(-) > > Index: linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c > =================================================================== > --- linux-3.5-rc4.orig/drivers/acpi/acpi_memhotplug.c 2012-06-25 04:53:04.000000000 +0900 > +++ linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c 2012-06-26 13:48:38.263940481 +0900 > @@ -318,7 +318,7 @@ static int acpi_memory_disable_device(st > */ > list_for_each_entry_safe(info, n, &mem_device->res_list, list) { > if (info->enabled) { > - result = remove_memory(info->start_addr, info->length); > + result = offline_memory(info->start_addr, info->length); > if (result) > return result; > } > Index: linux-3.5-rc4/drivers/base/memory.c > =================================================================== > --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-25 04:53:04.000000000 +0900 > +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:48:46.072842803 +0900 > @@ -266,8 +266,8 @@ memory_block_action(unsigned long phys_i > break; > case MEM_OFFLINE: > start_paddr = page_to_pfn(first_page) << PAGE_SHIFT; > - ret = remove_memory(start_paddr, > - nr_pages << PAGE_SHIFT); > + ret = offline_memory(start_paddr, > + nr_pages << PAGE_SHIFT); > break; > default: > WARN(1, KERN_WARNING "%s(%ld, %ld) unknown action: " > Index: linux-3.5-rc4/mm/memory_hotplug.c > =================================================================== > --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-25 04:53:04.000000000 +0900 > +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:46.072842803 +0900 > @@ -990,7 +990,7 @@ out: > return ret; > } > > -int remove_memory(u64 start, u64 size) > +int offline_memory(u64 start, u64 size) > { > unsigned long start_pfn, end_pfn; > > @@ -999,9 +999,9 @@ int remove_memory(u64 start, u64 size) > return offline_pages(start_pfn, end_pfn, 120 * HZ); > } > #else > -int remove_memory(u64 start, u64 size) > +int offline_memory(u64 start, u64 size) > { > return -EINVAL; > } > #endif /* CONFIG_MEMORY_HOTREMOVE */ > -EXPORT_SYMBOL_GPL(remove_memory); > +EXPORT_SYMBOL_GPL(offline_memory); > Index: linux-3.5-rc4/include/linux/memory_hotplug.h > =================================================================== > --- linux-3.5-rc4.orig/include/linux/memory_hotplug.h 2012-06-25 04:53:04.000000000 +0900 > +++ linux-3.5-rc4/include/linux/memory_hotplug.h 2012-06-26 13:48:38.264940468 +0900 > @@ -233,7 +233,7 @@ static inline int is_mem_section_removab > extern int mem_online_node(int nid); > extern int add_memory(int nid, u64 start, u64 size); > extern int arch_add_memory(int nid, u64 start, u64 size); > -extern int remove_memory(u64 start, u64 size); > +extern int offline_memory(u64 start, u64 size); > extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn, > int nr_pages); > extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms); > > > > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754227Ab2F0Im4 (ORCPT ); Wed, 27 Jun 2012 04:42:56 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:11016 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1753768Ab2F0Imx (ORCPT ); Wed, 27 Jun 2012 04:42:53 -0400 X-IronPort-AV: E=Sophos;i="4.77,483,1336320000"; d="scan'208";a="5273573" Message-ID: <4FEAC891.7030808@cn.fujitsu.com> Date: Wed, 27 Jun 2012 16:47:13 +0800 From: Wen Congyang User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100413 Fedora/3.0.4-2.fc13 Thunderbird/3.0.4 MIME-Version: 1.0 To: Yasuaki Ishimatsu CC: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com Subject: Re: [RFC PATCH 1/12] memory-hotplug : rename remove_memory to offline_memory References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9D5C.1080508@jp.fujitsu.com> <4FEAB2E1.3090200@cn.fujitsu.com> In-Reply-To: <4FEAB2E1.3090200@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2012/06/27 16:42:57, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2012/06/27 16:43:03, Serialize complete at 2012/06/27 16:43:03 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=ISO-2022-JP Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org At 06/27/2012 03:14 PM, Wen Congyang Wrote: > At 06/27/2012 01:42 PM, Yasuaki Ishimatsu Wrote: >> remove_memory() does not remove memory but just offlines memory. The patch >> changes name of it to offline_memory(). > > There are 3 functions in the kernel: > 1. add_memory() > 2. online_pages() > 3. remove_memory() > > So I think offline_pages() is better than offline_memory(). There is already a function named offline_pages(). So we should call offline_pages() instead of remove_memory() in memory_block_action(), and there is no need to rename remove_memory(). Thanks Wen Congyang > > Thanks > Wen Congyang >> >> CC: Len Brown >> CC: Benjamin Herrenschmidt >> CC: Paul Mackerras >> CC: Christoph Lameter >> Cc: Minchan Kim >> CC: Andrew Morton >> CC: KOSAKI Motohiro >> CC: Wen Congyang >> Signed-off-by: Yasuaki Ishimatsu >> >> --- >> drivers/acpi/acpi_memhotplug.c | 2 +- >> drivers/base/memory.c | 4 ++-- >> include/linux/memory_hotplug.h | 2 +- >> mm/memory_hotplug.c | 6 +++--- >> 4 files changed, 7 insertions(+), 7 deletions(-) >> >> Index: linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c >> =================================================================== >> --- linux-3.5-rc4.orig/drivers/acpi/acpi_memhotplug.c 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c 2012-06-26 13:48:38.263940481 +0900 >> @@ -318,7 +318,7 @@ static int acpi_memory_disable_device(st >> */ >> list_for_each_entry_safe(info, n, &mem_device->res_list, list) { >> if (info->enabled) { >> - result = remove_memory(info->start_addr, info->length); >> + result = offline_memory(info->start_addr, info->length); >> if (result) >> return result; >> } >> Index: linux-3.5-rc4/drivers/base/memory.c >> =================================================================== >> --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:48:46.072842803 +0900 >> @@ -266,8 +266,8 @@ memory_block_action(unsigned long phys_i >> break; >> case MEM_OFFLINE: >> start_paddr = page_to_pfn(first_page) << PAGE_SHIFT; >> - ret = remove_memory(start_paddr, >> - nr_pages << PAGE_SHIFT); >> + ret = offline_memory(start_paddr, >> + nr_pages << PAGE_SHIFT); >> break; >> default: >> WARN(1, KERN_WARNING "%s(%ld, %ld) unknown action: " >> Index: linux-3.5-rc4/mm/memory_hotplug.c >> =================================================================== >> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:46.072842803 +0900 >> @@ -990,7 +990,7 @@ out: >> return ret; >> } >> >> -int remove_memory(u64 start, u64 size) >> +int offline_memory(u64 start, u64 size) >> { >> unsigned long start_pfn, end_pfn; >> >> @@ -999,9 +999,9 @@ int remove_memory(u64 start, u64 size) >> return offline_pages(start_pfn, end_pfn, 120 * HZ); >> } >> #else >> -int remove_memory(u64 start, u64 size) >> +int offline_memory(u64 start, u64 size) >> { >> return -EINVAL; >> } >> #endif /* CONFIG_MEMORY_HOTREMOVE */ >> -EXPORT_SYMBOL_GPL(remove_memory); >> +EXPORT_SYMBOL_GPL(offline_memory); >> Index: linux-3.5-rc4/include/linux/memory_hotplug.h >> =================================================================== >> --- linux-3.5-rc4.orig/include/linux/memory_hotplug.h 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/include/linux/memory_hotplug.h 2012-06-26 13:48:38.264940468 +0900 >> @@ -233,7 +233,7 @@ static inline int is_mem_section_removab >> extern int mem_online_node(int nid); >> extern int add_memory(int nid, u64 start, u64 size); >> extern int arch_add_memory(int nid, u64 start, u64 size); >> -extern int remove_memory(u64 start, u64 size); >> +extern int offline_memory(u64 start, u64 size); >> extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn, >> int nr_pages); >> extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms); >> >> >> >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >> Please read the FAQ at http://www.tux.org/lkml/ >> > > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754346Ab2F0IpG (ORCPT ); Wed, 27 Jun 2012 04:45:06 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:58823 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1753741Ab2F0IpE (ORCPT ); Wed, 27 Jun 2012 04:45:04 -0400 X-IronPort-AV: E=Sophos;i="4.77,483,1336320000"; d="scan'208";a="5273610" Message-ID: <4FEAC916.7030506@cn.fujitsu.com> Date: Wed, 27 Jun 2012 16:49:26 +0800 From: Wen Congyang User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100413 Fedora/3.0.4-2.fc13 Thunderbird/3.0.4 MIME-Version: 1.0 To: Yasuaki Ishimatsu CC: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> In-Reply-To: <4FEA9DB1.7010303@jp.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2012/06/27 16:45:10, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2012/06/27 16:45:14, Serialize complete at 2012/06/27 16:45:14 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=ISO-2022-JP Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org At 06/27/2012 01:44 PM, Yasuaki Ishimatsu Wrote: > When offline_pages() is called to offlined memory, the function fails since > all memory has been offlined. In this case, the function should succeed. > The patch adds the check function into offline_pages(). You miss such case: some pages are online, while some pages are offline. offline_pages() will fail too in such case. Thanks Wen Congyang > > CC: Len Brown > CC: Benjamin Herrenschmidt > CC: Paul Mackerras > CC: Christoph Lameter > Cc: Minchan Kim > CC: Andrew Morton > CC: KOSAKI Motohiro > CC: Wen Congyang > Signed-off-by: Yasuaki Ishimatsu > > --- > drivers/base/memory.c | 20 ++++++++++++++++++++ > include/linux/memory.h | 1 + > mm/memory_hotplug.c | 5 +++++ > 3 files changed, 26 insertions(+) > > Index: linux-3.5-rc4/drivers/base/memory.c > =================================================================== > --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-26 13:28:16.726211752 +0900 > +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:34:22.423639904 +0900 > @@ -70,6 +70,26 @@ void unregister_memory_isolate_notifier( > } > EXPORT_SYMBOL(unregister_memory_isolate_notifier); > > +bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn) > +{ > + struct memory_block *mem; > + struct mem_section *section; > + unsigned long pfn, section_nr; > + > + for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { > + section_nr = pfn_to_section_nr(pfn); > + section = __nr_to_section(section_nr); > + mem = find_memory_block(section); > + if (!mem) > + continue; > + if (mem->state == MEM_OFFLINE) > + continue; > + return false; > + } > + > + return true; > +} > + > /* > * register_memory - Setup a sysfs device for a memory block > */ > Index: linux-3.5-rc4/include/linux/memory.h > =================================================================== > --- linux-3.5-rc4.orig/include/linux/memory.h 2012-06-25 04:53:04.000000000 +0900 > +++ linux-3.5-rc4/include/linux/memory.h 2012-06-26 13:34:22.424639891 +0900 > @@ -120,6 +120,7 @@ extern int memory_isolate_notify(unsigne > extern struct memory_block *find_memory_block_hinted(struct mem_section *, > struct memory_block *); > extern struct memory_block *find_memory_block(struct mem_section *); > +extern bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn); > #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION< enum mem_add_context { BOOT, HOTPLUG }; > #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ > Index: linux-3.5-rc4/mm/memory_hotplug.c > =================================================================== > --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:28:16.743211538 +0900 > +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:38.264940468 +0900 > @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned > > lock_memory_hotplug(); > > + if (memory_is_offline(start_pfn, end_pfn)) { > + ret = 0; > + goto out; > + } > + > zone = page_zone(pfn_to_page(start_pfn)); > node = zone_to_nid(zone); > nr_pages = end_pfn - start_pfn; > > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932441Ab2F1DB1 (ORCPT ); Wed, 27 Jun 2012 23:01:27 -0400 Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:58360 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932297Ab2F1DBY (ORCPT ); Wed, 27 Jun 2012 23:01:24 -0400 X-SecurityPolicyCheck: OK by SHieldMailChecker v1.7.4 Message-ID: <4FEBC8EE.7040207@jp.fujitsu.com> Date: Thu, 28 Jun 2012 12:01:02 +0900 From: Yasuaki Ishimatsu User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: Wen Congyang , CC: , , , , , , , , , , Subject: Re: [RFC PATCH 1/12] memory-hotplug : rename remove_memory to offline_memory References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9D5C.1080508@jp.fujitsu.com> <4FEAB2E1.3090200@cn.fujitsu.com> <4FEAC891.7030808@cn.fujitsu.com> In-Reply-To: <4FEAC891.7030808@cn.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi David and Wen, Thank you for reviewing my patch. 2012/06/27 17:47, Wen Congyang wrote: > At 06/27/2012 03:14 PM, Wen Congyang Wrote: >> At 06/27/2012 01:42 PM, Yasuaki Ishimatsu Wrote: >>> remove_memory() does not remove memory but just offlines memory. The patch >>> changes name of it to offline_memory(). >> >> There are 3 functions in the kernel: >> 1. add_memory() >> 2. online_pages() >> 3. remove_memory() >> >> So I think offline_pages() is better than offline_memory(). > > There is already a function named offline_pages(). So we > should call offline_pages() instead of remove_memory() in > memory_block_action(), and there is no need to rename > remove_memory(). As Wen says, Linux has 4 functions for memory hotplug already. In my recognition, these functions are prepared for following purpose. 1. add_memory : add physical memory 2. online_pages : online logical memory 3. remove_memory : offline logical memory 4. offline_pages : offline logical memory add_memory() is used for adding physical memory. I think remove_memory() would rather be used for removing physical memory than be used for removing logical memory. So I renamed remove_memory() to offline_memory(). How do you think? Regards, Yasuaki Ishimatsu > > Thanks > Wen Congyang > >> >> Thanks >> Wen Congyang >>> >>> CC: Len Brown >>> CC: Benjamin Herrenschmidt >>> CC: Paul Mackerras >>> CC: Christoph Lameter >>> Cc: Minchan Kim >>> CC: Andrew Morton >>> CC: KOSAKI Motohiro >>> CC: Wen Congyang >>> Signed-off-by: Yasuaki Ishimatsu >>> >>> --- >>> drivers/acpi/acpi_memhotplug.c | 2 +- >>> drivers/base/memory.c | 4 ++-- >>> include/linux/memory_hotplug.h | 2 +- >>> mm/memory_hotplug.c | 6 +++--- >>> 4 files changed, 7 insertions(+), 7 deletions(-) >>> >>> Index: linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c >>> =================================================================== >>> --- linux-3.5-rc4.orig/drivers/acpi/acpi_memhotplug.c 2012-06-25 04:53:04.000000000 +0900 >>> +++ linux-3.5-rc4/drivers/acpi/acpi_memhotplug.c 2012-06-26 13:48:38.263940481 +0900 >>> @@ -318,7 +318,7 @@ static int acpi_memory_disable_device(st >>> */ >>> list_for_each_entry_safe(info, n, &mem_device->res_list, list) { >>> if (info->enabled) { >>> - result = remove_memory(info->start_addr, info->length); >>> + result = offline_memory(info->start_addr, info->length); >>> if (result) >>> return result; >>> } >>> Index: linux-3.5-rc4/drivers/base/memory.c >>> =================================================================== >>> --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-25 04:53:04.000000000 +0900 >>> +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:48:46.072842803 +0900 >>> @@ -266,8 +266,8 @@ memory_block_action(unsigned long phys_i >>> break; >>> case MEM_OFFLINE: >>> start_paddr = page_to_pfn(first_page) << PAGE_SHIFT; >>> - ret = remove_memory(start_paddr, >>> - nr_pages << PAGE_SHIFT); >>> + ret = offline_memory(start_paddr, >>> + nr_pages << PAGE_SHIFT); >>> break; >>> default: >>> WARN(1, KERN_WARNING "%s(%ld, %ld) unknown action: " >>> Index: linux-3.5-rc4/mm/memory_hotplug.c >>> =================================================================== >>> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-25 04:53:04.000000000 +0900 >>> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:46.072842803 +0900 >>> @@ -990,7 +990,7 @@ out: >>> return ret; >>> } >>> >>> -int remove_memory(u64 start, u64 size) >>> +int offline_memory(u64 start, u64 size) >>> { >>> unsigned long start_pfn, end_pfn; >>> >>> @@ -999,9 +999,9 @@ int remove_memory(u64 start, u64 size) >>> return offline_pages(start_pfn, end_pfn, 120 * HZ); >>> } >>> #else >>> -int remove_memory(u64 start, u64 size) >>> +int offline_memory(u64 start, u64 size) >>> { >>> return -EINVAL; >>> } >>> #endif /* CONFIG_MEMORY_HOTREMOVE */ >>> -EXPORT_SYMBOL_GPL(remove_memory); >>> +EXPORT_SYMBOL_GPL(offline_memory); >>> Index: linux-3.5-rc4/include/linux/memory_hotplug.h >>> =================================================================== >>> --- linux-3.5-rc4.orig/include/linux/memory_hotplug.h 2012-06-25 04:53:04.000000000 +0900 >>> +++ linux-3.5-rc4/include/linux/memory_hotplug.h 2012-06-26 13:48:38.264940468 +0900 >>> @@ -233,7 +233,7 @@ static inline int is_mem_section_removab >>> extern int mem_online_node(int nid); >>> extern int add_memory(int nid, u64 start, u64 size); >>> extern int arch_add_memory(int nid, u64 start, u64 size); >>> -extern int remove_memory(u64 start, u64 size); >>> +extern int offline_memory(u64 start, u64 size); >>> extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn, >>> int nr_pages); >>> extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms); >>> >>> >>> >>> -- >>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in >>> the body of a message to majordomo@vger.kernel.org >>> More majordomo info at http://vger.kernel.org/majordomo-info.html >>> Please read the FAQ at http://www.tux.org/lkml/ >>> >> >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >> Please read the FAQ at http://www.tux.org/lkml/ >> > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: email@kvack.org > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751233Ab2F1Eup (ORCPT ); Thu, 28 Jun 2012 00:50:45 -0400 Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:50476 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750750Ab2F1Eun (ORCPT ); Thu, 28 Jun 2012 00:50:43 -0400 X-SecurityPolicyCheck: OK by SHieldMailChecker v1.7.4 Message-ID: <4FEBE280.4060107@jp.fujitsu.com> Date: Thu, 28 Jun 2012 13:50:08 +0900 From: Yasuaki Ishimatsu User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: Wen Congyang CC: , , , , , , , , , , , Subject: Re: [RFC PATCH 1/12] memory-hotplug : rename remove_memory to offline_memory References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9D5C.1080508@jp.fujitsu.com> <4FEAB2E1.3090200@cn.fujitsu.com> <4FEAC891.7030808@cn.fujitsu.com> <4FEBC8EE.7040207@jp.fujitsu.com> <4FEBCE9C.7030904@cn.fujitsu.com> In-Reply-To: <4FEBCE9C.7030904@cn.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Wen, 2012/06/28 12:25, Wen Congyang wrote: > At 06/28/2012 11:01 AM, Yasuaki Ishimatsu Wrote: >> Hi David and Wen, >> >> Thank you for reviewing my patch. >> >> 2012/06/27 17:47, Wen Congyang wrote: >>> At 06/27/2012 03:14 PM, Wen Congyang Wrote: >>>> At 06/27/2012 01:42 PM, Yasuaki Ishimatsu Wrote: >>>>> remove_memory() does not remove memory but just offlines memory. The patch >>>>> changes name of it to offline_memory(). >>>> >>>> There are 3 functions in the kernel: >>>> 1. add_memory() >>>> 2. online_pages() >>>> 3. remove_memory() >>>> >>>> So I think offline_pages() is better than offline_memory(). >>> >>> There is already a function named offline_pages(). So we >>> should call offline_pages() instead of remove_memory() in >>> memory_block_action(), and there is no need to rename >>> remove_memory(). >> >> As Wen says, Linux has 4 functions for memory hotplug already. >> In my recognition, these functions are prepared for following purpose. >> >> 1. add_memory : add physical memory >> 2. online_pages : online logical memory >> 3. remove_memory : offline logical memory >> 4. offline_pages : offline logical memory >> >> add_memory() is used for adding physical memory. I think remove_memory() >> would rather be used for removing physical memory than be used for removing >> logical memory. So I renamed remove_memory() to offline_memory(). >> How do you think? > > Hmm, remove_memory() will revert all things we do in add_memory(), so I think I think so too. add_memory() prepares to use physical memory. It prepares some structures (pgdat, page table, node, etc) for using the physical memory at the system. But it does not online the meomory. For onlining the memory, we use online_pages(). So I think that remove_memory() should remove these structures which are prepared by add_memory() not offline memory. But current remove_memory() code only calls offline_pages() and offlines memory. The patch series recreates remove_memory() for removing these structures after [RFC PATCH 3/12]. The reason to change the name of remove_memory() is a preparation to recreate it. Thanks, Yasuaki Ishimatsu > there is no need to rename it. If we rename it to offline_memory(), we should > also rename add_memory() to online_memory(). > > Thanks > Wen Congyang > >> >> Regards, >> Yasuaki Ishimatsu >> >>> >>> Thanks >>> Wen Congyang >>> >>>> >>>> Thanks >>>> Wen Congyang >>>>> From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751805Ab2F1FGn (ORCPT ); Thu, 28 Jun 2012 01:06:43 -0400 Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:37774 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751123Ab2F1FGl (ORCPT ); Thu, 28 Jun 2012 01:06:41 -0400 X-SecurityPolicyCheck: OK by SHieldMailChecker v1.7.4 Message-ID: <4FEBE646.5090801@jp.fujitsu.com> Date: Thu, 28 Jun 2012 14:06:14 +0900 From: Yasuaki Ishimatsu User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: Wen Congyang CC: , , , , , , , , , , Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> <4FEAC916.7030506@cn.fujitsu.com> In-Reply-To: <4FEAC916.7030506@cn.fujitsu.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Wen, 2012/06/27 17:49, Wen Congyang wrote: > At 06/27/2012 01:44 PM, Yasuaki Ishimatsu Wrote: >> When offline_pages() is called to offlined memory, the function fails since >> all memory has been offlined. In this case, the function should succeed. >> The patch adds the check function into offline_pages(). > > You miss such case: some pages are online, while some pages are offline. > offline_pages() will fail too in such case. You are right. But current code fails, when the function is called to offline memory. In this case, the function should succeed. So the patch confirms whether the memory was offlined or not. And if memory has already been offlined, offline_pages return 0. Thanks, Yasuaki Ishimatsu > > Thanks > Wen Congyang > >> >> CC: Len Brown >> CC: Benjamin Herrenschmidt >> CC: Paul Mackerras >> CC: Christoph Lameter >> Cc: Minchan Kim >> CC: Andrew Morton >> CC: KOSAKI Motohiro >> CC: Wen Congyang >> Signed-off-by: Yasuaki Ishimatsu >> >> --- >> drivers/base/memory.c | 20 ++++++++++++++++++++ >> include/linux/memory.h | 1 + >> mm/memory_hotplug.c | 5 +++++ >> 3 files changed, 26 insertions(+) >> >> Index: linux-3.5-rc4/drivers/base/memory.c >> =================================================================== >> --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-26 13:28:16.726211752 +0900 >> +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:34:22.423639904 +0900 >> @@ -70,6 +70,26 @@ void unregister_memory_isolate_notifier( >> } >> EXPORT_SYMBOL(unregister_memory_isolate_notifier); >> >> +bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn) >> +{ >> + struct memory_block *mem; >> + struct mem_section *section; >> + unsigned long pfn, section_nr; >> + >> + for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { >> + section_nr = pfn_to_section_nr(pfn); >> + section = __nr_to_section(section_nr); >> + mem = find_memory_block(section); >> + if (!mem) >> + continue; >> + if (mem->state == MEM_OFFLINE) >> + continue; >> + return false; >> + } >> + >> + return true; >> +} >> + >> /* >> * register_memory - Setup a sysfs device for a memory block >> */ >> Index: linux-3.5-rc4/include/linux/memory.h >> =================================================================== >> --- linux-3.5-rc4.orig/include/linux/memory.h 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/include/linux/memory.h 2012-06-26 13:34:22.424639891 +0900 >> @@ -120,6 +120,7 @@ extern int memory_isolate_notify(unsigne >> extern struct memory_block *find_memory_block_hinted(struct mem_section *, >> struct memory_block *); >> extern struct memory_block *find_memory_block(struct mem_section *); >> +extern bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn); >> #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION<> enum mem_add_context { BOOT, HOTPLUG }; >> #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ >> Index: linux-3.5-rc4/mm/memory_hotplug.c >> =================================================================== >> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:28:16.743211538 +0900 >> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:38.264940468 +0900 >> @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned >> >> lock_memory_hotplug(); >> >> + if (memory_is_offline(start_pfn, end_pfn)) { >> + ret = 0; >> + goto out; >> + } >> + >> zone = page_zone(pfn_to_page(start_pfn)); >> node = zone_to_nid(zone); >> nr_pages = end_pfn - start_pfn; >> >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >> Please read the FAQ at http://www.tux.org/lkml/ >> > > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751870Ab2F1F0n (ORCPT ); Thu, 28 Jun 2012 01:26:43 -0400 Received: from mail-yx0-f174.google.com ([209.85.213.174]:48499 "EHLO mail-yx0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751315Ab2F1F0l convert rfc822-to-8bit (ORCPT ); Thu, 28 Jun 2012 01:26:41 -0400 MIME-Version: 1.0 In-Reply-To: <4FEA9DB1.7010303@jp.fujitsu.com> References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> From: KOSAKI Motohiro Date: Thu, 28 Jun 2012 01:26:21 -0400 X-Google-Sender-Auth: Y18m_kKX9oj5-uF4wFT7hBHiGDE Message-ID: Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages To: Yasuaki Ishimatsu Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, wency@cn.fujitsu.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 27, 2012 at 1:44 AM, Yasuaki Ishimatsu wrote: > When offline_pages() is called to offlined memory, the function fails since > all memory has been offlined. In this case, the function should succeed. > The patch adds the check function into offline_pages(). I don't understand your point. I think following misoperation should fail. Otherwise administrator have no way to know their fault. $ echo offline > memoryN/state $ echo offline > memoryN/state In general, we don't like to ignore an error except the standard require it. > > CC: Len Brown > CC: Benjamin Herrenschmidt > CC: Paul Mackerras > CC: Christoph Lameter > Cc: Minchan Kim > CC: Andrew Morton > CC: KOSAKI Motohiro > CC: Wen Congyang > Signed-off-by: Yasuaki Ishimatsu > > --- >  drivers/base/memory.c  |   20 ++++++++++++++++++++ >  include/linux/memory.h |    1 + >  mm/memory_hotplug.c    |    5 +++++ >  3 files changed, 26 insertions(+) > > Index: linux-3.5-rc4/drivers/base/memory.c > =================================================================== > --- linux-3.5-rc4.orig/drivers/base/memory.c    2012-06-26 13:28:16.726211752 +0900 > +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:34:22.423639904 +0900 > @@ -70,6 +70,26 @@ void unregister_memory_isolate_notifier( >  } >  EXPORT_SYMBOL(unregister_memory_isolate_notifier); > > +bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn) I dislike this function name. 'memory' is too vague to me. > +{ > +       struct memory_block *mem; > +       struct mem_section *section; > +       unsigned long pfn, section_nr; > + > +       for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { > +               section_nr = pfn_to_section_nr(pfn); > +               section = __nr_to_section(section_nr); > +               mem = find_memory_block(section); This seems to have strong sparse dependency. Hm, I wonder why memory-hotplug.c can enable when X86_64_ACPI_NUMA. # eventually, we can have this option just 'select SPARSEMEM' config MEMORY_HOTPLUG bool "Allow for memory hot-add" depends on SPARSEMEM || X86_64_ACPI_NUMA > +               if (!mem) > +                       continue; > +               if (mem->state == MEM_OFFLINE) > +                       continue; > +               return false; > +       } > + > +       return true; > +} > + >  /* >  * register_memory - Setup a sysfs device for a memory block >  */ > Index: linux-3.5-rc4/include/linux/memory.h > =================================================================== > --- linux-3.5-rc4.orig/include/linux/memory.h   2012-06-25 04:53:04.000000000 +0900 > +++ linux-3.5-rc4/include/linux/memory.h        2012-06-26 13:34:22.424639891 +0900 > @@ -120,6 +120,7 @@ extern int memory_isolate_notify(unsigne >  extern struct memory_block *find_memory_block_hinted(struct mem_section *, >                                                        struct memory_block *); >  extern struct memory_block *find_memory_block(struct mem_section *); > +extern bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn); >  #define CONFIG_MEM_BLOCK_SIZE  (PAGES_PER_SECTION<  enum mem_add_context { BOOT, HOTPLUG }; >  #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ > Index: linux-3.5-rc4/mm/memory_hotplug.c > =================================================================== > --- linux-3.5-rc4.orig/mm/memory_hotplug.c      2012-06-26 13:28:16.743211538 +0900 > +++ linux-3.5-rc4/mm/memory_hotplug.c   2012-06-26 13:48:38.264940468 +0900 > @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned > >        lock_memory_hotplug(); > > +       if (memory_is_offline(start_pfn, end_pfn)) { > +               ret = 0; > +               goto out; > +       } > + >        zone = page_zone(pfn_to_page(start_pfn)); >        node = zone_to_nid(zone); >        nr_pages = end_pfn - start_pfn; > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org.  For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932295Ab2F1GCF (ORCPT ); Thu, 28 Jun 2012 02:02:05 -0400 Received: from fgwmail5.fujitsu.co.jp ([192.51.44.35]:53882 "EHLO fgwmail5.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750789Ab2F1GCD (ORCPT ); Thu, 28 Jun 2012 02:02:03 -0400 X-SecurityPolicyCheck: OK by SHieldMailChecker v1.7.4 Message-ID: <4FEBF342.9030303@jp.fujitsu.com> Date: Thu, 28 Jun 2012 15:01:38 +0900 From: Yasuaki Ishimatsu User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: KOSAKI Motohiro CC: Wen Congyang , , , , , , , , , , Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> <4FEAC916.7030506@cn.fujitsu.com> <4FEBE646.5090801@jp.fujitsu.com> In-Reply-To: Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Kosaki-san, 2012/06/28 14:27, KOSAKI Motohiro wrote: > On Thu, Jun 28, 2012 at 1:06 AM, Yasuaki Ishimatsu > wrote: >> Hi Wen, >> >> 2012/06/27 17:49, Wen Congyang wrote: >>> At 06/27/2012 01:44 PM, Yasuaki Ishimatsu Wrote: >>>> When offline_pages() is called to offlined memory, the function fails since >>>> all memory has been offlined. In this case, the function should succeed. >>>> The patch adds the check function into offline_pages(). >>> >>> You miss such case: some pages are online, while some pages are offline. >>> offline_pages() will fail too in such case. >> >> You are right. But current code fails, when the function is called to offline >> memory. In this case, the function should succeed. So the patch confirms >> whether the memory was offlined or not. And if memory has already been >> offlined, offline_pages return 0. > > Can you please explain why the caller can't check it? I hope to avoid > an ignorance > as far as we can. Of course, caller side can check it. But there is a possibility that offline_pages() is called by many functions. So I do not think that it is good that all functions which call offline_pages() check it. Thanks, Yasuaki Ishimatsu From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932502Ab2F1GwP (ORCPT ); Thu, 28 Jun 2012 02:52:15 -0400 Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:53239 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752235Ab2F1GwO (ORCPT ); Thu, 28 Jun 2012 02:52:14 -0400 X-SecurityPolicyCheck: OK by SHieldMailChecker v1.7.4 Message-ID: <4FEBFF08.60502@jp.fujitsu.com> Date: Thu, 28 Jun 2012 15:51:52 +0900 From: Yasuaki Ishimatsu User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: KOSAKI Motohiro CC: , , , , , , , , , , Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> In-Reply-To: Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Kosaki-san, 2012/06/28 14:26, KOSAKI Motohiro wrote: > On Wed, Jun 27, 2012 at 1:44 AM, Yasuaki Ishimatsu > wrote: >> When offline_pages() is called to offlined memory, the function fails since >> all memory has been offlined. In this case, the function should succeed. >> The patch adds the check function into offline_pages(). > > I don't understand your point. I think following misoperation should > fail. Otherwise > administrator have no way to know their fault. > > $ echo offline > memoryN/state > $ echo offline > memoryN/state > > In general, we don't like to ignore an error except the standard require it. I understood the intention of previous mail (why the caller can't check it? ). I'll move memory_is_offline() to caller side. >> >> CC: Len Brown >> CC: Benjamin Herrenschmidt >> CC: Paul Mackerras >> CC: Christoph Lameter >> Cc: Minchan Kim >> CC: Andrew Morton >> CC: KOSAKI Motohiro >> CC: Wen Congyang >> Signed-off-by: Yasuaki Ishimatsu >> >> --- >> drivers/base/memory.c | 20 ++++++++++++++++++++ >> include/linux/memory.h | 1 + >> mm/memory_hotplug.c | 5 +++++ >> 3 files changed, 26 insertions(+) >> >> Index: linux-3.5-rc4/drivers/base/memory.c >> =================================================================== >> --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-26 13:28:16.726211752 +0900 >> +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:34:22.423639904 +0900 >> @@ -70,6 +70,26 @@ void unregister_memory_isolate_notifier( >> } >> EXPORT_SYMBOL(unregister_memory_isolate_notifier); >> >> +bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn) > > I dislike this function name. 'memory' is too vague to me. O.K. I retry to change the name of the function. > > >> +{ >> + struct memory_block *mem; >> + struct mem_section *section; >> + unsigned long pfn, section_nr; >> + >> + for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { >> + section_nr = pfn_to_section_nr(pfn); >> + section = __nr_to_section(section_nr); >> + mem = find_memory_block(section); > > This seems to have strong sparse dependency. Thanks. I will consider other CONFIG_. Thanks. Yasuaki Ishimatsu > Hm, I wonder why memory-hotplug.c can enable when X86_64_ACPI_NUMA. > > # eventually, we can have this option just 'select SPARSEMEM' > config MEMORY_HOTPLUG > bool "Allow for memory hot-add" > depends on SPARSEMEM || X86_64_ACPI_NUMA > > >> + if (!mem) >> + continue; >> + if (mem->state == MEM_OFFLINE) >> + continue; >> + return false; >> + } >> + >> + return true; >> +} >> + >> /* >> * register_memory - Setup a sysfs device for a memory block >> */ >> Index: linux-3.5-rc4/include/linux/memory.h >> =================================================================== >> --- linux-3.5-rc4.orig/include/linux/memory.h 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/include/linux/memory.h 2012-06-26 13:34:22.424639891 +0900 >> @@ -120,6 +120,7 @@ extern int memory_isolate_notify(unsigne >> extern struct memory_block *find_memory_block_hinted(struct mem_section *, >> struct memory_block *); >> extern struct memory_block *find_memory_block(struct mem_section *); >> +extern bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn); >> #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION<> enum mem_add_context { BOOT, HOTPLUG }; >> #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ >> Index: linux-3.5-rc4/mm/memory_hotplug.c >> =================================================================== >> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:28:16.743211538 +0900 >> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:38.264940468 +0900 >> @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned >> >> lock_memory_hotplug(); >> >> + if (memory_is_offline(start_pfn, end_pfn)) { >> + ret = 0; >> + goto out; >> + } >> + >> zone = page_zone(pfn_to_page(start_pfn)); >> node = zone_to_nid(zone); >> nr_pages = end_pfn - start_pfn; >> >> -- >> To unsubscribe, send a message with 'unsubscribe linux-mm' in >> the body to majordomo@kvack.org. For more info on Linux MM, >> see: http://www.linux-mm.org/ . >> Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932549Ab2F1HBZ (ORCPT ); Thu, 28 Jun 2012 03:01:25 -0400 Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:38729 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751192Ab2F1HBY (ORCPT ); Thu, 28 Jun 2012 03:01:24 -0400 X-SecurityPolicyCheck: OK by SHieldMailChecker v1.7.4 Message-ID: <4FEC012E.5030209@jp.fujitsu.com> Date: Thu, 28 Jun 2012 16:01:02 +0900 From: Yasuaki Ishimatsu User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: David Rientjes CC: , , , , , , , , , , , Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> In-Reply-To: Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi David, 2012/06/27 15:16, David Rientjes wrote: > On Wed, 27 Jun 2012, Yasuaki Ishimatsu wrote: > >> Index: linux-3.5-rc4/mm/memory_hotplug.c >> =================================================================== >> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:28:16.743211538 +0900 >> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:38.264940468 +0900 >> @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned >> >> lock_memory_hotplug(); >> >> + if (memory_is_offline(start_pfn, end_pfn)) { >> + ret = 0; >> + goto out; >> + } >> + >> zone = page_zone(pfn_to_page(start_pfn)); >> node = zone_to_nid(zone); >> nr_pages = end_pfn - start_pfn; > > Are there additional prerequisites for this patch? Otherwise it changes > the return value of offline_memory() which will now call > acpi_memory_powerdown_device() in the acpi memhotplug case when disabling. > Is that a problem? I have understood there is a person who expects "offline_pages()" to fail in this case by kosaki's comment. So I'll move memory_is_offline to caller side. Thanks, Yasuaki Ishimatsu > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: email@kvack.org > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932571Ab2F1II0 (ORCPT ); Thu, 28 Jun 2012 04:08:26 -0400 Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:44063 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932486Ab2F1IIH (ORCPT ); Thu, 28 Jun 2012 04:08:07 -0400 X-SecurityPolicyCheck: OK by SHieldMailChecker v1.7.4 Message-ID: <4FEC10CB.3060403@jp.fujitsu.com> Date: Thu, 28 Jun 2012 17:07:39 +0900 From: Yasuaki Ishimatsu User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: Wen Congyang CC: , , , , , , , , , , Subject: Re: [RFC PATCH 4/12] memory-hotplug : remove /sys/firmware/memmap/X sysfs References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9E5F.4070205@jp.fujitsu.com> <4FEBFA8D.5040607@cn.fujitsu.com> In-Reply-To: <4FEBFA8D.5040607@cn.fujitsu.com> Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Wen, 2012/06/28 15:32, Wen Congyang wrote: > At 06/27/2012 01:47 PM, Yasuaki Ishimatsu Wrote: >> When (hot)adding memory into system, /sys/firmware/memmap/X/{end, start, type} >> sysfs files are created. But there is no code to remove these files. The patch >> implements the function to remove them. >> >> Note : The code does not free firmware_map_entry since there is no way to free >> memory which is allocated by bootmem. >> >> CC: Len Brown >> CC: Benjamin Herrenschmidt >> CC: Paul Mackerras >> CC: Christoph Lameter >> Cc: Minchan Kim >> CC: Andrew Morton >> CC: KOSAKI Motohiro >> CC: Wen Congyang >> Signed-off-by: Yasuaki Ishimatsu >> >> --- >> drivers/firmware/memmap.c | 71 +++++++++++++++++++++++++++++++++++++++++++ >> include/linux/firmware-map.h | 6 +++ >> mm/memory_hotplug.c | 6 +++ >> 3 files changed, 82 insertions(+), 1 deletion(-) >> >> Index: linux-3.5-rc4/mm/memory_hotplug.c >> =================================================================== >> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:37:30.546288901 +0900 >> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:44:37.069955820 +0900 >> @@ -661,7 +661,11 @@ EXPORT_SYMBOL_GPL(add_memory); >> >> int remove_memory(int nid, u64 start, u64 size) >> { >> - return -EBUSY; >> + lock_memory_hotplug(); >> + /* remove memmap entry */ >> + firmware_map_remove(start, start + size, "System RAM"); >> + unlock_memory_hotplug(); >> + return 0; >> >> } >> EXPORT_SYMBOL_GPL(remove_memory); >> Index: linux-3.5-rc4/include/linux/firmware-map.h >> =================================================================== >> --- linux-3.5-rc4.orig/include/linux/firmware-map.h 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/include/linux/firmware-map.h 2012-06-26 13:44:37.070955807 +0900 >> @@ -25,6 +25,7 @@ >> >> int firmware_map_add_early(u64 start, u64 end, const char *type); >> int firmware_map_add_hotplug(u64 start, u64 end, const char *type); >> +int firmware_map_remove(u64 start, u64 end, const char *type); >> >> #else /* CONFIG_FIRMWARE_MEMMAP */ >> >> @@ -38,6 +39,11 @@ static inline int firmware_map_add_hotpl >> return 0; >> } >> >> +static inline int firmware_map_remove(u64 start, u64 end, const char *type) >> +{ >> + return 0; >> +} >> + >> #endif /* CONFIG_FIRMWARE_MEMMAP */ >> >> #endif /* _LINUX_FIRMWARE_MAP_H */ >> Index: linux-3.5-rc4/drivers/firmware/memmap.c >> =================================================================== >> --- linux-3.5-rc4.orig/drivers/firmware/memmap.c 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/drivers/firmware/memmap.c 2012-06-26 13:47:17.606948898 +0900 >> @@ -123,6 +123,16 @@ static int firmware_map_add_entry(u64 st >> return 0; >> } >> >> +/** >> + * firmware_map_remove_entry() - Does the real work to remove a firmware >> + * memmap entry. >> + * @entry: removed entry. >> + **/ >> +static inline void firmware_map_remove_entry(struct firmware_map_entry *entry) >> +{ >> + list_del(&entry->list); >> +} >> + >> /* >> * Add memmap entry on sysfs >> */ >> @@ -144,6 +154,31 @@ static int add_sysfs_fw_map_entry(struct >> return 0; >> } >> >> +/* >> + * Remove memmap entry on sysfs >> + */ >> +static inline void remove_sysfs_fw_map_entry(struct firmware_map_entry *entry) >> +{ >> + kobject_del(&entry->kobj); >> +} >> + >> +/* >> + * Search memmap entry >> + */ >> + >> +struct firmware_map_entry * __meminit >> +find_firmware_map_entry(u64 start, u64 end, const char *type) >> +{ >> + struct firmware_map_entry *entry; >> + >> + list_for_each_entry(entry, &map_entries, list) >> + if ((entry->start == start) && (entry->end == end) && >> + (!strcmp(entry->type, type))) >> + return entry; >> + >> + return NULL; >> +} >> + >> /** >> * firmware_map_add_hotplug() - Adds a firmware mapping entry when we do >> * memory hotplug. >> @@ -196,6 +231,42 @@ int __init firmware_map_add_early(u64 st >> return firmware_map_add_entry(start, end, type, entry); >> } >> >> +void release_firmware_map_entry(struct firmware_map_entry *entry) >> +{ >> + /* >> + * FIXME : There is no idea. >> + * How to free the entry which allocated bootmem? >> + */ >> +} >> + >> +/** >> + * firmware_map_remove() - remove a firmware mapping entry >> + * @start: Start of the memory range. >> + * @end: End of the memory range (inclusive). >> + * @type: Type of the memory range. >> + * >> + * removes a firmware mapping entry. >> + * >> + * Returns 0 on success, or -EINVAL if no entry. >> + **/ >> +int __meminit firmware_map_remove(u64 start, u64 end, const char *type) >> +{ >> + struct firmware_map_entry *entry; >> + >> + entry = find_firmware_map_entry(start, end, type); > > Hmm, we cannot find the entry easily, because the end can be: > 1. start + size > 2. start + size - 1 > > So, We should fix this bug first. This is not a bug. start and size arguments of firmware_map_remove() include acpi_memory_info->{start_addr, length}. And when creating a firmware_map_entry, the entry is created by acpi_memory_info->{start_addr, length}. So I don't think that we need care your comment. > >> + if (!entry) >> + return -EINVAL; >> + >> + /* remove the memmap entry */ >> + remove_sysfs_fw_map_entry(entry); >> + >> + firmware_map_remove_entry(entry); >> + >> + release_firmware_map_entry(entry); > > I guess you want to free the memory in the above function. But I think it is > not a good idea to free it here. We should free it when the entry->kobj's kref > is decreased to 0. Thanks. I'll update your comment at next version. Thanks, Yasuaki Ishimatsu > > Thanks > Wen Congyang > >> + >> + return 0; >> +} >> + >> /* >> * Sysfs functions ------------------------------------------------------------- >> */ >> >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >> Please read the FAQ at http://www.tux.org/lkml/ >> > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: email@kvack.org > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932507Ab2F1Id7 (ORCPT ); Thu, 28 Jun 2012 04:33:59 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:48603 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S932436Ab2F1Idx (ORCPT ); Thu, 28 Jun 2012 04:33:53 -0400 X-IronPort-AV: E=Sophos;i="4.77,490,1336320000"; d="scan'208";a="5282558" Message-ID: <4FEC17F8.1000405@cn.fujitsu.com> Date: Thu, 28 Jun 2012 16:38:16 +0800 From: Wen Congyang User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100413 Fedora/3.0.4-2.fc13 Thunderbird/3.0.4 MIME-Version: 1.0 To: Yasuaki Ishimatsu CC: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com Subject: Re: [RFC PATCH 4/12] memory-hotplug : remove /sys/firmware/memmap/X sysfs References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9E5F.4070205@jp.fujitsu.com> <4FEBFA8D.5040607@cn.fujitsu.com> <4FEC10CB.3060403@jp.fujitsu.com> In-Reply-To: <4FEC10CB.3060403@jp.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2012/06/28 16:33:57, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2012/06/28 16:34:00, Serialize complete at 2012/06/28 16:34:00 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=ISO-8859-1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org At 06/28/2012 04:07 PM, Yasuaki Ishimatsu Wrote: > Hi Wen, > > 2012/06/28 15:32, Wen Congyang wrote: >> At 06/27/2012 01:47 PM, Yasuaki Ishimatsu Wrote: >>> When (hot)adding memory into system, /sys/firmware/memmap/X/{end, >>> start, type} >>> sysfs files are created. But there is no code to remove these files. >>> The patch >>> implements the function to remove them. >>> >>> Note : The code does not free firmware_map_entry since there is no >>> way to free >>> memory which is allocated by bootmem. >>> >>> CC: Len Brown >>> CC: Benjamin Herrenschmidt >>> CC: Paul Mackerras >>> CC: Christoph Lameter >>> Cc: Minchan Kim >>> CC: Andrew Morton >>> CC: KOSAKI Motohiro >>> CC: Wen Congyang >>> Signed-off-by: Yasuaki Ishimatsu >>> >>> --- >>> drivers/firmware/memmap.c | 71 >>> +++++++++++++++++++++++++++++++++++++++++++ >>> include/linux/firmware-map.h | 6 +++ >>> mm/memory_hotplug.c | 6 +++ >>> 3 files changed, 82 insertions(+), 1 deletion(-) >>> >>> Index: linux-3.5-rc4/mm/memory_hotplug.c >>> =================================================================== >>> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 >>> 13:37:30.546288901 +0900 >>> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 >>> 13:44:37.069955820 +0900 >>> @@ -661,7 +661,11 @@ EXPORT_SYMBOL_GPL(add_memory); >>> >>> int remove_memory(int nid, u64 start, u64 size) >>> { >>> - return -EBUSY; >>> + lock_memory_hotplug(); >>> + /* remove memmap entry */ >>> + firmware_map_remove(start, start + size, "System RAM"); >>> + unlock_memory_hotplug(); >>> + return 0; >>> >>> } >>> EXPORT_SYMBOL_GPL(remove_memory); >>> Index: linux-3.5-rc4/include/linux/firmware-map.h >>> =================================================================== >>> --- linux-3.5-rc4.orig/include/linux/firmware-map.h 2012-06-25 >>> 04:53:04.000000000 +0900 >>> +++ linux-3.5-rc4/include/linux/firmware-map.h 2012-06-26 >>> 13:44:37.070955807 +0900 >>> @@ -25,6 +25,7 @@ >>> >>> int firmware_map_add_early(u64 start, u64 end, const char *type); >>> int firmware_map_add_hotplug(u64 start, u64 end, const char *type); >>> +int firmware_map_remove(u64 start, u64 end, const char *type); >>> >>> #else /* CONFIG_FIRMWARE_MEMMAP */ >>> >>> @@ -38,6 +39,11 @@ static inline int firmware_map_add_hotpl >>> return 0; >>> } >>> >>> +static inline int firmware_map_remove(u64 start, u64 end, const char >>> *type) >>> +{ >>> + return 0; >>> +} >>> + >>> #endif /* CONFIG_FIRMWARE_MEMMAP */ >>> >>> #endif /* _LINUX_FIRMWARE_MAP_H */ >>> Index: linux-3.5-rc4/drivers/firmware/memmap.c >>> =================================================================== >>> --- linux-3.5-rc4.orig/drivers/firmware/memmap.c 2012-06-25 >>> 04:53:04.000000000 +0900 >>> +++ linux-3.5-rc4/drivers/firmware/memmap.c 2012-06-26 >>> 13:47:17.606948898 +0900 >>> @@ -123,6 +123,16 @@ static int firmware_map_add_entry(u64 st >>> return 0; >>> } >>> >>> +/** >>> + * firmware_map_remove_entry() - Does the real work to remove a >>> firmware >>> + * memmap entry. >>> + * @entry: removed entry. >>> + **/ >>> +static inline void firmware_map_remove_entry(struct >>> firmware_map_entry *entry) >>> +{ >>> + list_del(&entry->list); >>> +} >>> + >>> /* >>> * Add memmap entry on sysfs >>> */ >>> @@ -144,6 +154,31 @@ static int add_sysfs_fw_map_entry(struct >>> return 0; >>> } >>> >>> +/* >>> + * Remove memmap entry on sysfs >>> + */ >>> +static inline void remove_sysfs_fw_map_entry(struct >>> firmware_map_entry *entry) >>> +{ >>> + kobject_del(&entry->kobj); >>> +} >>> + >>> +/* >>> + * Search memmap entry >>> + */ >>> + >>> +struct firmware_map_entry * __meminit >>> +find_firmware_map_entry(u64 start, u64 end, const char *type) >>> +{ >>> + struct firmware_map_entry *entry; >>> + >>> + list_for_each_entry(entry, &map_entries, list) >>> + if ((entry->start == start) && (entry->end == end) && >>> + (!strcmp(entry->type, type))) >>> + return entry; >>> + >>> + return NULL; >>> +} >>> + >>> /** >>> * firmware_map_add_hotplug() - Adds a firmware mapping entry when >>> we do >>> * memory hotplug. >>> @@ -196,6 +231,42 @@ int __init firmware_map_add_early(u64 st >>> return firmware_map_add_entry(start, end, type, entry); >>> } >>> >>> +void release_firmware_map_entry(struct firmware_map_entry *entry) >>> +{ >>> + /* >>> + * FIXME : There is no idea. >>> + * How to free the entry which allocated bootmem? >>> + */ >>> +} >>> + >>> +/** >>> + * firmware_map_remove() - remove a firmware mapping entry >>> + * @start: Start of the memory range. >>> + * @end: End of the memory range (inclusive). >>> + * @type: Type of the memory range. >>> + * >>> + * removes a firmware mapping entry. >>> + * >>> + * Returns 0 on success, or -EINVAL if no entry. >>> + **/ >>> +int __meminit firmware_map_remove(u64 start, u64 end, const char *type) >>> +{ >>> + struct firmware_map_entry *entry; >>> + >>> + entry = find_firmware_map_entry(start, end, type); >> >> Hmm, we cannot find the entry easily, because the end can be: >> 1. start + size >> 2. start + size - 1 >> >> So, We should fix this bug first. > > This is not a bug. > > start and size arguments of firmware_map_remove() include > acpi_memory_info->{start_addr, length}. And when creating a > firmware_map_entry, > the entry is created by acpi_memory_info->{start_addr, length}. So I don't > think that we need care your comment. If the memory device is hotpluged before the os starts, and the memory map is included in e820 map, the entry will be created by firmware_map_add_early(). The function firmware_map_add_early() is called by e820_reserve_resources(): ===================== for (i = 0; i < e820_saved.nr_map; i++) { struct e820entry *entry = &e820_saved.map[i]; firmware_map_add_early(entry->addr, entry->addr + entry->size - 1, e820_type_to_string(entry->type)); } ===================== Note: the end is addr + size - 1, not addr + size. In such case, you cannot find the entry. Thanks Wen Congyang > >> >>> + if (!entry) >>> + return -EINVAL; >>> + >>> + /* remove the memmap entry */ >>> + remove_sysfs_fw_map_entry(entry); >>> + >>> + firmware_map_remove_entry(entry); >>> + >>> + release_firmware_map_entry(entry); >> >> I guess you want to free the memory in the above function. But I think >> it is >> not a good idea to free it here. We should free it when the >> entry->kobj's kref >> is decreased to 0. > > Thanks. > I'll update your comment at next version. > > Thanks, > Yasuaki Ishimatsu > >> >> Thanks >> Wen Congyang >> >>> + >>> + return 0; >>> +} >>> + >>> /* >>> * Sysfs functions >>> ------------------------------------------------------------- >>> */ >>> >>> -- >>> To unsubscribe from this list: send the line "unsubscribe >>> linux-kernel" in >>> the body of a message to majordomo@vger.kernel.org >>> More majordomo info at http://vger.kernel.org/majordomo-info.html >>> Please read the FAQ at http://www.tux.org/lkml/ >>> >> >> -- >> To unsubscribe, send a message with 'unsubscribe linux-mm' in >> the body to majordomo@kvack.org. For more info on Linux MM, >> see: http://www.linux-mm.org/ . >> Don't email: email@kvack.org >> > > > > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755832Ab2F2DJ7 (ORCPT ); Thu, 28 Jun 2012 23:09:59 -0400 Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:35032 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753521Ab2F2DJz (ORCPT ); Thu, 28 Jun 2012 23:09:55 -0400 X-SecurityPolicyCheck: OK by SHieldMailChecker v1.7.4 Message-ID: <4FED1C65.7010902@jp.fujitsu.com> Date: Fri, 29 Jun 2012 12:09:25 +0900 From: Yasuaki Ishimatsu User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: Wen Congyang CC: , , , , , , , , , , Subject: Re: [RFC PATCH 4/12] memory-hotplug : remove /sys/firmware/memmap/X sysfs References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9E5F.4070205@jp.fujitsu.com> <4FEBFA8D.5040607@cn.fujitsu.com> <4FEC10CB.3060403@jp.fujitsu.com> <4FEC17F8.1000405@cn.fujitsu.com> In-Reply-To: <4FEC17F8.1000405@cn.fujitsu.com> Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Wen, 2012/06/28 17:38, Wen Congyang wrote: > At 06/28/2012 04:07 PM, Yasuaki Ishimatsu Wrote: >> Hi Wen, >> >> 2012/06/28 15:32, Wen Congyang wrote: >>> At 06/27/2012 01:47 PM, Yasuaki Ishimatsu Wrote: >>>> When (hot)adding memory into system, /sys/firmware/memmap/X/{end, >>>> start, type} >>>> sysfs files are created. But there is no code to remove these files. >>>> The patch >>>> implements the function to remove them. >>>> >>>> Note : The code does not free firmware_map_entry since there is no >>>> way to free >>>> memory which is allocated by bootmem. >>>> >>>> CC: Len Brown >>>> CC: Benjamin Herrenschmidt >>>> CC: Paul Mackerras >>>> CC: Christoph Lameter >>>> Cc: Minchan Kim >>>> CC: Andrew Morton >>>> CC: KOSAKI Motohiro >>>> CC: Wen Congyang >>>> Signed-off-by: Yasuaki Ishimatsu >>>> >>>> --- >>>> drivers/firmware/memmap.c | 71 >>>> +++++++++++++++++++++++++++++++++++++++++++ >>>> include/linux/firmware-map.h | 6 +++ >>>> mm/memory_hotplug.c | 6 +++ >>>> 3 files changed, 82 insertions(+), 1 deletion(-) >>>> >>>> Index: linux-3.5-rc4/mm/memory_hotplug.c >>>> =================================================================== >>>> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 >>>> 13:37:30.546288901 +0900 >>>> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 >>>> 13:44:37.069955820 +0900 >>>> @@ -661,7 +661,11 @@ EXPORT_SYMBOL_GPL(add_memory); >>>> >>>> int remove_memory(int nid, u64 start, u64 size) >>>> { >>>> - return -EBUSY; >>>> + lock_memory_hotplug(); >>>> + /* remove memmap entry */ >>>> + firmware_map_remove(start, start + size, "System RAM"); >>>> + unlock_memory_hotplug(); >>>> + return 0; >>>> >>>> } >>>> EXPORT_SYMBOL_GPL(remove_memory); >>>> Index: linux-3.5-rc4/include/linux/firmware-map.h >>>> =================================================================== >>>> --- linux-3.5-rc4.orig/include/linux/firmware-map.h 2012-06-25 >>>> 04:53:04.000000000 +0900 >>>> +++ linux-3.5-rc4/include/linux/firmware-map.h 2012-06-26 >>>> 13:44:37.070955807 +0900 >>>> @@ -25,6 +25,7 @@ >>>> >>>> int firmware_map_add_early(u64 start, u64 end, const char *type); >>>> int firmware_map_add_hotplug(u64 start, u64 end, const char *type); >>>> +int firmware_map_remove(u64 start, u64 end, const char *type); >>>> >>>> #else /* CONFIG_FIRMWARE_MEMMAP */ >>>> >>>> @@ -38,6 +39,11 @@ static inline int firmware_map_add_hotpl >>>> return 0; >>>> } >>>> >>>> +static inline int firmware_map_remove(u64 start, u64 end, const char >>>> *type) >>>> +{ >>>> + return 0; >>>> +} >>>> + >>>> #endif /* CONFIG_FIRMWARE_MEMMAP */ >>>> >>>> #endif /* _LINUX_FIRMWARE_MAP_H */ >>>> Index: linux-3.5-rc4/drivers/firmware/memmap.c >>>> =================================================================== >>>> --- linux-3.5-rc4.orig/drivers/firmware/memmap.c 2012-06-25 >>>> 04:53:04.000000000 +0900 >>>> +++ linux-3.5-rc4/drivers/firmware/memmap.c 2012-06-26 >>>> 13:47:17.606948898 +0900 >>>> @@ -123,6 +123,16 @@ static int firmware_map_add_entry(u64 st >>>> return 0; >>>> } >>>> >>>> +/** >>>> + * firmware_map_remove_entry() - Does the real work to remove a >>>> firmware >>>> + * memmap entry. >>>> + * @entry: removed entry. >>>> + **/ >>>> +static inline void firmware_map_remove_entry(struct >>>> firmware_map_entry *entry) >>>> +{ >>>> + list_del(&entry->list); >>>> +} >>>> + >>>> /* >>>> * Add memmap entry on sysfs >>>> */ >>>> @@ -144,6 +154,31 @@ static int add_sysfs_fw_map_entry(struct >>>> return 0; >>>> } >>>> >>>> +/* >>>> + * Remove memmap entry on sysfs >>>> + */ >>>> +static inline void remove_sysfs_fw_map_entry(struct >>>> firmware_map_entry *entry) >>>> +{ >>>> + kobject_del(&entry->kobj); >>>> +} >>>> + >>>> +/* >>>> + * Search memmap entry >>>> + */ >>>> + >>>> +struct firmware_map_entry * __meminit >>>> +find_firmware_map_entry(u64 start, u64 end, const char *type) >>>> +{ >>>> + struct firmware_map_entry *entry; >>>> + >>>> + list_for_each_entry(entry, &map_entries, list) >>>> + if ((entry->start == start) && (entry->end == end) && >>>> + (!strcmp(entry->type, type))) >>>> + return entry; >>>> + >>>> + return NULL; >>>> +} >>>> + >>>> /** >>>> * firmware_map_add_hotplug() - Adds a firmware mapping entry when >>>> we do >>>> * memory hotplug. >>>> @@ -196,6 +231,42 @@ int __init firmware_map_add_early(u64 st >>>> return firmware_map_add_entry(start, end, type, entry); >>>> } >>>> >>>> +void release_firmware_map_entry(struct firmware_map_entry *entry) >>>> +{ >>>> + /* >>>> + * FIXME : There is no idea. >>>> + * How to free the entry which allocated bootmem? >>>> + */ >>>> +} >>>> + >>>> +/** >>>> + * firmware_map_remove() - remove a firmware mapping entry >>>> + * @start: Start of the memory range. >>>> + * @end: End of the memory range (inclusive). >>>> + * @type: Type of the memory range. >>>> + * >>>> + * removes a firmware mapping entry. >>>> + * >>>> + * Returns 0 on success, or -EINVAL if no entry. >>>> + **/ >>>> +int __meminit firmware_map_remove(u64 start, u64 end, const char *type) >>>> +{ >>>> + struct firmware_map_entry *entry; >>>> + >>>> + entry = find_firmware_map_entry(start, end, type); >>> >>> Hmm, we cannot find the entry easily, because the end can be: >>> 1. start + size >>> 2. start + size - 1 >>> >>> So, We should fix this bug first. >> >> This is not a bug. >> >> start and size arguments of firmware_map_remove() include >> acpi_memory_info->{start_addr, length}. And when creating a >> firmware_map_entry, >> the entry is created by acpi_memory_info->{start_addr, length}. So I don't >> think that we need care your comment. > > If the memory device is hotpluged before the os starts, and the memory > map is included in e820 map, the entry will be created by firmware_map_add_early(). > > The function firmware_map_add_early() is called by e820_reserve_resources(): > ===================== > for (i = 0; i < e820_saved.nr_map; i++) { > struct e820entry *entry = &e820_saved.map[i]; > firmware_map_add_early(entry->addr, > entry->addr + entry->size - 1, > e820_type_to_string(entry->type)); > } > ===================== > > Note: the end is addr + size - 1, not addr + size. > > In such case, you cannot find the entry. Thank you for your explanation. I understood it. end argument of firmware_map_add_hotplug() has always "addr + size", not "addr + size - 1". I think that changing argument of firmware_map_add_early() is high risk since the function has been used since early times. So, I will unify to "addr + size - 1". Thanks, Yasuaki Ishimatsu > Thanks > Wen Congyang > >> >>> >>>> + if (!entry) >>>> + return -EINVAL; >>>> + >>>> + /* remove the memmap entry */ >>>> + remove_sysfs_fw_map_entry(entry); >>>> + >>>> + firmware_map_remove_entry(entry); >>>> + >>>> + release_firmware_map_entry(entry); >>> >>> I guess you want to free the memory in the above function. But I think >>> it is >>> not a good idea to free it here. We should free it when the >>> entry->kobj's kref >>> is decreased to 0. >> >> Thanks. >> I'll update your comment at next version. >> >> Thanks, >> Yasuaki Ishimatsu >> >>> >>> Thanks >>> Wen Congyang >>> >>>> + >>>> + return 0; >>>> +} >>>> + >>>> /* >>>> * Sysfs functions >>>> ------------------------------------------------------------- >>>> */ >>>> >>>> -- >>>> To unsubscribe from this list: send the line "unsubscribe >>>> linux-kernel" in >>>> the body of a message to majordomo@vger.kernel.org >>>> More majordomo info at http://vger.kernel.org/majordomo-info.html >>>> Please read the FAQ at http://www.tux.org/lkml/ >>>> >>> >>> -- >>> To unsubscribe, send a message with 'unsubscribe linux-mm' in >>> the body to majordomo@kvack.org. For more info on Linux MM, >>> see: http://www.linux-mm.org/ . >>> Don't email: email@kvack.org >>> >> >> >> >> > > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755577Ab2F3P61 (ORCPT ); Sat, 30 Jun 2012 11:58:27 -0400 Received: from mail-pz0-f46.google.com ([209.85.210.46]:39109 "EHLO mail-pz0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754103Ab2F3P6Z (ORCPT ); Sat, 30 Jun 2012 11:58:25 -0400 Message-ID: <4FEF2214.4000205@gmail.com> Date: Sat, 30 Jun 2012 23:58:12 +0800 From: Jiang Liu User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 MIME-Version: 1.0 To: Yasuaki Ishimatsu CC: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, wency@cn.fujitsu.com Subject: Re: [RFC PATCH 10/12] memory-hotplug : free memmap of sparse-vmemmap References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEAA09F.5000907@jp.fujitsu.com> In-Reply-To: <4FEAA09F.5000907@jp.fujitsu.com> Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/27/2012 01:56 PM, Yasuaki Ishimatsu wrote: > I don't think that all pages of virtual mapping in removed memory can be > freed, since page which type is MIX_SECTION_INFO is difficult to free. > So, the patch only frees page which type is SECTION_INFO at first. > > CC: Len Brown > CC: Benjamin Herrenschmidt > CC: Paul Mackerras > CC: Christoph Lameter > Cc: Minchan Kim > CC: Andrew Morton > CC: KOSAKI Motohiro > CC: Wen Congyang > Signed-off-by: Yasuaki Ishimatsu > > --- > arch/x86/mm/init_64.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ > include/linux/mm.h | 2 + > mm/memory_hotplug.c | 5 ++ > mm/sparse.c | 5 +- > 4 files changed, 99 insertions(+), 2 deletions(-) > > Index: linux-3.5-rc4/include/linux/mm.h > =================================================================== > --- linux-3.5-rc4.orig/include/linux/mm.h 2012-06-27 09:11:13.790150442 +0900 > +++ linux-3.5-rc4/include/linux/mm.h 2012-06-27 09:11:16.433117400 +0900 > @@ -1588,6 +1588,8 @@ int vmemmap_populate(struct page *start_ > void vmemmap_populate_print_last(void); > void register_page_bootmem_memmap(unsigned long section_nr, struct page *map, > unsigned long size); > +void vmemmap_kfree(struct page *memmpa, unsigned long nr_pages); > +void vmemmap_free_bootmem(struct page *memmpa, unsigned long nr_pages); > > enum mf_flags { > MF_COUNT_INCREASED = 1 << 0, > Index: linux-3.5-rc4/mm/sparse.c > =================================================================== > --- linux-3.5-rc4.orig/mm/sparse.c 2012-06-27 09:06:35.317631878 +0900 > +++ linux-3.5-rc4/mm/sparse.c 2012-06-27 09:11:16.434117388 +0900 > @@ -614,12 +614,13 @@ static inline struct page *kmalloc_secti > /* This will make the necessary allocations eventually. */ > return sparse_mem_map_populate(pnum, nid); > } > -static void __kfree_section_memmap(struct page *memmap, unsigned long nr_pages) > +static void __kfree_section_memmap(struct page *page, unsigned long nr_pages) > { > - return; /* XXX: Not implemented yet */ > + vmemmap_kfree(page, nr_pages); > } > static void free_map_bootmem(struct page *page, unsigned long nr_pages) > { > + vmemmap_free_bootmem(page, nr_pages); > } > #else > static struct page *__kmalloc_section_memmap(unsigned long nr_pages) > Index: linux-3.5-rc4/arch/x86/mm/init_64.c > =================================================================== > --- linux-3.5-rc4.orig/arch/x86/mm/init_64.c 2012-06-27 09:11:13.791150430 +0900 > +++ linux-3.5-rc4/arch/x86/mm/init_64.c 2012-06-27 09:11:59.254581998 +0900 > @@ -978,6 +978,95 @@ vmemmap_populate(struct page *start_page > return 0; > } > > +unsigned long find_and_clear_pte_page(unsigned long addr, unsigned long end, > + struct page *page) I think the third parameter should be "struct page **pp" instead of "struct page *page". And "page = pte_page(*pte)" should be "*pp = pte_page(*pte)". Otherwise the found page pointer can't be returned to the caller and vmemmap_kfree() just sees random value in variable "page". > +{ > + pgd_t *pgd; > + pud_t *pud; > + pmd_t *pmd; > + pte_t *pte; > + unsigned long next; > + > + page = NULL; > + > + pgd = pgd_offset_k(addr); > + if (pgd_none(*pgd)) > + return PAGE_SIZE; > + > + pud = pud_offset(pgd, addr); > + if (pud_none(*pud)) > + return PAGE_SIZE; > + > + if (!cpu_has_pse) { > + next = (addr + PAGE_SIZE) & PAGE_MASK; > + pmd = pmd_offset(pud, addr); > + if (pmd_none(*pmd)) > + return next; > + > + pte = pte_offset_kernel(pmd, addr); > + if (pte_none(*pte)) > + return next; > + > + page = pte_page(*pte); > + pte_clear(&init_mm, addr, pte); > + } else { > + next = pmd_addr_end(addr, end); > + > + pmd = pmd_offset(pud, addr); > + if (pmd_none(*pmd)) > + return next; > + > + page = pmd_page(*pmd); > + pmd_clear(pmd); > + } > + > + return next; > +} > + > +void __meminit > +vmemmap_kfree(struct page *memmap, unsigned long nr_pages) > +{ > + unsigned long addr = (unsigned long)memmap; > + unsigned long end = (unsigned long)(memmap + nr_pages); > + unsigned long next; > + unsigned int order; > + struct page *page; > + > + for (; addr < end; addr = next) { > + next = find_and_clear_pte_page(addr, end, page); > + if (!page) > + continue; > + > + if (is_vmalloc_addr(page)) > + vfree(page); > + else { > + order = next - addr; > + free_pages((unsigned long)page, > + get_order(sizeof(struct page) * order)); > + } > + } > +} > + > +void __meminit > +vmemmap_free_bootmem(struct page *memmap, unsigned long nr_pages) > +{ > + unsigned long addr = (unsigned long)memmap; > + unsigned long end = (unsigned long)(memmap + nr_pages); > + unsigned long next; > + struct page *page; > + unsigned long magic; > + > + for (; addr < end; addr = next) { > + next = find_and_clear_pte_page(addr, end, page); > + if (!page) > + continue; > + > + magic = (unsigned long) page->lru.next; > + if (magic == SECTION_INFO) > + put_page_bootmem(page); > + } > +} > + > void __meminit > register_page_bootmem_memmap(unsigned long section_nr, struct page *start_page, > unsigned long size) > Index: linux-3.5-rc4/mm/memory_hotplug.c > =================================================================== > --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-27 09:11:13.789150454 +0900 > +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-27 09:11:16.436117363 +0900 > @@ -303,6 +303,8 @@ static int __meminit __add_section(int n > #ifdef CONFIG_SPARSEMEM_VMEMMAP > static int __remove_section(struct zone *zone, struct mem_section *ms) > { > + unsigned long flags; > + struct pglist_data *pgdat = zone->zone_pgdat; > int ret; > > if (!valid_section(ms)) > @@ -310,6 +312,9 @@ static int __remove_section(struct zone > > ret = unregister_memory_section(ms); > > + pgdat_resize_lock(pgdat, &flags); > + sparse_remove_one_section(zone, ms); > + pgdat_resize_unlock(pgdat, &flags); > return ret; > } > #else > > -- > To unsubscribe from this list: send the line "unsubscribe linux-acpi" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932345Ab2GBC51 (ORCPT ); Sun, 1 Jul 2012 22:57:27 -0400 Received: from fgwmail5.fujitsu.co.jp ([192.51.44.35]:48857 "EHLO fgwmail5.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932148Ab2GBC5X (ORCPT ); Sun, 1 Jul 2012 22:57:23 -0400 X-SecurityPolicyCheck: OK by SHieldMailChecker v1.7.4 Message-ID: <4FF10DF0.7000508@jp.fujitsu.com> Date: Mon, 2 Jul 2012 11:56:48 +0900 From: Yasuaki Ishimatsu User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: Jiang Liu CC: , , , , , , , , , , , Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> <4FEF2075.2050603@gmail.com> In-Reply-To: <4FEF2075.2050603@gmail.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jiang, 2012/07/01 0:51, Jiang Liu wrote: > On 06/27/2012 01:44 PM, Yasuaki Ishimatsu wrote: >> When offline_pages() is called to offlined memory, the function fails since >> all memory has been offlined. In this case, the function should succeed. >> The patch adds the check function into offline_pages(). >> >> CC: Len Brown >> CC: Benjamin Herrenschmidt >> CC: Paul Mackerras >> CC: Christoph Lameter >> Cc: Minchan Kim >> CC: Andrew Morton >> CC: KOSAKI Motohiro >> CC: Wen Congyang >> Signed-off-by: Yasuaki Ishimatsu >> >> --- >> drivers/base/memory.c | 20 ++++++++++++++++++++ >> include/linux/memory.h | 1 + >> mm/memory_hotplug.c | 5 +++++ >> 3 files changed, 26 insertions(+) >> >> Index: linux-3.5-rc4/drivers/base/memory.c >> =================================================================== >> --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-26 13:28:16.726211752 +0900 >> +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:34:22.423639904 +0900 >> @@ -70,6 +70,26 @@ void unregister_memory_isolate_notifier( >> } >> EXPORT_SYMBOL(unregister_memory_isolate_notifier); >> >> +bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn) >> +{ >> + struct memory_block *mem; >> + struct mem_section *section; >> + unsigned long pfn, section_nr; >> + >> + for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { >> + section_nr = pfn_to_section_nr(pfn); >> + section = __nr_to_section(section_nr); >> + mem = find_memory_block(section); > Seems find_memory_block_hinted() is more efficient than find_memory_block() here. Thanks. I'll update it. Thanks, Yasuaki Ishimatsu > >> + if (!mem) >> + continue; >> + if (mem->state == MEM_OFFLINE) >> + continue; >> + return false; >> + } >> + >> + return true; >> +} >> + >> /* >> * register_memory - Setup a sysfs device for a memory block >> */ >> Index: linux-3.5-rc4/include/linux/memory.h >> =================================================================== >> --- linux-3.5-rc4.orig/include/linux/memory.h 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/include/linux/memory.h 2012-06-26 13:34:22.424639891 +0900 >> @@ -120,6 +120,7 @@ extern int memory_isolate_notify(unsigne >> extern struct memory_block *find_memory_block_hinted(struct mem_section *, >> struct memory_block *); >> extern struct memory_block *find_memory_block(struct mem_section *); >> +extern bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn); >> #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION<> enum mem_add_context { BOOT, HOTPLUG }; >> #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ >> Index: linux-3.5-rc4/mm/memory_hotplug.c >> =================================================================== >> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:28:16.743211538 +0900 >> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:38.264940468 +0900 >> @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned >> >> lock_memory_hotplug(); >> >> + if (memory_is_offline(start_pfn, end_pfn)) { >> + ret = 0; >> + goto out; >> + } >> + >> zone = page_zone(pfn_to_page(start_pfn)); >> node = zone_to_nid(zone); >> nr_pages = end_pfn - start_pfn; >> >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >> > > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: email@kvack.org > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932153Ab2GBC5V (ORCPT ); Sun, 1 Jul 2012 22:57:21 -0400 Received: from fgwmail5.fujitsu.co.jp ([192.51.44.35]:48849 "EHLO fgwmail5.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932148Ab2GBC5T (ORCPT ); Sun, 1 Jul 2012 22:57:19 -0400 X-SecurityPolicyCheck: OK by SHieldMailChecker v1.7.4 Message-ID: <4FF10D1C.3060601@jp.fujitsu.com> Date: Mon, 2 Jul 2012 11:53:16 +0900 From: Yasuaki Ishimatsu User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: Jiang Liu CC: , , , , , , , , , , , Subject: Re: [RFC PATCH 2/12] memory-hogplug : check memory offline in offline_pages References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEA9DB1.7010303@jp.fujitsu.com> <4FEF1F6A.6090705@gmail.com> In-Reply-To: <4FEF1F6A.6090705@gmail.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jiang, Thank you for your feedback. 2012/07/01 0:46, Jiang Liu wrote: > On 06/27/2012 01:44 PM, Yasuaki Ishimatsu wrote: >> When offline_pages() is called to offlined memory, the function fails since >> all memory has been offlined. In this case, the function should succeed. >> The patch adds the check function into offline_pages(). >> >> CC: Len Brown >> CC: Benjamin Herrenschmidt >> CC: Paul Mackerras >> CC: Christoph Lameter >> Cc: Minchan Kim >> CC: Andrew Morton >> CC: KOSAKI Motohiro >> CC: Wen Congyang >> Signed-off-by: Yasuaki Ishimatsu >> >> --- >> drivers/base/memory.c | 20 ++++++++++++++++++++ >> include/linux/memory.h | 1 + >> mm/memory_hotplug.c | 5 +++++ >> 3 files changed, 26 insertions(+) >> >> Index: linux-3.5-rc4/drivers/base/memory.c >> =================================================================== >> --- linux-3.5-rc4.orig/drivers/base/memory.c 2012-06-26 13:28:16.726211752 +0900 >> +++ linux-3.5-rc4/drivers/base/memory.c 2012-06-26 13:34:22.423639904 +0900 >> @@ -70,6 +70,26 @@ void unregister_memory_isolate_notifier( >> } >> EXPORT_SYMBOL(unregister_memory_isolate_notifier); >> >> +bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn) >> +{ >> + struct memory_block *mem; >> + struct mem_section *section; >> + unsigned long pfn, section_nr; >> + >> + for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { >> + section_nr = pfn_to_section_nr(pfn); >> + section = __nr_to_section(section_nr); > Is it possible for __nr_to_section return NULL here? Yes. I'll add NULL check. > >> + mem = find_memory_block(section); >> + if (!mem) >> + continue; >> + if (mem->state == MEM_OFFLINE) >> + continue; >> + return false; >> + } >> + >> + return true; >> +} > Need a put_dev(&mem->dev) for the last memory block device handled before return. Thanks. I think kobject_put(&mem->dev.kobj) should be handled for all memory block devices found by find_memory_block(). I'll update it. Thanks, Yasuaki Ishimatsu > >> + >> /* >> * register_memory - Setup a sysfs device for a memory block >> */ >> Index: linux-3.5-rc4/include/linux/memory.h >> =================================================================== >> --- linux-3.5-rc4.orig/include/linux/memory.h 2012-06-25 04:53:04.000000000 +0900 >> +++ linux-3.5-rc4/include/linux/memory.h 2012-06-26 13:34:22.424639891 +0900 >> @@ -120,6 +120,7 @@ extern int memory_isolate_notify(unsigne >> extern struct memory_block *find_memory_block_hinted(struct mem_section *, >> struct memory_block *); >> extern struct memory_block *find_memory_block(struct mem_section *); >> +extern bool memory_is_offline(unsigned long start_pfn, unsigned long end_pfn); >> #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION<> enum mem_add_context { BOOT, HOTPLUG }; >> #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ >> Index: linux-3.5-rc4/mm/memory_hotplug.c >> =================================================================== >> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-26 13:28:16.743211538 +0900 >> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-26 13:48:38.264940468 +0900 >> @@ -887,6 +887,11 @@ static int __ref offline_pages(unsigned >> >> lock_memory_hotplug(); >> >> + if (memory_is_offline(start_pfn, end_pfn)) { >> + ret = 0; >> + goto out; >> + } >> + >> zone = page_zone(pfn_to_page(start_pfn)); >> node = zone_to_nid(zone); >> nr_pages = end_pfn - start_pfn; >> >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >> > > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: email@kvack.org > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932190Ab2GBDBq (ORCPT ); Sun, 1 Jul 2012 23:01:46 -0400 Received: from fgwmail5.fujitsu.co.jp ([192.51.44.35]:36247 "EHLO fgwmail5.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754798Ab2GBDBn (ORCPT ); Sun, 1 Jul 2012 23:01:43 -0400 X-SecurityPolicyCheck: OK by SHieldMailChecker v1.7.4 Message-ID: <4FF10EFF.5050803@jp.fujitsu.com> Date: Mon, 2 Jul 2012 12:01:19 +0900 From: Yasuaki Ishimatsu User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: Jiang Liu CC: , , , , , , , , , , , Subject: Re: [RFC PATCH 10/12] memory-hotplug : free memmap of sparse-vmemmap References: <4FEA9C88.1070800@jp.fujitsu.com> <4FEAA09F.5000907@jp.fujitsu.com> <4FEF2214.4000205@gmail.com> In-Reply-To: <4FEF2214.4000205@gmail.com> Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jiang, 2012/07/01 0:58, Jiang Liu wrote: > On 06/27/2012 01:56 PM, Yasuaki Ishimatsu wrote: >> I don't think that all pages of virtual mapping in removed memory can be >> freed, since page which type is MIX_SECTION_INFO is difficult to free. >> So, the patch only frees page which type is SECTION_INFO at first. >> >> CC: Len Brown >> CC: Benjamin Herrenschmidt >> CC: Paul Mackerras >> CC: Christoph Lameter >> Cc: Minchan Kim >> CC: Andrew Morton >> CC: KOSAKI Motohiro >> CC: Wen Congyang >> Signed-off-by: Yasuaki Ishimatsu >> >> --- >> arch/x86/mm/init_64.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ >> include/linux/mm.h | 2 + >> mm/memory_hotplug.c | 5 ++ >> mm/sparse.c | 5 +- >> 4 files changed, 99 insertions(+), 2 deletions(-) >> >> Index: linux-3.5-rc4/include/linux/mm.h >> =================================================================== >> --- linux-3.5-rc4.orig/include/linux/mm.h 2012-06-27 09:11:13.790150442 +0900 >> +++ linux-3.5-rc4/include/linux/mm.h 2012-06-27 09:11:16.433117400 +0900 >> @@ -1588,6 +1588,8 @@ int vmemmap_populate(struct page *start_ >> void vmemmap_populate_print_last(void); >> void register_page_bootmem_memmap(unsigned long section_nr, struct page *map, >> unsigned long size); >> +void vmemmap_kfree(struct page *memmpa, unsigned long nr_pages); >> +void vmemmap_free_bootmem(struct page *memmpa, unsigned long nr_pages); >> >> enum mf_flags { >> MF_COUNT_INCREASED = 1 << 0, >> Index: linux-3.5-rc4/mm/sparse.c >> =================================================================== >> --- linux-3.5-rc4.orig/mm/sparse.c 2012-06-27 09:06:35.317631878 +0900 >> +++ linux-3.5-rc4/mm/sparse.c 2012-06-27 09:11:16.434117388 +0900 >> @@ -614,12 +614,13 @@ static inline struct page *kmalloc_secti >> /* This will make the necessary allocations eventually. */ >> return sparse_mem_map_populate(pnum, nid); >> } >> -static void __kfree_section_memmap(struct page *memmap, unsigned long nr_pages) >> +static void __kfree_section_memmap(struct page *page, unsigned long nr_pages) >> { >> - return; /* XXX: Not implemented yet */ >> + vmemmap_kfree(page, nr_pages); >> } >> static void free_map_bootmem(struct page *page, unsigned long nr_pages) >> { >> + vmemmap_free_bootmem(page, nr_pages); >> } >> #else >> static struct page *__kmalloc_section_memmap(unsigned long nr_pages) >> Index: linux-3.5-rc4/arch/x86/mm/init_64.c >> =================================================================== >> --- linux-3.5-rc4.orig/arch/x86/mm/init_64.c 2012-06-27 09:11:13.791150430 +0900 >> +++ linux-3.5-rc4/arch/x86/mm/init_64.c 2012-06-27 09:11:59.254581998 +0900 >> @@ -978,6 +978,95 @@ vmemmap_populate(struct page *start_page >> return 0; >> } >> >> +unsigned long find_and_clear_pte_page(unsigned long addr, unsigned long end, >> + struct page *page) > I think the third parameter should be "struct page **pp" instead of "struct page *page". > And "page = pte_page(*pte)" should be "*pp = pte_page(*pte)". > Otherwise the found page pointer can't be returned to the caller and vmemmap_kfree() > just sees random value in variable "page". Oh, you are right. I'll update it. Thanks, Yasuaki Ishimatsu >> +{ >> + pgd_t *pgd; >> + pud_t *pud; >> + pmd_t *pmd; >> + pte_t *pte; >> + unsigned long next; >> + >> + page = NULL; >> + >> + pgd = pgd_offset_k(addr); >> + if (pgd_none(*pgd)) >> + return PAGE_SIZE; >> + >> + pud = pud_offset(pgd, addr); >> + if (pud_none(*pud)) >> + return PAGE_SIZE; >> + >> + if (!cpu_has_pse) { >> + next = (addr + PAGE_SIZE) & PAGE_MASK; >> + pmd = pmd_offset(pud, addr); >> + if (pmd_none(*pmd)) >> + return next; >> + >> + pte = pte_offset_kernel(pmd, addr); >> + if (pte_none(*pte)) >> + return next; >> + >> + page = pte_page(*pte); >> + pte_clear(&init_mm, addr, pte); >> + } else { >> + next = pmd_addr_end(addr, end); >> + >> + pmd = pmd_offset(pud, addr); >> + if (pmd_none(*pmd)) >> + return next; >> + >> + page = pmd_page(*pmd); >> + pmd_clear(pmd); >> + } >> + >> + return next; >> +} >> + >> +void __meminit >> +vmemmap_kfree(struct page *memmap, unsigned long nr_pages) >> +{ >> + unsigned long addr = (unsigned long)memmap; >> + unsigned long end = (unsigned long)(memmap + nr_pages); >> + unsigned long next; >> + unsigned int order; >> + struct page *page; >> + >> + for (; addr < end; addr = next) { >> + next = find_and_clear_pte_page(addr, end, page); >> + if (!page) >> + continue; >> + >> + if (is_vmalloc_addr(page)) >> + vfree(page); >> + else { >> + order = next - addr; >> + free_pages((unsigned long)page, >> + get_order(sizeof(struct page) * order)); >> + } >> + } >> +} >> + >> +void __meminit >> +vmemmap_free_bootmem(struct page *memmap, unsigned long nr_pages) >> +{ >> + unsigned long addr = (unsigned long)memmap; >> + unsigned long end = (unsigned long)(memmap + nr_pages); >> + unsigned long next; >> + struct page *page; >> + unsigned long magic; >> + >> + for (; addr < end; addr = next) { >> + next = find_and_clear_pte_page(addr, end, page); >> + if (!page) >> + continue; >> + >> + magic = (unsigned long) page->lru.next; >> + if (magic == SECTION_INFO) >> + put_page_bootmem(page); >> + } >> +} >> + >> void __meminit >> register_page_bootmem_memmap(unsigned long section_nr, struct page *start_page, >> unsigned long size) >> Index: linux-3.5-rc4/mm/memory_hotplug.c >> =================================================================== >> --- linux-3.5-rc4.orig/mm/memory_hotplug.c 2012-06-27 09:11:13.789150454 +0900 >> +++ linux-3.5-rc4/mm/memory_hotplug.c 2012-06-27 09:11:16.436117363 +0900 >> @@ -303,6 +303,8 @@ static int __meminit __add_section(int n >> #ifdef CONFIG_SPARSEMEM_VMEMMAP >> static int __remove_section(struct zone *zone, struct mem_section *ms) >> { >> + unsigned long flags; >> + struct pglist_data *pgdat = zone->zone_pgdat; >> int ret; >> >> if (!valid_section(ms)) >> @@ -310,6 +312,9 @@ static int __remove_section(struct zone >> >> ret = unregister_memory_section(ms); >> >> + pgdat_resize_lock(pgdat, &flags); >> + sparse_remove_one_section(zone, ms); >> + pgdat_resize_unlock(pgdat, &flags); >> return ret; >> } >> #else >> >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >> > > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: email@kvack.org >