From: Eric Dumazet <edumazet@kernel.org>
To: "David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Kuniyuki Iwashima <kuniyu@google.com>,
Neal Cardwell <ncardwell@google.com>
Cc: Simon Horman <horms@kernel.org>,
netdev@vger.kernel.org, Eric Dumazet <edumazet@kernel.org>
Subject: [PATCH net-next 5/5] selftests/net: packetdrill: add tcp_rcv_collapse.pkt
Date: Sat, 14 Nov 2026 16:51:50 +0100 [thread overview]
Message-ID: <20261114155150.235743-6-edumazet@kernel.org> (raw)
In-Reply-To: <20261114155150.235743-1-edumazet@kernel.org>
No packetdrill test was reaching the copy loop of tcp_collapse():
TcpExtTCPRcvCollapsed stays at zero for the whole TCP suite.
Add a test using a small locked SO_RCVBUF and out-of-order segments
sent in decreasing sequence order, so that they can not be coalesced
when they are queued. Their truesize exceeds sk_rcvbuf several times,
thus all of them can only be queued if tcp_prune_queue() collapses
them.
The test covers:
- A small out-of-order range made of two skbs.
- A big out-of-order range, bigger than one page.
- The receive queue, starting with a partially read skb.
It checks that TcpExtTCPRcvCollapsed is not zero, that nothing had
to be pruned, and that all the payload can be read.
Signed-off-by: Eric Dumazet <edumazet@kernel.org>
---
.../net/packetdrill/tcp_rcv_collapse.pkt | 230 ++++++++++++++++++
1 file changed, 230 insertions(+)
create mode 100644 tools/testing/selftests/net/packetdrill/tcp_rcv_collapse.pkt
diff --git a/tools/testing/selftests/net/packetdrill/tcp_rcv_collapse.pkt b/tools/testing/selftests/net/packetdrill/tcp_rcv_collapse.pkt
new file mode 100644
index 000000000000..5650c5138231
--- /dev/null
+++ b/tools/testing/selftests/net/packetdrill/tcp_rcv_collapse.pkt
@@ -0,0 +1,230 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// Exercise tcp_collapse() on the out-of-order queue and on the receive
+// queue, for small ranges and for ranges bigger than one page, and check
+// that no payload is lost.
+//
+// Out-of-order segments are sent in decreasing sequence order, so that
+// they can not be coalesced when they are queued: only tcp_collapse()
+// can merge them.
+
+--mss=1000
+
+`./defaults.sh`
+
+// Small locked receive buffer: sk_rcvbuf = 40000, can not grow.
+ +0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
+ +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+ +0 setsockopt(3, SOL_SOCKET, SO_RCVBUF, [20000], 4) = 0
+ +0 bind(3, ..., ...) = 0
+ +0 listen(3, 1) = 0
+
+ +0 < S 0:0(0) win 32792 <mss 1000,nop,wscale 7>
+ +0 > S. 0:0(0) ack 1 <mss 1460,nop,wscale 0>
+ +.1 < . 1:1(0) ack 1 win 257
+
+ +0 accept(3, ..., ...) = 4
+
+ +0 `nstat -n`
+
+// A small isolated range (12401:12601) made of two skbs.
+// Holes are left at 1:201 and 12301:12401.
+ +0 < . 12501:12601(100) ack 1 win 257
+ +0 < . 12401:12501(100) ack 1 win 257
+
+// A big range (201:12301) made of 121 skbs: their truesize is far bigger
+// than sk_rcvbuf, the out-of-order queue must be collapsed to queue them
+// all. Exactly when this happens depends on skb->truesize, so ACKs are
+// not checked here.
+ +0 < . 12201:12301(100) ack 1 win 257
+ +0 < . 12101:12201(100) ack 1 win 257
+ +0 < . 12001:12101(100) ack 1 win 257
+ +0 < . 11901:12001(100) ack 1 win 257
+ +0 < . 11801:11901(100) ack 1 win 257
+ +0 < . 11701:11801(100) ack 1 win 257
+ +0 < . 11601:11701(100) ack 1 win 257
+ +0 < . 11501:11601(100) ack 1 win 257
+ +0 < . 11401:11501(100) ack 1 win 257
+ +0 < . 11301:11401(100) ack 1 win 257
+ +0 < . 11201:11301(100) ack 1 win 257
+ +0 < . 11101:11201(100) ack 1 win 257
+ +0 < . 11001:11101(100) ack 1 win 257
+ +0 < . 10901:11001(100) ack 1 win 257
+ +0 < . 10801:10901(100) ack 1 win 257
+ +0 < . 10701:10801(100) ack 1 win 257
+ +0 < . 10601:10701(100) ack 1 win 257
+ +0 < . 10501:10601(100) ack 1 win 257
+ +0 < . 10401:10501(100) ack 1 win 257
+ +0 < . 10301:10401(100) ack 1 win 257
+ +0 < . 10201:10301(100) ack 1 win 257
+ +0 < . 10101:10201(100) ack 1 win 257
+ +0 < . 10001:10101(100) ack 1 win 257
+ +0 < . 9901:10001(100) ack 1 win 257
+ +0 < . 9801:9901(100) ack 1 win 257
+ +0 < . 9701:9801(100) ack 1 win 257
+ +0 < . 9601:9701(100) ack 1 win 257
+ +0 < . 9501:9601(100) ack 1 win 257
+ +0 < . 9401:9501(100) ack 1 win 257
+ +0 < . 9301:9401(100) ack 1 win 257
+ +0 < . 9201:9301(100) ack 1 win 257
+ +0 < . 9101:9201(100) ack 1 win 257
+ +0 < . 9001:9101(100) ack 1 win 257
+ +0 < . 8901:9001(100) ack 1 win 257
+ +0 < . 8801:8901(100) ack 1 win 257
+ +0 < . 8701:8801(100) ack 1 win 257
+ +0 < . 8601:8701(100) ack 1 win 257
+ +0 < . 8501:8601(100) ack 1 win 257
+ +0 < . 8401:8501(100) ack 1 win 257
+ +0 < . 8301:8401(100) ack 1 win 257
+ +0 < . 8201:8301(100) ack 1 win 257
+ +0 < . 8101:8201(100) ack 1 win 257
+ +0 < . 8001:8101(100) ack 1 win 257
+ +0 < . 7901:8001(100) ack 1 win 257
+ +0 < . 7801:7901(100) ack 1 win 257
+ +0 < . 7701:7801(100) ack 1 win 257
+ +0 < . 7601:7701(100) ack 1 win 257
+ +0 < . 7501:7601(100) ack 1 win 257
+ +0 < . 7401:7501(100) ack 1 win 257
+ +0 < . 7301:7401(100) ack 1 win 257
+ +0 < . 7201:7301(100) ack 1 win 257
+ +0 < . 7101:7201(100) ack 1 win 257
+ +0 < . 7001:7101(100) ack 1 win 257
+ +0 < . 6901:7001(100) ack 1 win 257
+ +0 < . 6801:6901(100) ack 1 win 257
+ +0 < . 6701:6801(100) ack 1 win 257
+ +0 < . 6601:6701(100) ack 1 win 257
+ +0 < . 6501:6601(100) ack 1 win 257
+ +0 < . 6401:6501(100) ack 1 win 257
+ +0 < . 6301:6401(100) ack 1 win 257
+ +0 < . 6201:6301(100) ack 1 win 257
+ +0 < . 6101:6201(100) ack 1 win 257
+ +0 < . 6001:6101(100) ack 1 win 257
+ +0 < . 5901:6001(100) ack 1 win 257
+ +0 < . 5801:5901(100) ack 1 win 257
+ +0 < . 5701:5801(100) ack 1 win 257
+ +0 < . 5601:5701(100) ack 1 win 257
+ +0 < . 5501:5601(100) ack 1 win 257
+ +0 < . 5401:5501(100) ack 1 win 257
+ +0 < . 5301:5401(100) ack 1 win 257
+ +0 < . 5201:5301(100) ack 1 win 257
+ +0 < . 5101:5201(100) ack 1 win 257
+ +0 < . 5001:5101(100) ack 1 win 257
+ +0 < . 4901:5001(100) ack 1 win 257
+ +0 < . 4801:4901(100) ack 1 win 257
+ +0 < . 4701:4801(100) ack 1 win 257
+ +0 < . 4601:4701(100) ack 1 win 257
+ +0 < . 4501:4601(100) ack 1 win 257
+ +0 < . 4401:4501(100) ack 1 win 257
+ +0 < . 4301:4401(100) ack 1 win 257
+ +0 < . 4201:4301(100) ack 1 win 257
+ +0 < . 4101:4201(100) ack 1 win 257
+ +0 < . 4001:4101(100) ack 1 win 257
+ +0 < . 3901:4001(100) ack 1 win 257
+ +0 < . 3801:3901(100) ack 1 win 257
+ +0 < . 3701:3801(100) ack 1 win 257
+ +0 < . 3601:3701(100) ack 1 win 257
+ +0 < . 3501:3601(100) ack 1 win 257
+ +0 < . 3401:3501(100) ack 1 win 257
+ +0 < . 3301:3401(100) ack 1 win 257
+ +0 < . 3201:3301(100) ack 1 win 257
+ +0 < . 3101:3201(100) ack 1 win 257
+ +0 < . 3001:3101(100) ack 1 win 257
+ +0 < . 2901:3001(100) ack 1 win 257
+ +0 < . 2801:2901(100) ack 1 win 257
+ +0 < . 2701:2801(100) ack 1 win 257
+ +0 < . 2601:2701(100) ack 1 win 257
+ +0 < . 2501:2601(100) ack 1 win 257
+ +0 < . 2401:2501(100) ack 1 win 257
+ +0 < . 2301:2401(100) ack 1 win 257
+ +0 < . 2201:2301(100) ack 1 win 257
+ +0 < . 2101:2201(100) ack 1 win 257
+ +0 < . 2001:2101(100) ack 1 win 257
+ +0 < . 1901:2001(100) ack 1 win 257
+ +0 < . 1801:1901(100) ack 1 win 257
+ +0 < . 1701:1801(100) ack 1 win 257
+ +0 < . 1601:1701(100) ack 1 win 257
+ +0 < . 1501:1601(100) ack 1 win 257
+ +0 < . 1401:1501(100) ack 1 win 257
+ +0 < . 1301:1401(100) ack 1 win 257
+ +0 < . 1201:1301(100) ack 1 win 257
+ +0 < . 1101:1201(100) ack 1 win 257
+ +0 < . 1001:1101(100) ack 1 win 257
+ +0 < . 901:1001(100) ack 1 win 257
+ +0 < . 801:901(100) ack 1 win 257
+ +0 < . 701:801(100) ack 1 win 257
+ +0 < . 601:701(100) ack 1 win 257
+ +0 < . 501:601(100) ack 1 win 257
+ +0 < . 401:501(100) ack 1 win 257
+ +0 < . 301:401(100) ack 1 win 257
+ +0 < . 201:301(100) ack 1 win 257
+
+ +0 `nstat -sz | grep -q "^TcpExtTCPRcvCollapsed *[1-9]"`
+ +0 `nstat -sz | grep -q "^TcpExtOfoPruned *0 "`
+
+// Fill the first hole: 1:12301 is moved to the receive queue.
+// A partial read leaves a partially consumed skb at the head of the
+// receive queue.
+ +0 < . 1:201(200) ack 1 win 257
+ +0 read(4, ..., 100) = 100
+
+// More out-of-order segments (12601:17601), following the small range:
+// the receive queue has to be collapsed as well.
+ +0 < . 17501:17601(100) ack 1 win 257
+ +0 < . 17401:17501(100) ack 1 win 257
+ +0 < . 17301:17401(100) ack 1 win 257
+ +0 < . 17201:17301(100) ack 1 win 257
+ +0 < . 17101:17201(100) ack 1 win 257
+ +0 < . 17001:17101(100) ack 1 win 257
+ +0 < . 16901:17001(100) ack 1 win 257
+ +0 < . 16801:16901(100) ack 1 win 257
+ +0 < . 16701:16801(100) ack 1 win 257
+ +0 < . 16601:16701(100) ack 1 win 257
+ +0 < . 16501:16601(100) ack 1 win 257
+ +0 < . 16401:16501(100) ack 1 win 257
+ +0 < . 16301:16401(100) ack 1 win 257
+ +0 < . 16201:16301(100) ack 1 win 257
+ +0 < . 16101:16201(100) ack 1 win 257
+ +0 < . 16001:16101(100) ack 1 win 257
+ +0 < . 15901:16001(100) ack 1 win 257
+ +0 < . 15801:15901(100) ack 1 win 257
+ +0 < . 15701:15801(100) ack 1 win 257
+ +0 < . 15601:15701(100) ack 1 win 257
+ +0 < . 15501:15601(100) ack 1 win 257
+ +0 < . 15401:15501(100) ack 1 win 257
+ +0 < . 15301:15401(100) ack 1 win 257
+ +0 < . 15201:15301(100) ack 1 win 257
+ +0 < . 15101:15201(100) ack 1 win 257
+ +0 < . 15001:15101(100) ack 1 win 257
+ +0 < . 14901:15001(100) ack 1 win 257
+ +0 < . 14801:14901(100) ack 1 win 257
+ +0 < . 14701:14801(100) ack 1 win 257
+ +0 < . 14601:14701(100) ack 1 win 257
+ +0 < . 14501:14601(100) ack 1 win 257
+ +0 < . 14401:14501(100) ack 1 win 257
+ +0 < . 14301:14401(100) ack 1 win 257
+ +0 < . 14201:14301(100) ack 1 win 257
+ +0 < . 14101:14201(100) ack 1 win 257
+ +0 < . 14001:14101(100) ack 1 win 257
+ +0 < . 13901:14001(100) ack 1 win 257
+ +0 < . 13801:13901(100) ack 1 win 257
+ +0 < . 13701:13801(100) ack 1 win 257
+ +0 < . 13601:13701(100) ack 1 win 257
+ +0 < . 13501:13601(100) ack 1 win 257
+ +0 < . 13401:13501(100) ack 1 win 257
+ +0 < . 13301:13401(100) ack 1 win 257
+ +0 < . 13201:13301(100) ack 1 win 257
+ +0 < . 13101:13201(100) ack 1 win 257
+ +0 < . 13001:13101(100) ack 1 win 257
+ +0 < . 12901:13001(100) ack 1 win 257
+ +0 < . 12801:12901(100) ack 1 win 257
+ +0 < . 12701:12801(100) ack 1 win 257
+ +0 < . 12601:12701(100) ack 1 win 257
+
+// Fill the second hole and check that all the payload can be read:
+// nothing was dropped to make room.
+ +0 < . 12301:12401(100) ack 1 win 257
+ +0 read(4, ..., 30000) = 17500
+
+ +0 `nstat -sz | grep -q "^TcpExtOfoPruned *0 "`
+ +0 `nstat -sz | grep -q "^TcpExtRcvPruned *0 "`
+ +0 `nstat -sz | grep -q "^TcpExtTCPRcvCollapseSkipped *0 "`
--
2.53.0
next prev parent reply other threads:[~2026-11-14 15:52 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-14 15:51 [PATCH net-next 0/5] tcp: better visibility when receive queues are full Eric Dumazet
2026-11-14 15:51 ` [PATCH net-next 1/5] tcp: add TCPRcvCollapseSkipped counter Eric Dumazet
2026-11-14 16:28 ` Kuniyuki Iwashima
2026-11-14 15:51 ` [PATCH net-next 2/5] selftests/net: packetdrill: add tcp_rcv_collapse_ratelimit.pkt Eric Dumazet
2026-11-14 16:34 ` Kuniyuki Iwashima
2026-11-14 15:51 ` [PATCH net-next 3/5] tcp: use SKB_DROP_REASON_SOCKET_RCVBUFF when over sk_rcvbuf Eric Dumazet
2026-11-14 16:36 ` Kuniyuki Iwashima
2026-11-14 15:51 ` [PATCH net-next 4/5] net: add SKB_DROP_REASON_MEMCG Eric Dumazet
2026-11-14 16:43 ` Kuniyuki Iwashima
2026-11-14 15:51 ` Eric Dumazet [this message]
2026-11-14 16:49 ` [PATCH net-next 5/5] selftests/net: packetdrill: add tcp_rcv_collapse.pkt Kuniyuki Iwashima
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261114155150.235743-6-edumazet@kernel.org \
--to=edumazet@kernel.org \
--cc=davem@davemloft.net \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox