Netdev List
 help / color / mirror / Atom feed
From: Paolo Abeni <pabeni@redhat.com>
To: Matthieu Baerts <matttbe@kernel.org>,
	Eric Dumazet <edumazet@kernel.org>,
	Kuniyuki Iwashima <kuniyu@google.com>
Cc: Mat Martineau <martineau@kernel.org>,
	Neal Cardwell <ncardwell@google.com>,
	"David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Simon Horman <horms@kernel.org>,
	Kuniyuki Iwashima <kuni1840@gmail.com>,
	netdev@vger.kernel.org, MPTCP Linux <mptcp@lists.linux.dev>
Subject: Re: [PATCH v1 net-next 3/8] tcp: Stop collapsing if not bloated.
Date: Mon, 16 Nov 2026 19:07:35 +0100	[thread overview]
Message-ID: <01c4e295-14b8-414e-9bf1-2be350466fe0@redhat.com> (raw)
In-Reply-To: <3d9efe33-f11d-4541-8000-01906197d2d1@kernel.org>

On 11/16/26 17:15, Matthieu Baerts wrote:
> Hi Eric, Kuniyuki, Paolo,
> 
> (+cc MPTCP ML)
> 
> On 14/11/2026 16:35, Eric Dumazet wrote:
>> Le sam. 14 nov. 2026 à 05:01, Kuniyuki Iwashima <kuniyu@google.com> a écrit :
>>>
>>> Even when a skb is not bloated, tcp_collapse() starts collapsing
>>> if the next skb has overlapping data.
>>>
>>> Also, tcp_collapse() does not stop until it reaches the tail or
>>> unmergable skb (SYN/FIN, unreadable frags).
>>>
>>> Assume we detect a low-density skb followed by fully-packed 4K-MSS
>>> GRO skbs:
>>>
>>>               skb->len  truesize  scaling_ratio
>>>    skb    #1      1448      2944      125 (49%)
>>>    skb    #2     65536     66432      252 (98%)
>>>    skb    #3     65536     66432      252 (98%)
>>>    ...
>>>    skb    #9     65536     66432      252 (98%)
>>>    --------------------------------------------
>>>    total                  534400
>>>
>>> Then, even the high-density skbs are repacked into lower-density
>>> skbs, and we end up consuming much more memory.
>>>
>>>               skb->len  truesize  scaling_ratio
>>>    nskb   #1      3776      4352      222 (86%)
>>>    nskb   #2      3776      4352      222 (86%)
>>>    ...
>>>    nskb #139      3776      4352      222 (86%)
>>>    nskb #140       872      2304       96 (37%)
>>>    --------------------------------------------
>>>    total                  607232 (+72832!)
>>>
>>> Even if we find a collapsible skb, we should not collapse
>>> subsequent skbs with scaling_ratio >= TCP_COLLAPSE_SCALING_RATIO.
>>>
>>> Conversely, even if tp->scaling_ratio is smaller than
>>> TCP_COLLAPSE_SCALING_RATIO, we should repack skbs once we
>>> start collapsing, which results in higher-density skb.
>>>
>>> Let's remove the next skb condition in the first loop,
>>> search for collapsible bloated skb range, and repeat
>>> collapsing for each range.
>>>
>>> Note that even when the next skb is not bloated, we must
>>> collapse it for OOO rbtree if it has overlapping data.
>>>
>>>          if ((list || !before(TCP_SKB_CB(n)->seq, sub_end)) &&
>>>              !tcp_collapse_skb_bloated(n, sub_end,
>>>                                        TCP_COLLAPSE_SCALING_RATIO))
>>>
>>> For example, bloated skb_1 and non-bloated skb_2 have overlapping
>>> data and only skb_1 is collapsed to nskb_1 and nskb_2.
>>>
>>>     skb_1 = [1000, 5000]
>>>     skb_2 = [2000, 66000]
>>>
>>> Then, nskb_2 will be inserted after skb_2 in rbtree, wrongly
>>> setting tp->ooo_last_skb to 5000.
>>>
>>>    nskb_1 = [1000, 4776]
>>>     skb_2 = [2000, 66000]
>>>    nskb_2 = [4776, 5000]
>>>
>>> This case is still inefficient, but a later patch handles this.
> 
> Thank you for working on that!
> 
>>> Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
>>> ---
>>>   net/ipv4/tcp_input.c | 66 +++++++++++++++++++++++++-------------------
>>>   1 file changed, 37 insertions(+), 29 deletions(-)
>>>
>>> diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
>>> index e07f43347409..5bd42a74c6f5 100644
>>> --- a/net/ipv4/tcp_input.c
>>> +++ b/net/ipv4/tcp_input.c
>>> @@ -5839,7 +5839,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
>>>   }
>>>
>>>   /* Collapse contiguous sequence of skbs head..tail with
>>> - * sequence numbers start..end.
>>> + * sequence numbers start..sub_end.
>>>    *
>>>    * If tail is NULL, this means until the end of the queue.
>>>    *
>>> @@ -5848,15 +5848,18 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
>>>    */
>>>   static void
>>>   tcp_collapse(struct sock *sk, struct sk_buff_head *list, struct rb_root *root,
>>> -            struct sk_buff *head, struct sk_buff *tail, u32 start, u32 end)
>>> +            struct sk_buff *head, struct sk_buff *tail, u32 start)
>>>   {
>>>          struct sk_buff *skb = head, *n;
>>>          struct sk_buff_head tmp;
>>>          u8 scaling_ratio;
>>> +       u32 sub_end;
>>>
>>>          scaling_ratio = min(tcp_sk(sk)->scaling_ratio,
>>>                              TCP_COLLAPSE_SCALING_RATIO);
>>>
>>> +       __skb_queue_head_init(&tmp);
>>> +
>>>          /* First, check that queue is collapsible and find
>>>           * the point where collapsing can be useful.
>>>           */
>>> @@ -5872,38 +5875,48 @@ tcp_collapse(struct sock *sk, struct sk_buff_head *list, struct rb_root *root,
>>>
>>>                  /* The first skb to collapse is:
>>>                   * - not SYN/FIN and
>>> -                * - the unread portion starting from "start" is bloated, or
>>> -                *   overlaps to the next one and mptcp allow collapsing.
>>> +                * - the unread portion starting from "start" is bloated.
>>>                   */
>>> -               if (!skb_frags_readable(skb) ||
>>> -                   TCP_SKB_CB(skb)->tcp_flags & (TCPHDR_SYN | TCPHDR_FIN))
>>> -                       goto skip_this;
>>> -
>>> -               if (tcp_collapse_skb_bloated(skb, start, scaling_ratio))
>>> -                       break;
>>> -
>>> -               if (n && n != tail && skb_frags_readable(n) &&
>>> -                   tcp_skb_can_collapse_rx(skb, n) &&
>>> -                   TCP_SKB_CB(skb)->end_seq != TCP_SKB_CB(n)->seq)
>>> +               if (skb_frags_readable(skb) &&
>>> +                   !(TCP_SKB_CB(skb)->tcp_flags & (TCPHDR_SYN | TCPHDR_FIN)) &&
>>> +                   tcp_collapse_skb_bloated(skb, start, scaling_ratio))
>>>                          break;
>>>
>>> -skip_this:
>>>                  /* Decided to skip this, advance start seq. */
>>>                  start = TCP_SKB_CB(skb)->end_seq;
>>>          }
>>>
>>>          if (!skb || skb == tail)
>>> -               return;
>>> +               goto end;
>>>
>>> -       __skb_queue_head_init(&tmp);
>>> +       /* Second, find consecutive collapsible skb. */
>>> +       sub_end = TCP_SKB_CB(skb)->end_seq;
>>> +
>>> +       for (n = tcp_skb_next(skb, list); n && n != tail; n = tcp_skb_next(n, list)) {
>>> +               if (!skb_frags_readable(n) ||
>>> +                   TCP_SKB_CB(n)->tcp_flags & (TCPHDR_SYN | TCPHDR_FIN) ||
>>> +                   !tcp_skb_can_collapse_rx(skb, n))
>>> +                       break;
>>
>>
>> Adding MPTCP maintainers.
> 
> Thank you!
> 
>> Before this patch, each candidate was tested against the current new
>> skb:
>>
>>          !tcp_skb_can_collapse_rx(nskb, skb)
>>
>> and nskb is the result of mptcp_skb_ext_move(nskb, skb), done with
>> the skb that was being copied when nskb was allocated.
>>
>> Now all candidates are tested against the first skb of the range,
>> before any extension has been moved.
>>
>> mptcp_ext_matches() is not symmetric (a 'from' skb without extension
>> matches anything), so the two are not equivalent when the range needs
>> more than one new skb. For instance:
>>
>>    skb1 (ext A, 6000 bytes), skb2 (ext A)
>>
>> nskb1 gets ext A, nskb2 is allocated while skb1 is still being
>> copied and gets no extension. Before the patch, skb2 was not merged
>> into nskb2 (to_ext == NULL, from_ext != NULL). Now it is, and its
>> extension is dropped.
>>
>> This might be fine since skb2 has the same mapping as nskb1, but
>> I would like MPTCP folks to confirm, and the changelog should
>> mention it.
> 
> This looks fine to me for MPTCP, and this series should make collapsing
> work better for MPTCP. If, by chance, Paolo has the opportunity to
> confirm this, that would be nice as he worked on this part for MPTCP.
> (But feel free to move on.)

The above scenario looks fine to me, too. Also the in-tree implementation
sends DSS (which get ext on the RX side) for each packet, so it should be
the most common scenario.

I spent some time trying to generate evil sequences of ext/noext that could
lead to bad results but I could not find any.

In any case, definitely +1 for me to mention the functional change in the
changelog.

Thanks,

Paolo


  reply	other threads:[~2026-11-16 18:07 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-14  4:00 [PATCH v1 net-next 0/8] tcp: Prevent tcp_collapse() from bloating queue Kuniyuki Iwashima
2026-11-14  4:00 ` [PATCH v1 net-next 1/8] tcp: Clean up the first loop in tcp_collapse() Kuniyuki Iwashima
2026-11-14 15:32   ` Eric Dumazet
2026-11-14 16:07     ` Kuniyuki Iwashima
2026-11-15  4:10   ` netdev-bot+sashiko
2026-11-14  4:00 ` [PATCH v1 net-next 2/8] tcp: Don't collapse high density skb Kuniyuki Iwashima
2026-11-14 15:33   ` Eric Dumazet
2026-11-14  4:00 ` [PATCH v1 net-next 3/8] tcp: Stop collapsing if not bloated Kuniyuki Iwashima
2026-11-14 15:35   ` Eric Dumazet
2026-11-16 16:15     ` Matthieu Baerts
2026-11-16 18:07       ` Paolo Abeni [this message]
2026-11-16 18:21         ` Kuniyuki Iwashima
2026-11-15  4:10   ` netdev-bot+sashiko
2026-11-14  4:00 ` [PATCH v1 net-next 4/8] net: Move SKB_SMALL_HEAD_CACHE_SIZE to skbuff.h Kuniyuki Iwashima
2026-11-14  4:00 ` [PATCH v1 net-next 5/8] tcp: Skip collapsing if collapsed skb is less-dense Kuniyuki Iwashima
2026-11-14 15:36   ` Eric Dumazet
2026-11-14 16:18     ` Kuniyuki Iwashima
2026-11-14  4:00 ` [PATCH v1 net-next 6/8] tcp: Allocate all new skb before collapsing Kuniyuki Iwashima
2026-11-14 15:37   ` Eric Dumazet
2026-11-15  4:10   ` netdev-bot+sashiko
2026-11-14  4:00 ` [PATCH v1 net-next 7/8] tcp: Batch memory accounting in tcp_collapse() Kuniyuki Iwashima
2026-11-14 15:38   ` Eric Dumazet
2026-11-14  4:00 ` [PATCH v1 net-next 8/8] selftest: packetdrill: Add test for tcp_collapse() Kuniyuki Iwashima
2026-11-14 15:39   ` Eric Dumazet
2026-11-14 16:20     ` Kuniyuki Iwashima
2026-11-15  4:10   ` netdev-bot+sashiko
2026-11-14 15:31 ` [PATCH v1 net-next 0/8] tcp: Prevent tcp_collapse() from bloating queue Eric Dumazet
2026-11-14 16:06   ` 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=01c4e295-14b8-414e-9bf1-2be350466fe0@redhat.com \
    --to=pabeni@redhat.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuni1840@gmail.com \
    --cc=kuniyu@google.com \
    --cc=martineau@kernel.org \
    --cc=matttbe@kernel.org \
    --cc=mptcp@lists.linux.dev \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    /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