net: lwip: scale buffer pool size with TFTP block size
PATCH 1/1 net: lwip: scale buffer pool size with TFTP block size
TFTP transfers fail when tftpblocksize is set to 8192 or larger due to insufficient buffer resources for IP fragment reassembly.
Adjust PBUF_POOL_SIZE and IP_REASS_MAX_PBUFS based on CONFIG_TFTP_BLOCKSIZE to support larger TFTP transfers while keeping memory usage efficient.
- CONFIG_TFTP_BLOCKSIZE >= 12288:PBUF_POOL_SIZE=18, IP_REASS_MAX_PBUFS=12
- CONFIG_TFTP_BLOCKSIZE >= 8192:PBUF_POOL_SIZE=12, IP_REASS_MAX_PBUFS=6
- CONFIG_TFTP_BLOCKSIZE undefined: PBUF_POOL_SIZE=8, IP_REASS_MAX_PBUFS=4
--- lib/lwip/u-boot/lwipopts.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
lib/lwip/u-boot/lwipopts.h +15 -0
@@ -65,7 +65,14 @@#define MEM_ALIGNMENT 8#define MEMP_NUM_TCP_SEG 16 + +#if defined(CONFIG_TFTP_BLOCKSIZE ) &&CONFIG_TFTP_BLOCKSIZE >=12288 +#define PBUF_POOL_SIZE 18 +#elif defined(CONFIG_TFTP_BLOCKSIZE ) &&CONFIG_TFTP_BLOCKSIZE >=8192 +#define PBUF_POOL_SIZE 12 +#else #define PBUF_POOL_SIZE 8 +#endif #define LWIP_ARP 1#define ARP_TABLE_SIZE 4
@@ -76,7 +83,15 @@#define IP_REASSEMBLY 1#define IP_FRAG 1#define IP_REASS_MAXAGE 3 + +#if defined(CONFIG_TFTP_BLOCKSIZE ) &&CONFIG_TFTP_BLOCKSIZE >=12288 +#define IP_REASS_MAX_PBUFS 12 +#elif defined(CONFIG_TFTP_BLOCKSIZE ) &&CONFIG_TFTP_BLOCKSIZE >=8192 +#define IP_REASS_MAX_PBUFS 6 +#else #define IP_REASS_MAX_PBUFS 4 +#endif +#define IP_FRAG_USES_STATIC_BUF 0#define IP_DEFAULT_TTL 255
Signature · 1 line
2.34.1
Hi Pranav,
Quoted 7 lines · Pranav Tilak
TFTP transfers fail when tftpblocksize is set to 8192 or larger due to insufficient buffer resources for IP fragment reassembly.
Adjust
PBUF_POOL_SIZEandIP_REASS_MAX_PBUFSbased onCONFIG_TFTP_BLOCKSIZEto support larger TFTP transfers while keeping memory usage efficient.
Quoted 5 lines
-
CONFIG_TFTP_BLOCKSIZE>= 12288:PBUF_POOL_SIZE=18, IP_REASS_MAX_PBUFS=12-
CONFIG_TFTP_BLOCKSIZE>= 8192:PBUF_POOL_SIZE=12, IP_REASS_MAX_PBUFS=6-
CONFIG_TFTP_BLOCKSIZEundefined: PBUF_POOL_SIZE=8, IP_REASS_MAX_PBUFS=4
How are these values computed? Could you find a formula instead of using #if/#elif/#else/endif?
Thanks,
Signature · 1 line
Jerome
Quoted 40 lines
Signed-off-by Pranav Tilak <[email protected]>--- lib/lwip/u-boot/lwipopts.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)lib/lwip/u-boot/lwipopts.h +15
-0@@ -65,7 +65,14 @@#define MEM_ALIGNMENT 8#define MEMP_NUM_TCP_SEG 16 + +#if defined(CONFIG_TFTP_BLOCKSIZE ) &&CONFIG_TFTP_BLOCKSIZE >=12288 +#define PBUF_POOL_SIZE 18 +#elif defined(CONFIG_TFTP_BLOCKSIZE ) &&CONFIG_TFTP_BLOCKSIZE >=8192 +#define PBUF_POOL_SIZE 12 +#else #define PBUF_POOL_SIZE 8 +#endif #define LWIP_ARP 1#define ARP_TABLE_SIZE 4@@ -76,7 +83,15 @@#define IP_REASSEMBLY 1#define IP_FRAG 1#define IP_REASS_MAXAGE 3 + +#if defined(CONFIG_TFTP_BLOCKSIZE ) &&CONFIG_TFTP_BLOCKSIZE >=12288 +#define IP_REASS_MAX_PBUFS 12 +#elif defined(CONFIG_TFTP_BLOCKSIZE ) &&CONFIG_TFTP_BLOCKSIZE >=8192 +#define IP_REASS_MAX_PBUFS 6 +#else #define IP_REASS_MAX_PBUFS 4 +#endif +#define IP_FRAG_USES_STATIC_BUF 0#define IP_DEFAULT_TTL 255
[Public]
Hi Jerome,
Quoted 27 lines
-----Original Message-----
From: Jerome Forissier <[email protected]>
Sent: Monday, March 9, 2026 1:38 PM
To: Vinay Tilak, Pranav <[email protected]>; [email protected]; Simek, Michal <[email protected]>
Cc: git (AMD-Xilinx) <[email protected]>; Begari, Padmarao <[email protected]>; Tom Rini <[email protected]>; [email protected]
Subject: Re: [PATCH] net: lwip: scale buffer pool size with TFTP block sizeCaution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
Hi Pranav,
Quoted 10 lines · Pranav Tilak
TFTP transfers fail when tftpblocksize is set to 8192 or larger due to insufficient buffer resources for IP fragment reassembly.
Adjust
PBUF_POOL_SIZEandIP_REASS_MAX_PBUFSbased onCONFIG_TFTP_BLOCKSIZEto support larger TFTP transfers while keeping memory usage efficient.-
CONFIG_TFTP_BLOCKSIZE>= 12288:PBUF_POOL_SIZE=18, IP_REASS_MAX_PBUFS=12
Quoted 8 lines
Quoted 5 lines
-
CONFIG_TFTP_BLOCKSIZE>= 8192:PBUF_POOL_SIZE=12, IP_REASS_MAX_PBUFS=6-
CONFIG_TFTP_BLOCKSIZEundefined: PBUF_POOL_SIZE=8, IP_REASS_MAX_PBUFS=4How are these values computed? Could you find a formula instead of using #if/#elif/#else/endif?
We can use this formula for calculating the values of PBUF_POOL_SIZE and IP_REASS_MAX_PBUFS. 1500 (MTU) - 20 (IP header) = 1480 usable bytes/fragments.IP_REASS_MAX_PBUFS = (((CONFIG_TFTP_BLOCKSIZE) + 1479) / 1480) + 2
[ceiling division to calculate fragment count + some headroom for next block sync]. PBUF_POOL_SIZE = (IP_REASS_MAX_PBUFS) * 2
[Reassembly buffers * 2].
We can scale only if CONFIG_TFTP_BLOCKSIZE > 4096 else use the default values.
Quoted 41 lines
Thanks,
--
JeromeQuoted 10 lines
Signed-off-by Pranav Tilak <[email protected]>--- lib/lwip/u-boot/lwipopts.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)lib/lwip/u-boot/lwipopts.h +0
-0lib/lwip/u-boot/lwipopts.h line 69
Quoted 5 lines
lib/lwip/u-boot/lwipopts.h +2
-0@@ -65,7 +65,14 @@#define MEM_ALIGNMENT 8#define MEMP_NUM_TCP_SEG 16 + +#if defined(CONFIG_TFTP_BLOCKSIZE) && CONFIG_TFTP_BLOCKSIZE >=12288
lib/lwip/u-boot/lwipopts.h line 71
Quoted 2 lines
lib/lwip/u-boot/lwipopts.h +2
-0+#define PBUF_POOL_SIZE 18 +#elif defined(CONFIG_TFTP_BLOCKSIZE) && CONFIG_TFTP_BLOCKSIZE >=8192
lib/lwip/u-boot/lwipopts.h line 87
Quoted 13 lines
lib/lwip/u-boot/lwipopts.h +5
-0+#define PBUF_POOL_SIZE 12 +#else #define PBUF_POOL_SIZE 8 +#endif #define LWIP_ARP 1#define ARP_TABLE_SIZE 4@@ -76,7 +83,15 @@#define IP_REASSEMBLY 1#define IP_FRAG 1#define IP_REASS_MAXAGE 3 + +#if defined(CONFIG_TFTP_BLOCKSIZE) && CONFIG_TFTP_BLOCKSIZE >=12288
lib/lwip/u-boot/lwipopts.h line 89
Quoted 2 lines
lib/lwip/u-boot/lwipopts.h +2
-0+#define IP_REASS_MAX_PBUFS 12 +#elif defined(CONFIG_TFTP_BLOCKSIZE) && CONFIG_TFTP_BLOCKSIZE >=8192
Quoted 8 lines
lib/lwip/u-boot/lwipopts.h line 97
Quoted 8 lines
lib/lwip/u-boot/lwipopts.h +4
-0+#define IP_REASS_MAX_PBUFS 6 +#else #define IP_REASS_MAX_PBUFS 4 +#endif +#define IP_FRAG_USES_STATIC_BUF 0#define IP_DEFAULT_TTL 255
Thanks,
Pranav Tilak
Hi,
Quoted 40 lines · Pranav
[Public]
Hi Jerome,
Quoted 27 lines
-----Original Message-----
From: Jerome Forissier <[email protected]>
Sent: Monday, March 9, 2026 1:38 PM
To: Vinay Tilak, Pranav <[email protected]>; [email protected]; Simek, Michal <[email protected]>
Cc: git (AMD-Xilinx) <[email protected]>; Begari, Padmarao <[email protected]>; Tom Rini <[email protected]>; [email protected]
Subject: Re: [PATCH] net: lwip: scale buffer pool size with TFTP block sizeCaution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
Hi Pranav,
Quoted 10 lines · Pranav Tilak
TFTP transfers fail when tftpblocksize is set to 8192 or larger due to insufficient buffer resources for IP fragment reassembly.
Adjust
PBUF_POOL_SIZEandIP_REASS_MAX_PBUFSbased onCONFIG_TFTP_BLOCKSIZEto support larger TFTP transfers while keeping memory usage efficient.-
CONFIG_TFTP_BLOCKSIZE>= 12288:PBUF_POOL_SIZE=18, IP_REASS_MAX_PBUFS=12Quoted 8 lines
Quoted 5 lines
-
CONFIG_TFTP_BLOCKSIZE>= 8192:PBUF_POOL_SIZE=12, IP_REASS_MAX_PBUFS=6-
CONFIG_TFTP_BLOCKSIZEundefined: PBUF_POOL_SIZE=8, IP_REASS_MAX_PBUFS=4How are these values computed? Could you find a formula instead of using #if/#elif/#else/endif?
Quoted 6 lines
We can use this formula for calculating the values of
PBUF_POOL_SIZEandIP_REASS_MAX_PBUFS. 1500 (MTU) - 20 (IP header) = 1480 usable bytes/fragments.IP_REASS_MAX_PBUFS= (((CONFIG_TFTP_BLOCKSIZE) + 1479) / 1480) + 2
[ceiling division to calculate fragment count + some headroom for next block sync].PBUF_POOL_SIZE= (IP_REASS_MAX_PBUFS) * 2
[Reassembly buffers * 2].
The lwip comment for IP_REASS_MAX_PBUFS only suggest PBUF_POOL_SIZE is more than 2x IP_REASS_MAX_PBUFS when both IPv4 and IPv6 is enabled.
Maybe something like following should work?
#if defined(CONFIG_TFTP_BLOCKSIZE) && CONFIG_TFTP_BLOCKSIZE > 4096 #define PBUF_POOL_SIZE (((CONFIG_TFTP_BLOCKSIZE + 1479) / 1480) + 6) #else [...] #define IP_REASS_MAX_PBUFS (PBUF_POOL_SIZE - 4)
That seem to work great when I test with TFTP_BLOCKSIZE=16352 on my Rockchip boards together with a PBUF_POOL_BUFSIZE fix [1].
[1] https://lore.kernel.org/u-boot/[email protected]/
Regards,
Jonas
Quoted 54 lines
We can scale only if
CONFIG_TFTP_BLOCKSIZE> 4096 else use the default values.Quoted 41 lines
Thanks,
--
JeromeQuoted 10 lines
Signed-off-by Pranav Tilak <[email protected]>--- lib/lwip/u-boot/lwipopts.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)lib/lwip/u-boot/lwipopts.h +0
-0lib/lwip/u-boot/lwipopts.h line 69
Quoted 5 lines
lib/lwip/u-boot/lwipopts.h +2
-0@@ -65,7 +65,14 @@#define MEM_ALIGNMENT 8#define MEMP_NUM_TCP_SEG 16 + +#if defined(CONFIG_TFTP_BLOCKSIZE) && CONFIG_TFTP_BLOCKSIZE >=12288
lib/lwip/u-boot/lwipopts.h line 71
Quoted 2 lines
lib/lwip/u-boot/lwipopts.h +2
-0+#define PBUF_POOL_SIZE 18 +#elif defined(CONFIG_TFTP_BLOCKSIZE) && CONFIG_TFTP_BLOCKSIZE >=8192
lib/lwip/u-boot/lwipopts.h line 87
Quoted 13 lines
lib/lwip/u-boot/lwipopts.h +5
-0+#define PBUF_POOL_SIZE 12 +#else #define PBUF_POOL_SIZE 8 +#endif #define LWIP_ARP 1#define ARP_TABLE_SIZE 4@@ -76,7 +83,15 @@#define IP_REASSEMBLY 1#define IP_FRAG 1#define IP_REASS_MAXAGE 3 + +#if defined(CONFIG_TFTP_BLOCKSIZE) && CONFIG_TFTP_BLOCKSIZE >=12288
lib/lwip/u-boot/lwipopts.h line 89
Quoted 2 lines
lib/lwip/u-boot/lwipopts.h +2
-0+#define IP_REASS_MAX_PBUFS 12 +#elif defined(CONFIG_TFTP_BLOCKSIZE) && CONFIG_TFTP_BLOCKSIZE >=8192
Quoted 8 lines
lib/lwip/u-boot/lwipopts.h line 97
Quoted 8 lines
lib/lwip/u-boot/lwipopts.h +4
-0+#define IP_REASS_MAX_PBUFS 6 +#else #define IP_REASS_MAX_PBUFS 4 +#endif +#define IP_FRAG_USES_STATIC_BUF 0#define IP_DEFAULT_TTL 255Thanks,
Pranav Tilak
[Public]
Hi Jonas,
Quoted 70 lines
-----Original Message-----
From: Jonas Karlman <[email protected]>
Sent: Tuesday, March 10, 2026 2:49 AM
To: Vinay Tilak, Pranav <[email protected]>; Jerome Forissier <[email protected]>
Cc: [email protected]; Simek, Michal <[email protected]>; git (AMD-Xilinx) <[email protected]>; Begari, Padmarao <[email protected]>; Tom Rini <[email protected]>; [email protected]
Subject: Re: [PATCH] net: lwip: scale buffer pool size with TFTP block sizeCaution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
Hi,
Quoted 11 lines · Pranav
[Public]
Hi Jerome,
Quoted 7 lines
-----Original Message-----
From: Jerome Forissier <[email protected]>
Sent: Monday, March 9, 2026 1:38 PM
To: Vinay Tilak, Pranav <[email protected]>; [email protected]; Simek, Michal <[email protected]>
Cc: git (AMD-Xilinx) <[email protected]>; Begari, Padmarao <[email protected]>; Tom Rini <[email protected]>;Quoted 23 lines
Quoted 23 lines
Subject: Re: [PATCH] net: lwip: scale buffer pool size with TFTP block size
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
Hi Pranav,
Quoted 13 lines · Pranav Tilak
TFTP transfers fail when tftpblocksize is set to 8192 or larger due to insufficient buffer resources for IP fragment reassembly.
Adjust
PBUF_POOL_SIZEandIP_REASS_MAX_PBUFSbased onCONFIG_TFTP_BLOCKSIZEto support larger TFTP transfers while keeping memory usage efficient.-
CONFIG_TFTP_BLOCKSIZE>= 12288:PBUF_POOL_SIZE=18, IP_REASS_MAX_PBUFS=12-
CONFIG_TFTP_BLOCKSIZE>= 8192:PBUF_POOL_SIZE=12, IP_REASS_MAX_PBUFS=6Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
-
CONFIG_TFTP_BLOCKSIZEundefined: PBUF_POOL_SIZE=8, IP_REASS_MAX_PBUFS=4How are these values computed? Could you find a formula instead of using #if/#elif/#else/endif?
We can use this formula for calculating the values of
PBUF_POOL_SIZEand
IP_REASS_MAX_PBUFS.Quoted 3 lines
1500 (MTU) - 20 (IP header) = 1480 usable bytes/fragments.
IP_REASS_MAX_PBUFS= (((CONFIG_TFTP_BLOCKSIZE) + 1479) / 1480) + 2 [ceiling division to calculate fragment count + some headroom for nextblock sync].
Quoted 1 line
PBUF_POOL_SIZE= (IP_REASS_MAX_PBUFS) * 2 [Reassembly buffers * 2].The lwip comment for
IP_REASS_MAX_PBUFSonly suggestPBUF_POOL_SIZEis more than 2xIP_REASS_MAX_PBUFSwhen both IPv4 and IPv6 is enabled.
Quoted 9 lines
Maybe something like following should work?
#if
defined(CONFIG_TFTP_BLOCKSIZE)&&CONFIG_TFTP_BLOCKSIZE> 4096
#definePBUF_POOL_SIZE(((CONFIG_TFTP_BLOCKSIZE+ 1479) /
1480) + 6)
#else
[...]
#defineIP_REASS_MAX_PBUFS(PBUF_POOL_SIZE- 4)
Yes we can implement it in this way.
Will send v2 patch making these changes.
Thanks,
Pranav Tilak
Quoted 66 lines
That seem to work great when I test with TFTP_BLOCKSIZE=16352 on my Rockchip boards together with a
PBUF_POOL_BUFSIZEfix [1].[1] https://lore.kernel.org/u-boot/20260309210642.522626-1-
[email protected]/Regards,
JonasQuoted 2 lines
We can scale only if
CONFIG_TFTP_BLOCKSIZE> 4096 else use the defaultvalues.
Quoted 54 lines
Quoted 17 lines
Thanks,
--
JeromeQuoted 12 lines
Signed-off-by Pranav Tilak <[email protected]>--- lib/lwip/u-boot/lwipopts.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)lib/lwip/u-boot/lwipopts.h +0
-0@@ -65,7 +65,14 @@#define MEM_ALIGNMENT 8Quoted 6 lines
lib/lwip/u-boot/lwipopts.h
Quoted 3 lines
lib/lwip/u-boot/lwipopts.h +2
-0#define MEMP_NUM_TCP_SEG 16 + +#if defined(CONFIG_TFTP_BLOCKSIZE) && CONFIG_TFTP_BLOCKSIZE >=12288
lib/lwip/u-boot/lwipopts.h line 71
Quoted 2 lines
lib/lwip/u-boot/lwipopts.h +2
-0+#define PBUF_POOL_SIZE 18 +#elif defined(CONFIG_TFTP_BLOCKSIZE ) &&CONFIG_TFTP_BLOCKSIZE =
Quoted 15 lines
8192
lib/lwip/u-boot/lwipopts.h line 87
Quoted 13 lines
lib/lwip/u-boot/lwipopts.h +5
-0+#define PBUF_POOL_SIZE 12 +#else #define PBUF_POOL_SIZE 8 +#endif #define LWIP_ARP 1#define ARP_TABLE_SIZE 4@@ -76,7 +83,15 @@#define IP_REASSEMBLY 1#define IP_FRAG 1#define IP_REASS_MAXAGE 3 + +#if defined(CONFIG_TFTP_BLOCKSIZE) && CONFIG_TFTP_BLOCKSIZE >=12288
Quoted 2 lines
lib/lwip/u-boot/lwipopts.h line 89
Quoted 2 lines
lib/lwip/u-boot/lwipopts.h +2
-0+#define IP_REASS_MAX_PBUFS 12 +#elif defined(CONFIG_TFTP_BLOCKSIZE ) &&CONFIG_TFTP_BLOCKSIZE =
Quoted 9 lines
8192
lib/lwip/u-boot/lwipopts.h line 97
Quoted 8 lines
lib/lwip/u-boot/lwipopts.h +4
-0+#define IP_REASS_MAX_PBUFS 6 +#else #define IP_REASS_MAX_PBUFS 4 +#endif +#define IP_FRAG_USES_STATIC_BUF 0#define IP_DEFAULT_TTL 255Thanks,
Pranav Tilak