๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
1 messages
1 total messages Started by Eric Dumazet Sat, 14 Nov 2026 15:39
Re: [PATCH v1 net-next 8/8] selftest: packetdrill: Add test for tcp_collapse().
#16379
Author: Eric Dumazet
Date: Sat, 14 Nov 2026 15:39
142 lines
14084 bytes
Le sam. 14 nov. 2026 ร  05:01, Kuniyuki Iwashima <kuniyu@google.com> a รฉcrit :
>
> tcp_collapse() now does not collapse high-density skbs and a
> low-density skb sandwitched by hihg-density skbs.
>

s/sandwitched/sandwiched/
s/hihg/high/


> tcp_collapse.pkt verifies the behaviour by
>
> 1. set a large SO_RCVBUF
> 2. send one high-density skb with 100 bytes read()
> 3. send one high-density skb
> 4. send one low-density skb
> 5. send one high-density skb
> 6. send 30 low-density skbs
> 7. set a small SO_RCVBUF
> 8. send a small data to trigger tcp_collapse()
> 9. check TcpExtTCPRcvCollapsed via nstat
>
> Without the series, the first high-density skb is collapsed.
> In addition, the first low-density skb drags the following
> high-density skb into collapsing, consuming more memory.
>
> If we remove sk_forced_mem_schedule() without this series,
> sk->sk_forwad_alloc becomes negative at the end of tcp_collapse().

s/sk_forwad_alloc/sk_forward_alloc/

>
> Note that 30 segments are to make the memory savings large
> enough so that the margin can absorb minor size delta of
> struct sk_buff or L1_CACHE_BYTES across configs.
>
> skb truesize, TCP_COLLAPSE_MAX_SIZE, TCP_COLLAPSE_SCALING_RATIO
> depend on PAGE_SIZE being 4K, so the test is skipped if getconf
> returns non-4K PAGE_SIZE.
>
> Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
> ---
>  .../selftests/net/packetdrill/ksft_runner.sh  |   9 ++
>  .../net/packetdrill/tcp_collapse.pkt          | 135 ++++++++++++++++++
>  2 files changed, 144 insertions(+)
>  create mode 100644 tools/testing/selftests/net/packetdrill/tcp_collapse.pkt
>
> diff --git a/tools/testing/selftests/net/packetdrill/ksft_runner.sh b/tools/testing/selftests/net/packetdrill/ksft_runner.sh
> index 0a97d5ae3469..250d143bb9f7 100755
> --- a/tools/testing/selftests/net/packetdrill/ksft_runner.sh
> +++ b/tools/testing/selftests/net/packetdrill/ksft_runner.sh
> @@ -44,6 +44,15 @@ if [ -z "$(which packetdrill)" ]; then
>         exit "$KSFT_SKIP"
>  fi
>
> +page_size=$(grep -E '^--define="?PAGE_SIZE=' $script | sed -E 's/.*PAGE_SIZE="?([0-9]+)"?.*/\1/')
> +if [[ -n "$page_size" ]]; then
> +       cur_page_size=$(getconf PAGESIZE 2>/dev/null)
> +       if [[ "$cur_page_size" != "$page_size" ]]; then
> +               ktap_skip_all "requires PAGE_SIZE=$page_size (current: ${cur_page_size:-unknown})"
> +               exit "$KSFT_SKIP"
> +       fi
> +fi
> +
>  declare -a optargs
>  failfunc=ktap_test_fail
>
> diff --git a/tools/testing/selftests/net/packetdrill/tcp_collapse.pkt b/tools/testing/selftests/net/packetdrill/tcp_collapse.pkt
> new file mode 100644
> index 000000000000..90e8be86968f
> --- /dev/null
> +++ b/tools/testing/selftests/net/packetdrill/tcp_collapse.pkt
> @@ -0,0 +1,135 @@
> +// SPDX-License-Identifier: GPL-2.0
> +//
> +// Test that tcp_collapse() only collapses bloated skb runs, skips leading
> +// and trailing high-density skbs, skips isolated bloated skbs when collapsing
> +// them would not shrink truesize, and properly recovers receive buffer space.
> +
> +--mss=1000
> +--define="PAGE_SIZE=4096"
> +
> +`./defaults.sh`
> +
> +// Establish a connection with a large receive buffer.
> +// __sock_set_rcvbuf() doubles, so 2000000
> +   +0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
> +   +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
> +   +0 setsockopt(3, SOL_SOCKET, SO_RCVBUF, [1000000], 4) = 0
> +   +0 bind(3, ..., ...) = 0
> +   +0 listen(3, 1) = 0
> +
> +   +0 < S 0:0(0) win 32792 <mss 1000,nop,nop,sackOK,nop,wscale 7>
> +   +0 > S. 0:0(0) ack 1 win 65535 <mss 1460,nop,nop,sackOK,nop,wscale 4>
> +   +0 < . 1:1(0) ack 1 win 65535
> +
> +   +0 accept(3, ..., ...) = 4
> +
> +// 1. Queue two high-density 62,000 B segments (each adds 15 pages of frag
> +// truesize with enough margin across NET_SKB_PAD, L1_CACHE_BYTES, and
> +// MAX_SKB_FRAGS configs).
> +// Read 100 bytes from the first one so before(skb->seq, tp->copied_seq) is true.
> +   +0 < P. 1:62001(62000) ack 1 win 65535
> +    * > .  1:1(0) ack 62001
> +   +0 read(4, ..., 100) = 100
> +
> +   +0 < P. 62001:124001(62000) ack 1 win 65535
> +    * > .  1:1(0) ack 124001
> +
> +// 2. Queue an isolated bloated 1,000 B segment.
> +   +0 < P. 124001:125001(1000) ack 1 win 65535
> +    * > .  1:1(0) ack 125001
> +
> +// 3. Queue another high-density 62,000 B segment.
> +   +0 < P. 125001:187001(62000) ack 1 win 65535
> +    * > .  1:1(0) ack 187001
> +
> +// 4. Queue a run of 30 bloated 1,000 B segments.

This test only covers the receive queue.

Most of the new logic in patch 3 is about the out-of-order queue
(overlapping skbs, monotonic seq/end_seq in the rbtree), and nothing
exercises it: before this series, TcpExtTCPRcvCollapsed stays at zero
for the whole packetdrill TCP suite.

I have a test collapsing the out-of-order queue (segments sent in
decreasing sequence order so that they are not coalesced when
queued), it passes on top of your series. I can send it after your
v2, or you can add something similar here.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads