Article View: linux.kernel.netdev
Article #11786Re: [PATCH net] tcp: rate limit receive queue collapsing
From: Willem de Bruijn
Date: Thu, 05 Nov 2026 15:07
Date: Thu, 05 Nov 2026 15:07
74 lines
14589 bytes
14589 bytes
Eric Dumazet wrote:
> When a socket is over its receive buffer limit and its sk_rcvbuf can
> not grow, every incoming segment that needs memory goes through
> tcp_prune_queue(), which runs tcp_collapse_ofo_queue() and tcp_collapse()
> on the receive queue. Both walk their whole queue, even when there is
> nothing left to collapse.
>
> A peer can trigger this walk per packet, without refilling memory:
>
> 1) The segment lands last in the out-of-order queue. Since commit
> b0e01253a764 ("tcp: refine tcp_prune_ofo_queue() logic"),
> tcp_prune_ofo_queue() drops nothing, the segment is dropped and
> the queues are unchanged. The peer can send it again forever.
>
> 2) The segment lands second to last: one skb is pruned, and one small
> segment fills that space again.
>
> 3) The out-of-order queue is empty and the receive queue alone is over
> the limit (application not reading). Collapsing frees nothing,
> the out-of-order segment is dropped, and the window is not closed.
>
> 4) Collapsing frees just one skb, enough to queue the segment. The next
> segment is over the limit again.
>
> Only allow a collapse if at least 1/8 of sk_rcvbuf of new memory was
> queued in the receive queues since the previous collapse. This restores
> the "12.5 % of the queue capacity" amortization of the 2018 SegmentSmack
> fixes (CVE-2018-5390), using the same unit as the sk_rcvbuf limit, so
> that peers sending small (bloated) segments are not penalized.
>
> The credit is the net growth of sk_rmem_alloc in tcp_queue_rcv() and
> tcp_data_queue_ofo(), so that:
>
> - Coalescing a segment into the tailroom of the previous skb charges no
> memory, and earns no credit.
> - An out-of-order segment replacing or covering queued skbs only earns
> the memory it adds.
> - Duplicates earn nothing.
> - Data moved from the out-of-order queue to the receive queue
> (tcp_ofo_queue()) is not credited twice.
>
> In-order data is credited too, so that a receive queue filled by
> bloated in-order segments can still be collapsed when a hole appears.
>
> In-order segments are rate limited as well: a peer could otherwise send
> small in-order segments that each trigger a collapse freeing a single
> skb, enough to queue the segment, while the out-of-order queue holds
> many skbs that can not be collapsed.
>
> The credit is tracked in a new u32 tp->rcv_collapse_credit, placed in a
> hole of the tcp_sock_write_rx group: no other field moves, and tcp_sock
> size is unchanged. tcp_queue_rcv() now samples sk_rmem_alloc, and
> writes the credit until it saturates at sk_rcvbuf, so that the fast path
> stops writing it after a full buffer of new memory. Saturating at the
> goal would not work: sk_rcvbuf, and the goal with it, can grow later
> (for instance in tcp_clamp_window(), just before the goal is checked),
> and a socket over its limit can not earn more credit until the
> application reads.
>
> When collapsing is not allowed, tcp_prune_queue() goes directly to
> tcp_prune_ofo_queue(), which is cheap in the cases above.
>
> A regular flow can see a difference when it goes over its limit before
> 1/8 of sk_rcvbuf of new memory was queued since the previous collapse:
> out-of-order skbs can be pruned (even for an in-order segment filling a
> hole), and an in-order segment that still does not fit is dropped,
> with a zero window advertised, where a collapse might have made room.
>
> Fixes: b0e01253a764 ("tcp: refine tcp_prune_ofo_queue() logic")
> Reported-by: Chris Mason <mason@kernel.org>
> Signed-off-by: Eric Dumazet <edumazet@kernel.org>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Technical Details
Message-ID:
<willemdebruijn.kernel.641932d269d@gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-357462-linux-kernel-netdev=dewy.ruReferences:
<20261105124043.1543405-1-edumazet@kernel.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-357462-linux-kernel-netdev=dewy.ru
From: willemdebruijn.kernel@gmail.com (Willem de Bruijn)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] tcp: rate limit receive queue collapsing
Date: Thu, 05 Nov 2026 10:07:51 -0500
Organization: Usenet Network
Message-ID: <willemdebruijn.kernel.641932d269d@gmail.com>
References: <20261105124043.1543405-1-edumazet@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain;
charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
logging-data="3668792"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:iPCbmNk91cK8HyEuIMMIr1dpXJA= sha256:S+nm2G8fCDLuIurXZM/Lcb26CHzs1B3MUy/ZyjxxTHM=
sha1:FVXXpRDl9taNpllDWMg7PHkVRNM= sha256:vZ1uK5cemL2+CD3kxVgXTrRN4R8/AYgHuogWIyL5ON8=
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 CA9C511300F; Thu, 5 Nov 2026 18:48:47 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.149
X-Spam-Status: No, score=-3.149 tagged_above=-9999 required=6.31
tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001,
HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1,
RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
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 afJFiYJAScga;
Thu, 5 Nov 2026 18:48:37 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-357462-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
by mail.dewy.ru (Postfix) with ESMTPS id 5EC5B113004; Thu, 5 Nov 2026 18:48:25 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sin.lore.kernel.org (Postfix) with ESMTP id 04B2624322; Thu, 5 Nov 2026 15:07:57 +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=1793891274;
b=g5CrwIlfqRLTOq8oTICxptmm0wcH1JgPIGz2OT1u+5CH3LysER0ayNCgDVXhJ0Qi0Utj
480X5Gdggf/B+JMlPRz6/WGfRWtfquYcpeLo9xycqfc6aaCrBbwmJRhkKx/UO8MqpSRoB
Hkc7uBiJcK027K1xtbq5Uz/nxmwy/mfY3AQkiQBc4zZdgrxAmhbsj/gzPz1gaE9mrlt0p
NV3B/RtHpTjnmh/jLuGiiHrZCUgavp+ejjGS4/QTfDT1BuCuzPoahdIqXV8jU2nvnFRo4
qj14efeI7IFkkIukcWTjpogDzNuLpAz3BCefshaQ+I9+SxSU8ZrWRw8ZFi3+913WhKg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793891274;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
Received:Date:From:To:Cc:Message-ID:In-Reply-To:References:Subject:
X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type:
Content-Transfer-Encoding;
bh=k4lAZXF634haTmHf/i5p2AigpE4w64cfJ6rIv2nQMJM=;
b=l4z14CLeNRAKl4+SH64A13ElVmy0p7kgdMUTn2OH7mTx0kcJgRNkCuOf29mJxJW/WVoh
wsb7RycPnkuUpKRxlHqwK/73KQ/mq+UOa2pic1AW0eCF+f6CUY/j5gijdOHnESMOY4UIw
9mmX/tqjfXxLjNkzFBUo96uNory9ZQWcvZbeEi2GyaVeTuLaSYO2vh8rQ0IPGiO+ka/1c
ekWUBO8Iej06ruZ2rAbdn72jydO8S7kVdpqi56XqpMHk/X4awVVEdLw/OCrtDnSM5kjte
vtTxajKrT975xTiq/zpEjGnpypOq1WglslRfP3S+9LhGyqh/uPWVwntEuCEqoGsXAPw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="y5B/nidW";
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
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 663BB606A32E;
Thu, 5 Nov 2026 15:07:54 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=y5B/nidW
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.222.43
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1793891273;
b=oZgWDar4TNF7EoCOEyyPc9WPu++J3ZyYaMx+5c/pYpmSrQRKwhNOPP7XBYsqZeVv5ui3
MOUJFhs6MoZMis5vVbWWWkoGM0fJ/gu7CSNxfERo782erM0nyj7Vfw1YiaxlveMQQ61Iz
9Oj/nIXmQhScBfNXSXO9bXZzuJsIBW+0+HhpRS9byiEbAwssZDZx8mhjtivO6M7kDtsNe
7qhAI86hwlxw9X/Ydhqk83JSG3bBbrHUwZ8RpteO+BHn8IqStgNrtdi2iadJiQKdKGhly
kfN8j8qOVL5ulU2N8xmTkXuS7N7XkPxSZ7lfyBO6tnGn4l3Kk1AOWMxG20UDf3/A8Fg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793891273;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Date:From:To:Cc:
Message-ID:In-Reply-To:References:Subject:MIME-Version:Content-Type:
Content-Transfer-Encoding;
bh=k4lAZXF634haTmHf/i5p2AigpE4w64cfJ6rIv2nQMJM=;
b=JxqyQmPRiwQV1/lOZLkqlwrdQMU3YbEakMmtlZ7DayiK6XSG9FsjTJbBMbAwJjp3ix2I
+IpVfHxLKf7iQV5opG2Vj7KZgT7Dun6XvGS7ii/VfA3gCNN0b28YmInlWFSnt4IP8Slft
0wwwgi5HT6RBkZSD8PXsoTdPeW94op7wdTLBseDARCgZeSadSlrQlUDPWsLkWewHyH8IL
iXaL+PjAtQxIKElbYEhT1SXx/cpC3IdOvfT/g9tRTyOT41iWEunLTgK8u1dGzlgZGyxEy
ZUoFSx28hy07j2+ruLzTwfxVpAxnkq3QH6oZvhuy4Ugy4s4oKcn9W0k2arV2+1nnjtg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="y5B/nidW";
arc=none smtp.remote-ip=209.85.222.43
X-Received: from mail-ua1-f43.google.com (mail-ua1-f43.google.com [209.85.222.43])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1D773606A31B
for <netdev@vger.kernel.org>; Thu, 5 Nov 2026 15:07:52 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1D773606A31B
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-ua1-f43.google.com with SMTP id a1e0cc1a2514c-9903fde8db8so506238241.2
for <netdev@vger.kernel.org>; Thu, 05 Nov 2026 07:07:52 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1793891272; x=1794496072; darn=vger.kernel.org;
h=content-transfer-encoding:content-type:mime-version:subject
:references:in-reply-to:message-id:cc:to:from:date:from:to:cc
:subject:date:message-id:reply-to:content-type;
bh=k4lAZXF634haTmHf/i5p2AigpE4w64cfJ6rIv2nQMJM=;
b=y5B/nidWRQu7hph/E9TROo0pFFeFkHfz7RY+zmqPwDz01Il/jgguKcdV7/Cfhq+owB
azchre2G44+ETvbIvnHkQGDFhaP8ae52m/NPVEBjJvL9kOwpHJDB1hT2zMSTUavvGZMy
uTS2KnGAlwuS1AzEoBTtzurCiBFu95q/J62gIZfze5nVy2XFOF1g3A/W68oBfVydqPd+
2woOgkvlcAFcrRPhzIaKhSRrYCiU/Z3lbUWPEylhr+mb3WWYEOwgqGjKdg46LFTOctPD
SJmLdYNSkiG76FFpnb/sqa1H74QN7+D5cP20sTKL+TMHPBu8EzUlay1DEFEghYKpdWn1
acKA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1793891272; x=1794496072;
h=content-transfer-encoding:content-type:mime-version:subject
:references:in-reply-to:message-id:cc:to:from:date:x-gm-gg
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
:content-type;
bh=k4lAZXF634haTmHf/i5p2AigpE4w64cfJ6rIv2nQMJM=;
b=MfFhl3Ra0mKcIQ4jajlvZbEyBR7bZNeayDr+5a/MH78KFQXWy3yD/ekpv35RcpZ9px
gi4/IHVvWENuLWHzYf9ffspWp9BcI30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nn8soPx+UnHxX0VP6WqRYOqFuRFPh5sQ81KhD3Z4crzzbwXOWZ0huEZAjFYNVQp9gtaMHURz
cb+kFwRhYy0mNbUdfq
X-Received: by 2002:a05:6122:1d46:b0:5bd:aba5:3830 with SMTP id 71dfb90a1353d-5ec68295940mr9754553e0c.0.1793891272015;
Thu, 05 Nov 2026 07:07:52 -0800 (PST)
X-Received: from gmail.com (223.230.150.34.bc.googleusercontent.com. [34.150.230.223])
by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-998d37aad94sm4816212241.0.2026.11.05.07.07.51
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Thu, 05 Nov 2026 07:07:51 -0800 (PST)
X-Cc: netdev@vger.kernel.org,
edumazet@kernel.org,
Simon Horman <horms@kernel.org>,
Neal Cardwell <ncardwell@google.com>,
Kuniyuki Iwashima <kuniyu@google.com>,
Willem de Bruijn <willemb@google.com>,
Chris Mason <mason@kernel.org>
X-In-Reply-To: <20261105124043.1543405-1-edumazet@kernel.org>
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