From 8e2722e1cae6d7a2c65d26d4393e1bcf6550cd40 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Wed, 27 Mar 2024 16:15:13 +0100 Subject: [PATCH] net: Provide separate configs for TX/RX memory pool for variable bufs Instead of having a single config specifying the memory pool size for variable-sized net buffers, have a separate one for TX and RX for better configuration granularity when optimizing memory usage of the application. Deprecate the old configuration but use its value as a default (for now) for the new configs. This will need to change when the config is deleted. Signed-off-by: Robert Lubos --- .../networking/net_config_guide.rst | 4 ++-- subsys/net/ip/Kconfig | 20 +++++++++++++++++-- subsys/net/ip/net_pkt.c | 4 ++-- subsys/net/ip/tcp.c | 4 ++-- subsys/net/lib/capture/capture.c | 4 +++- subsys/net/lib/shell/mem.c | 3 ++- tests/drivers/build_all/ethernet/prj.conf | 3 ++- tests/net/6lo/testcase.yaml | 3 ++- tests/net/all/prj.conf | 3 ++- tests/net/ipv6/testcase.yaml | 3 ++- tests/net/tcp/testcase.yaml | 3 ++- 11 files changed, 39 insertions(+), 15 deletions(-) diff --git a/doc/connectivity/networking/net_config_guide.rst b/doc/connectivity/networking/net_config_guide.rst index b834174497..177ff434e8 100644 --- a/doc/connectivity/networking/net_config_guide.rst +++ b/doc/connectivity/networking/net_config_guide.rst @@ -35,8 +35,8 @@ are able to either send or receive at the same time. When data is received from the network, it is placed into net_buf data portion. Depending on device resources and desired network usage, user can tweak the size of the fixed buffer by setting :kconfig:option:`CONFIG_NET_BUF_DATA_SIZE`, and - the size of the data pool size by setting :kconfig:option:`CONFIG_NET_BUF_DATA_POOL_SIZE` - if variable size buffers are used. + the size of the data pool size by setting :kconfig:option:`CONFIG_NET_PKT_BUF_RX_DATA_POOL_SIZE` + and :kconfig:option:`CONFIG_NET_PKT_BUF_TX_DATA_POOL_SIZE` if variable size buffers are used. When using the fixed size data buffers, the memory consumption of network buffers can be tweaked by selecting the size of the data part according to what kind of network diff --git a/subsys/net/ip/Kconfig b/subsys/net/ip/Kconfig index 4de15ada6d..bc5442d44b 100644 --- a/subsys/net/ip/Kconfig +++ b/subsys/net/ip/Kconfig @@ -668,12 +668,28 @@ config NET_BUF_DATA_SIZE This value tells what is the fixed size of each network buffer. config NET_BUF_DATA_POOL_SIZE - int "Size of the memory pool where buffers are allocated from" + int "[DEPRECATED] Size of the memory pool where buffers are allocated from" default 4096 if NET_L2_ETHERNET default 2048 depends on NET_BUF_VARIABLE_DATA_SIZE help - This value tell what is the size of the memory pool where each + This config is deprecated, use NET_PKT_BUF_RX_DATA_POOL_SIZE and + NET_PKT_BUF_TX_DATA_POOL_SIZE instead. + +config NET_PKT_BUF_RX_DATA_POOL_SIZE + int "Size of the RX memory pool where buffers are allocated from" + default NET_BUF_DATA_POOL_SIZE + depends on NET_BUF_VARIABLE_DATA_SIZE + help + This value tell what is the size of the RX memory pool where each + network buffer is allocated from. + +config NET_PKT_BUF_TX_DATA_POOL_SIZE + int "Size of the TX memory pool where buffers are allocated from" + default NET_BUF_DATA_POOL_SIZE + depends on NET_BUF_VARIABLE_DATA_SIZE + help + This value tell what is the size of the TX memory pool where each network buffer is allocated from. config NET_PKT_BUF_USER_DATA_SIZE diff --git a/subsys/net/ip/net_pkt.c b/subsys/net/ip/net_pkt.c index d7556a5023..81d9d35b73 100644 --- a/subsys/net/ip/net_pkt.c +++ b/subsys/net/ip/net_pkt.c @@ -129,9 +129,9 @@ NET_BUF_POOL_FIXED_DEFINE(tx_bufs, CONFIG_NET_BUF_TX_COUNT, CONFIG_NET_BUF_DATA_ #else /* !CONFIG_NET_BUF_FIXED_DATA_SIZE */ -NET_BUF_POOL_VAR_DEFINE(rx_bufs, CONFIG_NET_BUF_RX_COUNT, CONFIG_NET_BUF_DATA_POOL_SIZE, +NET_BUF_POOL_VAR_DEFINE(rx_bufs, CONFIG_NET_BUF_RX_COUNT, CONFIG_NET_PKT_BUF_RX_DATA_POOL_SIZE, CONFIG_NET_PKT_BUF_USER_DATA_SIZE, NULL); -NET_BUF_POOL_VAR_DEFINE(tx_bufs, CONFIG_NET_BUF_TX_COUNT, CONFIG_NET_BUF_DATA_POOL_SIZE, +NET_BUF_POOL_VAR_DEFINE(tx_bufs, CONFIG_NET_BUF_TX_COUNT, CONFIG_NET_PKT_BUF_TX_DATA_POOL_SIZE, CONFIG_NET_PKT_BUF_USER_DATA_SIZE, NULL); #endif /* CONFIG_NET_BUF_FIXED_DATA_SIZE */ diff --git a/subsys/net/ip/tcp.c b/subsys/net/ip/tcp.c index 6636b3d303..49ad112b52 100644 --- a/subsys/net/ip/tcp.c +++ b/subsys/net/ip/tcp.c @@ -45,7 +45,7 @@ static int tcp_rx_window = #if defined(CONFIG_NET_BUF_FIXED_DATA_SIZE) (CONFIG_NET_BUF_RX_COUNT * CONFIG_NET_BUF_DATA_SIZE) / 3; #else - CONFIG_NET_BUF_DATA_POOL_SIZE / 3; + CONFIG_NET_PKT_BUF_RX_DATA_POOL_SIZE / 3; #endif /* CONFIG_NET_BUF_FIXED_DATA_SIZE */ #endif static int tcp_tx_window = @@ -55,7 +55,7 @@ static int tcp_tx_window = #if defined(CONFIG_NET_BUF_FIXED_DATA_SIZE) (CONFIG_NET_BUF_TX_COUNT * CONFIG_NET_BUF_DATA_SIZE) / 3; #else - CONFIG_NET_BUF_DATA_POOL_SIZE / 3; + CONFIG_NET_PKT_BUF_TX_DATA_POOL_SIZE / 3; #endif /* CONFIG_NET_BUF_FIXED_DATA_SIZE */ #endif #ifdef CONFIG_NET_TCP_RANDOMIZED_RTO diff --git a/subsys/net/lib/capture/capture.c b/subsys/net/lib/capture/capture.c index 27114ca7e6..fcd7bb0677 100644 --- a/subsys/net/lib/capture/capture.c +++ b/subsys/net/lib/capture/capture.c @@ -41,8 +41,10 @@ NET_PKT_SLAB_DEFINE(capture_pkts, CONFIG_NET_CAPTURE_PKT_COUNT); NET_BUF_POOL_FIXED_DEFINE(capture_bufs, CONFIG_NET_CAPTURE_BUF_COUNT, CONFIG_NET_BUF_DATA_SIZE, 4, NULL); #else +#define DATA_POOL_SIZE MAX(NET_PKT_BUF_RX_DATA_POOL_SIZE, NET_PKT_BUF_TX_DATA_POOL_SIZE) + NET_BUF_POOL_VAR_DEFINE(capture_bufs, CONFIG_NET_CAPTURE_BUF_COUNT, - CONFIG_NET_BUF_DATA_POOL_SIZE, 4, NULL); + DATA_POOL_SIZE, 4, NULL); #endif static sys_slist_t net_capture_devlist; diff --git a/subsys/net/lib/shell/mem.c b/subsys/net/lib/shell/mem.c index 47058f9276..7bbe0b5e21 100644 --- a/subsys/net/lib/shell/mem.c +++ b/subsys/net/lib/shell/mem.c @@ -107,7 +107,8 @@ static int cmd_net_mem(const struct shell *sh, size_t argc, char *argv[]) #if defined(CONFIG_NET_BUF_FIXED_DATA_SIZE) PR("Fragment length %d bytes\n", CONFIG_NET_BUF_DATA_SIZE); #else - PR("Fragment data pool size %d bytes\n", CONFIG_NET_BUF_DATA_POOL_SIZE); + PR("Fragment RX data pool size %d bytes\n", CONFIG_NET_PKT_BUF_RX_DATA_POOL_SIZE); + PR("Fragment TX data pool size %d bytes\n", CONFIG_NET_PKT_BUF_TX_DATA_POOL_SIZE); #endif /* CONFIG_NET_BUF_FIXED_DATA_SIZE */ PR("Network buffer pools:\n"); diff --git a/tests/drivers/build_all/ethernet/prj.conf b/tests/drivers/build_all/ethernet/prj.conf index 208ed81da3..938aa284a4 100644 --- a/tests/drivers/build_all/ethernet/prj.conf +++ b/tests/drivers/build_all/ethernet/prj.conf @@ -11,7 +11,8 @@ CONFIG_NET_PKT_RX_COUNT=14 CONFIG_NET_PKT_TX_COUNT=14 CONFIG_NET_BUF_RX_COUNT=36 CONFIG_NET_BUF_TX_COUNT=36 -CONFIG_NET_BUF_DATA_POOL_SIZE=4096 +CONFIG_NET_PKT_BUF_RX_DATA_POOL_SIZE=4096 +CONFIG_NET_PKT_BUF_TX_DATA_POOL_SIZE=4096 # Disable L2 CONFIG_NET_L2_ETHERNET=n diff --git a/tests/net/6lo/testcase.yaml b/tests/net/6lo/testcase.yaml index 5d3b13b945..a6a1294f6d 100644 --- a/tests/net/6lo/testcase.yaml +++ b/tests/net/6lo/testcase.yaml @@ -14,4 +14,5 @@ tests: net.6lo.variable_buf_size: extra_configs: - CONFIG_NET_BUF_VARIABLE_DATA_SIZE=y - - CONFIG_NET_BUF_DATA_POOL_SIZE=4096 + - CONFIG_NET_PKT_BUF_RX_DATA_POOL_SIZE=4096 + - CONFIG_NET_PKT_BUF_TX_DATA_POOL_SIZE=4096 diff --git a/tests/net/all/prj.conf b/tests/net/all/prj.conf index 8eb3c445c7..dfdb46eeaf 100644 --- a/tests/net/all/prj.conf +++ b/tests/net/all/prj.conf @@ -25,7 +25,8 @@ CONFIG_NET_BUF_LOG_LEVEL_DBG=y CONFIG_NET_BUF_WARN_ALLOC_INTERVAL=2 CONFIG_NET_BUF_SIMPLE_LOG=y CONFIG_NET_BUF_POOL_USAGE=y -#CONFIG_NET_BUF_DATA_POOL_SIZE=4096 +#CONFIG_NET_PKT_BUF_RX_DATA_POOL_SIZE=4096 +#CONFIG_NET_PKT_BUF_TX_DATA_POOL_SIZE=4096 CONFIG_NET_BUF_FIXED_DATA_SIZE=y CONFIG_NET_BUF_VARIABLE_DATA_SIZE=n CONFIG_NET_PKT_RX_COUNT=10 diff --git a/tests/net/ipv6/testcase.yaml b/tests/net/ipv6/testcase.yaml index 48abbd37ab..1fbe64f067 100644 --- a/tests/net/ipv6/testcase.yaml +++ b/tests/net/ipv6/testcase.yaml @@ -10,4 +10,5 @@ tests: net.ipv6.variable_buf_size: extra_configs: - CONFIG_NET_BUF_VARIABLE_DATA_SIZE=y - - CONFIG_NET_BUF_DATA_POOL_SIZE=4096 + - CONFIG_NET_PKT_BUF_RX_DATA_POOL_SIZE=4096 + - CONFIG_NET_PKT_BUF_TX_DATA_POOL_SIZE=4096 diff --git a/tests/net/tcp/testcase.yaml b/tests/net/tcp/testcase.yaml index a60128f049..7f4a509553 100644 --- a/tests/net/tcp/testcase.yaml +++ b/tests/net/tcp/testcase.yaml @@ -13,4 +13,5 @@ tests: net.tcp.variable_buf_size: extra_configs: - CONFIG_NET_BUF_VARIABLE_DATA_SIZE=y - - CONFIG_NET_BUF_DATA_POOL_SIZE=4096 + - CONFIG_NET_PKT_BUF_RX_DATA_POOL_SIZE=4096 + - CONFIG_NET_PKT_BUF_TX_DATA_POOL_SIZE=4096