Article View: linux.kernel.netdev
Article #17823[PATCH nf-next v1 0/5] netfilter: nf_conncount: reduce list_lock contention at the limit
From: Vladimir Vdovin
Date: Tue, 17 Nov 2026 11:53
Date: Tue, 17 Nov 2026 11:53
108 lines
16399 bytes
16399 bytes
Follow-up to [1]: Florian asked for the slot count to come from the
cpu count, Fernando for a way to see the contention. Additional
profiling showed the slot locks were not the main problem, the
per-key list is.
The setup is a 128-cpu hypervisor (64 rx queues) running openvswitch
with per-zone conntrack limits under a 2 Mpps SYN flood against one
VM. OVS keys nf_conncount by zone id, so the whole zone shares one
nf_conncount_list and its list_lock. Once the zone is at its limit
(500k), 96.8% of all cycles are in native_queued_spin_lock_slowpath
behind the spin_lock_bh() in count_tree(), and the host is
unreachable.
Two things add up to that:
* openvswitch has no way to ask whether the zone has room without
recording the connection, so above the limit every packet still
takes list_lock, records an entry that ovs_ct_commit() rejects at
once, and leaves it for gc to evict;
* the gc walk stops after 64 *evicted* entries, but live entries and
-EAGAIN entries do not count, so under flood every walk covers the
whole list: 500k nf_conntrack_find_get() under list_lock with BH
off. And nf_conncount_gc_list() takes the trylock before it checks
whether gc already ran this jiffy, so the count-only lookup is not
lockless either.
Patch 1, nf_conncount: bound the gc walk by examined entries.
A pass stops after 128 examined entries and the list is rotated so
successive passes still cover all of it.
Patch 2, nf_conncount: check last_gc before taking list_lock.
The count-only lookup stays lockless when gc already ran this
jiffy; one cpu per jiffy touches the lock, the rest read the count.
Patch 3, nf_conncount: size the number of slots from the cpu count.
Florian's suggestion from [1].
Patch 4, openvswitch: do not record connections above the zone limit.
Look the count up first with the existing count-only mode of
nf_conncount_count_skb() and record only below the limit.
Patch 5, openvswitch: warn about a zone above its limit without a lock.
The shared state of net_warn_ratelimited() was 2.7% of all cycles.
Each half was also tried alone: patches 1-3 without 4 leave the host
as it was (94% in the slowpath, recording path), patches 4-5 without
1-3 too (97%: the check and the recording are not atomic, every gc
pass that dips the count below the limit lets a burst of cpus record
past it, and the first of them walks the whole list under list_lock).
Numbers, two separate before/after measurements on the same machine.
1. The production case, before and after the whole series:
openvswitch, zone at its limit, 2 Mpps SYN flood.
spinlock slowpath softirq host
unpatched 96% 100% unreachable
patches 1-5 0% 40% responsive
2. The nf_conncount part alone, without openvswitch, before and after
patches 1-3: two netns over a veth pair, iptables "-m connlimit
--connlimit-above 10000 --connlimit-mask 0" in the receiving one
(one list, the same shape as a zone), trafgen in the other with 64
threads sending SYNs from random sources to random ports. veth
delivers on the sending cpu, so that is 64 cpus on one list_lock.
Measured with the list full:
nf_conncount_count_skb() calls/s
unpatched 0.5 - 4 ms 40k
patches 1-3 16 - 64 us 340k
The lock stays contended here, over 90% of all cycles in the
slowpath both before and after, because connlimit records every
connection, see below. What changes is how long the lock is held
per acquisition, and with it how many packets get through.
The connlimit matches record before they compare, as openvswitch did,
and unlike openvswitch they cannot stop: a match does not know whether
the connection will be dropped, and a softlimit setup needs the
connections above the limit counted. So they keep the convoy, and
patches 1-3 are what helps them.
Tested on the nft side with a ct count test between two netns (limit
enforced, closed and dropped connections reclaimed, list recovers
after being full) under DEBUG_LIST and lockdep.
[1] https://lore.kernel.org/all/20260413123712.42993-1-deliran@verdict.gg/
Vladimir Vdovin (5):
netfilter: nf_conncount: bound the gc walk by examined entries
netfilter: nf_conncount: check last_gc before taking list_lock in
gc_list
netfilter: nf_conncount: size the number of slots from the cpu count
openvswitch: conntrack: do not record connections above the zone limit
openvswitch: conntrack: warn about a zone above its limit without a
lock
net/netfilter/nf_conncount.c | 86 +++++++++++++++++++++++++++++-------
net/openvswitch/conntrack.c | 31 +++++++++++--
net/openvswitch/datapath.h | 1 +
3 files changed, 99 insertions(+), 19 deletions(-)
base-commit: 734bef548a96e8774d6eef5dfa2026c6edc4e80b
--
2.56.0
Technical Details
Message-ID:
<20261117115308.95134-1-deliran@verdict.gg>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365207-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365207-linux-kernel-netdev=dewy.ru From: deliran@verdict.gg (Vladimir Vdovin) Newsgroups: linux.kernel.netdev Subject: [PATCH nf-next v1 0/5] netfilter: nf_conncount: reduce list_lock contention at the limit Date: Tue, 17 Nov 2026 14:53:03 +0300 Organization: Usenet Network Message-ID: <20261117115308.95134-1-deliran@verdict.gg> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2320082"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:ryNRbarUfFl9vFY2LDCHOa2oBpg= sha256:LWQksYJC1PmbERBuAEbvHNhTNWb4/AurOlF5ZmTB928= sha1:fI36W1k/xorQjNBgG+l5/2MlW4I= sha256:Gpgs6k8mc6v9JILd8RBtH82Gaep8XiqPcQqymV5e6Y8= 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 ABFF8114F30; Tue, 17 Nov 2026 14:54:10 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.05 X-Spam-Status: No, score=-3.05 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, 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, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=verdict.gg 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 Dix6zZtu8q9y; Tue, 17 Nov 2026 14:54:06 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-365207-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=verdict.gg X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id C7077114F1C; Tue, 17 Nov 2026 14:53:55 +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 730CD29826; Tue, 17 Nov 2026 11:53:52 +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=1794916428; b=lSVKDq3A/UPkIJmUJht6jbhv1A0mnQWmtF4beqTHhr0knaa8ztjITYh03C2qAZGrbCu1 XazVu2ohpEVOS98MzXL2KPeflMkHuX2yVhbNk2/V7aIgYVOysAdsKVTmMBLunhGJV/IaQ CUqS7QS7H4IpVBEHl7jVUK7kAdj9iVRPrD9MRQ9OWHp8QYNjwwOIVhE4C6VaER4ea0te5 o/euN6IRXdqXj9O9IJXQSRHaV9fy23dfPexlaevpEmYZgnAtEPYbn4RS9h27zYU+EvvuA ymemyvyLWlEuLs+JZa9efDr/PTyIdQ9JYKRAOSIA2DkhWh1kt36TrmQYrK3o88c4g3Q== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794916428; h=X-Original-To:Received:DMARC-Filter:Received:X-ICL-RepId: Dkim-Signature:mail-alias-created-date:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:X-Mailing-List:List-Id:List-Post:List-Help: List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version: Content-Transfer-Encoding:X-Proofpoint-ORIG-GUID: X-Proofpoint-Spam-Info:X-Proofpoint-Spam-Details-Enc: X-Authority-Info-Out:X-Proofpoint-GUID:X-JNJ; bh=ns7yWOxeWCLlUtscnHrHlNmxNz7q83rrXK4tG+VKh8Q=; b=ZLFqy0IEgRp78LJ92/TbL2Sl/VGGENztOSIBxjtEfW9PujiMYqAPwtfD/w0dQf2Pin5A fCfKoDYF64HS808Tzu3IeddPtJP59R7+qy1U9KoWOyZlmEVwhg/9X3iIrLDUM3XcnH/5D zXciMkaEuLsjul8R4RgpT300N3LVKNNl/vkHx/XxLbfEp+nrzEvf2fvBzxcHk1FwIxDhB AzzgCX4Vpc05rCG1XzSeMxU2sZTpEqp1u8Nr4ZrvmKiQLXDEeiPJXHCpnIMNI/HLTDA5X jpYiZSva42oOrxHXGNWAo4PE8FKntD7ulPd4okV2ohQfZ8Tqc5B0/OYSqxXhsNJaoRQ== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=verdict.gg header.i=@verdict.gg header.a=rsa-sha256 header.s=sig1 header.b=CeOBFq9W; dmarc=none header.from=verdict.gg; spf=pass smtp.mailfrom=verdict.gg; 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 3DCC0606A338; Tue, 17 Nov 2026 11:53:48 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=verdict.gg header.i=@verdict.gg header.a=rsa-sha256 header.s=sig1 header.b=CeOBFq9W X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=57.103.64.156 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794916427; b=NZQQDCaq+Z27ZC9ecg4v/tsYntjaU3ndkOqBCwzT+IjByaXIgnbfSJrdwYN5A+dGMrlw xSCVSp3Z2MwzmaXaZXjDedwXNUBIZJgTxOwXIeQ1MM9G14LDDWtF/tfe2M8RfyP8AybUI Irx3JpV4lb0w42Flzi5gd1nXWzVB+WT5gOIOEsBH0FE7XQBbNZ4zUpEkWd0A3VUS6fvxu i23niHpIjd+qR7smeY1CKI6Nw6n7EripxWh5yX/rEEnUoL8TGzdGxPVc3n14uWeCrK7lo lxZ65cJJDoi8NgB6ILCnLy4kYpQNP5EMT/HZrZR0xct3J5pYaIAFWMxItoEG7gNRW2g== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794916427; h=DMARC-Filter:Received:X-ICL-RepId:Dkim-Signature: mail-alias-created-date:Received:From:To:Cc:Subject:Date:Message-ID: X-Mailer:MIME-Version:Content-Transfer-Encoding: X-Proofpoint-ORIG-GUID:X-Proofpoint-Spam-Info: X-Proofpoint-Spam-Details-Enc:X-Authority-Info-Out:X-Proofpoint-GUID: X-JNJ; bh=ns7yWOxeWCLlUtscnHrHlNmxNz7q83rrXK4tG+VKh8Q=; b=tm5QQgb6p/u5kcSCzqk2puL5kelDyqE3wqgwY7LfnyNX7skSlTuXn6eRH0DK3Z6UZTDH i471ZRlAHK/GQYXaIYiCb/V6ZWfvqrFAcGVIaPa2zgMoHSZ9tNmAVXmY+IaJWoPajEsrE ABye+3RclQLC7puH5bG4azeo8uYDkAmlq97MM/PEwPMo2xhfYp+CBNERQrulVLmmE/u2v P4BT49MKirAb5+2kF1ESRz4TLniVygDFdUUzikPS7Lsg8EJ4HZdvlLThA3gXWdQllhMcS Lma6BB0BDEb3qpzMmv+307QhSO8uqvrtYcVnug2G4f7kJRkH+dhS+Xv7uJutJjtf80A== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=verdict.gg; spf=pass smtp.mailfrom=verdict.gg; dkim=pass header.d=verdict.gg header.i=@verdict.gg header.a=rsa-sha256 header.s=sig1 header.b=CeOBFq9W; arc=none smtp.remote-ip=57.103.64.156 X-Received: from outbound.pv.icloud.com (pv-2002k-snip4-5.eps.apple.com [57.103.64.156]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 950ED606A339 for <netdev@vger.kernel.org>; Tue, 17 Nov 2026 11:53:45 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 950ED606A339 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=verdict.gg X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=verdict.gg X-Received: from outbound.pv.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-1a-20-percent-1 (Postfix) with ESMTPS id B31C0180021F; Tue, 17 Nov 2026 11:53:42 +0000 (UTC) X-ICL-RepId: 01a1e95b-134a-7881-8211-7e3aa6e1aea3 X-Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=verdict.gg; s=sig1; t=1794916424; x=1826452424; bh=ns7yWOxeWCLlUtscnHrHlNmxNz7q83rrXK4tG+VKh8Q=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=CeOBFq9Wq6SF12AI3PIzC+yhacxQt06xNouKJjDYd/qlyO54ahFa5blSVQqEIW8aBrn0DFA/uxXTz61OcMdOHpxWquuFr/humHVgOfb+KCc6v7ayUySzfKoV0Js+0hG6eaM0BL8OJdYUmtse09rKsObZ3Feq5ZHn1ly7uXiVC8zPV+nGBkHhVfGkTWa+QjC/aIwb4CfPxh2uzCXKQ84uh6wofzK/2/7ODq+K3Khk0x7jc30H//h2h8iFpd2dpla2lZixugv0DmKIMqYjlfJNjgHeb3b1goy2Y5qS+GlOAo3Cphw3bGa4uNy6K4A8AR/8TBAb4XWQjfgQZJMBCil+gA== X-mail-alias-created-date: 1621344842221 X-Received: from DelNac.mail.msk (unknown [17.156.192.29]) by p00-icloudmta-asmtp-us-west-1a-20-percent-1 (Postfix) with ESMTPSA id D715218001BF; Tue, 17 Nov 2026 11:53:37 +0000 (UTC) X-Cc: Kees Cook <kees@kernel.org>, "Gustavo A. R. Silva" <gustavoars@kernel.org>, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, dev@openvswitch.org, linux-hardening@vger.kernel.org, Fernando Fernandez Mancera <fmancera@suse.de>, Vladimir Vdovin <deliran@verdict.gg> X-Mailer: git-send-email 2.56.0 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 X-Proofpoint-ORIG-GUID: gEgYC-vKQFDSq_RvjCOrLk78npJMFyKi X-Proofpoint-Spam-Info: AW1haW4tMjYxMTE3MDA0NyBTYWx0ZWRfX5PyWIkEjCkfp UVH0iuk1ep33Ra8VI5YwxsacQFIG2OLtr85rLHrCgMggSnsssrCSnTdCqlU3vmLIsQ13RtJvm5c i3QCpr+zKIdlJ05RuRQZrd7inXU3H7k= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTE3MDA0NyBTYWx0ZWRfX+266nEAjpd+A ZlpjiECXwQSLGExP/07Il/YeSYfZzFeK9iVxRdVG7/1NJrM7q29LS/hrjjUUeNlUHpC8D40UQq4 XV/OT9MK3x84ZK8fMeIzC6WIhcO/uLkxx6bynHzXFaiXutwnZoY/Gv4uQ8D/W6eeVB8YhIw4jM8 nxSJxkhk1sq8C0y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