The SWIOTLB bounce buffer pool size is hardcoded at 64 MB via IO_TLB_DEFAULT_SIZE with no compile-time knob to adjust it. On memory-constrained embedded or mobile platforms equipped with a hardware IOMMU (e.g., ARM SMMU) covering most DMA-capable devices, reserving 64 MB at boot is unnecessarily wasteful — the SWIOTLB is only exercised for devices that bypass the IOMMU or have restricted DMA address ranges. Introduce CONFIG_SWIOTLB_DEFAULT_SIZE_MB, an integer Kconfig option (range 1–64 MB, default 64) that allows platforms to set a smaller compile-time default. IO_TLB_DEFAULT_SIZE is updated to derive from this value when CONFIG_SWIOTLB is enabled, preserving the existing 64 MB default when the option is not configured. The runtime "swiotlb=<nslabs>" kernel parameter override remains fully supported and takes precedence over the compile-time default.
Unified · Split
| @@ -140,8 +140,11 @@ Data structures concepts · 139 unmodified lines | |||
| 140 | ------------------------ | 140 | ------------------------ |
| 141 | Memory used for swiotlb bounce buffers is allocated from overall system memory | 141 | Memory used for swiotlb bounce buffers is allocated from overall system memory |
| 142 | as one or more "pools". The default pool is allocated during system boot with a | 142 | as one or more "pools". The default pool is allocated during system boot with a |
| 143 | default size of 64 MiB. The default pool size may be modified with the | 143 | default size of 64 MiB, which can be changed at compile time via |
| 144 | "swiotlb=" kernel boot line parameter. The default size may also be adjusted | 144 | CONFIG_SWIOTLB_DEFAULT_SIZE_MB. The default pool size may also be |
| 145 | modified at runtime with the "swiotlb=" kernel boot line parameter, | ||
| 146 | which takes precedence over the compile-time default. The default size | ||
| 147 | may also be adjusted | ||
| 145 | due to other conditions, such as running in a CoCo VM, as described above. If | 148 | due to other conditions, such as running in a CoCo VM, as described above. If |
| 146 | CONFIG_SWIOTLB_DYNAMIC is enabled, additional pools may be allocated later in | 149 | CONFIG_SWIOTLB_DYNAMIC is enabled, additional pools may be allocated later in |
| 147 | the life of the system. Each pool must be a contiguous range of physical | 150 | the life of the system. Each pool must be a contiguous range of physical |
| @@ -32,8 +32,12 @@ struct scatterlist; · 31 unmodified lines | |||
| 32 | #define IO_TLB_SHIFT 11 | 32 | #define IO_TLB_SHIFT 11 |
| 33 | #define IO_TLB_SIZE (1 << IO_TLB_SHIFT) | 33 | #define IO_TLB_SIZE (1 << IO_TLB_SHIFT) |
| 34 | 34 | ||
| 35 | /* default to 64MB */ | 35 | /* compile-time default; overridable via CONFIG_SWIOTLB_DEFAULT_SIZE_MB */ |
| 36 | #define IO_TLB_DEFAULT_SIZE (64UL<<20) | 36 | #ifdef CONFIG_SWIOTLB |
| 37 | #define IO_TLB_DEFAULT_SIZE ((unsigned long)CONFIG_SWIOTLB_DEFAULT_SIZE_MB << 20) | ||
| 38 | #else | ||
| 39 | #define IO_TLB_DEFAULT_SIZE (64UL << 20) | ||
| 40 | #endif | ||
| 37 | 41 | ||
| 38 | unsigned long swiotlb_size_or_default(void); | 42 | unsigned long swiotlb_size_or_default(void); |
| 39 | void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags, | 43 | void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags, |
| @@ -86,6 +86,28 @@ config SWIOTLB · 85 unmodified lines | |||
| 86 | bool | 86 | bool |
| 87 | select NEED_DMA_MAP_STATE | 87 | select NEED_DMA_MAP_STATE |
| 88 | 88 | ||
| 89 | config SWIOTLB_DEFAULT_SIZE_MB | ||
| 90 | int "Default SWIOTLB bounce buffer size in MB" | ||
| 91 | depends on SWIOTLB | ||
| 92 | range 1 64 | ||
| 93 | default 64 | ||
| 94 | help | ||
| 95 | Sets the default size of the software IO TLB (SWIOTLB) bounce buffer | ||
| 96 | pool allocated at boot time. The default is 64 MB. | ||
| 97 | |||
| 98 | On memory-constrained embedded or mobile platforms (e.g., those with | ||
| 99 | a hardware IOMMU such as ARM SMMU covering most DMA-capable devices), | ||
| 100 | a smaller value such as 4 or 8 MB may be sufficient. The SWIOTLB is | ||
| 101 | then only needed for devices that bypass the IOMMU or have restricted | ||
| 102 | DMA address ranges. | ||
| 103 | |||
| 104 | The minimum allowed value is 1 MB. This compile-time default can be | ||
| 105 | overridden at runtime using the "swiotlb=<nslabs>" kernel command line | ||
| 106 | parameter. Refer to Documentation/admin-guide/kernel-parameters.txt | ||
| 107 | for details. | ||
| 108 | |||
| 109 | If unsure, leave at the default value of 64. | ||
| 110 | |||
| 89 | config SWIOTLB_DYNAMIC | 111 | config SWIOTLB_DYNAMIC |
| 90 | bool "Dynamic allocation of DMA bounce buffers" | 112 | bool "Dynamic allocation of DMA bounce buffers" |
| 91 | default n | 113 | default n |