Skip to content

Commit 6503357

Browse files
committed
arm64: swiotlb: Reduce the default size if no ZONE_DMA bouncing needed
With CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC enabled, the arm64 kernel still allocates the default SWIOTLB buffer (64MB) even if ZONE_DMA is disabled or all the RAM fits into this zone. However, this potentially wastes a non-negligible amount of memory on platforms with little RAM. Reduce the SWIOTLB size to 1MB per 1GB of RAM if only needed for kmalloc() buffer bouncing. Signed-off-by: Catalin Marinas <[email protected]> Suggested-by: Ross Burton <[email protected]> Cc: Ross Burton <[email protected]> Cc: Will Deacon <[email protected]> Reviewed-by: Robin Murphy <[email protected]>
1 parent 6465e26 commit 6503357

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

arch/arm64/mm/init.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/nodemask.h>
1717
#include <linux/initrd.h>
1818
#include <linux/gfp.h>
19+
#include <linux/math.h>
1920
#include <linux/memblock.h>
2021
#include <linux/sort.h>
2122
#include <linux/of.h>
@@ -493,8 +494,16 @@ void __init mem_init(void)
493494
{
494495
bool swiotlb = max_pfn > PFN_DOWN(arm64_dma_phys_limit);
495496

496-
if (IS_ENABLED(CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC))
497+
if (IS_ENABLED(CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC) && !swiotlb) {
498+
/*
499+
* If no bouncing needed for ZONE_DMA, reduce the swiotlb
500+
* buffer for kmalloc() bouncing to 1MB per 1GB of RAM.
501+
*/
502+
unsigned long size =
503+
DIV_ROUND_UP(memblock_phys_mem_size(), 1024);
504+
swiotlb_adjust_size(min(swiotlb_size_or_default(), size));
497505
swiotlb = true;
506+
}
498507

499508
swiotlb_init(swiotlb, SWIOTLB_VERBOSE);
500509

0 commit comments

Comments
 (0)