tcp: better memory control for not-yet-accepted sockets
Subsystems (4)
cover tcp: better memory control for not-yet-accepted sockets
Address a possible OOM condition caused by a recent change.
Add a new packetdrill test checking the expected behavior.
Eric Dumazet (2):
tcp: refine sk_rcvbuf increase for ooo packets selftests/net: packetdrill: add tcp_ooo-before-and-after-accept.pkt
net/ipv4/tcp_input.c | 4 +- .../tcp_ooo-before-and-after-accept.pkt | 53 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/net/packetdrill/tcp_ooo-before-and-after-accept.pkt
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
PATCH 1/2 tcp: refine sk_rcvbuf increase for ooo packets
When a passive flow has not been accepted yet, it is not wise to increase sk_rcvbuf when receiving ooo packets.
A very busy server might tune down tcp_rmem[1] to better control how much memory can be used by sockets waiting in its listeners accept queues.
--- net/ipv4/tcp_input.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/ipv4/tcp_input.c +3 -1
@@ -5181,7 +5181,9 @@ static void tcp_data_queue_ofo(struct sock *sk, struct sk_buff *skb)skb_condense (skb);skb_set_owner_r (skb, sk); } -tcp_rcvbuf_grow (sk); +/* do not grow rcvbuf for not-yet-accepted or orphaned sockets. */ +if (sk->sk_socket) +tcp_rcvbuf_grow (sk); } static int __must_check tcp_queue_rcv(struct sock *sk, struct sk_buff *skb,
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
PATCH 2/2 selftests/net: packetdrill: add tcp_ooo-before-and-after-accept.pkt
In reply to Eric DumazetTest how new passive flows react to ooo incoming packets.
Their sk_rcvbuf can increase only after accept().
--- .../tcp_ooo-before-and-after-accept.pkt | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tools/testing/selftests/net/packetdrill/tcp_ooo-before-and-after-accept.pkt
tools/testing/selftests/net/packetdrill/tcp_ooo-before-and-after-accept.pkt new file +53 -0
@@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0 + +--mss=1000 + +`./defaults.sh +sysctl -q net.ipv4.tcp_rmem="4096 131072 $((32*1024*1024))"` + +// Test that a not-yet-accepted socket does not change +// its initial sk_rcvbuf (tcp_rmem[1]) when receiving ooo packets. + + +0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3 + +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0 + +0 bind(3, ..., ...) = 0 + +0 listen(3, 1) = 0 + + +0 < S 0:0(0) win 65535 <mss 1000,nop,nop,sackOK,nop,wscale 7> + +0 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK,nop,wscale 10> + +.1 < . 1:1(0) ack 1 win 257 + +0 < . 2001:41001(39000) ack 1 win 257 + +0 > . 1:1(0) ack 1 <nop,nop,sack 2001:41001> + +0 < . 41001:101001(60000) ack 1 win 257 + +0 > . 1:1(0) ack 1 <nop,nop,sack 2001:101001> + +0 < . 1:1001(1000) ack 1 win 257 + +0 > . 1:1(0) ack 1001 <nop,nop,sack 2001:101001> + +0 < . 1001:2001(1000) ack 1 win 257 + +0 > . 1:1(0) ack 101001 + + +0 accept(3, ..., ...) = 4 + + +0 %{ assert SK_MEMINFO_RCVBUF == 131072, SK_MEMINFO_RCVBUF }% + + +0 close(4) = 0 + +0 close(3) = 0 + +// Test that ooo packets for accepted sockets do increase sk_rcvbuf + +0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3 + +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0 + +0 bind(3, ..., ...) = 0 + +0 listen(3, 1) = 0 + + +0 < S 0:0(0) win 65535 <mss 1000,nop,nop,sackOK,nop,wscale 7> + +0 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK,nop,wscale 10> + +.1 < . 1:1(0) ack 1 win 257 + + +0 accept(3, ..., ...) = 4 + + +0 < . 2001:41001(39000) ack 1 win 257 + +0 > . 1:1(0) ack 1 <nop,nop,sack 2001:41001> + +0 < . 41001:101001(60000) ack 1 win 257 + +0 > . 1:1(0) ack 1 <nop,nop,sack 2001:101001> + + +0 %{ assert SK_MEMINFO_RCVBUF > 131072, SK_MEMINFO_RCVBUF }% +
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Mon, 7 Jul 2025 21:38:58 +0000 you wrote:
Address a possible OOM condition caused by a recent change.
Add a new packetdrill test checking the expected behavior.
Eric Dumazet (2):
tcp: refinesk_rcvbufincrease for ooo packets selftests/net: packetdrill: add tcp_ooo-before-and-after-accept.pkt[...]
Here is the summary with links:
- [net,1/2] tcp: refine sk_rcvbuf increase for ooo packets
https://git.kernel.org/netdev/net/c/1a03edeb84e6 - [net,2/2] selftests/net: packetdrill: add tcp_ooo-before-and-after-accept.pkt https://git.kernel.org/netdev/net/c/b939c074efc1
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html