Skip to content

Commit

Permalink
Merge branch 'lwip/acceptmbox_config' into 'master'
Browse files Browse the repository at this point in the history
change(lwip): Added macro to configure TCP accept mailbox size

See merge request espressif/esp-idf!27276
  • Loading branch information
espressif-abhikroy committed Jan 3, 2024
2 parents 562b579 + 0c41c4e commit 0c99a58
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions components/esp_wifi/src/wifi_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ static void esp_wifi_config_info(void)
#endif

#ifdef CONFIG_ESP_NETIF_TCPIP_LWIP
ESP_LOGI(TAG, "accept mbox: %d", CONFIG_LWIP_TCP_ACCEPTMBOX_SIZE);
ESP_LOGI(TAG, "tcpip mbox: %d", CONFIG_LWIP_TCPIP_RECVMBOX_SIZE);
ESP_LOGI(TAG, "udp mbox: %d", CONFIG_LWIP_UDP_RECVMBOX_SIZE);
ESP_LOGI(TAG, "tcp mbox: %d", CONFIG_LWIP_TCP_RECVMBOX_SIZE);
Expand Down
14 changes: 14 additions & 0 deletions components/lwip/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,20 @@ menu "LWIP"
mail box is full, the LWIP drops the packets. So generally we need to make sure the TCP
receive mail box is big enough to avoid packet drop between LWIP core and application.

config LWIP_TCP_ACCEPTMBOX_SIZE
int "Default TCP accept mail box size"
default 6
range 1 64 if !LWIP_WND_SCALE
range 1 255 if LWIP_WND_SCALE
help
Set TCP accept mail box size. Generally bigger value means supporting larger backlogs
but more memory. The recommended value is 6, but applications can set it to a lower value
if listening servers are meant to have a smaller backlog.

TCP accept mail box is a per socket mail box, when the application listens for connections
with a given listening TCP socket. If the mailbox is full, LWIP will send a RST packet and
the client will fail to connect.

config LWIP_TCP_QUEUE_OOSEQ
bool "Queue incoming out-of-order segments"
default y
Expand Down
2 changes: 1 addition & 1 deletion components/lwip/port/include/lwipopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ static inline uint32_t timeout_from_offered(uint32_t lease, uint32_t min)
* The queue size value itself is platform-dependent, but is passed to
* sys_mbox_new() when the acceptmbox is created.
*/
#define DEFAULT_ACCEPTMBOX_SIZE 6
#define DEFAULT_ACCEPTMBOX_SIZE CONFIG_LWIP_TCP_ACCEPTMBOX_SIZE

/**
* DEFAULT_THREAD_STACKSIZE: The stack size used by any other lwIP thread.
Expand Down
1 change: 1 addition & 0 deletions docs/en/api-guides/coexist.rst
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ Setting Coexistence Compile-time Options
#) :ref:`CONFIG_LWIP_TCP_SND_BUF_DEFAULT`: reduce the default TX buffer size for TCP sockets.
#) :ref:`CONFIG_LWIP_TCP_WND_DEFAULT`: reduce the default size of the RX window for TCP sockets.
#) :ref:`CONFIG_LWIP_TCP_RECVMBOX_SIZE`: reduce the size of the TCP receive mailbox.
#) :ref:`CONFIG_LWIP_TCP_ACCEPTMBOX_SIZE`: reduce the size of the TCP accept mailbox.
#) :ref:`CONFIG_LWIP_UDP_RECVMBOX_SIZE`: reduce the size of the UDP receive mailbox.
#) :ref:`CONFIG_LWIP_TCPIP_RECVMBOX_SIZE`: reduce the size of TCPIP task receive mailbox.

Expand Down
1 change: 1 addition & 0 deletions docs/en/api-guides/lwip.rst
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ Most lwIP RAM usage is on-demand, as RAM is allocated from the heap as needed. T

- Reducing :ref:`CONFIG_LWIP_MAX_SOCKETS` reduces the maximum number of sockets in the system. This also causes TCP sockets in the ``WAIT_CLOSE`` state to be closed and recycled more rapidly when needed to open a new socket, further reducing peak RAM usage.
- Reducing :ref:`CONFIG_LWIP_TCPIP_RECVMBOX_SIZE`, :ref:`CONFIG_LWIP_TCP_RECVMBOX_SIZE` and :ref:`CONFIG_LWIP_UDP_RECVMBOX_SIZE` reduce RAM usage at the expense of throughput, depending on usage.
- Reducing :ref:`CONFIG_LWIP_TCP_ACCEPTMBOX_SIZE` reduce RAM usage by limiting concurrent accepted connections.
- Reducing :ref:`CONFIG_LWIP_TCP_MSL` and :ref:`CONFIG_LWIP_TCP_FIN_WAIT_TIMEOUT` reduces the maximum segment lifetime in the system. This also causes TCP sockets in the ``TIME_WAIT`` and ``FIN_WAIT_2`` states to be closed and recycled more rapidly.
- Disabling :ref:`CONFIG_LWIP_IPV6` can save about 39 KB for firmware size and 2 KB RAM when the system is powered up and 7 KB RAM when the TCP/IP stack is running. If there is no requirement for supporting IPV6, it can be disabled to save flash and RAM footprint.
- Disabling :ref:`CONFIG_LWIP_IPV4` can save about 26 KB of firmware size and 600 B RAM on power up and 6 KB RAM when the TCP/IP stack is running. If the local network supports IPv6-only configuration, IPv4 can be disabled to save flash and RAM footprint.
Expand Down

0 comments on commit 0c99a58

Please sign in to comment.