History

dma/swiotlb: introduce Kconfig option for compile-time default pool size

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.

Jagadeesh Pagadala committed 4 months ago

Commit 3cf67bb1 parent 01886163 files · +33 −4Browse files

Unified · Split

3 files
  1. Documentation/core-api/swiotlb.rst +5 −2
  2. include/linux/swiotlb.h +6 −2
  3. kernel/dma/Kconfig +22 −0
Documentation/core-api/swiotlb.rst+5−2
@@ -140,8 +140,11 @@ Data structures concepts · 139 unmodified lines
140140 ------------------------
141141 Memory used for swiotlb bounce buffers is allocated from overall system memory
142142 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
144−"swiotlb=" kernel boot line parameter. The default size may also be adjusted
143+default size of 64 MiB, which can be changed at compile time via
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
145148 due to other conditions, such as running in a CoCo VM, as described above. If
146149 CONFIG_SWIOTLB_DYNAMIC is enabled, additional pools may be allocated later in
147150 the life of the system. Each pool must be a contiguous range of physical
include/linux/swiotlb.h+6−2
@@ -32,8 +32,12 @@ struct scatterlist; · 31 unmodified lines
3232 #define IO_TLB_SHIFT 11
3333 #define IO_TLB_SIZE (1 << IO_TLB_SHIFT)
3434
35−/* default to 64MB */
36−#define IO_TLB_DEFAULT_SIZE (64UL<<20)
35+/* compile-time default; overridable via CONFIG_SWIOTLB_DEFAULT_SIZE_MB */
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
3741
3842 unsigned long swiotlb_size_or_default(void);
3943 void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
kernel/dma/Kconfig+22−0
@@ -86,6 +86,28 @@ config SWIOTLB · 85 unmodified lines
8686 bool
8787 select NEED_DMA_MAP_STATE
8888
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+
89111 config SWIOTLB_DYNAMIC
90112 bool "Dynamic allocation of DMA bounce buffers"
91113 default n

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t