memblock, x86: Reimplement memblock_find_dma_reserve() using iterators
memblock_find_dma_reserve() wants to find out how much memory is reserved under MAX_DMA_PFN. memblock_x86_memory_[free_]in_range() are used to find out the amounts of all available and free memory in the area, which are then subtracted to find out the amount of reservation. memblock_x86_memblock_[free_]in_range() are implemented using __memblock_x86_memory_in_range() which builds ranges from memblock and then count them, which is rather unnecessarily complex. This patch open codes the counting logic directly in memblock_find_dma_reserve() using memblock iterators and removes now unused __memblock_x86_memory_in_range() and find_range_array(). Signed-off-by: Tejun Heo <tj@kernel.org> Link: http://lkml.kernel.org/r/1310462166-31469-11-git-send-email-tj@kernel.org Cc: Yinghai Lu <yinghai@kernel.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@redhat.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
This commit is contained in:

committed by
H. Peter Anvin

parent
8a9ca34c11
commit
6b5d41a1b9
@@ -1093,15 +1093,30 @@ void __init memblock_x86_fill(void)
|
||||
void __init memblock_find_dma_reserve(void)
|
||||
{
|
||||
#ifdef CONFIG_X86_64
|
||||
u64 free_size_pfn;
|
||||
u64 mem_size_pfn;
|
||||
u64 nr_pages = 0, nr_free_pages = 0;
|
||||
unsigned long start_pfn, end_pfn;
|
||||
phys_addr_t start, end;
|
||||
int i;
|
||||
u64 u;
|
||||
|
||||
/*
|
||||
* need to find out used area below MAX_DMA_PFN
|
||||
* need to use memblock to get free size in [0, MAX_DMA_PFN]
|
||||
* at first, and assume boot_mem will not take below MAX_DMA_PFN
|
||||
*/
|
||||
mem_size_pfn = memblock_x86_memory_in_range(0, MAX_DMA_PFN << PAGE_SHIFT) >> PAGE_SHIFT;
|
||||
free_size_pfn = memblock_x86_free_memory_in_range(0, MAX_DMA_PFN << PAGE_SHIFT) >> PAGE_SHIFT;
|
||||
set_dma_reserve(mem_size_pfn - free_size_pfn);
|
||||
for_each_mem_pfn_range(i, MAX_NUMNODES, &start_pfn, &end_pfn, NULL) {
|
||||
start_pfn = min_t(unsigned long, start_pfn, MAX_DMA_PFN);
|
||||
end_pfn = min_t(unsigned long, end_pfn, MAX_DMA_PFN);
|
||||
nr_pages += end_pfn - start_pfn;
|
||||
}
|
||||
|
||||
for_each_free_mem_range(u, MAX_NUMNODES, &start, &end, NULL) {
|
||||
start_pfn = min_t(unsigned long, PFN_UP(start), MAX_DMA_PFN);
|
||||
end_pfn = min_t(unsigned long, PFN_DOWN(end), MAX_DMA_PFN);
|
||||
if (start_pfn < end_pfn)
|
||||
nr_free_pages += end_pfn - start_pfn;
|
||||
}
|
||||
|
||||
set_dma_reserve(nr_pages - nr_free_pages);
|
||||
#endif
|
||||
}
|
||||
|
Reference in New Issue
Block a user