arm64: swiotlb: Reduce the default size if no ZONE_DMA bouncing needed
Catalin Marinas
maintainerPATCH 1/1 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.
--- arch/arm64/mm/init.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
arch/arm64/mm/init.c +9 -1
@@ -493,8 +493,16 @@ void __init mem_init(void) {bool swiotlb = max_pfn >PFN_DOWN (arm64_dma_phys_limit); -if (IS_ENABLED (CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC )) +if (IS_ENABLED (CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC ) && !swiotlb) { +/* +* If no bouncing needed for ZONE_DMA, reduce the swiotlb +* buffer for kmalloc() bouncing to 1MB per 1GB of RAM. +*/ +unsigned long size = +ALIGN (memblock_phys_mem_size (),SZ_1G ) >>10 ; +swiotlb_adjust_size (min (swiotlb_size_or_default (), size)); swiotlb = true; + }swiotlb_init (swiotlb,SWIOTLB_VERBOSE );
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 23 lines · Catalin Marinas
With
CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOCenabled, the arm64 kernel still allocates the default SWIOTLB buffer (64MB) even ifZONE_DMAis 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 Robin Murphy <[email protected]>Cc Will Deacon <[email protected]>--- arch/arm64/mm/init.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)arch/arm64/mm/init.c +0
-0@@ -493,8 +493,16 @@ void __init mem_init(void) {
arch/arm64/mm/init.c void __init mem_init(void) · line 502
Quoted 10 lines
arch/arm64/mm/init.c +7
-1bool swiotlb = max_pfn >PFN_DOWN (arm64_dma_phys_limit); -if (IS_ENABLED (CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC )) +if (IS_ENABLED (CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC ) && !swiotlb) { +/* +* If no bouncing needed for ZONE_DMA, reduce the swiotlb +* buffer for kmalloc() bouncing to 1MB per 1GB of RAM. +*/ +unsigned long size = +ALIGN (memblock_phys_mem_size (),SZ_1G ) >>10 ;
Hmm, I wondered if DIV_ROUND_UP(memblock_phys_mem_size(), 1024) might be any easier, but by the time I've typed it out it's still just as long :)
Either way then,
Reviewed-by Robin Murphy <[email protected]>
arch/arm64/mm/init.c void __init mem_init(void) · line 508
Quoted 6 lines
arch/arm64/mm/init.c +2
-0+swiotlb_adjust_size (min (swiotlb_size_or_default (), size)); swiotlb = true; + }swiotlb_init (swiotlb,SWIOTLB_VERBOSE );
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Catalin Marinas
maintainerQuoted 28 lines · Robin Murphy
Quoted 27 lines · Catalin Marinas
With
CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOCenabled, the arm64 kernel still allocates the default SWIOTLB buffer (64MB) even ifZONE_DMAis 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 Robin Murphy <[email protected]>Cc Will Deacon <[email protected]>--- arch/arm64/mm/init.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)arch/arm64/mm/init.c +2
-1@@ -493,8 +493,16 @@ void __init mem_init(void) {bool swiotlb = max_pfn >PFN_DOWN (arm64_dma_phys_limit); -if (IS_ENABLED (CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC )) +if (IS_ENABLED (CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC ) && !swiotlb) { +/*
Quoted 8 lines
arch/arm64/mm/init.c void __init mem_init(void) · line 502
Quoted 5 lines
arch/arm64/mm/init.c +5
-0+* If no bouncing needed for ZONE_DMA, reduce the swiotlb +* buffer for kmalloc() bouncing to 1MB per 1GB of RAM. +*/ +unsigned long size = +ALIGN (memblock_phys_mem_size (),SZ_1G ) >>10 ;Hmm, I wondered if
DIV_ROUND_UP(memblock_phys_mem_size(), 1024)might be any easier, but by the time I've typed it out it's still just as long :)
It's not the same result as it's rounded up to the nearest KB rather than MB. But this may work as well. I just made up this number really.
Signature · 6 lines
Catalin _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 9 lines · Catalin Marinas
With
CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOCenabled, the arm64 kernel still allocates the default SWIOTLB buffer (64MB) even ifZONE_DMAis 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.[...]
Applied to arm64 (for-next/misc), thanks!
Also changed the division to DIV_ROUND_UP() as per Robin's suggestion.
[1/1] arm64: swiotlb: Reduce the default size if no ZONE_DMA bouncing needed
https://git.kernel.org/arm64/c/65033574ade9
Signature · 7 lines
Catalin _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel