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 <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2024-03-27 16:15:13 +01:00 committed by Maureen Helm
parent f2d1851c2b
commit 8e2722e1ca
11 changed files with 39 additions and 15 deletions

View file

@ -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

View file

@ -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

View file

@ -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 */

View file

@ -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

View file

@ -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;

View file

@ -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");

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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