From patchwork Thu Nov 1 09:44:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [v3,12/12] memory-hotplug: free node_data when a node is offlined From: Wen Congyang X-Patchwork-Id: 196132 Message-Id: <1351763083-7905-13-git-send-email-wency@cn.fujitsu.com> To: x86@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, linux-ia64@vger.kernel.org, cmetcalf@tilera.com, sparclinux@vger.kernel.org Cc: Len Brown , Wen Congyang , Jianguo Wu , Yasuaki Ishimatsu , paulus@samba.org, Minchan Kim , KOSAKI Motohiro , David Rientjes , Christoph Lameter , Andrew Morton , Jiang Liu Date: Thu, 1 Nov 2012 17:44:43 +0800 We call hotadd_new_pgdat() to allocate memory to store node_data. So we should free it when removing a node. CC: David Rientjes CC: Jiang Liu CC: Len Brown CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro CC: Yasuaki Ishimatsu Signed-off-by: Wen Congyang --- mm/memory_hotplug.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index d965da3..e281c31 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1320,9 +1320,12 @@ static int check_cpu_on_node(void *data) /* offline the node if all memory sections of this node are removed */ static void try_offline_node(int nid) { + pg_data_t *pgdat = NODE_DATA(nid); unsigned long start_pfn = NODE_DATA(nid)->node_start_pfn; - unsigned long end_pfn = start_pfn + NODE_DATA(nid)->node_spanned_pages; + unsigned long end_pfn = start_pfn + pgdat->node_spanned_pages; unsigned long pfn; + struct page *pgdat_page = virt_to_page(pgdat); + int i; for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { unsigned long section_nr = pfn_to_section_nr(pfn); @@ -1349,6 +1352,21 @@ static void try_offline_node(int nid) */ node_set_offline(nid); unregister_one_node(nid); + + if (!PageSlab(pgdat_page) && !PageCompound(pgdat_page)) + /* node data is allocated from boot memory */ + return; + + /* free waittable in each zone */ + for (i = 0; i < MAX_NR_ZONES; i++) { + struct zone *zone = pgdat->node_zones + i; + + if (zone->wait_table) + vfree(zone->wait_table); + } + + arch_refresh_nodedata(nid, NULL); + arch_free_nodedata(pgdat); } int __ref remove_memory(int nid, u64 start, u64 size)