From f0c27bd69bdfedff16bc31dafa305371437f4f52 Mon Sep 17 00:00:00 2001 From: ColorfulRhino <131405023+ColorfulRhino@users.noreply.github.com> Date: Wed, 10 Apr 2024 20:01:27 +0200 Subject: [PATCH] kernel 6.6: 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. --- ...size-if-no-ZONE_DMA-bouncing-needed.patch} | 0 ...-size-if-no-ZONE_DMA-bouncing-needed.patch | 56 +++++++++++++++++++ ...-size-if-no-ZONE_DMA-bouncing-needed.patch | 56 +++++++++++++++++++ ...-size-if-no-ZONE_DMA-bouncing-needed.patch | 56 +++++++++++++++++++ ...-size-if-no-ZONE_DMA-bouncing-needed.patch | 56 +++++++++++++++++++ ...-size-if-no-ZONE_DMA-bouncing-needed.patch | 56 +++++++++++++++++++ ...-size-if-no-ZONE_DMA-bouncing-needed.patch | 56 +++++++++++++++++++ ...-size-if-no-ZONE_DMA-bouncing-needed.patch | 56 +++++++++++++++++++ 8 files changed, 392 insertions(+) rename patch/kernel/archive/{meson64-6.6/arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch => meson-6.6/0010-arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch} (100%) create mode 100644 patch/kernel/archive/meson64-6.6/0010-arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch create mode 100644 patch/kernel/archive/rk322x-6.6/0010-arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch create mode 100644 patch/kernel/archive/rockchip-6.6/patches.armbian/0010-arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch create mode 100644 patch/kernel/archive/rockchip64-6.6/0010-arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch create mode 100644 patch/kernel/archive/sm8250-6.6/0010-arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch create mode 100644 patch/kernel/archive/sunxi-6.6/patches.armbian/0010-arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch create mode 100644 patch/kernel/archive/uefi-arm64-6.6/0010-arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch diff --git a/patch/kernel/archive/meson64-6.6/arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch b/patch/kernel/archive/meson-6.6/0010-arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch similarity index 100% rename from patch/kernel/archive/meson64-6.6/arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch rename to patch/kernel/archive/meson-6.6/0010-arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch diff --git a/patch/kernel/archive/meson64-6.6/0010-arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch b/patch/kernel/archive/meson64-6.6/0010-arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch new file mode 100644 index 0000000000..c31c4414fb --- /dev/null +++ b/patch/kernel/archive/meson64-6.6/0010-arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch @@ -0,0 +1,56 @@ +From 7648741002eeb851ceb394864253445b77ea3d25 Mon Sep 17 00:00:00 2001 +From: Catalin Marinas +Date: Wed, 10 Apr 2024 08:25:37 -0400 +Subject: [PATCH] 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 +Suggested-by: Ross Burton +Cc: Ross Burton +Cc: Will Deacon +Reviewed-by: Robin Murphy +--- + arch/arm64/mm/init.c | 11 ++++++++++- + 1 file changed, 10 insertions(+), 1 deletion(-) + +diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c +index 8a0f8604348b..8deec68028ac 100644 +--- a/arch/arm64/mm/init.c ++++ b/arch/arm64/mm/init.c +@@ -16,6 +16,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -493,8 +494,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 = ++ DIV_ROUND_UP(memblock_phys_mem_size(), 1024); ++ swiotlb_adjust_size(min(swiotlb_size_or_default(), size)); + swiotlb = true; ++ } + + swiotlb_init(swiotlb, SWIOTLB_VERBOSE); + +-- +2.39.2 + diff --git a/patch/kernel/archive/rk322x-6.6/0010-arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch b/patch/kernel/archive/rk322x-6.6/0010-arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch new file mode 100644 index 0000000000..c31c4414fb --- /dev/null +++ b/patch/kernel/archive/rk322x-6.6/0010-arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch @@ -0,0 +1,56 @@ +From 7648741002eeb851ceb394864253445b77ea3d25 Mon Sep 17 00:00:00 2001 +From: Catalin Marinas +Date: Wed, 10 Apr 2024 08:25:37 -0400 +Subject: [PATCH] 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 +Suggested-by: Ross Burton +Cc: Ross Burton +Cc: Will Deacon +Reviewed-by: Robin Murphy +--- + arch/arm64/mm/init.c | 11 ++++++++++- + 1 file changed, 10 insertions(+), 1 deletion(-) + +diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c +index 8a0f8604348b..8deec68028ac 100644 +--- a/arch/arm64/mm/init.c ++++ b/arch/arm64/mm/init.c +@@ -16,6 +16,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -493,8 +494,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 = ++ DIV_ROUND_UP(memblock_phys_mem_size(), 1024); ++ swiotlb_adjust_size(min(swiotlb_size_or_default(), size)); + swiotlb = true; ++ } + + swiotlb_init(swiotlb, SWIOTLB_VERBOSE); + +-- +2.39.2 + diff --git a/patch/kernel/archive/rockchip-6.6/patches.armbian/0010-arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch b/patch/kernel/archive/rockchip-6.6/patches.armbian/0010-arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch new file mode 100644 index 0000000000..c31c4414fb --- /dev/null +++ b/patch/kernel/archive/rockchip-6.6/patches.armbian/0010-arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch @@ -0,0 +1,56 @@ +From 7648741002eeb851ceb394864253445b77ea3d25 Mon Sep 17 00:00:00 2001 +From: Catalin Marinas +Date: Wed, 10 Apr 2024 08:25:37 -0400 +Subject: [PATCH] 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 +Suggested-by: Ross Burton +Cc: Ross Burton +Cc: Will Deacon +Reviewed-by: Robin Murphy +--- + arch/arm64/mm/init.c | 11 ++++++++++- + 1 file changed, 10 insertions(+), 1 deletion(-) + +diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c +index 8a0f8604348b..8deec68028ac 100644 +--- a/arch/arm64/mm/init.c ++++ b/arch/arm64/mm/init.c +@@ -16,6 +16,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -493,8 +494,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 = ++ DIV_ROUND_UP(memblock_phys_mem_size(), 1024); ++ swiotlb_adjust_size(min(swiotlb_size_or_default(), size)); + swiotlb = true; ++ } + + swiotlb_init(swiotlb, SWIOTLB_VERBOSE); + +-- +2.39.2 + diff --git a/patch/kernel/archive/rockchip64-6.6/0010-arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch b/patch/kernel/archive/rockchip64-6.6/0010-arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch new file mode 100644 index 0000000000..c31c4414fb --- /dev/null +++ b/patch/kernel/archive/rockchip64-6.6/0010-arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch @@ -0,0 +1,56 @@ +From 7648741002eeb851ceb394864253445b77ea3d25 Mon Sep 17 00:00:00 2001 +From: Catalin Marinas +Date: Wed, 10 Apr 2024 08:25:37 -0400 +Subject: [PATCH] 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 +Suggested-by: Ross Burton +Cc: Ross Burton +Cc: Will Deacon +Reviewed-by: Robin Murphy +--- + arch/arm64/mm/init.c | 11 ++++++++++- + 1 file changed, 10 insertions(+), 1 deletion(-) + +diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c +index 8a0f8604348b..8deec68028ac 100644 +--- a/arch/arm64/mm/init.c ++++ b/arch/arm64/mm/init.c +@@ -16,6 +16,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -493,8 +494,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 = ++ DIV_ROUND_UP(memblock_phys_mem_size(), 1024); ++ swiotlb_adjust_size(min(swiotlb_size_or_default(), size)); + swiotlb = true; ++ } + + swiotlb_init(swiotlb, SWIOTLB_VERBOSE); + +-- +2.39.2 + diff --git a/patch/kernel/archive/sm8250-6.6/0010-arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch b/patch/kernel/archive/sm8250-6.6/0010-arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch new file mode 100644 index 0000000000..c31c4414fb --- /dev/null +++ b/patch/kernel/archive/sm8250-6.6/0010-arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch @@ -0,0 +1,56 @@ +From 7648741002eeb851ceb394864253445b77ea3d25 Mon Sep 17 00:00:00 2001 +From: Catalin Marinas +Date: Wed, 10 Apr 2024 08:25:37 -0400 +Subject: [PATCH] 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 +Suggested-by: Ross Burton +Cc: Ross Burton +Cc: Will Deacon +Reviewed-by: Robin Murphy +--- + arch/arm64/mm/init.c | 11 ++++++++++- + 1 file changed, 10 insertions(+), 1 deletion(-) + +diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c +index 8a0f8604348b..8deec68028ac 100644 +--- a/arch/arm64/mm/init.c ++++ b/arch/arm64/mm/init.c +@@ -16,6 +16,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -493,8 +494,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 = ++ DIV_ROUND_UP(memblock_phys_mem_size(), 1024); ++ swiotlb_adjust_size(min(swiotlb_size_or_default(), size)); + swiotlb = true; ++ } + + swiotlb_init(swiotlb, SWIOTLB_VERBOSE); + +-- +2.39.2 + diff --git a/patch/kernel/archive/sunxi-6.6/patches.armbian/0010-arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch b/patch/kernel/archive/sunxi-6.6/patches.armbian/0010-arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch new file mode 100644 index 0000000000..c31c4414fb --- /dev/null +++ b/patch/kernel/archive/sunxi-6.6/patches.armbian/0010-arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch @@ -0,0 +1,56 @@ +From 7648741002eeb851ceb394864253445b77ea3d25 Mon Sep 17 00:00:00 2001 +From: Catalin Marinas +Date: Wed, 10 Apr 2024 08:25:37 -0400 +Subject: [PATCH] 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 +Suggested-by: Ross Burton +Cc: Ross Burton +Cc: Will Deacon +Reviewed-by: Robin Murphy +--- + arch/arm64/mm/init.c | 11 ++++++++++- + 1 file changed, 10 insertions(+), 1 deletion(-) + +diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c +index 8a0f8604348b..8deec68028ac 100644 +--- a/arch/arm64/mm/init.c ++++ b/arch/arm64/mm/init.c +@@ -16,6 +16,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -493,8 +494,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 = ++ DIV_ROUND_UP(memblock_phys_mem_size(), 1024); ++ swiotlb_adjust_size(min(swiotlb_size_or_default(), size)); + swiotlb = true; ++ } + + swiotlb_init(swiotlb, SWIOTLB_VERBOSE); + +-- +2.39.2 + diff --git a/patch/kernel/archive/uefi-arm64-6.6/0010-arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch b/patch/kernel/archive/uefi-arm64-6.6/0010-arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch new file mode 100644 index 0000000000..c31c4414fb --- /dev/null +++ b/patch/kernel/archive/uefi-arm64-6.6/0010-arm64-swiotlb-Reduce-the-default-size-if-no-ZONE_DMA-bouncing-needed.patch @@ -0,0 +1,56 @@ +From 7648741002eeb851ceb394864253445b77ea3d25 Mon Sep 17 00:00:00 2001 +From: Catalin Marinas +Date: Wed, 10 Apr 2024 08:25:37 -0400 +Subject: [PATCH] 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 +Suggested-by: Ross Burton +Cc: Ross Burton +Cc: Will Deacon +Reviewed-by: Robin Murphy +--- + arch/arm64/mm/init.c | 11 ++++++++++- + 1 file changed, 10 insertions(+), 1 deletion(-) + +diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c +index 8a0f8604348b..8deec68028ac 100644 +--- a/arch/arm64/mm/init.c ++++ b/arch/arm64/mm/init.c +@@ -16,6 +16,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -493,8 +494,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 = ++ DIV_ROUND_UP(memblock_phys_mem_size(), 1024); ++ swiotlb_adjust_size(min(swiotlb_size_or_default(), size)); + swiotlb = true; ++ } + + swiotlb_init(swiotlb, SWIOTLB_VERBOSE); + +-- +2.39.2 +