Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tcp: Recover from iob shortage with TCP_WRITE_BUFFERS #11406

Merged
merged 1 commit into from Dec 16, 2023

Conversation

PetteriAimonen
Copy link
Contributor

Summary

When CONFIG_NET_TCP_WRITE_BUFFERS is enabled, iobs are used for both queuing data from application, and for assembling packets for sending. If there is a system-wide shortage of iobs, it could happen that there is not enough free space to form any packets to send. The buffers allocated for TCP data also can't be released until the packet is sent.

Normally this should be avoided by setting suitable values for CONFIG_IOB_NBUFFERS and CONFIG_IOB_THROTTLE. The default values are ok for light usage, but can run out when using multiple simultaneous TCP streams.

Before this commit, iob shortage would cause TCP connections to get stuck and eventually timeout. With this change, TCP stack sends smaller packets, eventually freeing some buffers from the write queue.

Impact

In normal usage no effect. If system is running out of io buffers, TCP packet sizes will be smaller than maximum but will be sent sooner. If network warnings are enabled, notice is printed about this.

Testing

Problem first noticed on custom STM32F417 board when network performance testing with the default configuration:

CONFIG_IOB_NBUFFERS=36
CONFIG_IOB_THROTTLE=8
CONFIG_IOB_BUFSIZE=196
CONFIG_NET_SEND_BUFSIZE=3000

Originally the TCP connection stopped transferring after a few tens of megabytes. Closing and reopening a new connection still worked. Debugger showed that there were 7 free buffers (1372 bytes), while psock_send_eventhandler() was trying to send the MSS of 1440 bytes. devif_iob_send() then returned ENOMEM and same thing repeated next time around.

With this change the connection recovered from buffer shortage and continued transferring.

When CONFIG_NET_TCP_WRITE_BUFFERS is enabled, iobs are used for
both queuing data from application, and for assembling packets
for sending. If there is a system-wide shortage of iobs, it could
happen that there is not enough free space to form any packets
to send. The buffers allocated for TCP data also can't be released
until the packet is sent.

Normally this should be avoided by setting suitable values for
CONFIG_IOB_NBUFFERS and CONFIG_IOB_THROTTLE. The default values
are ok for light usage, but can run out when using multiple
simultaneous TCP streams.

Before this commit, iob shortage would cause TCP connections to
get stuck and eventually timeout. With this change, TCP stack
sends smaller packets, eventually freeing some buffers from the
write queue.
@xiaoxiang781216 xiaoxiang781216 merged commit 06e5b66 into apache:master Dec 16, 2023
26 checks passed
@jerpelea jerpelea added this to To-Add in Release Notes - 12.4.0 Dec 27, 2023
@jerpelea jerpelea moved this from To-Add to Net in Release Notes - 12.4.0 Jan 8, 2024
@jerpelea jerpelea moved this from Net to processed in Release Notes - 12.4.0 Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants