Skip to contentSkip to conversation

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

PATCH Superseded [email protected] 3 participants 7 messages Jun 16 – Jul 2 DMA mapping helpers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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

From: Jagadeesh Pagadala <[email protected]>

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.

---
The SWIOTLB bounce buffer pool size is hardcoded at 64 MB. On memory-constrained platforms with a hardware IOMMU (e.g., ARM SMMU), this reservation is wasteful as SWIOTLB is only needed for devices that bypass the IOMMU or have restricted DMA address ranges.

Introduce CONFIG_SWIOTLB_DEFAULT_SIZE_MB (range 1–64 MB, default 64) to allow a smaller compile-time default. The runtime "swiotlb=" parameter override remains supported and takes precedence.

Before (default 64 MB):

  [    0.000000] software IO TLB: area num 8.
  [    0.000000] software IO TLB: mapped [mem 0x00000000fbfff000-0x00000000fffff000] (64MB)

After (CONFIG_SWIOTLB_DEFAULT_SIZE_MB=2):

  [    0.000000] software IO TLB: area num 8.
  [    0.000000] software IO TLB: SWIOTLB bounce buffer size roundup to 2MB
  [    0.000000] software IO TLB: mapped [mem 0x00000000ffdff000-0x00000000fffff000] (2MB)
---
 include/linux/swiotlb.h |  8 ++++++--
 kernel/dma/Kconfig      | 22 ++++++++++++++++++++++
 2 files changed, 28 insertions(+), 2 deletions(-)
include/linux/swiotlb.h +6 -2
index 3dae0f592063..1665a9ce8f94 100644
@@ -32,8 +32,12 @@ struct scatterlist;
 #define IO_TLB_SHIFT 11
 #define IO_TLB_SIZE (1 << IO_TLB_SHIFT)
 
-/* default to 64MB */
-#define IO_TLB_DEFAULT_SIZE (64UL<<20)
+/* compile-time default; overridable via CONFIG_SWIOTLB_DEFAULT_SIZE_MB */
+#ifdef CONFIG_SWIOTLB
+#define IO_TLB_DEFAULT_SIZE ((unsigned long)CONFIG_SWIOTLB_DEFAULT_SIZE_MB << 20)
+#else
+#define IO_TLB_DEFAULT_SIZE (64UL << 20)
+#endif
 
 unsigned long swiotlb_size_or_default(void);
 void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
kernel/dma/Kconfig +22 -0
index 0a4ba21a57a7..3830a63ae032 100644
@@ -86,6 +86,28 @@ config SWIOTLB
 	bool
 	select NEED_DMA_MAP_STATE
 
+config SWIOTLB_DEFAULT_SIZE_MB
+	int "Default SWIOTLB bounce buffer size in MB"
+	depends on SWIOTLB
+	range 1 64
+	default 64
+	help
+	  Sets the default size of the software IO TLB (SWIOTLB) bounce buffer
+	  pool allocated at boot time. The default is 64 MB.
+
+	  On memory-constrained embedded or mobile platforms (e.g., those with
+	  a hardware IOMMU such as ARM SMMU covering most DMA-capable devices),
+	  a smaller value such as 4 or 8 MB may be sufficient. The SWIOTLB is
+	  then only needed for devices that bypass the IOMMU or have restricted
+	  DMA address ranges.
+
+	  The minimum allowed value is 1 MB. This compile-time default can be
+	  overridden at runtime using the "swiotlb=<nslabs>" kernel command line
+	  parameter. Refer to Documentation/admin-guide/kernel-parameters.txt
+	  for details.
+
+	  If unsure, leave at the default value of 64.
+
 config SWIOTLB_DYNAMIC
 	bool "Dynamic allocation of DMA bounce buffers"
 	default n

---
base-commit: 4fa3f5fabb30bf00d7475d5a33459ea83d639bf9
change-id: 20260617-swiotlb-c215ce0b23f7

Best regards,

Signature · 1 line
Bibek Kumar Patro <[email protected]>
#1 lore raw
Quoted 11 lines · On Tue, Jun 16, 2026 at 10:36 PM <[email protected]> wrote:

From: Jagadeesh Pagadala <[email protected]>

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.

Quoted 9 lines

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.

Just curious, why is not "swiotlb=" enough in your case?

Thanks,
Mostafa

Quoted 87 lines

---
The SWIOTLB bounce buffer pool size is hardcoded at 64 MB. On memory-constrained platforms with a hardware IOMMU (e.g., ARM SMMU), this reservation is wasteful as SWIOTLB is only needed for devices that bypass the IOMMU or have restricted DMA address ranges.

Introduce CONFIG_SWIOTLB_DEFAULT_SIZE_MB (range 1–64 MB, default 64) to allow a smaller compile-time default. The runtime "swiotlb=" parameter override remains supported and takes precedence.

Before (default 64 MB):

  [    0.000000] software IO TLB: area num 8.
  [    0.000000] software IO TLB: mapped [mem 0x00000000fbfff000-0x00000000fffff000] (64MB)

After (CONFIG_SWIOTLB_DEFAULT_SIZE_MB=2):

  [    0.000000] software IO TLB: area num 8.
  [    0.000000] software IO TLB: SWIOTLB bounce buffer size roundup to 2MB
  [    0.000000] software IO TLB: mapped [mem 0x00000000ffdff000-0x00000000fffff000] (2MB)
---
 include/linux/swiotlb.h |  8 ++++++--
 kernel/dma/Kconfig      | 22 ++++++++++++++++++++++
 2 files changed, 28 insertions(+), 2 deletions(-)
include/linux/swiotlb.h +6 -2
index 3dae0f592063..1665a9ce8f94 100644
@@ -32,8 +32,12 @@ struct scatterlist;
 #define IO_TLB_SHIFT 11
 #define IO_TLB_SIZE (1 << IO_TLB_SHIFT)
 
-/* default to 64MB */
-#define IO_TLB_DEFAULT_SIZE (64UL<<20)
+/* compile-time default; overridable via CONFIG_SWIOTLB_DEFAULT_SIZE_MB */
+#ifdef CONFIG_SWIOTLB
+#define IO_TLB_DEFAULT_SIZE ((unsigned long)CONFIG_SWIOTLB_DEFAULT_SIZE_MB << 20)
+#else
+#define IO_TLB_DEFAULT_SIZE (64UL << 20)
+#endif
 
 unsigned long swiotlb_size_or_default(void);
 void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
kernel/dma/Kconfig +22 -1
index 0a4ba21a57a7..3830a63ae032 100644
@@ -86,6 +86,28 @@ config SWIOTLB
        bool
        select NEED_DMA_MAP_STATE
 
+config SWIOTLB_DEFAULT_SIZE_MB
+       int "Default SWIOTLB bounce buffer size in MB"
+       depends on SWIOTLB
+       range 1 64
+       default 64
+       help
+         Sets the default size of the software IO TLB (SWIOTLB) bounce buffer
+         pool allocated at boot time. The default is 64 MB.
+
+         On memory-constrained embedded or mobile platforms (e.g., those with
+         a hardware IOMMU such as ARM SMMU covering most DMA-capable devices),
+         a smaller value such as 4 or 8 MB may be sufficient. The SWIOTLB is
+         then only needed for devices that bypass the IOMMU or have restricted
+         DMA address ranges.
+
+         The minimum allowed value is 1 MB. This compile-time default can be
+         overridden at runtime using the "swiotlb=<nslabs>" kernel command line
+         parameter. Refer to Documentation/admin-guide/kernel-parameters.txt
+         for details.
+
+         If unsure, leave at the default value of 64.
+
 config SWIOTLB_DYNAMIC
        bool "Dynamic allocation of DMA bounce buffers"
        default n
 
---

base-commit: 4fa3f5fabb30bf00d7475d5a33459ea83d639bf9
change-id: 20260617-swiotlb-c215ce0b23f7

Best regards,
--
Bibek Kumar Patro <[email protected]>

#2 lore raw
Quoted 18 lines · Mostafa Saleh
Quoted 17 lines · On Tue, Jun 16, 2026 at 10:36 PM <[email protected]> wrote:

From: Jagadeesh Pagadala <[email protected]>

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.

Quoted 6 lines
Quoted 3 lines

The runtime "swiotlb=<nslabs>" kernel parameter override remains fully supported and takes precedence over the compile-time default.

Just curious, why is not "swiotlb=" enough in your case?

We are looking for an approach where we can set a default value of IO_TLB_DEFAULT_SIZE to maintain and sustain it for a specific platform or a kernel configuration.

So introducing a Kconfig tunable seemed to be a maintainable approach compared to "swiotlb=" runtime variable.
(since defconfig is the right mechanism for platform specific compile-time defaults)

Further in case of any bootloader constraints - to make default runtime parameter, it might require firmware changes on production devices as well. (since in embedded/mobile platforms the kernel command line is typically managed by the bootloader)

Thanks & regards,
Bibek

Quoted 90 lines

Thanks,
Mostafa

Quoted 87 lines

---
The SWIOTLB bounce buffer pool size is hardcoded at 64 MB. On memory-constrained platforms with a hardware IOMMU (e.g., ARM SMMU), this reservation is wasteful as SWIOTLB is only needed for devices that bypass the IOMMU or have restricted DMA address ranges.

Introduce CONFIG_SWIOTLB_DEFAULT_SIZE_MB (range 1–64 MB, default 64) to allow a smaller compile-time default. The runtime "swiotlb=" parameter override remains supported and takes precedence.

Before (default 64 MB):

   [    0.000000] software IO TLB: area num 8.
   [    0.000000] software IO TLB: mapped [mem 0x00000000fbfff000-0x00000000fffff000] (64MB)

After (CONFIG_SWIOTLB_DEFAULT_SIZE_MB=2):

   [    0.000000] software IO TLB: area num 8.
   [    0.000000] software IO TLB: SWIOTLB bounce buffer size roundup to 2MB
   [    0.000000] software IO TLB: mapped [mem 0x00000000ffdff000-0x00000000fffff000] (2MB)
---
  include/linux/swiotlb.h |  8 ++++++--
  kernel/dma/Kconfig      | 22 ++++++++++++++++++++++
  2 files changed, 28 insertions(+), 2 deletions(-)
include/linux/swiotlb.h +6 -2
index 3dae0f592063..1665a9ce8f94 100644
@@ -32,8 +32,12 @@ struct scatterlist;
  #define IO_TLB_SHIFT 11
  #define IO_TLB_SIZE (1 << IO_TLB_SHIFT)
 
-/* default to 64MB */
-#define IO_TLB_DEFAULT_SIZE (64UL<<20)
+/* compile-time default; overridable via CONFIG_SWIOTLB_DEFAULT_SIZE_MB */
+#ifdef CONFIG_SWIOTLB
+#define IO_TLB_DEFAULT_SIZE ((unsigned long)CONFIG_SWIOTLB_DEFAULT_SIZE_MB << 20)
+#else
+#define IO_TLB_DEFAULT_SIZE (64UL << 20)
+#endif
 
  unsigned long swiotlb_size_or_default(void);
  void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
kernel/dma/Kconfig +22 -1
index 0a4ba21a57a7..3830a63ae032 100644
@@ -86,6 +86,28 @@ config SWIOTLB
         bool
         select NEED_DMA_MAP_STATE
 
+config SWIOTLB_DEFAULT_SIZE_MB
+       int "Default SWIOTLB bounce buffer size in MB"
+       depends on SWIOTLB
+       range 1 64
+       default 64
+       help
+         Sets the default size of the software IO TLB (SWIOTLB) bounce buffer
+         pool allocated at boot time. The default is 64 MB.
+
+         On memory-constrained embedded or mobile platforms (e.g., those with
+         a hardware IOMMU such as ARM SMMU covering most DMA-capable devices),
+         a smaller value such as 4 or 8 MB may be sufficient. The SWIOTLB is
+         then only needed for devices that bypass the IOMMU or have restricted
+         DMA address ranges.
+
+         The minimum allowed value is 1 MB. This compile-time default can be
+         overridden at runtime using the "swiotlb=<nslabs>" kernel command line
+         parameter. Refer to Documentation/admin-guide/kernel-parameters.txt
+         for details.
+
+         If unsure, leave at the default value of 64.
+
  config SWIOTLB_DYNAMIC
         bool "Dynamic allocation of DMA bounce buffers"
         default n
 
---

base-commit: 4fa3f5fabb30bf00d7475d5a33459ea83d639bf9
change-id: 20260617-swiotlb-c215ce0b23f7

Best regards,
--
Bibek Kumar Patro <[email protected]>

#3 lore raw
In reply to [email protected]

From: [email protected] <[email protected]> Sent: Tuesday, June 16, 2026 2:36 PM

Quoted 32 lines

From: Jagadeesh Pagadala <[email protected]>

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.

---
The SWIOTLB bounce buffer pool size is hardcoded at 64 MB. On memory-constrained platforms with a hardware IOMMU (e.g., ARM SMMU), this reservation is wasteful as SWIOTLB is only needed for devices that bypass the IOMMU or have restricted DMA address ranges.

Introduce CONFIG_SWIOTLB_DEFAULT_SIZE_MB (range 1–64 MB, default 64) to allow a smaller compile-time default. The runtime "swiotlb=" parameter override remains supported and takes precedence.

Quoted 8 lines

Before (default 64 MB):

  [    0.000000] software IO TLB: area num 8.
  [    0.000000] software IO TLB: mapped [mem 0x00000000fbfff000-0x00000000fffff000] (64MB)

After (CONFIG_SWIOTLB_DEFAULT_SIZE_MB=2):

  [    0.000000] software IO TLB: area num 8.
  [    0.000000] software IO TLB: SWIOTLB bounce buffer size roundup to 2MB
  [    0.000000] software IO TLB: mapped [mem 0x00000000ffdff000-0x00000000fffff000] (2MB)

This message sequence is surprising to me -- there should not be any roundup if the default size is 2 MiB and there are 8 CPUs. I ran the patch with 8 CPUs and set CONFIG_SWIOTLB_DEFAULT_SIZE_MB=2, and
no roundup was reported. I'm curious as to what configuration produced the "roundup" message.

Also, there's some text in Documentation/core-api/swiotlb.rst that describes the default size of the swiotlb, and how it can be overridden with the swiotlb= kernel boot option. This patch should include an update to that text to mention the new CONFIG option.

Michael

Quoted 66 lines
---
 include/linux/swiotlb.h |  8 ++++++--
 kernel/dma/Kconfig      | 22 ++++++++++++++++++++++
 2 files changed, 28 insertions(+), 2 deletions(-)
include/linux/swiotlb.h +6 -2
index 3dae0f592063..1665a9ce8f94 100644
@@ -32,8 +32,12 @@ struct scatterlist;
 #define IO_TLB_SHIFT 11
 #define IO_TLB_SIZE (1 << IO_TLB_SHIFT)
 
-/* default to 64MB */
-#define IO_TLB_DEFAULT_SIZE (64UL<<20)
+/* compile-time default; overridable via CONFIG_SWIOTLB_DEFAULT_SIZE_MB */
+#ifdef CONFIG_SWIOTLB
+#define IO_TLB_DEFAULT_SIZE ((unsigned long)CONFIG_SWIOTLB_DEFAULT_SIZE_MB << 20)
+#else
+#define IO_TLB_DEFAULT_SIZE (64UL << 20)
+#endif
 
 unsigned long swiotlb_size_or_default(void);
 void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
kernel/dma/Kconfig +22 -1
index 0a4ba21a57a7..3830a63ae032 100644
@@ -86,6 +86,28 @@ config SWIOTLB
 	bool
 	select NEED_DMA_MAP_STATE
 
+config SWIOTLB_DEFAULT_SIZE_MB
+	int "Default SWIOTLB bounce buffer size in MB"
+	depends on SWIOTLB
+	range 1 64
+	default 64
+	help
+	  Sets the default size of the software IO TLB (SWIOTLB) bounce buffer
+	  pool allocated at boot time. The default is 64 MB.
+
+	  On memory-constrained embedded or mobile platforms (e.g., those with
+	  a hardware IOMMU such as ARM SMMU covering most DMA-capable devices),
+	  a smaller value such as 4 or 8 MB may be sufficient. The SWIOTLB is
+	  then only needed for devices that bypass the IOMMU or have restricted
+	  DMA address ranges.
+
+	  The minimum allowed value is 1 MB. This compile-time default can be
+	  overridden at runtime using the "swiotlb=<nslabs>" kernel command line
+	  parameter. Refer to Documentation/admin-guide/kernel-parameters.txt
+	  for details.
+
+	  If unsure, leave at the default value of 64.
+
 config SWIOTLB_DYNAMIC
 	bool "Dynamic allocation of DMA bounce buffers"
 	default n
 
---

base-commit: 4fa3f5fabb30bf00d7475d5a33459ea83d639bf9
change-id: 20260617-swiotlb-c215ce0b23f7

Best regards,
--
Bibek Kumar Patro <[email protected]>

#4 lore raw
Quoted 42 lines · Michael Kelley

From: [email protected] <[email protected]> Sent: Tuesday, June 16, 2026 2:36 PM

Quoted 32 lines

From: Jagadeesh Pagadala <[email protected]>

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.

---
The SWIOTLB bounce buffer pool size is hardcoded at 64 MB. On memory-constrained platforms with a hardware IOMMU (e.g., ARM SMMU), this reservation is wasteful as SWIOTLB is only needed for devices that bypass the IOMMU or have restricted DMA address ranges.

Introduce CONFIG_SWIOTLB_DEFAULT_SIZE_MB (range 1–64 MB, default 64) to allow a smaller compile-time default. The runtime "swiotlb=" parameter override remains supported and takes precedence.

Quoted 8 lines

Before (default 64 MB):

   [    0.000000] software IO TLB: area num 8.
   [    0.000000] software IO TLB: mapped [mem 0x00000000fbfff000-0x00000000fffff000] (64MB)

After (CONFIG_SWIOTLB_DEFAULT_SIZE_MB=2):

   [    0.000000] software IO TLB: area num 8.
   [    0.000000] software IO TLB: SWIOTLB bounce buffer size roundup to 2MB
   [    0.000000] software IO TLB: mapped [mem 0x00000000ffdff000-0x00000000fffff000] (2MB)
Quoted 6 lines

This message sequence is surprising to me -- there should not be any roundup if the default size is 2 MiB and there are 8 CPUs. I ran the patch with 8 CPUs and set CONFIG_SWIOTLB_DEFAULT_SIZE_MB=2, and
no roundup was reported. I'm curious as to what configuration produced the "roundup" message.

I see inside swiotlb.c, we have a print for rounding off based on the number of slabs, inside the check for "round_up_default_nslabs()" pr_info("SWIOTLB bounce buffer size roundup to %luMB",

Probability of getting the print based on the number of slabs. <I am assuming your configuration is having nslabs in power of 2>

Quoted 5 lines

Also, there's some text in Documentation/core-api/swiotlb.rst that describes the default size of the swiotlb, and how it can be overridden with the swiotlb= kernel boot option. This patch should include an update to that text to mention the new CONFIG option.

Ack, thanks for this suggestion. I will incorporate in next revision. It would be a good information for someone trying a similar approach for setting the default option to custom value.

Thanks & regards,
Bibek

Quoted 69 lines

Michael

Quoted 66 lines
---
  include/linux/swiotlb.h |  8 ++++++--
  kernel/dma/Kconfig      | 22 ++++++++++++++++++++++
  2 files changed, 28 insertions(+), 2 deletions(-)
include/linux/swiotlb.h +6 -2
index 3dae0f592063..1665a9ce8f94 100644
@@ -32,8 +32,12 @@ struct scatterlist;
  #define IO_TLB_SHIFT 11
  #define IO_TLB_SIZE (1 << IO_TLB_SHIFT)
 
-/* default to 64MB */
-#define IO_TLB_DEFAULT_SIZE (64UL<<20)
+/* compile-time default; overridable via CONFIG_SWIOTLB_DEFAULT_SIZE_MB */
+#ifdef CONFIG_SWIOTLB
+#define IO_TLB_DEFAULT_SIZE ((unsigned long)CONFIG_SWIOTLB_DEFAULT_SIZE_MB << 20)
+#else
+#define IO_TLB_DEFAULT_SIZE (64UL << 20)
+#endif
 
  unsigned long swiotlb_size_or_default(void);
  void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
kernel/dma/Kconfig +22 -1
index 0a4ba21a57a7..3830a63ae032 100644
@@ -86,6 +86,28 @@ config SWIOTLB
  	bool
  	select NEED_DMA_MAP_STATE
 
+config SWIOTLB_DEFAULT_SIZE_MB
+	int "Default SWIOTLB bounce buffer size in MB"
+	depends on SWIOTLB
+	range 1 64
+	default 64
+	help
+	  Sets the default size of the software IO TLB (SWIOTLB) bounce buffer
+	  pool allocated at boot time. The default is 64 MB.
+
+	  On memory-constrained embedded or mobile platforms (e.g., those with
+	  a hardware IOMMU such as ARM SMMU covering most DMA-capable devices),
+	  a smaller value such as 4 or 8 MB may be sufficient. The SWIOTLB is
+	  then only needed for devices that bypass the IOMMU or have restricted
+	  DMA address ranges.
+
+	  The minimum allowed value is 1 MB. This compile-time default can be
+	  overridden at runtime using the "swiotlb=<nslabs>" kernel command line
+	  parameter. Refer to Documentation/admin-guide/kernel-parameters.txt
+	  for details.
+
+	  If unsure, leave at the default value of 64.
+
  config SWIOTLB_DYNAMIC
  	bool "Dynamic allocation of DMA bounce buffers"
  	default n
 
---

base-commit: 4fa3f5fabb30bf00d7475d5a33459ea83d639bf9
change-id: 20260617-swiotlb-c215ce0b23f7

Best regards,
--
Bibek Kumar Patro <[email protected]>

#5 lore raw
Quoted 45 lines · Bibek Kumar Patro
Quoted 42 lines · Michael Kelley

From: [email protected] <[email protected]> Sent: Tuesday, June 16, 2026 2:36 PM

Quoted 40 lines

From: Jagadeesh Pagadala <[email protected]>

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.

---
The SWIOTLB bounce buffer pool size is hardcoded at 64 MB. On memory-constrained platforms with a hardware IOMMU (e.g., ARM SMMU), this reservation is wasteful as SWIOTLB is only needed for devices that bypass the IOMMU or have restricted DMA address ranges.

Introduce CONFIG_SWIOTLB_DEFAULT_SIZE_MB (range 1–64 MB, default 64) to allow a smaller compile-time default. The runtime "swiotlb=" parameter override remains supported and takes precedence.

Before (default 64 MB):
   [    0.000000] software IO TLB: area num 8.
   [    0.000000] software IO TLB: mapped [mem 0x00000000fbfff000-0x00000000fffff000] (64MB)

After (CONFIG_SWIOTLB_DEFAULT_SIZE_MB=2):
   [    0.000000] software IO TLB: area num 8.
   [    0.000000] software IO TLB: SWIOTLB bounce buffer size roundup to 2MB [    0.000000] software IO TLB: mapped [mem 0x00000000ffdff000-0x00000000fffff000] (2MB)

Quoted 6 lines
Quoted 6 lines

This message sequence is surprising to me -- there should not be any roundup if the default size is 2 MiB and there are 8 CPUs. I ran the patch with 8 CPUs and set CONFIG_SWIOTLB_DEFAULT_SIZE_MB=2, and
no roundup was reported. I'm curious as to what configuration produced the "roundup" message.

I might have misunderstood your query Michael, you're correct.

I rechecked my system configuration with 8 CPUs and CONFIG_SWIOTLB_DEFAULT_SIZE_MB=2, and I did not get the "roundup" message. I did a few experiments while developing the patch initially with CONFIG_SWIOTLB_DEFAULT_SIZE_MB across a range of values. CONFIG_SWIOTLB_DEFAULT_SIZE_MB=1 gives the roundup message:

  [    0.000000] software IO TLB: area num 8.
  [    0.000000] software IO TLB: SWIOTLB bounce buffer size roundup to 2MB
  [    0.000000] software IO TLB: mapped [mem 

0x00000000ffdff000-0x00000000fffff000] (2MB)

With CONFIG_SWIOTLB_DEFAULT_SIZE_MB=1:

nslabs = CONFIG_SWIOTLB_DEFAULT_SIZE_MB << 9 = 1 << 9 = 512

With 8 CPUs, default_nareas = 8, so the minimum required nslabs is:

IO_TLB_SEGSIZE * default_nareas = 128 * 8 = 1024

Since 512 < 1024, nslabs is rounded up to 1024 (2MB), which explains
the roundup message.
I have incorrectly labelled this log in cover letter by posting the logs for CONFIG_SWIOTLB_DEFAULT_SIZE_MB=1 instead of CONFIG_SWIOTLB_DEFAULT_SIZE_MB=2
I will correct this info in the cover letter while sending the next
revision along with the documentation update as you suggested.

Thanks & regards,
Bibek

Quoted 102 lines

I see inside swiotlb.c, we have a print for rounding off based on the number of slabs, inside the check for "round_up_default_nslabs()" pr_info("SWIOTLB bounce buffer size roundup to %luMB",

Probability of getting the print based on the number of slabs. <I am assuming your configuration is having nslabs in power of 2>

Quoted 5 lines

Also, there's some text in Documentation/core-api/swiotlb.rst that describes the default size of the swiotlb, and how it can be overridden with the swiotlb= kernel boot option. This patch should include an update to that text to mention the new CONFIG option.

Ack, thanks for this suggestion. I will incorporate in next revision. It would be a good information for someone trying a similar approach for setting the default option to custom value.

Thanks & regards,
Bibek

Quoted 79 lines

Michael

Quoted 76 lines

---
  include/linux/swiotlb.h |  8 ++++++-- kernel/dma/Kconfig      | 22 ++++++++++++++++++++++

  2 files changed, 28 insertions(+), 2 deletions(-)
include/linux/swiotlb.h +1 -2
index 3dae0f592063..1665a9ce8f94 100644
@@ -32,8 +32,12 @@ struct scatterlist;
   #define IO_TLB_SHIFT 11
   #define IO_TLB_SIZE (1 << IO_TLB_SHIFT)
 
-/* default to 64MB */
-#define IO_TLB_DEFAULT_SIZE (64UL<<20)
+/* compile-time default; overridable via 

CONFIG_SWIOTLB_DEFAULT_SIZE_MB */

include/linux/swiotlb.h +2 -0
+#ifdef CONFIG_SWIOTLB
+#define IO_TLB_DEFAULT_SIZE ((unsigned 

long)CONFIG_SWIOTLB_DEFAULT_SIZE_MB << 20)

include/linux/swiotlb.h +3 -0
+#else
+#define IO_TLB_DEFAULT_SIZE (64UL << 20)
+#endif

  unsigned long swiotlb_size_or_default(void);
  void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,

kernel/dma/Kconfig +0 -0
index 0a4ba21a57a7..3830a63ae032 100644
@@ -86,6 +86,28 @@ config SWIOTLB

      bool
      select NEED_DMA_MAP_STATE

+config SWIOTLB_DEFAULT_SIZE_MB
+    int "Default SWIOTLB bounce buffer size in MB"
+    depends on SWIOTLB
+    range 1 64
+    default 64
+    help
+      Sets the default size of the software IO TLB (SWIOTLB) bounce buffer
+      pool allocated at boot time. The default is 64 MB. +
+      On memory-constrained embedded or mobile platforms (e.g., those with
+      a hardware IOMMU such as ARM SMMU covering most DMA-capable devices),
+      a smaller value such as 4 or 8 MB may be sufficient. The SWIOTLB is
+      then only needed for devices that bypass the IOMMU or have restricted
+      DMA address ranges.
+
+      The minimum allowed value is 1 MB. This compile-time default can be
+      overridden at runtime using the "swiotlb=<nslabs>" kernel command line
+      parameter. Refer to Documentation/admin-guide/kernel- parameters.txt
+      for details.

kernel/dma/Kconfig +3 -0
+
+      If unsure, leave at the default value of 64.
+

  config SWIOTLB_DYNAMIC
      bool "Dynamic allocation of DMA bounce buffers" default n

---
base-commit: 4fa3f5fabb30bf00d7475d5a33459ea83d639bf9
change-id: 20260617-swiotlb-c215ce0b23f7

Best regards,

Signature · 1 line
Bibek Kumar Patro <[email protected]>
#6 lore raw

From: Bibek Kumar Patro <[email protected]> Sent: Thursday, July 2, 2026 6:45 AM

Quoted 80 lines · Bibek Kumar Patro
Quoted 49 lines · Michael Kelley
Quoted 46 lines

From: [email protected] <[email protected]>
Sent: Tuesday, June 16, 2026 2:36 PM

Quoted 43 lines

From: Jagadeesh Pagadala <[email protected]>

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.

---
The SWIOTLB bounce buffer pool size is hardcoded at 64 MB. On memory-constrained platforms with a hardware IOMMU (e.g., ARM SMMU), this reservation is wasteful as SWIOTLB is only needed for devices that bypass the IOMMU or have restricted DMA address ranges.

Introduce CONFIG_SWIOTLB_DEFAULT_SIZE_MB (range 1–64 MB, default 64) to allow a smaller compile-time default. The runtime "swiotlb=" parameter override remains supported and takes precedence.

Before (default 64 MB):
   [    0.000000] software IO TLB: area num 8.
   [    0.000000] software IO TLB: mapped [mem
0x00000000fbfff000-0x00000000fffff000] (64MB)

After (CONFIG_SWIOTLB_DEFAULT_SIZE_MB=2):
   [    0.000000] software IO TLB: area num 8.
   [    0.000000] software IO TLB: SWIOTLB bounce buffer size roundup to 2MB
   [    0.000000] software IO TLB: mapped [mem 0x00000000ffdff000-0x00000000fffff000] (2MB)

Quoted 7 lines
Quoted 7 lines

This message sequence is surprising to me -- there should not be any roundup if the default size is 2 MiB and there are 8 CPUs. I ran the patch
with 8 CPUs and set CONFIG_SWIOTLB_DEFAULT_SIZE_MB=2, and no roundup was reported. I'm curious as to what configuration produced the "roundup" message.

I might have misunderstood your query Michael, you're correct.

I rechecked my system configuration with 8 CPUs and CONFIG_SWIOTLB_DEFAULT_SIZE_MB=2, and I did not get the "roundup" message. I did a few experiments while developing the patch initially with CONFIG_SWIOTLB_DEFAULT_SIZE_MB across a range of values. CONFIG_SWIOTLB_DEFAULT_SIZE_MB=1 gives the roundup message:

   [    0.000000] software IO TLB: area num 8.
   [    0.000000] software IO TLB: SWIOTLB bounce buffer size roundup to 2MB
   [    0.000000] software IO TLB: mapped [mem

0x00000000ffdff000-0x00000000fffff000] (2MB)

With CONFIG_SWIOTLB_DEFAULT_SIZE_MB=1:

   nslabs = CONFIG_SWIOTLB_DEFAULT_SIZE_MB << 9 = 1 << 9 = 512

With 8 CPUs, default_nareas = 8, so the minimum required nslabs is:

   IO_TLB_SEGSIZE * default_nareas = 128 * 8 = 1024
Quoted 8 lines

Since 512 < 1024, nslabs is rounded up to 1024 (2MB), which explains the roundup message.
I have incorrectly labelled this log in cover letter by posting the logs for CONFIG_SWIOTLB_DEFAULT_SIZE_MB=1 instead of CONFIG_SWIOTLB_DEFAULT_SIZE_MB=2
I will correct this info in the cover letter while sending the next revision along with the documentation update as you suggested.

Thanks. That all makes sense now.

Michael