diff options
author | Tejun Heo <tj@kernel.org> | 2011-12-08 13:22:07 -0500 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2011-12-08 13:22:07 -0500 |
commit | c0ce8fef55896a2813a3d94e1b2d0e6d7fab6228 (patch) | |
tree | 616396e0b08f0a41eafd7d4a10bd3b2fee5726c8 /mm/memblock.c | |
parent | eb18f1b5bfb99b1d7d2f5d792e6ee5c9b7d89330 (diff) |
memblock: Reimplement memblock_enforce_memory_limit() using __memblock_remove()
With recent updates, the basic memblock operations are robust enough
that there's no reason for memblock_enfore_memory_limit() to directly
manipulate memblock region arrays. Reimplement it using
__memblock_remove().
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/memblock.c')
-rw-r--r-- | mm/memblock.c | 42 |
1 files changed, 13 insertions, 29 deletions
diff --git a/mm/memblock.c b/mm/memblock.c index 945dc31258eb..b44875f5a996 100644 --- a/mm/memblock.c +++ b/mm/memblock.c | |||
@@ -804,44 +804,28 @@ phys_addr_t __init_memblock memblock_end_of_DRAM(void) | |||
804 | } | 804 | } |
805 | 805 | ||
806 | /* You must call memblock_analyze() after this. */ | 806 | /* You must call memblock_analyze() after this. */ |
807 | void __init memblock_enforce_memory_limit(phys_addr_t memory_limit) | 807 | void __init memblock_enforce_memory_limit(phys_addr_t limit) |
808 | { | 808 | { |
809 | unsigned long i; | 809 | unsigned long i; |
810 | phys_addr_t limit; | 810 | phys_addr_t max_addr = (phys_addr_t)ULLONG_MAX; |
811 | struct memblock_region *p; | ||
812 | 811 | ||
813 | if (!memory_limit) | 812 | if (!limit) |
814 | return; | 813 | return; |
815 | 814 | ||
816 | /* Truncate the memblock regions to satisfy the memory limit. */ | 815 | /* find out max address */ |
817 | limit = memory_limit; | ||
818 | for (i = 0; i < memblock.memory.cnt; i++) { | 816 | for (i = 0; i < memblock.memory.cnt; i++) { |
819 | if (limit > memblock.memory.regions[i].size) { | 817 | struct memblock_region *r = &memblock.memory.regions[i]; |
820 | limit -= memblock.memory.regions[i].size; | ||
821 | continue; | ||
822 | } | ||
823 | |||
824 | memblock.memory.regions[i].size = limit; | ||
825 | memblock.memory.cnt = i + 1; | ||
826 | break; | ||
827 | } | ||
828 | |||
829 | memory_limit = memblock_end_of_DRAM(); | ||
830 | 818 | ||
831 | /* And truncate any reserves above the limit also. */ | 819 | if (limit <= r->size) { |
832 | for (i = 0; i < memblock.reserved.cnt; i++) { | 820 | max_addr = r->base + limit; |
833 | p = &memblock.reserved.regions[i]; | 821 | break; |
834 | |||
835 | if (p->base > memory_limit) | ||
836 | p->size = 0; | ||
837 | else if ((p->base + p->size) > memory_limit) | ||
838 | p->size = memory_limit - p->base; | ||
839 | |||
840 | if (p->size == 0) { | ||
841 | memblock_remove_region(&memblock.reserved, i); | ||
842 | i--; | ||
843 | } | 822 | } |
823 | limit -= r->size; | ||
844 | } | 824 | } |
825 | |||
826 | /* truncate both memory and reserved regions */ | ||
827 | __memblock_remove(&memblock.memory, max_addr, (phys_addr_t)ULLONG_MAX); | ||
828 | __memblock_remove(&memblock.reserved, max_addr, (phys_addr_t)ULLONG_MAX); | ||
845 | } | 829 | } |
846 | 830 | ||
847 | static int __init_memblock memblock_search(struct memblock_type *type, phys_addr_t addr) | 831 | static int __init_memblock memblock_search(struct memblock_type *type, phys_addr_t addr) |