Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754128Ab0GVS0f (ORCPT ); Thu, 22 Jul 2010 14:26:35 -0400 Received: from rcsinet10.oracle.com ([148.87.113.121]:42707 "EHLO rcsinet10.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759436Ab0GVSWl (ORCPT ); Thu, 22 Jul 2010 14:22:41 -0400 From: Yinghai Lu To: Ingo Molnar , Thomas Gleixner , "H. Peter Anvin" , Andrew Morton , David Miller , Benjamin Herrenschmidt , Linus Torvalds Cc: Johannes Weiner , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, Benjamin Herrenschmidt , Yinghai Lu Subject: [PATCH 17/31] memblock: split memblock_find_base() out of __memblock_alloc_base() Date: Thu, 22 Jul 2010 11:20:50 -0700 Message-Id: <1279822864-17154-18-git-send-email-yinghai@kernel.org> X-Mailer: git-send-email 1.6.4.2 In-Reply-To: <1279822864-17154-1-git-send-email-yinghai@kernel.org> References: <1279822864-17154-1-git-send-email-yinghai@kernel.org> X-Source-IP: acsmt354.oracle.com [141.146.40.154] X-Auth-Type: Internal IP X-CT-RefId: str=0001.0A090208.4C488C45.01BF,ss=1,fgs=0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4021 Lines: 122 From: Benjamin Herrenschmidt This will be used by the array resize code and might prove useful to some arch code as well at which point it can be made non-static. Also add comment as to why aligning size is important [ Yinghai Lu ]: it should return MEMBLOCK_ERROR when it fail to find a range Signed-off-by: Yinghai Lu Signed-off-by: Benjamin Herrenschmidt --- mm/memblock.c | 58 +++++++++++++++++++++++++++++++++++++------------------- 1 files changed, 38 insertions(+), 20 deletions(-) diff --git a/mm/memblock.c b/mm/memblock.c index 1283893..17403e6 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -345,12 +345,15 @@ phys_addr_t __init memblock_alloc_nid(phys_addr_t size, phys_addr_t align, int n BUG_ON(0 == size); + /* We align the size to limit fragmentation. Without this, a lot of + * small allocs quickly eat up the whole reserve array on sparc + */ + size = memblock_align_up(size, align); + /* We do a bottom-up search for a region with the right * nid since that's easier considering how memblock_nid_range() * works */ - size = memblock_align_up(size, align); - for (i = 0; i < mem->cnt; i++) { phys_addr_t ret = memblock_alloc_nid_region(&mem->regions[i], size, align, nid); @@ -366,20 +369,7 @@ phys_addr_t __init memblock_alloc(phys_addr_t size, phys_addr_t align) return memblock_alloc_base(size, align, MEMBLOCK_ALLOC_ACCESSIBLE); } -phys_addr_t __init memblock_alloc_base(phys_addr_t size, phys_addr_t align, phys_addr_t max_addr) -{ - phys_addr_t alloc; - - alloc = __memblock_alloc_base(size, align, max_addr); - - if (alloc == 0) - panic("ERROR: Failed to allocate 0x%llx bytes below 0x%llx.\n", - (unsigned long long) size, (unsigned long long) max_addr); - - return alloc; -} - -phys_addr_t __init __memblock_alloc_base(phys_addr_t size, phys_addr_t align, phys_addr_t max_addr) +static phys_addr_t __init memblock_find_base(phys_addr_t size, phys_addr_t align, phys_addr_t max_addr) { long i; phys_addr_t base = 0; @@ -387,8 +377,6 @@ phys_addr_t __init __memblock_alloc_base(phys_addr_t size, phys_addr_t align, ph BUG_ON(0 == size); - size = memblock_align_up(size, align); - /* Pump up max_addr */ if (max_addr == MEMBLOCK_ALLOC_ACCESSIBLE) max_addr = memblock.current_limit; @@ -405,13 +393,43 @@ phys_addr_t __init __memblock_alloc_base(phys_addr_t size, phys_addr_t align, ph continue; base = min(memblockbase + memblocksize, max_addr); res_base = memblock_find_region(memblockbase, base, size, align); - if (res_base != MEMBLOCK_ERROR && - memblock_add_region(&memblock.reserved, res_base, size) >= 0) + if (res_base != MEMBLOCK_ERROR) return res_base; } + return MEMBLOCK_ERROR; +} + +phys_addr_t __init __memblock_alloc_base(phys_addr_t size, phys_addr_t align, phys_addr_t max_addr) +{ + phys_addr_t found; + + /* We align the size to limit fragmentation. Without this, a lot of + * small allocs quickly eat up the whole reserve array on sparc + */ + size = memblock_align_up(size, align); + + found = memblock_find_base(size, align, max_addr); + if (found != MEMBLOCK_ERROR && + memblock_add_region(&memblock.reserved, found, size) >= 0) + return found; + return 0; } +phys_addr_t __init memblock_alloc_base(phys_addr_t size, phys_addr_t align, phys_addr_t max_addr) +{ + phys_addr_t alloc; + + alloc = __memblock_alloc_base(size, align, max_addr); + + if (alloc == 0) + panic("ERROR: Failed to allocate 0x%llx bytes below 0x%llx.\n", + (unsigned long long) size, (unsigned long long) max_addr); + + return alloc; +} + + /* You must call memblock_analyze() before this. */ phys_addr_t __init memblock_phys_mem_size(void) { -- 1.6.4.2 -- 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/