Article View: linux.kernel.netdev
Article #18172Re: [PATCH v2 net-next 5/7] tcp: Allocate all new skb before collapsing.
From: netdev-bot+sashiko
Date: Tue, 17 Nov 2026 23:13
Date: Tue, 17 Nov 2026 23:13
175 lines
14630 bytes
14630 bytes
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] This patch makes tcp_collapse() (net/ipv4/tcp_input.c)
allocate every replacement skb for a section up front with GFP_ATOMIC,…
- [Low] The commit message says the old alloc_skb() failure path only
left duplicate skbs that waste memory.
- [Low] In tcp_collapse() (net/ipv4/tcp_input.c), this patch adds a
second job to the second-loop break condition: stop once…
--
tcp: Allocate all new skb before collapsing.
This commit makes tcp_collapse() allocate every replacement skb for a
section into a temporary pool before it copies any data. An alloc_skb()
failure then no longer leaves partially copied originals and duplicate
new skbs behind. Sections are capped at TCP_COLLAPSE_MAX_TOTAL_SIZE (16
skbs), except for a single bloated skb or overlapping ofo skbs.
> If alloc_skb() fails while splitting a large bloated skb across
> multiple new skbs, the partially-copied skb is not removed and
> new skbs remain in the queue as duplicates, consuming more memory.
[Severity: Low]
The code change looks right. For the ofo rbtree case, though, is this
description of the old failure path complete?
In the old code, a failed alloc_skb() jumped to end:. That path inserted
every deferred nskb from tmp with tcp_rbtree_insert() while the partially
copied original was still in the tree. tcp_rbtree_insert() sends equal
seq to the right:
if (before(TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb1)->seq))
p = &parent->rb_left;
else
p = &parent->rb_right;
So the first nskb sorts after the original even though its end_seq is
smaller. Its seq is equal to or after the original's seq.
If this happens at the tail of the ofo queue, tcp_collapse_ofo_queue()
sets tp->ooo_last_skb = skb_rb_last(). That points at an skb whose
end_seq is below data already queued, which breaks the assumption behind
the tcp_data_queue_ofo() fast path:
if (!before(seq, TCP_SKB_CB(tp->ooo_last_skb)->end_seq)) {
This patch fixes that as well, because no partial copy is left behind.
Could the commit message mention the restored ordering invariant, so
stable backporters can see it?
> diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
> index 92a4c978f9309..afc3c69eba781 100644
> --- a/net/ipv4/tcp_input.c
> +++ b/net/ipv4/tcp_input.c
> @@ -5812,6 +5812,7 @@ static struct sk_buff *tcp_skb_next(struct sk_buff *skb, struct sk_buff_head *li
> #define TCP_COLLAPSE_SCALING_RATIO \
> ((TCP_COLLAPSE_MAX_SIZE << TCP_RMEM_TO_WIN_SCALE) / \
> (SKB_TRUESIZE(TCP_COLLAPSE_MAX_SIZE)))
> +#define TCP_COLLAPSE_MAX_TOTAL_SIZE (TCP_COLLAPSE_MAX_SIZE * 16)
[Severity: Low]
This isn't a bug, but would a short comment help here? Neither this macro
nor the break condition in tcp_collapse() says that the cap:
- bounds the all-or-nothing preallocation into pool,
- is measured in sequence space from start, and
- is skipped for the first skb and for overlapping ofo skbs.
The only comment above the condition is still:
/* seq and end_seq must increase monotonically for rbtree. */
and it only covers the overlap exemption.
[ ... ]
> @@ -5908,8 +5911,9 @@ tcp_collapse(struct sock *sk, struct sk_buff_head *list, struct rb_root *root,
>
> /* seq and end_seq must increase monotonically for rbtree. */
> if ((list || !before(TCP_SKB_CB(n)->seq, sub_end)) &&
> - !tcp_collapse_skb_bloated(n, sub_end,
> - TCP_COLLAPSE_SCALING_RATIO))
> + (TCP_SKB_CB(n)->end_seq - start >= TCP_COLLAPSE_MAX_TOTAL_SIZE ||
> + !tcp_collapse_skb_bloated(n, sub_end,
> + TCP_COLLAPSE_SCALING_RATIO)))
> break;
>
> sub_end = TCP_SKB_CB(n)->end_seq;
[ ... ]
> @@ -5932,14 +5938,19 @@ tcp_collapse(struct sock *sk, struct sk_buff_head *list, struct rb_root *root,
> goto restart;
> }
>
> - while (before(start, sub_end)) {
> - int copy = min_t(int, TCP_COLLAPSE_MAX_SIZE, sub_end - start);
> - struct sk_buff *nskb;
> -
> - nskb = alloc_skb(copy, GFP_ATOMIC);
> + while (nskbs--) {
> + nskb = alloc_skb(nskbs ? TCP_COLLAPSE_MAX_SIZE : remainder,
> + GFP_ATOMIC);
> if (!nskb)
> goto end;
>
> + __skb_queue_tail(&pool, nskb);
> + }
[Severity: Medium]
Can the batch allocated here grow far beyond TCP_COLLAPSE_MAX_TOTAL_SIZE
for the ofo rbtree?
When list is NULL and n overlaps the current section,
before(TCP_SKB_CB(n)->seq, sub_end) is true. The whole break condition in
the second loop is then false. Neither the new cap nor the bloat test
runs, and n is always added to the section.
The overlap chain appears to be under the remote peer's control.
tcp_data_queue_ofo() keeps partially overlapping segments:
if (after(seq, TCP_SKB_CB(skb1)->seq)) {
/* Partial overlap. */
tcp_dsack_set(sk, seq, TCP_SKB_CB(skb1)->end_seq);
tcp_try_coalesce() refuses them because from->seq != to->end_seq.
tcp_collapse_ofo_queue() only ends a range at a gap:
if (!skb ||
after(TCP_SKB_CB(skb)->seq, end) ||
before(TCP_SKB_CB(skb)->end_seq, start)) {
A sender could send a long chain of small ofo segments, each overlapping
the previous one by one byte. That gives one tcp_collapse() section
covering the whole ofo queue. Small segments count as bloated, so they
also pass the density check.
This loop would then allocate about (sub_end - start) /
TCP_COLLAPSE_MAX_SIZE GFP_ATOMIC skbs at once. Every original skb is
still queued at that point. The pool is not charged to sk_rmem_alloc
until each nskb is dequeued. That stays true after the later patch
"tcp: Batch memory accounting in tcp_collapse()".
Before this patch, originals were freed as they were consumed, so the
extra memory at peak was about one new skb. Now the peak per socket is
close to old_truesize + new_truesize, limited only by sk_rcvbuf. Is that
intended?
There is also the failure case. One alloc_skb() failure discards the
whole batch. Under memory pressure, could a queue shaped this way never
make collapse progress?
The commit message says the cap bounds the temporary allocation and
treats overlapping OOO skbs as an exception. That exception seems to be
fully under the remote sender's control. The preallocation loop is also
unchanged at the end of the series.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116230555.2305867-1-kuniyu%40google.com
Technical Details
Message-ID:
<179495722211.3136.15241045445062201797@kernel.org>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365693-linux-kernel-netdev=dewy.ruReferences:
<20261116230555.2305867-6-kuniyu@google.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365693-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH v2 net-next 5/7] tcp: Allocate all new skb before collapsing. Date: Tue, 17 Nov 2026 23:13:42 +0000 Organization: Usenet Network Message-ID: <179495722211.3136.15241045445062201797@kernel.org> References: <20261116230555.2305867-6-kuniyu@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2451949"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:KFepWAswo23wsesgyIgh9WYPkUg= sha256:py1i+Q3fFiLRrpOUf5MiTzj8ozveO8liLsioBxrmRhc= sha1:sCpZU5tp/fOMmv7/bORSlvo6dls= sha256:J7gX486zS13TlL7miFHSqN5oqO0GViZ7kpgMOHx91oU= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 048A61150DE; Wed, 18 Nov 2026 02:14:06 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.4 X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VI0ryud6DzRd; Wed, 18 Nov 2026 02:14:02 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-365693-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id E73291150E9; Wed, 18 Nov 2026 02:13:53 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 2C1953424F; Tue, 17 Nov 2026 23:13:49 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1794957224; b=BiCF/PKzLDXV/d1orjKJS+AmNAEB3nYwHlLvLomrknQnV1j6r9oMndeU6GulgOEQvkQq aJ9WrOuKhB/jZgRLBGXBx0AFsdGA/bc/MWIQuRsLE7qhTrVdj6ng0I850lXMjUWr5GGT7 Lh9iF/fMfM3arn+FSxp3EYr5Vvk6crpJ59VKcD2ANg9F0GneSTQR0ToBgT2oSWAE+gEQ3 WMwnc6vD+fGb2lYyGn5v4HX+/up7Kutnipj5RG/JZ9THULXD+cuYJKzKS+dyQmQ5/KVzL 9xpon423V26QLAN8MwUT27jEGLECmNL+e9dFdUMWEw8EtkP1ZySDj5mKTQUjdNBgRCw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794957224; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=YwZwj/n+VRmpfJQeULH3OEv0yOcIiFih9ma9S3v9x38=; b=c+WI58SttYeneZcYODDZVzBRdwMMOziUk7lvRoRP4kK2sWYW2NILep18xqkABOXV5c8l TQpByi7CqLby5I1v9jj10NsqiUUXNN8FPkJHyPM3+iV1NHjkR1HNCzxhrPjjbUPMluPx1 oBDZU4JNvYAaS/cPxMk6b+WM575tYp5G0QJFUDC3l+Czd8Io5nLIEPUBzvFtasawFPWQI q0SMnx3gfGMTtlSFVBXiu7V97idyket+nDfeIh2ypeK9AFAG6smNibFhoZp/dm68FJB/j 9fdCqw4ttSfGxkRqQpV1QypFD9NqhHHIBca/0bgaB8LOB5vcluQFvLWiBXRKJiyi9ww== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=eOaISg0c; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3DD1C606A885; Tue, 17 Nov 2026 23:13:44 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=eOaISg0c X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794957223; b=N1NYUuf0nJ2i2oghMe+nHG8Quz4eATYnlmuUaOSBRQ1h8mZ9fuIGTnS4oPAulvEY1PgA pl1yBLefD/Bh4wkvJ+cYhLAwXdVGrpZBssJgeG8oD5IICXdIMzCTZlcngv2y+bBWZwDmf MB5dvmIxtkXPr0+nibKkpxnJGSjUTKLjVoKtQqMbNUTH9dWRrpE6QIcjnjMT8Ctw1FG6J x3efM2y+EiGDndZWqPcMp0NXfoiouHanb4MC15mxvO03t8uwIgt/B+9e9f3vH85B6f0rF ILsBPGKvNDo5VAhwYOk/s08rXv922PbxZP57nj7u610AwpOxVzMfMKUITZJw3XxjZwQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794957223; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=YwZwj/n+VRmpfJQeULH3OEv0yOcIiFih9ma9S3v9x38=; b=KQ1IPyUtjiu4r0NccBcSuiZYLtqckXEZtcivnDju47FBWX1FkxwRHkl0hd+40hKy4Uox b+drZKsHEKhYDYuw1Vl+oMiIORiK+cbvVXdvVTKDLxPhaB+NamTXKxNPq4nA6cvEo3jB9 EsPnDpC41ssmHv/X7OQewHCMZthS5SCmT9QBBR80TI70rcLeRFhTeJdfjluxQljTtPDLx mnhsocsrAxv8IxNY9S6J4Dq2RbDj0BdxhfDdvgHz+ytV+lCFAnfImcVxirZdtoaqdjOEn UpptLXksJ+sBW5ARwwGMg0z0c5AM5UEZA+waqVV0mH2ThrAf3D/Wk8agF4J4IIEe7wg== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=eOaISg0c; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F394606A88F; Tue, 17 Nov 2026 23:13:43 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85B291F000C6; Tue, 17 Nov 2026 23:13:42 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794957223; bh=YwZwj/n+VRmpfJQeULH3OEv0yOcIiFih9ma9S3v9x38=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=eOaISg0c0/dYK6zLv8uIKRbPxSp+VedmmKsJr3YDaSIytyiwuIm7ep+G5NFpXJ919 GchS4PjNp7r+kSvGWw/JnuYL2sbcqKcYIduJ/sSTqImPMiBvgcSyfYF5i85LNbiJ+4 hRoRVT7UfUgBrm+qjPZfAmrYnaV7KLFR0XG7Xx6qodj7lJdfP0mGId45Fj1hcPSKoE rmcYygCXyy8Snuj9qp4anRQW/zgqn5cfAE112HJPcWkVosH4TlzG4tLsGFBkEWg4tI OyS/erK640CMdu4VJbp7WbxiqwyXvD8it4r3HRHOFKOMPl4lJQe6b/6AMC346vAg4/ I//LKfCmNj2mw== X-Cc: edumazet@kernel.org, ncardwell@google.com, davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, matttbe@kernel.org, martineau@kernel.org, horms@kernel.org, kuni1840@gmail.com, netdev@vger.kernel.org, mptcp@lists.linux.dev X-In-Reply-To: <20261116230555.2305867-6-kuniyu@google.com> X-sashiko-severity: Medium X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list