aboutsummaryrefslogtreecommitdiffstats
path: root/mm
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2011-12-08 13:22:08 -0500
committerTejun Heo <tj@kernel.org>2011-12-08 13:22:08 -0500
commit1440c4e2c918532f39131c3330fe2226e16be7b6 (patch)
tree316b945da272f43bdb88d295c48926e471e47fad /mm
parent6fbef13c4feaf0c5576e2315f4d2999c4b670c88 (diff)
memblock: Track total size of regions automatically
Total size of memory regions was calculated by memblock_analyze() requiring explicitly calling the function between operations which can change memory regions and possible users of total size, which is cumbersome and fragile. This patch makes each memblock_type track total size automatically with minor modifications to memblock manipulation functions and remove requirements on calling memblock_analyze(). [__]memblock_dump_all() now also dumps the total size of reserved regions. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Yinghai Lu <yinghai@kernel.org>
Diffstat (limited to 'mm')
-rw-r--r--mm/memblock.c27
1 files changed, 13 insertions, 14 deletions
diff --git a/mm/memblock.c b/mm/memblock.c
index b44875f5a996..f39964184b4a 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -179,12 +179,14 @@ int __init_memblock memblock_reserve_reserved_regions(void)
179 179
180static void __init_memblock memblock_remove_region(struct memblock_type *type, unsigned long r) 180static void __init_memblock memblock_remove_region(struct memblock_type *type, unsigned long r)
181{ 181{
182 type->total_size -= type->regions[r].size;
182 memmove(&type->regions[r], &type->regions[r + 1], 183 memmove(&type->regions[r], &type->regions[r + 1],
183 (type->cnt - (r + 1)) * sizeof(type->regions[r])); 184 (type->cnt - (r + 1)) * sizeof(type->regions[r]));
184 type->cnt--; 185 type->cnt--;
185 186
186 /* Special case for empty arrays */ 187 /* Special case for empty arrays */
187 if (type->cnt == 0) { 188 if (type->cnt == 0) {
189 WARN_ON(type->total_size != 0);
188 type->cnt = 1; 190 type->cnt = 1;
189 type->regions[0].base = 0; 191 type->regions[0].base = 0;
190 type->regions[0].size = 0; 192 type->regions[0].size = 0;
@@ -314,6 +316,7 @@ static void __init_memblock memblock_insert_region(struct memblock_type *type,
314 rgn->size = size; 316 rgn->size = size;
315 memblock_set_region_node(rgn, nid); 317 memblock_set_region_node(rgn, nid);
316 type->cnt++; 318 type->cnt++;
319 type->total_size += size;
317} 320}
318 321
319/** 322/**
@@ -340,10 +343,11 @@ static int __init_memblock memblock_add_region(struct memblock_type *type,
340 343
341 /* special case for empty array */ 344 /* special case for empty array */
342 if (type->regions[0].size == 0) { 345 if (type->regions[0].size == 0) {
343 WARN_ON(type->cnt != 1); 346 WARN_ON(type->cnt != 1 || type->total_size);
344 type->regions[0].base = base; 347 type->regions[0].base = base;
345 type->regions[0].size = size; 348 type->regions[0].size = size;
346 memblock_set_region_node(&type->regions[0], MAX_NUMNODES); 349 memblock_set_region_node(&type->regions[0], MAX_NUMNODES);
350 type->total_size = size;
347 return 0; 351 return 0;
348 } 352 }
349repeat: 353repeat:
@@ -453,7 +457,8 @@ static int __init_memblock memblock_isolate_range(struct memblock_type *type,
453 * to process the next region - the new top half. 457 * to process the next region - the new top half.
454 */ 458 */
455 rgn->base = base; 459 rgn->base = base;
456 rgn->size = rend - rgn->base; 460 rgn->size -= base - rbase;
461 type->total_size -= base - rbase;
457 memblock_insert_region(type, i, rbase, base - rbase, 462 memblock_insert_region(type, i, rbase, base - rbase,
458 memblock_get_region_node(rgn)); 463 memblock_get_region_node(rgn));
459 } else if (rend > end) { 464 } else if (rend > end) {
@@ -462,7 +467,8 @@ static int __init_memblock memblock_isolate_range(struct memblock_type *type,
462 * current region - the new bottom half. 467 * current region - the new bottom half.
463 */ 468 */
464 rgn->base = end; 469 rgn->base = end;
465 rgn->size = rend - rgn->base; 470 rgn->size -= end - rbase;
471 type->total_size -= end - rbase;
466 memblock_insert_region(type, i--, rbase, end - rbase, 472 memblock_insert_region(type, i--, rbase, end - rbase,
467 memblock_get_region_node(rgn)); 473 memblock_get_region_node(rgn));
468 } else { 474 } else {
@@ -784,10 +790,9 @@ phys_addr_t __init memblock_alloc_try_nid(phys_addr_t size, phys_addr_t align, i
784 * Remaining API functions 790 * Remaining API functions
785 */ 791 */
786 792
787/* You must call memblock_analyze() before this. */
788phys_addr_t __init memblock_phys_mem_size(void) 793phys_addr_t __init memblock_phys_mem_size(void)
789{ 794{
790 return memblock.memory_size; 795 return memblock.memory.total_size;
791} 796}
792 797
793/* lowest address */ 798/* lowest address */
@@ -803,7 +808,6 @@ phys_addr_t __init_memblock memblock_end_of_DRAM(void)
803 return (memblock.memory.regions[idx].base + memblock.memory.regions[idx].size); 808 return (memblock.memory.regions[idx].base + memblock.memory.regions[idx].size);
804} 809}
805 810
806/* You must call memblock_analyze() after this. */
807void __init memblock_enforce_memory_limit(phys_addr_t limit) 811void __init memblock_enforce_memory_limit(phys_addr_t limit)
808{ 812{
809 unsigned long i; 813 unsigned long i;
@@ -906,7 +910,9 @@ static void __init_memblock memblock_dump(struct memblock_type *type, char *name
906void __init_memblock __memblock_dump_all(void) 910void __init_memblock __memblock_dump_all(void)
907{ 911{
908 pr_info("MEMBLOCK configuration:\n"); 912 pr_info("MEMBLOCK configuration:\n");
909 pr_info(" memory size = 0x%llx\n", (unsigned long long)memblock.memory_size); 913 pr_info(" memory size = %#llx reserved size = %#llx\n",
914 (unsigned long long)memblock.memory.total_size,
915 (unsigned long long)memblock.reserved.total_size);
910 916
911 memblock_dump(&memblock.memory, "memory"); 917 memblock_dump(&memblock.memory, "memory");
912 memblock_dump(&memblock.reserved, "reserved"); 918 memblock_dump(&memblock.reserved, "reserved");
@@ -914,13 +920,6 @@ void __init_memblock __memblock_dump_all(void)
914 920
915void __init memblock_analyze(void) 921void __init memblock_analyze(void)
916{ 922{
917 int i;
918
919 memblock.memory_size = 0;
920
921 for (i = 0; i < memblock.memory.cnt; i++)
922 memblock.memory_size += memblock.memory.regions[i].size;
923
924 /* We allow resizing from there */ 923 /* We allow resizing from there */
925 memblock_can_resize = 1; 924 memblock_can_resize = 1;
926} 925}