From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ea0-f179.google.com (mail-ea0-f179.google.com [209.85.215.179]) by kanga.kvack.org (Postfix) with ESMTP id 600716B0039 for ; Tue, 7 Jan 2014 10:16:52 -0500 (EST) Received: by mail-ea0-f179.google.com with SMTP id r15so273722ead.38 for ; Tue, 07 Jan 2014 07:16:51 -0800 (PST) Received: from e06smtp16.uk.ibm.com (e06smtp16.uk.ibm.com. [195.75.94.112]) by mx.google.com with ESMTPS id y48si9813035eew.247.2014.01.07.07.16.50 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 07 Jan 2014 07:16:50 -0800 (PST) Received: from /spool/local by e06smtp16.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 7 Jan 2014 15:16:49 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id 646EB17D8066 for ; Tue, 7 Jan 2014 15:16:55 +0000 (GMT) Received: from d06av09.portsmouth.uk.ibm.com (d06av09.portsmouth.uk.ibm.com [9.149.37.250]) by b06cxnps3075.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s07FGYxi328056 for ; Tue, 7 Jan 2014 15:16:34 GMT Received: from d06av09.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av09.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s07FGj9U019517 for ; Tue, 7 Jan 2014 08:16:46 -0700 From: Philipp Hachtmann Subject: [PATCH 0/2] Small fixes to memblock and nobootmem Date: Tue, 7 Jan 2014 16:16:12 +0100 Message-Id: <1389107774-54978-1-git-send-email-phacht@linux.vnet.ibm.com> Sender: owner-linux-mm@kvack.org List-ID: To: akpm@linux-foundation.org, jiang.liu@huawei.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, iamjoonsoo.kim@lge.com, hannes@cmpxchg.org, tangchen@cn.fujitsu.com, tj@kernel.org, toshi.kani@hp.com, Philipp Hachtmann While working on the conversion of the s390 port to use memblock and nobootmem instead of bootmem I discovered two small bugs: alloc_memory_core_early() in mm/nobootmem.c called memblock_reserve() without forwarding the return value of memblock_reserve(). free_low_memory_core() (used by free_all_bootmem) in mm/nobootmem.c already took care of releasing the memblock.reserved array in case it has been allocated using memblock itself. This behaviour was missing for memblock.memory. Cases where memblock.memory grows bigger than the initial 128 entries have been seen. So this should be supported as well. Philipp Hachtmann (2): mm, nobootmem: Add return value check in __alloc_memory_core_early() mm: free memblock.memory in free_all_bootmem include/linux/memblock.h | 1 + mm/memblock.c | 12 ++++++++++++ mm/nobootmem.c | 11 +++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) -- 1.8.4.5 -- 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-ee0-f53.google.com (mail-ee0-f53.google.com [74.125.83.53]) by kanga.kvack.org (Postfix) with ESMTP id C1E0F6B003B for ; Tue, 7 Jan 2014 10:17:04 -0500 (EST) Received: by mail-ee0-f53.google.com with SMTP id b57so136788eek.26 for ; Tue, 07 Jan 2014 07:17:04 -0800 (PST) Received: from e06smtp15.uk.ibm.com (e06smtp15.uk.ibm.com. [195.75.94.111]) by mx.google.com with ESMTPS id b44si1641379eez.14.2014.01.07.07.17.03 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 07 Jan 2014 07:17:04 -0800 (PST) Received: from /spool/local by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 7 Jan 2014 15:17:03 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id EAEF4219005E for ; Tue, 7 Jan 2014 15:16:59 +0000 (GMT) Received: from d06av09.portsmouth.uk.ibm.com (d06av09.portsmouth.uk.ibm.com [9.149.37.250]) by b06cxnps3074.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s07FGm341376700 for ; Tue, 7 Jan 2014 15:16:48 GMT Received: from d06av09.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av09.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s07FH0Hj020168 for ; Tue, 7 Jan 2014 08:17:00 -0700 From: Philipp Hachtmann Subject: [PATCH 1/2] mm, nobootmem: Add return value check in __alloc_memory_core_early() Date: Tue, 7 Jan 2014 16:16:13 +0100 Message-Id: <1389107774-54978-2-git-send-email-phacht@linux.vnet.ibm.com> In-Reply-To: <1389107774-54978-1-git-send-email-phacht@linux.vnet.ibm.com> References: <1389107774-54978-1-git-send-email-phacht@linux.vnet.ibm.com> Sender: owner-linux-mm@kvack.org List-ID: To: akpm@linux-foundation.org, jiang.liu@huawei.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, iamjoonsoo.kim@lge.com, hannes@cmpxchg.org, tangchen@cn.fujitsu.com, tj@kernel.org, toshi.kani@hp.com, Philipp Hachtmann When memblock_reserve() fails because memblock.reserved.regions cannot be resized, the caller (e.g. alloc_bootmem()) is not informed of the failed allocation. Therefore alloc_bootmem() silently returns the same pointer again and again. This patch adds a check for the return value of memblock_reserve() in __alloc_memory_core(). Signed-off-by: Philipp Hachtmann --- mm/nobootmem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/nobootmem.c b/mm/nobootmem.c index 2c254d3..3a7e14d 100644 --- a/mm/nobootmem.c +++ b/mm/nobootmem.c @@ -45,7 +45,9 @@ static void * __init __alloc_memory_core_early(int nid, u64 size, u64 align, if (!addr) return NULL; - memblock_reserve(addr, size); + if (memblock_reserve(addr, size)) + return NULL; + ptr = phys_to_virt(addr); memset(ptr, 0, size); /* -- 1.8.4.5 -- 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-ea0-f169.google.com (mail-ea0-f169.google.com [209.85.215.169]) by kanga.kvack.org (Postfix) with ESMTP id DB6A76B003D for ; Tue, 7 Jan 2014 10:17:06 -0500 (EST) Received: by mail-ea0-f169.google.com with SMTP id l9so229188eaj.28 for ; Tue, 07 Jan 2014 07:17:06 -0800 (PST) Received: from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com. [195.75.94.108]) by mx.google.com with ESMTPS id i1si89270578eev.68.2014.01.07.07.17.05 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 07 Jan 2014 07:17:06 -0800 (PST) Received: from /spool/local by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 7 Jan 2014 15:17:05 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id 41B9817D8059 for ; Tue, 7 Jan 2014 15:17:11 +0000 (GMT) Received: from d06av09.portsmouth.uk.ibm.com (d06av09.portsmouth.uk.ibm.com [9.149.37.250]) by b06cxnps3075.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s07FGoje65536142 for ; Tue, 7 Jan 2014 15:16:50 GMT Received: from d06av09.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av09.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s07FH1o3020248 for ; Tue, 7 Jan 2014 08:17:02 -0700 From: Philipp Hachtmann Subject: [PATCH 2/2] mm: free memblock.memory in free_all_bootmem Date: Tue, 7 Jan 2014 16:16:14 +0100 Message-Id: <1389107774-54978-3-git-send-email-phacht@linux.vnet.ibm.com> In-Reply-To: <1389107774-54978-1-git-send-email-phacht@linux.vnet.ibm.com> References: <1389107774-54978-1-git-send-email-phacht@linux.vnet.ibm.com> Sender: owner-linux-mm@kvack.org List-ID: To: akpm@linux-foundation.org, jiang.liu@huawei.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, iamjoonsoo.kim@lge.com, hannes@cmpxchg.org, tangchen@cn.fujitsu.com, tj@kernel.org, toshi.kani@hp.com, Philipp Hachtmann When calling free_all_bootmem() the free areas under memblock's control are released to the buddy allocator. Additionally the reserved list is freed if it was reallocated by memblock. The same should apply for the memory list. Signed-off-by: Philipp Hachtmann --- include/linux/memblock.h | 1 + mm/memblock.c | 12 ++++++++++++ mm/nobootmem.c | 7 ++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 77c60e5..d174922 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -52,6 +52,7 @@ phys_addr_t memblock_find_in_range_node(phys_addr_t start, phys_addr_t end, phys_addr_t memblock_find_in_range(phys_addr_t start, phys_addr_t end, phys_addr_t size, phys_addr_t align); phys_addr_t get_allocated_memblock_reserved_regions_info(phys_addr_t *addr); +phys_addr_t get_allocated_memblock_memory_regions_info(phys_addr_t *addr); void memblock_allow_resize(void); int memblock_add_node(phys_addr_t base, phys_addr_t size, int nid); int memblock_add(phys_addr_t base, phys_addr_t size); diff --git a/mm/memblock.c b/mm/memblock.c index 53e477b..1a11d04 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -271,6 +271,18 @@ phys_addr_t __init_memblock get_allocated_memblock_reserved_regions_info( memblock.reserved.max); } +phys_addr_t __init_memblock get_allocated_memblock_memory_regions_info( + phys_addr_t *addr) +{ + if (memblock.memory.regions == memblock_memory_init_regions) + return 0; + + *addr = __pa(memblock.memory.regions); + + return PAGE_ALIGN(sizeof(struct memblock_region) * + memblock.memory.max); +} + /** * memblock_double_array - double the size of the memblock regions array * @type: memblock type of the regions array being doubled diff --git a/mm/nobootmem.c b/mm/nobootmem.c index 3a7e14d..83f36d3 100644 --- a/mm/nobootmem.c +++ b/mm/nobootmem.c @@ -122,11 +122,16 @@ static unsigned long __init free_low_memory_core_early(void) for_each_free_mem_range(i, MAX_NUMNODES, &start, &end, NULL) count += __free_memory_core(start, end); - /* free range that is used for reserved array if we allocate it */ + /* Free memblock.reserved array if it was allocated */ size = get_allocated_memblock_reserved_regions_info(&start); if (size) count += __free_memory_core(start, start + size); + /* Free memblock.memory array if it was allocated */ + size = get_allocated_memblock_memory_regions_info(&start); + if (size) + count += __free_memory_core(start, start + size); + return count; } -- 1.8.4.5 -- 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-qa0-f49.google.com (mail-qa0-f49.google.com [209.85.216.49]) by kanga.kvack.org (Postfix) with ESMTP id F2A236B004D for ; Tue, 7 Jan 2014 10:19:46 -0500 (EST) Received: by mail-qa0-f49.google.com with SMTP id k4so640692qaq.8 for ; Tue, 07 Jan 2014 07:19:46 -0800 (PST) Received: from mail-qe0-x22e.google.com (mail-qe0-x22e.google.com [2607:f8b0:400d:c02::22e]) by mx.google.com with ESMTPS id g6si593804qab.55.2014.01.07.07.19.45 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 07 Jan 2014 07:19:46 -0800 (PST) Received: by mail-qe0-f46.google.com with SMTP id a11so451824qen.5 for ; Tue, 07 Jan 2014 07:19:45 -0800 (PST) Date: Tue, 7 Jan 2014 10:19:42 -0500 From: Tejun Heo Subject: Re: [PATCH 1/2] mm, nobootmem: Add return value check in __alloc_memory_core_early() Message-ID: <20140107151942.GA3231@htj.dyndns.org> References: <1389107774-54978-1-git-send-email-phacht@linux.vnet.ibm.com> <1389107774-54978-2-git-send-email-phacht@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1389107774-54978-2-git-send-email-phacht@linux.vnet.ibm.com> Sender: owner-linux-mm@kvack.org List-ID: To: Philipp Hachtmann Cc: akpm@linux-foundation.org, jiang.liu@huawei.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, iamjoonsoo.kim@lge.com, hannes@cmpxchg.org, tangchen@cn.fujitsu.com, toshi.kani@hp.com On Tue, Jan 07, 2014 at 04:16:13PM +0100, Philipp Hachtmann wrote: > When memblock_reserve() fails because memblock.reserved.regions cannot > be resized, the caller (e.g. alloc_bootmem()) is not informed of the > failed allocation. Therefore alloc_bootmem() silently returns the same > pointer again and again. > This patch adds a check for the return value of memblock_reserve() in > __alloc_memory_core(). > > Signed-off-by: Philipp Hachtmann Reviewed-by: Tejun Heo Thanks. -- tejun -- 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-qc0-f177.google.com (mail-qc0-f177.google.com [209.85.216.177]) by kanga.kvack.org (Postfix) with ESMTP id D09546B005A for ; Tue, 7 Jan 2014 10:23:32 -0500 (EST) Received: by mail-qc0-f177.google.com with SMTP id m20so260159qcx.8 for ; Tue, 07 Jan 2014 07:23:32 -0800 (PST) Received: from mail-qe0-x22d.google.com (mail-qe0-x22d.google.com [2607:f8b0:400d:c02::22d]) by mx.google.com with ESMTPS id nh12si76701109qeb.4.2014.01.07.07.23.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 07 Jan 2014 07:23:32 -0800 (PST) Received: by mail-qe0-f45.google.com with SMTP id 6so470439qea.32 for ; Tue, 07 Jan 2014 07:23:31 -0800 (PST) Date: Tue, 7 Jan 2014 10:23:28 -0500 From: Tejun Heo Subject: Re: [PATCH 2/2] mm: free memblock.memory in free_all_bootmem Message-ID: <20140107152328.GB3231@htj.dyndns.org> References: <1389107774-54978-1-git-send-email-phacht@linux.vnet.ibm.com> <1389107774-54978-3-git-send-email-phacht@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1389107774-54978-3-git-send-email-phacht@linux.vnet.ibm.com> Sender: owner-linux-mm@kvack.org List-ID: To: Philipp Hachtmann Cc: akpm@linux-foundation.org, jiang.liu@huawei.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, iamjoonsoo.kim@lge.com, hannes@cmpxchg.org, tangchen@cn.fujitsu.com, toshi.kani@hp.com On Tue, Jan 07, 2014 at 04:16:14PM +0100, Philipp Hachtmann wrote: > When calling free_all_bootmem() the free areas under memblock's > control are released to the buddy allocator. Additionally the > reserved list is freed if it was reallocated by memblock. > The same should apply for the memory list. > > Signed-off-by: Philipp Hachtmann Reviewed-by: Tejun Heo Thanks. -- tejun -- 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-pd0-f169.google.com (mail-pd0-f169.google.com [209.85.192.169]) by kanga.kvack.org (Postfix) with ESMTP id 4BE856B0035 for ; Tue, 7 Jan 2014 23:09:02 -0500 (EST) Received: by mail-pd0-f169.google.com with SMTP id v10so1257905pde.0 for ; Tue, 07 Jan 2014 20:09:01 -0800 (PST) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com. [119.145.14.64]) by mx.google.com with ESMTPS id vb7si60161663pbc.302.2014.01.07.20.08.28 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 07 Jan 2014 20:09:01 -0800 (PST) Message-ID: <52CCCF24.4080300@huawei.com> Date: Wed, 8 Jan 2014 12:08:04 +0800 From: Jianguo Wu MIME-Version: 1.0 Subject: Re: [PATCH 2/2] mm: free memblock.memory in free_all_bootmem References: <1389107774-54978-1-git-send-email-phacht@linux.vnet.ibm.com> <1389107774-54978-3-git-send-email-phacht@linux.vnet.ibm.com> In-Reply-To: <1389107774-54978-3-git-send-email-phacht@linux.vnet.ibm.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: Philipp Hachtmann Cc: akpm@linux-foundation.org, jiang.liu@huawei.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, iamjoonsoo.kim@lge.com, hannes@cmpxchg.org, tangchen@cn.fujitsu.com, tj@kernel.org, toshi.kani@hp.com On 2014/1/7 23:16, Philipp Hachtmann wrote: > When calling free_all_bootmem() the free areas under memblock's > control are released to the buddy allocator. Additionally the > reserved list is freed if it was reallocated by memblock. > The same should apply for the memory list. > > Signed-off-by: Philipp Hachtmann > --- > include/linux/memblock.h | 1 + > mm/memblock.c | 12 ++++++++++++ > mm/nobootmem.c | 7 ++++++- > 3 files changed, 19 insertions(+), 1 deletion(-) > > diff --git a/include/linux/memblock.h b/include/linux/memblock.h > index 77c60e5..d174922 100644 > --- a/include/linux/memblock.h > +++ b/include/linux/memblock.h > @@ -52,6 +52,7 @@ phys_addr_t memblock_find_in_range_node(phys_addr_t start, phys_addr_t end, > phys_addr_t memblock_find_in_range(phys_addr_t start, phys_addr_t end, > phys_addr_t size, phys_addr_t align); > phys_addr_t get_allocated_memblock_reserved_regions_info(phys_addr_t *addr); > +phys_addr_t get_allocated_memblock_memory_regions_info(phys_addr_t *addr); > void memblock_allow_resize(void); > int memblock_add_node(phys_addr_t base, phys_addr_t size, int nid); > int memblock_add(phys_addr_t base, phys_addr_t size); > diff --git a/mm/memblock.c b/mm/memblock.c > index 53e477b..1a11d04 100644 > --- a/mm/memblock.c > +++ b/mm/memblock.c > @@ -271,6 +271,18 @@ phys_addr_t __init_memblock get_allocated_memblock_reserved_regions_info( > memblock.reserved.max); > } > > +phys_addr_t __init_memblock get_allocated_memblock_memory_regions_info( > + phys_addr_t *addr) > +{ > + if (memblock.memory.regions == memblock_memory_init_regions) > + return 0; > + > + *addr = __pa(memblock.memory.regions); > + > + return PAGE_ALIGN(sizeof(struct memblock_region) * > + memblock.memory.max); > +} > + > /** > * memblock_double_array - double the size of the memblock regions array > * @type: memblock type of the regions array being doubled > diff --git a/mm/nobootmem.c b/mm/nobootmem.c > index 3a7e14d..83f36d3 100644 > --- a/mm/nobootmem.c > +++ b/mm/nobootmem.c > @@ -122,11 +122,16 @@ static unsigned long __init free_low_memory_core_early(void) > for_each_free_mem_range(i, MAX_NUMNODES, &start, &end, NULL) > count += __free_memory_core(start, end); > > - /* free range that is used for reserved array if we allocate it */ > + /* Free memblock.reserved array if it was allocated */ > size = get_allocated_memblock_reserved_regions_info(&start); > if (size) > count += __free_memory_core(start, start + size); > > + /* Free memblock.memory array if it was allocated */ > + size = get_allocated_memblock_memory_regions_info(&start); > + if (size) > + count += __free_memory_core(start, start + size); > + Hi Philipp, For some archs, like arm64, would use memblock.memory after system booting, so we can not simply released to the buddy allocator, maybe need !defined(CONFIG_ARCH_DISCARD_MEMBLOCK). #ifdef CONFIG_HAVE_ARCH_PFN_VALID int pfn_valid(unsigned long pfn) { return memblock_is_memory(pfn << PAGE_SHIFT); } EXPORT_SYMBOL(pfn_valid); Thanks, Jianguo Wu > return count; > } > -- 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-ee0-f51.google.com (mail-ee0-f51.google.com [74.125.83.51]) by kanga.kvack.org (Postfix) with ESMTP id C744C6B0035 for ; Wed, 8 Jan 2014 08:42:22 -0500 (EST) Received: by mail-ee0-f51.google.com with SMTP id b15so691985eek.38 for ; Wed, 08 Jan 2014 05:42:22 -0800 (PST) Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com. [195.75.94.106]) by mx.google.com with ESMTPS id r9si93294608eeo.212.2014.01.08.05.42.21 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 08 Jan 2014 05:42:21 -0800 (PST) Received: from /spool/local by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 8 Jan 2014 13:42:19 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id 5E9F817D805F for ; Wed, 8 Jan 2014 13:42:26 +0000 (GMT) Received: from d06av02.portsmouth.uk.ibm.com (d06av02.portsmouth.uk.ibm.com [9.149.37.228]) by b06cxnps3075.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s08Dg4ae59375770 for ; Wed, 8 Jan 2014 13:42:05 GMT Received: from d06av02.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s08DgETx009943 for ; Wed, 8 Jan 2014 06:42:16 -0700 Date: Wed, 8 Jan 2014 14:42:13 +0100 From: Philipp Hachtmann Subject: Re: [PATCH 2/2] mm: free memblock.memory in free_all_bootmem Message-ID: <20140108144213.4c1995b2@lilie> In-Reply-To: <52CCCF24.4080300@huawei.com> References: <1389107774-54978-1-git-send-email-phacht@linux.vnet.ibm.com> <1389107774-54978-3-git-send-email-phacht@linux.vnet.ibm.com> <52CCCF24.4080300@huawei.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Sender: owner-linux-mm@kvack.org List-ID: To: Jianguo Wu Cc: akpm@linux-foundation.org, jiang.liu@huawei.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, iamjoonsoo.kim@lge.com, hannes@cmpxchg.org, tangchen@cn.fujitsu.com, tj@kernel.org, toshi.kani@hp.com Am Wed, 8 Jan 2014 12:08:04 +0800 schrieb Jianguo Wu : > For some archs, like arm64, would use memblock.memory after system > booting, so we can not simply released to the buddy allocator, maybe > need !defined(CONFIG_ARCH_DISCARD_MEMBLOCK). Oh, I see. I have added some ifdefs to prevent memblock.memory from being freed when CONFIG_ARCH_DISCARD_MEMBLOCK is not set. Here is a replacement for the patch. Kind regards Philipp =46rom aca95bcb9d79388b68bf18e7bae4353259b6758f Mon Sep 17 00:00:00 2001 From: Philipp Hachtmann Date: Thu, 19 Dec 2013 15:53:46 +0100 Subject: [PATCH 2/2] mm: free memblock.memory in free_all_bootmem When calling free_all_bootmem() the free areas under memblock's control are released to the buddy allocator. Additionally the reserved list is freed if it was reallocated by memblock. The same should apply for the memory list. Signed-off-by: Philipp Hachtmann --- include/linux/memblock.h | 1 + mm/memblock.c | 16 ++++++++++++++++ mm/nobootmem.c | 10 +++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 77c60e5..d174922 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -52,6 +52,7 @@ phys_addr_t memblock_find_in_range_node(phys_addr_t start= , phys_addr_t end, phys_addr_t memblock_find_in_range(phys_addr_t start, phys_addr_t end, phys_addr_t size, phys_addr_t align); phys_addr_t get_allocated_memblock_reserved_regions_info(phys_addr_t *addr= ); +phys_addr_t get_allocated_memblock_memory_regions_info(phys_addr_t *addr); void memblock_allow_resize(void); int memblock_add_node(phys_addr_t base, phys_addr_t size, int nid); int memblock_add(phys_addr_t base, phys_addr_t size); diff --git a/mm/memblock.c b/mm/memblock.c index 53e477b..a78b2e9 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -271,6 +271,22 @@ phys_addr_t __init_memblock get_allocated_memblock_res= erved_regions_info( memblock.reserved.max); } =20 +#ifdef CONFIG_ARCH_DISCARD_MEMBLOCK + +phys_addr_t __init_memblock get_allocated_memblock_memory_regions_info( + phys_addr_t *addr) +{ + if (memblock.memory.regions =3D=3D memblock_memory_init_regions) + return 0; + + *addr =3D __pa(memblock.memory.regions); + + return PAGE_ALIGN(sizeof(struct memblock_region) * + memblock.memory.max); +} + +#endif + /** * memblock_double_array - double the size of the memblock regions array * @type: memblock type of the regions array being doubled diff --git a/mm/nobootmem.c b/mm/nobootmem.c index 3a7e14d..63ff3f6 100644 --- a/mm/nobootmem.c +++ b/mm/nobootmem.c @@ -122,11 +122,19 @@ static unsigned long __init free_low_memory_core_earl= y(void) for_each_free_mem_range(i, MAX_NUMNODES, &start, &end, NULL) count +=3D __free_memory_core(start, end); =20 - /* free range that is used for reserved array if we allocate it */ + /* Free memblock.reserved array if it was allocated */ size =3D get_allocated_memblock_reserved_regions_info(&start); if (size) count +=3D __free_memory_core(start, start + size); =20 +#ifdef CONFIG_ARCH_DISCARD_MEMBLOCK + + /* Free memblock.memory array if it was allocated */ + size =3D get_allocated_memblock_memory_regions_info(&start); + if (size) + count +=3D __free_memory_core(start, start + size); +#endif + return count; } =20 --=20 1.8.4.5 -- 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-yh0-f47.google.com (mail-yh0-f47.google.com [209.85.213.47]) by kanga.kvack.org (Postfix) with ESMTP id 622206B0031 for ; Wed, 8 Jan 2014 18:30:59 -0500 (EST) Received: by mail-yh0-f47.google.com with SMTP id t59so645093yho.34 for ; Wed, 08 Jan 2014 15:30:59 -0800 (PST) Received: from mail-ie0-x229.google.com (mail-ie0-x229.google.com [2607:f8b0:4001:c03::229]) by mx.google.com with ESMTPS id s6si2543259yho.14.2014.01.08.15.30.58 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 08 Jan 2014 15:30:58 -0800 (PST) Received: by mail-ie0-f169.google.com with SMTP id e14so2838674iej.0 for ; Wed, 08 Jan 2014 15:30:57 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <20140108144213.4c1995b2@lilie> References: <1389107774-54978-1-git-send-email-phacht@linux.vnet.ibm.com> <1389107774-54978-3-git-send-email-phacht@linux.vnet.ibm.com> <52CCCF24.4080300@huawei.com> <20140108144213.4c1995b2@lilie> Date: Wed, 8 Jan 2014 15:30:57 -0800 Message-ID: Subject: Re: [PATCH 2/2] mm: free memblock.memory in free_all_bootmem From: Yinghai Lu Content-Type: text/plain; charset=ISO-8859-1 Sender: owner-linux-mm@kvack.org List-ID: To: Philipp Hachtmann Cc: Jianguo Wu , Andrew Morton , Jiang Liu , Linux Kernel Mailing List , Linux MM , Joonsoo Kim , Johannes Weiner , Tang Chen , Tejun Heo , Toshi Kani On Wed, Jan 8, 2014 at 5:42 AM, Philipp Hachtmann wrote: > Am Wed, 8 Jan 2014 12:08:04 +0800 > schrieb Jianguo Wu : > >> For some archs, like arm64, would use memblock.memory after system >> booting, so we can not simply released to the buddy allocator, maybe >> need !defined(CONFIG_ARCH_DISCARD_MEMBLOCK). > > Oh, I see. I have added some ifdefs to prevent memblock.memory from > being freed when CONFIG_ARCH_DISCARD_MEMBLOCK is not set. > > Here is a replacement for the patch. > > Kind regards > > Philipp > > From aca95bcb9d79388b68bf18e7bae4353259b6758f Mon Sep 17 00:00:00 2001 > From: Philipp Hachtmann > Date: Thu, 19 Dec 2013 15:53:46 +0100 > Subject: [PATCH 2/2] mm: free memblock.memory in free_all_bootmem > > When calling free_all_bootmem() the free areas under memblock's > control are released to the buddy allocator. Additionally the > reserved list is freed if it was reallocated by memblock. > The same should apply for the memory list. > > Signed-off-by: Philipp Hachtmann > --- > include/linux/memblock.h | 1 + > mm/memblock.c | 16 ++++++++++++++++ > mm/nobootmem.c | 10 +++++++++- > 3 files changed, 26 insertions(+), 1 deletion(-) > > diff --git a/include/linux/memblock.h b/include/linux/memblock.h > index 77c60e5..d174922 100644 > --- a/include/linux/memblock.h > +++ b/include/linux/memblock.h > @@ -52,6 +52,7 @@ phys_addr_t memblock_find_in_range_node(phys_addr_t start, phys_addr_t end, > phys_addr_t memblock_find_in_range(phys_addr_t start, phys_addr_t end, > phys_addr_t size, phys_addr_t align); > phys_addr_t get_allocated_memblock_reserved_regions_info(phys_addr_t *addr); > +phys_addr_t get_allocated_memblock_memory_regions_info(phys_addr_t *addr); > void memblock_allow_resize(void); > int memblock_add_node(phys_addr_t base, phys_addr_t size, int nid); > int memblock_add(phys_addr_t base, phys_addr_t size); > diff --git a/mm/memblock.c b/mm/memblock.c > index 53e477b..a78b2e9 100644 > --- a/mm/memblock.c > +++ b/mm/memblock.c > @@ -271,6 +271,22 @@ phys_addr_t __init_memblock get_allocated_memblock_reserved_regions_info( > memblock.reserved.max); > } > > +#ifdef CONFIG_ARCH_DISCARD_MEMBLOCK > + > +phys_addr_t __init_memblock get_allocated_memblock_memory_regions_info( > + phys_addr_t *addr) > +{ > + if (memblock.memory.regions == memblock_memory_init_regions) > + return 0; > + > + *addr = __pa(memblock.memory.regions); > + > + return PAGE_ALIGN(sizeof(struct memblock_region) * > + memblock.memory.max); > +} > + > +#endif > + > /** > * memblock_double_array - double the size of the memblock regions array > * @type: memblock type of the regions array being doubled > diff --git a/mm/nobootmem.c b/mm/nobootmem.c > index 3a7e14d..63ff3f6 100644 > --- a/mm/nobootmem.c > +++ b/mm/nobootmem.c > @@ -122,11 +122,19 @@ static unsigned long __init free_low_memory_core_early(void) > for_each_free_mem_range(i, MAX_NUMNODES, &start, &end, NULL) > count += __free_memory_core(start, end); > > - /* free range that is used for reserved array if we allocate it */ > + /* Free memblock.reserved array if it was allocated */ > size = get_allocated_memblock_reserved_regions_info(&start); > if (size) > count += __free_memory_core(start, start + size); > > +#ifdef CONFIG_ARCH_DISCARD_MEMBLOCK > + > + /* Free memblock.memory array if it was allocated */ > + size = get_allocated_memblock_memory_regions_info(&start); > + if (size) > + count += __free_memory_core(start, start + size); > +#endif > + > return count; > } I sent similar before. http://www.gossamer-threads.com/lists/engine?do=post_attachment;postatt_id=49616;list=linux http://www.gossamer-threads.com/lists/linux/kernel/1556026?do=post_view_threaded#1556026 Also for arches that do not free memblock, do they still need to access memblock.reserved.regions ? Yinghai -- 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 S1752388AbaAGPQ6 (ORCPT ); Tue, 7 Jan 2014 10:16:58 -0500 Received: from e06smtp12.uk.ibm.com ([195.75.94.108]:52375 "EHLO e06smtp12.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750983AbaAGPQu (ORCPT ); Tue, 7 Jan 2014 10:16:50 -0500 From: Philipp Hachtmann To: akpm@linux-foundation.org, jiang.liu@huawei.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, iamjoonsoo.kim@lge.com, hannes@cmpxchg.org, tangchen@cn.fujitsu.com, tj@kernel.org, toshi.kani@hp.com, Philipp Hachtmann Subject: [PATCH 0/2] Small fixes to memblock and nobootmem Date: Tue, 7 Jan 2014 16:16:12 +0100 Message-Id: <1389107774-54978-1-git-send-email-phacht@linux.vnet.ibm.com> X-Mailer: git-send-email 1.8.4.5 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14010715-8372-0000-0000-00000843F9A0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org While working on the conversion of the s390 port to use memblock and nobootmem instead of bootmem I discovered two small bugs: alloc_memory_core_early() in mm/nobootmem.c called memblock_reserve() without forwarding the return value of memblock_reserve(). free_low_memory_core() (used by free_all_bootmem) in mm/nobootmem.c already took care of releasing the memblock.reserved array in case it has been allocated using memblock itself. This behaviour was missing for memblock.memory. Cases where memblock.memory grows bigger than the initial 128 entries have been seen. So this should be supported as well. Philipp Hachtmann (2): mm, nobootmem: Add return value check in __alloc_memory_core_early() mm: free memblock.memory in free_all_bootmem include/linux/memblock.h | 1 + mm/memblock.c | 12 ++++++++++++ mm/nobootmem.c | 11 +++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) -- 1.8.4.5 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752564AbaAGPRK (ORCPT ); Tue, 7 Jan 2014 10:17:10 -0500 Received: from e06smtp17.uk.ibm.com ([195.75.94.113]:36501 "EHLO e06smtp17.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751741AbaAGPRG (ORCPT ); Tue, 7 Jan 2014 10:17:06 -0500 From: Philipp Hachtmann To: akpm@linux-foundation.org, jiang.liu@huawei.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, iamjoonsoo.kim@lge.com, hannes@cmpxchg.org, tangchen@cn.fujitsu.com, tj@kernel.org, toshi.kani@hp.com, Philipp Hachtmann Subject: [PATCH 1/2] mm, nobootmem: Add return value check in __alloc_memory_core_early() Date: Tue, 7 Jan 2014 16:16:13 +0100 Message-Id: <1389107774-54978-2-git-send-email-phacht@linux.vnet.ibm.com> X-Mailer: git-send-email 1.8.4.5 In-Reply-To: <1389107774-54978-1-git-send-email-phacht@linux.vnet.ibm.com> References: <1389107774-54978-1-git-send-email-phacht@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14010715-0542-0000-0000-00000795F931 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When memblock_reserve() fails because memblock.reserved.regions cannot be resized, the caller (e.g. alloc_bootmem()) is not informed of the failed allocation. Therefore alloc_bootmem() silently returns the same pointer again and again. This patch adds a check for the return value of memblock_reserve() in __alloc_memory_core(). Signed-off-by: Philipp Hachtmann --- mm/nobootmem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/nobootmem.c b/mm/nobootmem.c index 2c254d3..3a7e14d 100644 --- a/mm/nobootmem.c +++ b/mm/nobootmem.c @@ -45,7 +45,9 @@ static void * __init __alloc_memory_core_early(int nid, u64 size, u64 align, if (!addr) return NULL; - memblock_reserve(addr, size); + if (memblock_reserve(addr, size)) + return NULL; + ptr = phys_to_virt(addr); memset(ptr, 0, size); /* -- 1.8.4.5 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752593AbaAGPRR (ORCPT ); Tue, 7 Jan 2014 10:17:17 -0500 Received: from e06smtp10.uk.ibm.com ([195.75.94.106]:57840 "EHLO e06smtp10.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751743AbaAGPRH (ORCPT ); Tue, 7 Jan 2014 10:17:07 -0500 From: Philipp Hachtmann To: akpm@linux-foundation.org, jiang.liu@huawei.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, iamjoonsoo.kim@lge.com, hannes@cmpxchg.org, tangchen@cn.fujitsu.com, tj@kernel.org, toshi.kani@hp.com, Philipp Hachtmann Subject: [PATCH 2/2] mm: free memblock.memory in free_all_bootmem Date: Tue, 7 Jan 2014 16:16:14 +0100 Message-Id: <1389107774-54978-3-git-send-email-phacht@linux.vnet.ibm.com> X-Mailer: git-send-email 1.8.4.5 In-Reply-To: <1389107774-54978-1-git-send-email-phacht@linux.vnet.ibm.com> References: <1389107774-54978-1-git-send-email-phacht@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14010715-4966-0000-0000-0000080167B9 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When calling free_all_bootmem() the free areas under memblock's control are released to the buddy allocator. Additionally the reserved list is freed if it was reallocated by memblock. The same should apply for the memory list. Signed-off-by: Philipp Hachtmann --- include/linux/memblock.h | 1 + mm/memblock.c | 12 ++++++++++++ mm/nobootmem.c | 7 ++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 77c60e5..d174922 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -52,6 +52,7 @@ phys_addr_t memblock_find_in_range_node(phys_addr_t start, phys_addr_t end, phys_addr_t memblock_find_in_range(phys_addr_t start, phys_addr_t end, phys_addr_t size, phys_addr_t align); phys_addr_t get_allocated_memblock_reserved_regions_info(phys_addr_t *addr); +phys_addr_t get_allocated_memblock_memory_regions_info(phys_addr_t *addr); void memblock_allow_resize(void); int memblock_add_node(phys_addr_t base, phys_addr_t size, int nid); int memblock_add(phys_addr_t base, phys_addr_t size); diff --git a/mm/memblock.c b/mm/memblock.c index 53e477b..1a11d04 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -271,6 +271,18 @@ phys_addr_t __init_memblock get_allocated_memblock_reserved_regions_info( memblock.reserved.max); } +phys_addr_t __init_memblock get_allocated_memblock_memory_regions_info( + phys_addr_t *addr) +{ + if (memblock.memory.regions == memblock_memory_init_regions) + return 0; + + *addr = __pa(memblock.memory.regions); + + return PAGE_ALIGN(sizeof(struct memblock_region) * + memblock.memory.max); +} + /** * memblock_double_array - double the size of the memblock regions array * @type: memblock type of the regions array being doubled diff --git a/mm/nobootmem.c b/mm/nobootmem.c index 3a7e14d..83f36d3 100644 --- a/mm/nobootmem.c +++ b/mm/nobootmem.c @@ -122,11 +122,16 @@ static unsigned long __init free_low_memory_core_early(void) for_each_free_mem_range(i, MAX_NUMNODES, &start, &end, NULL) count += __free_memory_core(start, end); - /* free range that is used for reserved array if we allocate it */ + /* Free memblock.reserved array if it was allocated */ size = get_allocated_memblock_reserved_regions_info(&start); if (size) count += __free_memory_core(start, start + size); + /* Free memblock.memory array if it was allocated */ + size = get_allocated_memblock_memory_regions_info(&start); + if (size) + count += __free_memory_core(start, start + size); + return count; } -- 1.8.4.5 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751945AbaAGPTz (ORCPT ); Tue, 7 Jan 2014 10:19:55 -0500 Received: from mail-qe0-f48.google.com ([209.85.128.48]:48947 "EHLO mail-qe0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751057AbaAGPTq (ORCPT ); Tue, 7 Jan 2014 10:19:46 -0500 Date: Tue, 7 Jan 2014 10:19:42 -0500 From: Tejun Heo To: Philipp Hachtmann Cc: akpm@linux-foundation.org, jiang.liu@huawei.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, iamjoonsoo.kim@lge.com, hannes@cmpxchg.org, tangchen@cn.fujitsu.com, toshi.kani@hp.com Subject: Re: [PATCH 1/2] mm, nobootmem: Add return value check in __alloc_memory_core_early() Message-ID: <20140107151942.GA3231@htj.dyndns.org> References: <1389107774-54978-1-git-send-email-phacht@linux.vnet.ibm.com> <1389107774-54978-2-git-send-email-phacht@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1389107774-54978-2-git-send-email-phacht@linux.vnet.ibm.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 07, 2014 at 04:16:13PM +0100, Philipp Hachtmann wrote: > When memblock_reserve() fails because memblock.reserved.regions cannot > be resized, the caller (e.g. alloc_bootmem()) is not informed of the > failed allocation. Therefore alloc_bootmem() silently returns the same > pointer again and again. > This patch adds a check for the return value of memblock_reserve() in > __alloc_memory_core(). > > Signed-off-by: Philipp Hachtmann Reviewed-by: Tejun Heo Thanks. -- tejun From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752657AbaAGPXn (ORCPT ); Tue, 7 Jan 2014 10:23:43 -0500 Received: from mail-qe0-f53.google.com ([209.85.128.53]:38358 "EHLO mail-qe0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752637AbaAGPXc (ORCPT ); Tue, 7 Jan 2014 10:23:32 -0500 Date: Tue, 7 Jan 2014 10:23:28 -0500 From: Tejun Heo To: Philipp Hachtmann Cc: akpm@linux-foundation.org, jiang.liu@huawei.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, iamjoonsoo.kim@lge.com, hannes@cmpxchg.org, tangchen@cn.fujitsu.com, toshi.kani@hp.com Subject: Re: [PATCH 2/2] mm: free memblock.memory in free_all_bootmem Message-ID: <20140107152328.GB3231@htj.dyndns.org> References: <1389107774-54978-1-git-send-email-phacht@linux.vnet.ibm.com> <1389107774-54978-3-git-send-email-phacht@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1389107774-54978-3-git-send-email-phacht@linux.vnet.ibm.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 07, 2014 at 04:16:14PM +0100, Philipp Hachtmann wrote: > When calling free_all_bootmem() the free areas under memblock's > control are released to the buddy allocator. Additionally the > reserved list is freed if it was reallocated by memblock. > The same should apply for the memory list. > > Signed-off-by: Philipp Hachtmann Reviewed-by: Tejun Heo Thanks. -- tejun From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755006AbaAHEJK (ORCPT ); Tue, 7 Jan 2014 23:09:10 -0500 Received: from szxga01-in.huawei.com ([119.145.14.64]:11823 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754852AbaAHEJG (ORCPT ); Tue, 7 Jan 2014 23:09:06 -0500 Message-ID: <52CCCF24.4080300@huawei.com> Date: Wed, 8 Jan 2014 12:08:04 +0800 From: Jianguo Wu User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 MIME-Version: 1.0 To: Philipp Hachtmann CC: , , , , , , , , Subject: Re: [PATCH 2/2] mm: free memblock.memory in free_all_bootmem References: <1389107774-54978-1-git-send-email-phacht@linux.vnet.ibm.com> <1389107774-54978-3-git-send-email-phacht@linux.vnet.ibm.com> In-Reply-To: <1389107774-54978-3-git-send-email-phacht@linux.vnet.ibm.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.24.155] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2014/1/7 23:16, Philipp Hachtmann wrote: > When calling free_all_bootmem() the free areas under memblock's > control are released to the buddy allocator. Additionally the > reserved list is freed if it was reallocated by memblock. > The same should apply for the memory list. > > Signed-off-by: Philipp Hachtmann > --- > include/linux/memblock.h | 1 + > mm/memblock.c | 12 ++++++++++++ > mm/nobootmem.c | 7 ++++++- > 3 files changed, 19 insertions(+), 1 deletion(-) > > diff --git a/include/linux/memblock.h b/include/linux/memblock.h > index 77c60e5..d174922 100644 > --- a/include/linux/memblock.h > +++ b/include/linux/memblock.h > @@ -52,6 +52,7 @@ phys_addr_t memblock_find_in_range_node(phys_addr_t start, phys_addr_t end, > phys_addr_t memblock_find_in_range(phys_addr_t start, phys_addr_t end, > phys_addr_t size, phys_addr_t align); > phys_addr_t get_allocated_memblock_reserved_regions_info(phys_addr_t *addr); > +phys_addr_t get_allocated_memblock_memory_regions_info(phys_addr_t *addr); > void memblock_allow_resize(void); > int memblock_add_node(phys_addr_t base, phys_addr_t size, int nid); > int memblock_add(phys_addr_t base, phys_addr_t size); > diff --git a/mm/memblock.c b/mm/memblock.c > index 53e477b..1a11d04 100644 > --- a/mm/memblock.c > +++ b/mm/memblock.c > @@ -271,6 +271,18 @@ phys_addr_t __init_memblock get_allocated_memblock_reserved_regions_info( > memblock.reserved.max); > } > > +phys_addr_t __init_memblock get_allocated_memblock_memory_regions_info( > + phys_addr_t *addr) > +{ > + if (memblock.memory.regions == memblock_memory_init_regions) > + return 0; > + > + *addr = __pa(memblock.memory.regions); > + > + return PAGE_ALIGN(sizeof(struct memblock_region) * > + memblock.memory.max); > +} > + > /** > * memblock_double_array - double the size of the memblock regions array > * @type: memblock type of the regions array being doubled > diff --git a/mm/nobootmem.c b/mm/nobootmem.c > index 3a7e14d..83f36d3 100644 > --- a/mm/nobootmem.c > +++ b/mm/nobootmem.c > @@ -122,11 +122,16 @@ static unsigned long __init free_low_memory_core_early(void) > for_each_free_mem_range(i, MAX_NUMNODES, &start, &end, NULL) > count += __free_memory_core(start, end); > > - /* free range that is used for reserved array if we allocate it */ > + /* Free memblock.reserved array if it was allocated */ > size = get_allocated_memblock_reserved_regions_info(&start); > if (size) > count += __free_memory_core(start, start + size); > > + /* Free memblock.memory array if it was allocated */ > + size = get_allocated_memblock_memory_regions_info(&start); > + if (size) > + count += __free_memory_core(start, start + size); > + Hi Philipp, For some archs, like arm64, would use memblock.memory after system booting, so we can not simply released to the buddy allocator, maybe need !defined(CONFIG_ARCH_DISCARD_MEMBLOCK). #ifdef CONFIG_HAVE_ARCH_PFN_VALID int pfn_valid(unsigned long pfn) { return memblock_is_memory(pfn << PAGE_SHIFT); } EXPORT_SYMBOL(pfn_valid); Thanks, Jianguo Wu > return count; > } > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756765AbaAHNm0 (ORCPT ); Wed, 8 Jan 2014 08:42:26 -0500 Received: from e06smtp12.uk.ibm.com ([195.75.94.108]:42525 "EHLO e06smtp12.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756045AbaAHNmW convert rfc822-to-8bit (ORCPT ); Wed, 8 Jan 2014 08:42:22 -0500 Date: Wed, 8 Jan 2014 14:42:13 +0100 From: Philipp Hachtmann To: Jianguo Wu Cc: , , , , , , , , Subject: Re: [PATCH 2/2] mm: free memblock.memory in free_all_bootmem Message-ID: <20140108144213.4c1995b2@lilie> In-Reply-To: <52CCCF24.4080300@huawei.com> References: <1389107774-54978-1-git-send-email-phacht@linux.vnet.ibm.com> <1389107774-54978-3-git-send-email-phacht@linux.vnet.ibm.com> <52CCCF24.4080300@huawei.com> X-Mailer: Claws Mail 3.8.0 (GTK+ 2.24.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8BIT X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14010813-8372-0000-0000-000008465E17 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am Wed, 8 Jan 2014 12:08:04 +0800 schrieb Jianguo Wu : > For some archs, like arm64, would use memblock.memory after system > booting, so we can not simply released to the buddy allocator, maybe > need !defined(CONFIG_ARCH_DISCARD_MEMBLOCK). Oh, I see. I have added some ifdefs to prevent memblock.memory from being freed when CONFIG_ARCH_DISCARD_MEMBLOCK is not set. Here is a replacement for the patch. Kind regards Philipp >>From aca95bcb9d79388b68bf18e7bae4353259b6758f Mon Sep 17 00:00:00 2001 From: Philipp Hachtmann Date: Thu, 19 Dec 2013 15:53:46 +0100 Subject: [PATCH 2/2] mm: free memblock.memory in free_all_bootmem When calling free_all_bootmem() the free areas under memblock's control are released to the buddy allocator. Additionally the reserved list is freed if it was reallocated by memblock. The same should apply for the memory list. Signed-off-by: Philipp Hachtmann --- include/linux/memblock.h | 1 + mm/memblock.c | 16 ++++++++++++++++ mm/nobootmem.c | 10 +++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 77c60e5..d174922 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -52,6 +52,7 @@ phys_addr_t memblock_find_in_range_node(phys_addr_t start, phys_addr_t end, phys_addr_t memblock_find_in_range(phys_addr_t start, phys_addr_t end, phys_addr_t size, phys_addr_t align); phys_addr_t get_allocated_memblock_reserved_regions_info(phys_addr_t *addr); +phys_addr_t get_allocated_memblock_memory_regions_info(phys_addr_t *addr); void memblock_allow_resize(void); int memblock_add_node(phys_addr_t base, phys_addr_t size, int nid); int memblock_add(phys_addr_t base, phys_addr_t size); diff --git a/mm/memblock.c b/mm/memblock.c index 53e477b..a78b2e9 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -271,6 +271,22 @@ phys_addr_t __init_memblock get_allocated_memblock_reserved_regions_info( memblock.reserved.max); } +#ifdef CONFIG_ARCH_DISCARD_MEMBLOCK + +phys_addr_t __init_memblock get_allocated_memblock_memory_regions_info( + phys_addr_t *addr) +{ + if (memblock.memory.regions == memblock_memory_init_regions) + return 0; + + *addr = __pa(memblock.memory.regions); + + return PAGE_ALIGN(sizeof(struct memblock_region) * + memblock.memory.max); +} + +#endif + /** * memblock_double_array - double the size of the memblock regions array * @type: memblock type of the regions array being doubled diff --git a/mm/nobootmem.c b/mm/nobootmem.c index 3a7e14d..63ff3f6 100644 --- a/mm/nobootmem.c +++ b/mm/nobootmem.c @@ -122,11 +122,19 @@ static unsigned long __init free_low_memory_core_early(void) for_each_free_mem_range(i, MAX_NUMNODES, &start, &end, NULL) count += __free_memory_core(start, end); - /* free range that is used for reserved array if we allocate it */ + /* Free memblock.reserved array if it was allocated */ size = get_allocated_memblock_reserved_regions_info(&start); if (size) count += __free_memory_core(start, start + size); +#ifdef CONFIG_ARCH_DISCARD_MEMBLOCK + + /* Free memblock.memory array if it was allocated */ + size = get_allocated_memblock_memory_regions_info(&start); + if (size) + count += __free_memory_core(start, start + size); +#endif + return count; } -- 1.8.4.5 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757602AbaAHXbA (ORCPT ); Wed, 8 Jan 2014 18:31:00 -0500 Received: from mail-ie0-f182.google.com ([209.85.223.182]:49241 "EHLO mail-ie0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757109AbaAHXa6 (ORCPT ); Wed, 8 Jan 2014 18:30:58 -0500 MIME-Version: 1.0 In-Reply-To: <20140108144213.4c1995b2@lilie> References: <1389107774-54978-1-git-send-email-phacht@linux.vnet.ibm.com> <1389107774-54978-3-git-send-email-phacht@linux.vnet.ibm.com> <52CCCF24.4080300@huawei.com> <20140108144213.4c1995b2@lilie> Date: Wed, 8 Jan 2014 15:30:57 -0800 X-Google-Sender-Auth: -xH8FafCMYblyLQ4IMglDqcHxJw Message-ID: Subject: Re: [PATCH 2/2] mm: free memblock.memory in free_all_bootmem From: Yinghai Lu To: Philipp Hachtmann Cc: Jianguo Wu , Andrew Morton , Jiang Liu , Linux Kernel Mailing List , Linux MM , Joonsoo Kim , Johannes Weiner , Tang Chen , Tejun Heo , Toshi Kani 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 On Wed, Jan 8, 2014 at 5:42 AM, Philipp Hachtmann wrote: > Am Wed, 8 Jan 2014 12:08:04 +0800 > schrieb Jianguo Wu : > >> For some archs, like arm64, would use memblock.memory after system >> booting, so we can not simply released to the buddy allocator, maybe >> need !defined(CONFIG_ARCH_DISCARD_MEMBLOCK). > > Oh, I see. I have added some ifdefs to prevent memblock.memory from > being freed when CONFIG_ARCH_DISCARD_MEMBLOCK is not set. > > Here is a replacement for the patch. > > Kind regards > > Philipp > > From aca95bcb9d79388b68bf18e7bae4353259b6758f Mon Sep 17 00:00:00 2001 > From: Philipp Hachtmann > Date: Thu, 19 Dec 2013 15:53:46 +0100 > Subject: [PATCH 2/2] mm: free memblock.memory in free_all_bootmem > > When calling free_all_bootmem() the free areas under memblock's > control are released to the buddy allocator. Additionally the > reserved list is freed if it was reallocated by memblock. > The same should apply for the memory list. > > Signed-off-by: Philipp Hachtmann > --- > include/linux/memblock.h | 1 + > mm/memblock.c | 16 ++++++++++++++++ > mm/nobootmem.c | 10 +++++++++- > 3 files changed, 26 insertions(+), 1 deletion(-) > > diff --git a/include/linux/memblock.h b/include/linux/memblock.h > index 77c60e5..d174922 100644 > --- a/include/linux/memblock.h > +++ b/include/linux/memblock.h > @@ -52,6 +52,7 @@ phys_addr_t memblock_find_in_range_node(phys_addr_t start, phys_addr_t end, > phys_addr_t memblock_find_in_range(phys_addr_t start, phys_addr_t end, > phys_addr_t size, phys_addr_t align); > phys_addr_t get_allocated_memblock_reserved_regions_info(phys_addr_t *addr); > +phys_addr_t get_allocated_memblock_memory_regions_info(phys_addr_t *addr); > void memblock_allow_resize(void); > int memblock_add_node(phys_addr_t base, phys_addr_t size, int nid); > int memblock_add(phys_addr_t base, phys_addr_t size); > diff --git a/mm/memblock.c b/mm/memblock.c > index 53e477b..a78b2e9 100644 > --- a/mm/memblock.c > +++ b/mm/memblock.c > @@ -271,6 +271,22 @@ phys_addr_t __init_memblock get_allocated_memblock_reserved_regions_info( > memblock.reserved.max); > } > > +#ifdef CONFIG_ARCH_DISCARD_MEMBLOCK > + > +phys_addr_t __init_memblock get_allocated_memblock_memory_regions_info( > + phys_addr_t *addr) > +{ > + if (memblock.memory.regions == memblock_memory_init_regions) > + return 0; > + > + *addr = __pa(memblock.memory.regions); > + > + return PAGE_ALIGN(sizeof(struct memblock_region) * > + memblock.memory.max); > +} > + > +#endif > + > /** > * memblock_double_array - double the size of the memblock regions array > * @type: memblock type of the regions array being doubled > diff --git a/mm/nobootmem.c b/mm/nobootmem.c > index 3a7e14d..63ff3f6 100644 > --- a/mm/nobootmem.c > +++ b/mm/nobootmem.c > @@ -122,11 +122,19 @@ static unsigned long __init free_low_memory_core_early(void) > for_each_free_mem_range(i, MAX_NUMNODES, &start, &end, NULL) > count += __free_memory_core(start, end); > > - /* free range that is used for reserved array if we allocate it */ > + /* Free memblock.reserved array if it was allocated */ > size = get_allocated_memblock_reserved_regions_info(&start); > if (size) > count += __free_memory_core(start, start + size); > > +#ifdef CONFIG_ARCH_DISCARD_MEMBLOCK > + > + /* Free memblock.memory array if it was allocated */ > + size = get_allocated_memblock_memory_regions_info(&start); > + if (size) > + count += __free_memory_core(start, start + size); > +#endif > + > return count; > } I sent similar before. http://www.gossamer-threads.com/lists/engine?do=post_attachment;postatt_id=49616;list=linux http://www.gossamer-threads.com/lists/linux/kernel/1556026?do=post_view_threaded#1556026 Also for arches that do not free memblock, do they still need to access memblock.reserved.regions ? Yinghai