From fcd7f3671f9a93bffa9941744691344c5b551692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20Kr=C3=B3lik?= <66667989+Damian-Nordic@users.noreply.github.com> Date: Thu, 25 Apr 2024 14:39:48 +0200 Subject: [PATCH 1/2] [nrf fromtree] [nrfconnect] Optimize packet buffer size (#33137) Matter requires that regular Matter messages fit in IPv6 MTU of 1280 bytes so the default packet buffer size of 1583 bytes seems excessively large for some configurations. Especially that the buffers only hold the UDP payload in the case of non-LWIP transports. There are two exceptions to the above though: 1. Minimal mDNS uses the same packet buffer pool and mDNS message size is not limited to 1280 bytes, so shrinking the buffer size below MTU might have a negative impact on the mDNS behavior. 2. Matter allows definining so called large messages that can be bigger than 1280 bytes and sent over TCP, but that is not implemented yet and will likely require a different allocation mechanism. Signed-off-by: Damian Krolik --- src/platform/nrfconnect/SystemPlatformConfig.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/platform/nrfconnect/SystemPlatformConfig.h b/src/platform/nrfconnect/SystemPlatformConfig.h index 549c89245f..de2f59cb7e 100644 --- a/src/platform/nrfconnect/SystemPlatformConfig.h +++ b/src/platform/nrfconnect/SystemPlatformConfig.h @@ -51,6 +51,20 @@ struct ChipDeviceEvent; #define CHIP_SYSTEM_CONFIG_PACKETBUFFER_POOL_SIZE 15 #endif +#ifndef CHIP_SYSTEM_CONFIG_PACKETBUFFER_CAPACITY_MAX +#ifdef CONFIG_WIFI_NRF700X +// Minimal mDNS uses Matter packet buffers, so as long as minimal mDNS is used +// in Nordic's Wi-Fi solution, the packet buffers must be a bit bigger than what +// is required by Matter. +#define CHIP_SYSTEM_CONFIG_PACKETBUFFER_CAPACITY_MAX CONFIG_NRF_WIFI_IFACE_MTU +#else +// Matter specification requires that Matter messages fit in IPV6 MTU of 1280B +// unless for large messages that can be sent over BTP or TCP. But those will +// likely require a separate buffer pool or employ chained buffers. +#define CHIP_SYSTEM_CONFIG_PACKETBUFFER_CAPACITY_MAX 1280 +#endif // CONFIG_WIFI_NRF700X +#endif // CHIP_SYSTEM_CONFIG_PACKETBUFFER_CAPACITY_MAX + // ========== Platform-specific Configuration Overrides ========= // Disable Zephyr Socket extensions module, as the Zephyr RTOS now implements recvmsg() From 1a9ad1054a2174e13ca42af1c4b5c570f2405715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20Kr=C3=B3lik?= <66667989+Damian-Nordic@users.noreply.github.com> Date: Tue, 7 May 2024 22:59:57 +0200 Subject: [PATCH 2/2] [nrf fromtree] [mrp] Make sure not all packet buffers are used for retransmissions (#33334) On constrained devices, the number of available packet buffers can be very low. During stress testing a device that has 8 buffers available, which is the default on many platforms, it was observed that the device would receive a lot of parallel read requests and then it would use all its buffers for responses. The responses would then be stored in the retransmission table, awaiting an ACK, but the ACK would never arrive because of lack of available buffers. Configure the retransmission table size to be less than the number of packet buffers to make sure that not all buffers are held by the retransmission entries, in which case the device is unable to receive an ACK and hence it becomes unavailable until any message times out. Signed-off-by: Damian Krolik --- src/messaging/ReliableMessageProtocolConfig.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/messaging/ReliableMessageProtocolConfig.h b/src/messaging/ReliableMessageProtocolConfig.h index 44480a44eb..136d9b2a06 100644 --- a/src/messaging/ReliableMessageProtocolConfig.h +++ b/src/messaging/ReliableMessageProtocolConfig.h @@ -130,7 +130,10 @@ namespace chip { #if CHIP_SYSTEM_CONFIG_USE_LWIP #if !LWIP_PBUF_FROM_CUSTOM_POOLS && PBUF_POOL_SIZE != 0 -#define CHIP_CONFIG_RMP_RETRANS_TABLE_SIZE std::min(PBUF_POOL_SIZE, CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS) +// Configure the table size to be less than the number of packet buffers to make sure +// that not all buffers are held by the retransmission entries, in which case the device +// is unable to receive an ACK and hence becomes unavailable until a message times out. +#define CHIP_CONFIG_RMP_RETRANS_TABLE_SIZE std::min(PBUF_POOL_SIZE - 1, CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS) #else #define CHIP_CONFIG_RMP_RETRANS_TABLE_SIZE CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS #endif // !LWIP_PBUF_FROM_CUSTOM_POOLS && PBUF_POOL_SIZE != 0 @@ -138,7 +141,11 @@ namespace chip { #else // CHIP_SYSTEM_CONFIG_USE_LWIP #if CHIP_SYSTEM_CONFIG_PACKETBUFFER_POOL_SIZE != 0 -#define CHIP_CONFIG_RMP_RETRANS_TABLE_SIZE std::min(CHIP_SYSTEM_CONFIG_PACKETBUFFER_POOL_SIZE, CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS) +// Configure the table size to be less than the number of packet buffers to make sure +// that not all buffers are held by the retransmission entries, in which case the device +// is unable to receive an ACK and hence becomes unavailable until a message times out. +#define CHIP_CONFIG_RMP_RETRANS_TABLE_SIZE \ + std::min(CHIP_SYSTEM_CONFIG_PACKETBUFFER_POOL_SIZE - 1, CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS) #else #define CHIP_CONFIG_RMP_RETRANS_TABLE_SIZE CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS #endif // CHIP_SYSTEM_CONFIG_PACKETBUFFER_POOL_SIZE != 0