[PATCH] net: lwip: scale buffer pool size with TFTP block size

Vinay Tilak, Pranav Pranav.VinayTilak at amd.com
Tue Mar 10 12:45:48 CET 2026


[Public]

Hi Jonas,

> -----Original Message-----
> From: Jonas Karlman <jonas at kwiboo.se>
> Sent: Tuesday, March 10, 2026 2:49 AM
> To: Vinay Tilak, Pranav <Pranav.VinayTilak at amd.com>; Jerome Forissier
> <jerome.forissier at arm.com>
> Cc: u-boot at lists.denx.de; Simek, Michal <michal.simek at amd.com>; git
> (AMD-Xilinx) <git at amd.com>; Begari, Padmarao
> <Padmarao.Begari at amd.com>; Tom Rini <trini at konsulko.com>;
> nd at arm.com
> 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,
>
> On 3/9/2026 2:19 PM, Vinay Tilak, Pranav wrote:
> > [Public]
> >
> > Hi Jerome,
> >
> >> -----Original Message-----
> >> From: Jerome Forissier <jerome.forissier at arm.com>
> >> Sent: Monday, March 9, 2026 1:38 PM
> >> To: Vinay Tilak, Pranav <Pranav.VinayTilak at amd.com>;
> >> u-boot at lists.denx.de; Simek, Michal <michal.simek at amd.com>
> >> Cc: git (AMD-Xilinx) <git at amd.com>; Begari, Padmarao
> >> <Padmarao.Begari at amd.com>; Tom Rini <trini at konsulko.com>;
> nd at arm.com
> >> 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,
> >>
> >> On 05/03/2026 07:40, Pranav Tilak wrote:
> >>> 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
> >>
> >> How 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].
>
> 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)
>

Yes we can implement it in this way.
Will send v2 patch making these changes.

Thanks,
Pranav Tilak

> 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/20260309210642.522626-1-
> jonas at kwiboo.se/
>
> Regards,
> Jonas
>
> >
> > We can scale only if CONFIG_TFTP_BLOCKSIZE > 4096 else use the default
> values.
> >>
> >> Thanks,
> >> --
> >> Jerome
> >>
> >>> Signed-off-by: Pranav Tilak <pranav.vinaytilak at amd.com>
> >>> ---
> >>>  lib/lwip/u-boot/lwipopts.h | 15 +++++++++++++++
> >>>  1 file changed, 15 insertions(+)
> >>>
> >>> diff --git a/lib/lwip/u-boot/lwipopts.h b/lib/lwip/u-boot/lwipopts.h
> >>> index e8a2c9d7a0a..b4ff31096fe 100644
> >>> --- a/lib/lwip/u-boot/lwipopts.h
> >>> +++ b/lib/lwip/u-boot/lwipopts.h
> >>> @@ -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
> >
> > Thanks,
> > Pranav Tilak



More information about the U-Boot mailing list