From 336c0946fa3c7fdbbaeecfea4056eb57c0917c2c Mon Sep 17 00:00:00 2001 From: Paul Guyot Date: Thu, 2 Nov 2023 07:47:16 +0100 Subject: [PATCH 1/2] Add missing configuration for DEFAULT_ACCEPTMBOX_SIZE (fix #12509) Signed-off-by: Paul Guyot --- components/esp_wifi/src/wifi_init.c | 1 + components/lwip/Kconfig | 14 ++++++++++++++ components/lwip/port/include/lwipopts.h | 2 +- tools/ldgen/samples/sdkconfig | 1 + 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/components/esp_wifi/src/wifi_init.c b/components/esp_wifi/src/wifi_init.c index 73b11acf9ab..71614fcd8be 100644 --- a/components/esp_wifi/src/wifi_init.c +++ b/components/esp_wifi/src/wifi_init.c @@ -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_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); diff --git a/components/lwip/Kconfig b/components/lwip/Kconfig index 6204816fd42..e4a9e4c7305 100644 --- a/components/lwip/Kconfig +++ b/components/lwip/Kconfig @@ -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_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 diff --git a/components/lwip/port/include/lwipopts.h b/components/lwip/port/include/lwipopts.h index 55ce6558f82..9ca5d876142 100644 --- a/components/lwip/port/include/lwipopts.h +++ b/components/lwip/port/include/lwipopts.h @@ -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_ACCEPTMBOX_SIZE /** * DEFAULT_THREAD_STACKSIZE: The stack size used by any other lwIP thread. diff --git a/tools/ldgen/samples/sdkconfig b/tools/ldgen/samples/sdkconfig index a43ae9db5d3..a07b7101f2c 100644 --- a/tools/ldgen/samples/sdkconfig +++ b/tools/ldgen/samples/sdkconfig @@ -362,6 +362,7 @@ CONFIG_LWIP_TCP_MSL=60000 CONFIG_LWIP_TCP_SND_BUF_DEFAULT=5744 CONFIG_LWIP_TCP_WND_DEFAULT=5744 CONFIG_LWIP_TCP_RECVMBOX_SIZE=6 +CONFIG_LWIP_ACCEPTMBOX_SIZE=6 CONFIG_LWIP_TCP_QUEUE_OOSEQ=y CONFIG_LWIP_TCP_OVERSIZE_MSS=y CONFIG_LWIP_TCP_OVERSIZE_QUARTER_MSS= From 0c41c4e1da3b50a133f253207db29ab249c4c699 Mon Sep 17 00:00:00 2001 From: Abhik Roy Date: Fri, 1 Dec 2023 00:07:38 +1100 Subject: [PATCH 2/2] change(lwip): Added macro to configure TCP accept mailbox size --- components/esp_wifi/src/wifi_init.c | 2 +- components/lwip/Kconfig | 2 +- components/lwip/port/include/lwipopts.h | 2 +- docs/en/api-guides/coexist.rst | 1 + docs/en/api-guides/lwip.rst | 1 + tools/ldgen/samples/sdkconfig | 1 - 6 files changed, 5 insertions(+), 4 deletions(-) diff --git a/components/esp_wifi/src/wifi_init.c b/components/esp_wifi/src/wifi_init.c index 71614fcd8be..effe3f52f8c 100644 --- a/components/esp_wifi/src/wifi_init.c +++ b/components/esp_wifi/src/wifi_init.c @@ -190,7 +190,7 @@ static void esp_wifi_config_info(void) #endif #ifdef CONFIG_ESP_NETIF_TCPIP_LWIP - ESP_LOGI(TAG, "accept mbox: %d", CONFIG_LWIP_ACCEPTMBOX_SIZE); + 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); diff --git a/components/lwip/Kconfig b/components/lwip/Kconfig index e4a9e4c7305..10e9af7d931 100644 --- a/components/lwip/Kconfig +++ b/components/lwip/Kconfig @@ -665,7 +665,7 @@ 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_ACCEPTMBOX_SIZE + config LWIP_TCP_ACCEPTMBOX_SIZE int "Default TCP accept mail box size" default 6 range 1 64 if !LWIP_WND_SCALE diff --git a/components/lwip/port/include/lwipopts.h b/components/lwip/port/include/lwipopts.h index 9ca5d876142..9ce2ddc94b4 100644 --- a/components/lwip/port/include/lwipopts.h +++ b/components/lwip/port/include/lwipopts.h @@ -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 CONFIG_LWIP_ACCEPTMBOX_SIZE +#define DEFAULT_ACCEPTMBOX_SIZE CONFIG_LWIP_TCP_ACCEPTMBOX_SIZE /** * DEFAULT_THREAD_STACKSIZE: The stack size used by any other lwIP thread. diff --git a/docs/en/api-guides/coexist.rst b/docs/en/api-guides/coexist.rst index d0a626097a6..8ffd53f036c 100644 --- a/docs/en/api-guides/coexist.rst +++ b/docs/en/api-guides/coexist.rst @@ -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. diff --git a/docs/en/api-guides/lwip.rst b/docs/en/api-guides/lwip.rst index 43055ed2ba5..a0017f656d0 100644 --- a/docs/en/api-guides/lwip.rst +++ b/docs/en/api-guides/lwip.rst @@ -505,6 +505,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. diff --git a/tools/ldgen/samples/sdkconfig b/tools/ldgen/samples/sdkconfig index a07b7101f2c..a43ae9db5d3 100644 --- a/tools/ldgen/samples/sdkconfig +++ b/tools/ldgen/samples/sdkconfig @@ -362,7 +362,6 @@ CONFIG_LWIP_TCP_MSL=60000 CONFIG_LWIP_TCP_SND_BUF_DEFAULT=5744 CONFIG_LWIP_TCP_WND_DEFAULT=5744 CONFIG_LWIP_TCP_RECVMBOX_SIZE=6 -CONFIG_LWIP_ACCEPTMBOX_SIZE=6 CONFIG_LWIP_TCP_QUEUE_OOSEQ=y CONFIG_LWIP_TCP_OVERSIZE_MSS=y CONFIG_LWIP_TCP_OVERSIZE_QUARTER_MSS=