]> granicus.if.org Git - esp-idf/commitdiff
lwip: Allow configuring/disabling some TCP options to save RAM
authorAngus Gratton <angus@espressif.com>
Thu, 22 Jun 2017 07:14:21 +0000 (17:14 +1000)
committerAngus Gratton <gus@projectgus.com>
Fri, 23 Jun 2017 06:26:11 +0000 (16:26 +1000)
RAM savings are small, but may add up when running large numbers of sockets.

components/lwip/Kconfig
components/lwip/core/pbuf.c
components/lwip/include/lwip/port/lwipopts.h
components/lwip/port/debug/lwip_debug.c

index 436d0839364ab2a24430be27c455d3f4ce9a53b1..38107b8ac808dc95a0d79549fa379a159ea02dd4 100644 (file)
@@ -68,6 +68,8 @@ config LWIP_IP_REASSEMBLY
     help
         Enabling this option allows reassemblying incoming fragmented IP packets.
 
+menu "TCP"
+
 config TCP_MAXRTX
     int "Maximum number of retransmissions of data segments"
     default 12
@@ -82,6 +84,79 @@ config TCP_SYNMAXRTX
     help
         Set maximum number of retransmissions of SYN segments.
 
+config TCP_MSS
+    int "Maximum Segment Size (MSS)"
+    default 1436
+    range 1220 1436
+    help
+        Set maximum segment size for TCP transmission.
+
+        Can be set lower to save RAM, the default value 1436 will give best throughput.
+
+config TCP_SND_BUF_DEFAULT
+    int "Default send buffer size"
+    default 5744  # 4 * default MSS
+    range 2440 65535
+    help
+        Set default send buffer size for new TCP sockets.
+
+        Per-socket send buffer size can be changed at runtime
+        with lwip_setsockopt(s, TCP_SNDBUF, ...).
+
+        This value must be at least 2x the MSS size, and the default
+        is 4x the default MSS size.
+
+        Setting a smaller default SNDBUF size can save some RAM, but
+        will decrease performance.
+
+config TCP_WND_DEFAULT
+    int "Default receive window size"
+    default 5744 # 4 * default MSS
+    range 2440 65535
+    help
+        Set default TCP receive window size for new TCP sockets.
+
+        Per-socket receive window size can be changed at runtime
+        with lwip_setsockopt(s, TCP_WINDOW, ...).
+
+        Setting a smaller default receive window size can save some RAM,
+        but will significantly decrease performance.
+
+config TCP_QUEUE_OOSEQ
+    bool "Queue incoming out-of-order segments"
+    default y
+    help
+        Queue incoming out-of-order segments for later use.
+
+        Disable this option to save some RAM during TCP sessions, at the expense
+        of increased retransmissions if segments arrive out of order.
+
+choice TCP_OVERSIZE
+    prompt "Pre-allocate transmit PBUF size"
+    default TCP_OVERSIZE_MSS
+    help
+        Allows enabling "oversize" allocation of TCP transmission pbufs ahead of time,
+        which can reduce the length of pbuf chains used for transmission.
+
+        This will not make a difference to sockets where Nagle's algorithm
+        is disabled.
+
+        Default value of MSS is fine for most applications, 25% MSS may save
+        some RAM when only transmitting small amounts of data. Disabled will
+        have worst performance and fragmentation characteristics, but uses
+        least RAM overall.
+
+config TCP_OVERSIZE_MSS
+     bool "MSS"
+config TCP_OVERSIZE_QUARTER_MSS
+     bool "25% MSS"
+config TCP_OVERSIZE_DISABLE
+     bool "Disabled"
+
+endchoice
+
+endmenu # TCP
+
 config LWIP_DHCP_DOES_ARP_CHECK
     bool "Enable an ARP check on the offered address"
     default y
index 84dcc3103657aeefecbddccb8eff29f90ec8d91c..8c2eb05a54658f3eb76fbd9f01eae51e92f341ae 100755 (executable)
@@ -69,7 +69,7 @@
 #include "lwip/memp.h"
 #include "lwip/pbuf.h"
 #include "lwip/sys.h"
-#if LWIP_TCP && TCP_QUEUE_OOSEQ
+#if LWIP_TCP && (TCP_QUEUE_OOSEQ || ESP_LWIP)
 #include "lwip/priv/tcp_priv.h"
 #endif
 #if LWIP_CHECKSUM_ON_COPY
index 10b0dd7c7cb8148abcee26e11e8bb09f814c3fe5..a4b07006e75fdc1823de457ae91640cb64ff2264 100644 (file)
  * TCP_QUEUE_OOSEQ==1: TCP will queue segments that arrive out of order.
  * Define to 0 if your device is low on memory.
  */
-#define TCP_QUEUE_OOSEQ                 1
+#define TCP_QUEUE_OOSEQ                 CONFIG_TCP_QUEUE_OOSEQ
 
 /*
  *     LWIP_EVENT_API==1: The user defines lwip_tcp_event() to receive all
  *     LWIP_CALLBACK_API==1: The PCB callback function is called directly
  *         for the event. This is the default.
 */
-#define TCP_MSS                         1460
+#define TCP_MSS                         CONFIG_TCP_MSS
 
 /**
  * TCP_MAXRTX: Maximum number of retransmissions of data segments.
  */
 #define TCP_LISTEN_BACKLOG              1
 
+
+/**
+ * TCP_OVERSIZE: The maximum number of bytes that tcp_write may
+ * allocate ahead of time
+ */
+#ifdef CONFIG_TCP_OVERSIZE_MSS
+#define TCP_OVERSIZE                    TCP_MSS
+#endif
+#ifdef CONFIG_TCP_OVERSIZE_QUARTER_MSS
+#define TCP_OVERSIZE                    (TCP_MSS/4)
+#endif
+#ifdef CONFIG_TCP_OVERSIZE_DISABLE
+#define TCP_OVERSIZE                    0
+#endif
+#ifndef TCP_OVERSIZE
+#error "One of CONFIG_TCP_OVERSIZE_xxx options should be set by sdkconfig"
+#endif
+
 /*
    ----------------------------------
    ---------- Pbuf options ----------
 #define ESP_DHCP_TIMER                  1
 #define ESP_LWIP_LOGI(...)              ESP_LOGI("lwip", __VA_ARGS__)
 
-#define TCP_WND_DEFAULT                 (4*TCP_MSS)
-#define TCP_SND_BUF_DEFAULT             (4*TCP_MSS)
+#define TCP_WND_DEFAULT                 CONFIG_TCP_WND_DEFAULT
+#define TCP_SND_BUF_DEFAULT             CONFIG_TCP_SND_BUF_DEFAULT
 
 #if ESP_PERF
 #define DBG_PERF_PATH_SET(dir, point)
index 155941c1c5cea6cc6634b40eac95c7d85501153a..2a48608cf308e0cda3b89b4befc84f650e41a969 100644 (file)
@@ -110,9 +110,11 @@ static void dbg_lwip_tcp_pcb_one_show(struct tcp_pcb* pcb)
     seg = pcb->unacked;
     DBG_LWIP_SEG_SHOW(seg);
 
-    ESP_LWIP_LOGI("ooseg semengts:");
+#if TCP_QUEUE_OOSEQ
+    ESP_LWIP_LOGI("ooseq semengts:");
     seg = pcb->ooseq;
     DBG_LWIP_SEG_SHOW(seg);
+#endif
 
     ESP_LWIP_LOGI("refused data=%p", pcb->refused_data);