embedded resource_error ai_generated true

lwIP: pbuf_alloc failed: PBUF_POOL exhausted, total=16, free=0, low=0

ID: embedded/lwip-pbuf-pool-exhaustion

Also available as: JSON · Markdown · 中文
82%Fix Rate
86%Confidence
1Evidence
2024-08-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
lwIP 2.1.3 active
lwIP 2.2.0 active
STM32Cube_FW_H7_V1.11.0 active

Root Cause

The lwIP PBUF_POOL memory pool is empty because all buffers are in use, typically due to network traffic spikes, memory leaks from unprocessed packets, or insufficient pool size configuration.

generic

中文

lwIP的PBUF_POOL内存池为空,因为所有缓冲区都在使用中,通常由于网络流量峰值、未处理数据包的内存泄漏或池大小配置不足引起。

Official Documentation

https://www.nongnu.org/lwip/2_1_x/group__pbuf.html

Workarounds

  1. 85% success Increase PBUF_POOL_SIZE in lwipopts.h (e.g., from 16 to 32 or 64) to handle burst traffic, and reduce PBUF_POOL_BUFSIZE if packet sizes are small.
    Increase PBUF_POOL_SIZE in lwipopts.h (e.g., from 16 to 32 or 64) to handle burst traffic, and reduce PBUF_POOL_BUFSIZE if packet sizes are small.
  2. 75% success Add a check in the Ethernet ISR to drop packets if pool is low, preventing system lockup: `if (pbuf_alloc(PBUF_RAW, 0, PBUF_POOL) == NULL) { return ERR_MEM; }`
    Add a check in the Ethernet ISR to drop packets if pool is low, preventing system lockup: `if (pbuf_alloc(PBUF_RAW, 0, PBUF_POOL) == NULL) { return ERR_MEM; }`
  3. 80% success Implement a periodic task to free orphaned pbufs by checking `lwip_stats.mem.used` and calling `tcpip_thread()` processing to flush queues.
    Implement a periodic task to free orphaned pbufs by checking `lwip_stats.mem.used` and calling `tcpip_thread()` processing to flush queues.

中文步骤

  1. Increase PBUF_POOL_SIZE in lwipopts.h (e.g., from 16 to 32 or 64) to handle burst traffic, and reduce PBUF_POOL_BUFSIZE if packet sizes are small.
  2. Add a check in the Ethernet ISR to drop packets if pool is low, preventing system lockup: `if (pbuf_alloc(PBUF_RAW, 0, PBUF_POOL) == NULL) { return ERR_MEM; }`
  3. Implement a periodic task to free orphaned pbufs by checking `lwip_stats.mem.used` and calling `tcpip_thread()` processing to flush queues.

Dead Ends

Common approaches that don't work:

  1. 80% fail

    Larger windows require more buffers; if the pool size isn't increased, exhaustion still occurs under load.

  2. 90% fail

    This shifts computation to CPU but doesn't affect buffer allocation; pool exhaustion persists.

  3. 95% fail

    ARP cache management doesn't free PBUF_POOL buffers; those are for packet data, not ARP entries.