From 794adc5814b0cf6d235fa902aad5f4cb06d7c329 Mon Sep 17 00:00:00 2001 From: chao an Date: Sun, 18 Dec 2022 17:12:28 +0800 Subject: [PATCH] net/tcp: contig received data to reducing iob consumption Fragmentation of network data will intensify iob consumption, if the device receives a message storm of fragmented packets, the iob cache will not be effectively used, this is not allowed on iot devices since the resources of such devices are limited. Of course, this also takes some disadvantages: data needs to be copied. This option will brings some balance on resource-constrained devices, enable this config to reduce the consumption of iob, the received iob buffers will be merged into the contiguous iob chain. Signed-off-by: chao an --- net/tcp/Kconfig | 14 ++++++++++++++ net/tcp/tcp_callback.c | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/net/tcp/Kconfig b/net/tcp/Kconfig index bea9f5159f..c0a42f3727 100644 --- a/net/tcp/Kconfig +++ b/net/tcp/Kconfig @@ -194,6 +194,20 @@ config NET_TCP_WRBUFFER_DUMP endif # NET_TCP_WRITE_BUFFERS +config NET_TCP_RECV_CONTIG + bool "Enable TCP/IP receive data in a continuous poll" + default y + ---help--- + This option will enable TCP/IP receive data into a continuous iob chain. + Fragmentation of network data will intensify iob consumption, if + the device receives a message storm of fragmented packets, the iob + cache will not be effectively used, this is not allowed on iot devices + since the resources of such devices are limited. Of course, this + also takes some disadvantages: data needs to be copied. + This option will brings some balance on resource-constrained devices, + enable this config to reduce the consumption of iob, the received iob + buffers will be merged into the contiguous iob chain. + config NET_TCPBACKLOG bool "TCP/IP backlog support" default n diff --git a/net/tcp/tcp_callback.c b/net/tcp/tcp_callback.c index 6d27baa457..9640224ccd 100644 --- a/net/tcp/tcp_callback.c +++ b/net/tcp/tcp_callback.c @@ -258,6 +258,14 @@ uint16_t tcp_datahandler(FAR struct net_driver_s *dev, iob_concat(conn->readahead, iob); } +#ifdef CONFIG_NET_TCP_RECV_CONTIG + /* Merge an iob chain into a continuous space, thereby reducing iob + * consumption. + */ + + conn->readahead = iob_contig(conn->readahead); +#endif + netdev_iob_clear(dev); #ifdef CONFIG_NET_TCP_NOTIFIER