memblock: Add arch function to control coalescing of memblock memory regions
authorBenjamin Herrenschmidt <benh@kernel.crashing.org>
Tue, 6 Jul 2010 22:39:14 +0000 (15:39 -0700)
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>
Thu, 5 Aug 2010 02:56:21 +0000 (12:56 +1000)
Some archs such as ARM want to avoid coalescing accross things such
as the lowmem/highmem boundary or similar. This provides the option
to control it via an arch callback for which a weak default is provided
which always allows coalescing.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
include/linux/memblock.h
mm/memblock.c

index 150be938b910b608d1dbc32cec60acf2b6ec2d85..e5e8f9db3a84b185d97fb9e972530f67d181d6a4 100644 (file)
@@ -72,6 +72,8 @@ extern void memblock_dump_all(void);
 
 /* Provided by the architecture */
 extern phys_addr_t memblock_nid_range(phys_addr_t start, phys_addr_t end, int *nid);
+extern int memblock_memory_can_coalesce(phys_addr_t addr1, phys_addr_t size1,
+                                  phys_addr_t addr2, phys_addr_t size2);
 
 /**
  * memblock_set_current_limit - Set the current allocation limit to allow
index 0787790b1ce0b0f7fd30b86f9563c16e9acde63f..8715f09434dfd18a7851b800698777e9941933f9 100644 (file)
@@ -241,6 +241,12 @@ static int memblock_double_array(struct memblock_type *type)
        return 0;
 }
 
+extern int __weak memblock_memory_can_coalesce(phys_addr_t addr1, phys_addr_t size1,
+                                         phys_addr_t addr2, phys_addr_t size2)
+{
+       return 1;
+}
+
 static long memblock_add_region(struct memblock_type *type, phys_addr_t base, phys_addr_t size)
 {
        unsigned long coalesced = 0;
@@ -262,6 +268,10 @@ static long memblock_add_region(struct memblock_type *type, phys_addr_t base, ph
                        return 0;
 
                adjacent = memblock_addrs_adjacent(base, size, rgnbase, rgnsize);
+               /* Check if arch allows coalescing */
+               if (adjacent != 0 && type == &memblock.memory &&
+                   !memblock_memory_can_coalesce(base, size, rgnbase, rgnsize))
+                       break;
                if (adjacent > 0) {
                        type->regions[i].base -= size;
                        type->regions[i].size += size;
@@ -274,7 +284,14 @@ static long memblock_add_region(struct memblock_type *type, phys_addr_t base, ph
                }
        }
 
-       if ((i < type->cnt - 1) && memblock_regions_adjacent(type, i, i+1)) {
+       /* If we plugged a hole, we may want to also coalesce with the
+        * next region
+        */
+       if ((i < type->cnt - 1) && memblock_regions_adjacent(type, i, i+1) &&
+           ((type != &memblock.memory || memblock_memory_can_coalesce(type->regions[i].base,
+                                                            type->regions[i].size,
+                                                            type->regions[i+1].base,
+                                                            type->regions[i+1].size)))) {
                memblock_coalesce_regions(type, i, i+1);
                coalesced++;
        }