Article View: linux.kernel.netdev
Article #20280[PATCH net-next v5 0/4] net: make moving a device to another netns cheaper
From: Qiliang Yuan
Date: Sat, 21 Nov 2026 23:21
Date: Sat, 21 Nov 2026 23:21
117 lines
14417 bytes
14417 bytes
Moving a device to another netns waits in rcu_barrier() with RTNL held.
Container and sandbox managers move one end of a veth pair for every
new network namespace, so this barrier limits how fast such namespaces
can be created on the whole system, to about 70 per second with 4
CPUs online however many threads create them.
The barrier was added for NETDEV_UNREGISTER_FINAL, which is long gone,
but it still keeps cached IPv4 routes through the moved device from
being accepted in the old netns, and it lets the RCU callbacks of the
nexthops removed with the device release their IPv6 route exceptions
before the move. Routes through nexthop objects are not fully covered by
it: their cached dst entries are released by an RCU callback queued from
another RCU callback, so a socket in the old netns can still send
through a device that now belongs to another netns whenever the route
generation numbers of the two netns happen to match.
Patches 1 and 2 draw the IPv4 rt_genid and the IPv6 fib6_sernum bumps
from sequences shared by all netns, so a cached route no longer matches
another netns. Patch 3 releases the cached routes of a nexthop when it
is removed from a group, instead of leaving its IPv6 exceptions valid
until it is freed. With these, nothing relies on the barrier, and patch
4 removes it.
Without patch 3, removing the barrier lets a socket keep sending through
a moved device that carries no IPv6 address and is a member of a nexthop
group, until its exceptions are released. Datagrams a socket in netns A
sent through such a device after it moved to netns B, 10 trials,
median and range, with patches 1, 2 and 4 before and 1-4 after:
before (datagrams) after (datagrams) change
per trial 886 (399-6542) 0 -100%
Creating 400 netns, each with a veth pair whose host end is moved back
to the initial netns, a tap device, addresses and routes, in a guest
with 4 CPUs online, median of 5 runs:
before (netns/s) after (netns/s) change
1 thread 27 31 +15%
4 threads 37 48 +30%
16 threads 67 103 +54%
Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
---
V4 -> V5:
- 1/4, 2/4: publish each value drawn from the shared sequence with a
cmpxchg on the netns counter, drawing again if another bump changed it
first, instead of storing it with atomic_set(). This keeps the routing
change ordered before the new value and the value before the nodes
stamped with it, and keeps a stalled bump from overwriting a newer
value, so rt_genid and fib6_sernum stay monotonic per netns (Ralf Lici)
- Rebase onto net-next and remeasure
V3 -> V4:
- 2/4: reject the initial fib6_sernum in rt6_is_valid(), which a route
can record while fib6_add() has published it but not bumped the sernum
yet (Sashiko review)
- 3/4: release the per-cpu routes and exceptions of the removed IPv6
nexthop instead of bumping the IPv6 sernum once per group, and flush
the IPv4 route cache at most once; this also drops the forward
declaration (Jakub Kicinski, Sashiko review)
- 3/4: with the exceptions released when the nexthop leaves the group,
4/4 no longer lets nexthop_free_rcu() remove them after the old netns
freed its rt6_stats (Sashiko review on 4/4)
- Drop the Fixes and Reviewed-by tags (Jakub Kicinski)
- Rebase onto net-next and remeasure in a 32 vCPU guest with 4 CPUs
online, so the netns creation rates differ from v3
V2 -> V3:
- Add patch 3: flush the cached routes of a group when one of its
nexthops is removed. Without it, patch 4 lets a socket keep sending
through a moved device that has no IPv6 address (Sashiko review)
- 1/4, 2/4: say that cached routes carry values drawn from the sequence
because inserting a route bumps it, not because NETDEV_UP does, and
that this holds until the sequence wraps (Sashiko review)
- 1/4, 2/4: add Kuniyuki's Reviewed-by, the code changes only in comments
- 4/4: commit message only, keep Eric's and Kuniyuki's Reviewed-by
- Rebase onto net-next and remeasure in another guest, where the barrier
costs about 4 ms per move instead of about 10 ms, so the gains are
smaller than in v2
- Send from my linux.dev address
V1 -> V2:
- 2/3: keep the initial fib6_sernum of each netns and never hand it out
from the shared sequence, instead of drawing a value at netns creation
(Eric Dumazet); 1/3: do the same for rt_genid
- 2/3: note that fib6_sernum is no longer monotonic per netns (Eric
Dumazet); 1/3: likewise for rt_genid
- Drop Kuniyuki's Reviewed-by from 1/3 and 2/3, which changed
- Rebase onto net-next and remeasure
v4: https://lore.kernel.org/r/20261117-bug-net-netns-move-rcu-barrier-v4-0-43e1ca0aac7f@linux.dev
v3: https://lore.kernel.org/r/20261109-bug-net-netns-move-rcu-barrier-v3-0-6084b02610b3@linux.dev
v2: https://lore.kernel.org/r/20261019-bug-net-netns-move-rcu-barrier-v2-0-b6eb7780c492@gmail.com
v1: https://lore.kernel.org/r/20261016-bug-net-netns-move-rcu-barrier-v1-0-4157d798658f@gmail.com
---
Qiliang Yuan (4):
ipv4: draw rt_genid from a sequence shared by all netns
ipv6: take fib6_sernum from a sequence shared by all netns
nexthop: release cached routes when a nexthop leaves a group
net: remove rcu_barrier() from __dev_change_net_namespace()
include/net/net_namespace.h | 5 +----
net/core/dev.c | 1 -
net/ipv4/nexthop.c | 15 +++++++++++++++
net/ipv4/route.c | 36 ++++++++++++++++++++++++++++++++++++
net/ipv6/ip6_fib.c | 28 +++++++++++++++++++++++++++-
net/ipv6/route.c | 6 +++++-
6 files changed, 84 insertions(+), 7 deletions(-)
---
base-commit: 2208ab00f4f213ade91ab775e7f8c4dacdcc856e
change-id: 20261016-bug-net-netns-move-rcu-barrier-d998c6395830
Best regards,
--
Qiliang Yuan <qiliang.yuan@linux.dev>
Technical Details
Message-ID:
<20261121-bug-net-netns-move-rcu-barrier-v5-0-100a3b5d9090@linux.dev>Path:
mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368514-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368514-linux-kernel-netdev=dewy.ru From: qiliang.yuan@linux.dev (Qiliang Yuan) Newsgroups: linux.kernel.netdev Subject: [PATCH net-next v5 0/4] net: make moving a device to another netns cheaper Date: Sat, 21 Nov 2026 18:21:18 -0500 Organization: Usenet Network Message-ID: <20261121-bug-net-netns-move-rcu-barrier-v5-0-100a3b5d9090@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="3520296"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:/0zEwWzzthhit3yAH7kQemBcaeo= sha256:BMkSowApz/1TSStf+EZuwB84RP3cvWVPPo02adbHhzk= sha1:BcqMDqunQLRUlRCvNq+KqAtmJ1U= sha256:SEPxxzzDV5XSQVQVuUb3mjnLVN7FKM5Tbrdd79FxU9Y= 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 A913A115C2F; Sun, 22 Nov 2026 02:21:52 +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 (1024-bit key) header.d=linux.dev 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 uA3kcLOwhPJw; Sun, 22 Nov 2026 02:21:48 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-368514-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id 3BDD5DFFA1; Sun, 22 Nov 2026 02:21:40 +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 8DC0C23571; Sat, 21 Nov 2026 23:21:37 +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=1795303294; b=dXLOGyQlUbu0Uvv8Qgr3fyPHUMDnpoi7SzUL4VyOQM2NqXyAEsXVJWF1v+NHCH3qSYm2 RNV5R5xISVlwBnF2ISTS79uWvTDsTmMng/siCbSgJKs75UIyalvJtPJ9U7Rg3ujVXIRy7 5PCNo5H5EoNMN916+EHJaYOaGsm7CE2okBuSncXW1KPxmdNtlG4xYomkmHCO6jxd6KJ4O uzaVe8ADQSvtUXfiNI0XKM3GnkkwaH/T+sgbdbFAoaSa1q8O/yFM1WgBW3xPzri7Ief3D MB0oV8MhQn7Mt6rioDuxy3kgTagabdb3VwQvHgdZ2Wl3m0Y2gdZZpoDQ30bT/oGbPnQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795303294; h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature: X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:From:Subject: Date:Message-Id:X-Mailing-List:List-Id:List-Post:List-Help: List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version: Content-Type:Content-Transfer-Encoding:X-B4-Tracking:To:Cc:X-Mailer; bh=Aj67hpSVfvyNeY2bYAHOKOCgXRNNXNasIUFLScoP+LQ=; b=3Aw+Uo6S+XhhcCS9Zlsd8EwVyf4JmhYnCldCDPqAFmJUP3NpNxF3rUP+eye6kdcI9dTr glImgogdRCxabJjJBuC69vh8pbZ2Sq6t9Crha1MawaK7EONFDMBuoVUwQlpoPQRp6SD0c cPBmN4vrJp8pUKmBm8bbM5GzN159AABbVQC6Cpp8fyyEfWiXxS9AUdAgPJYwZmo4htctm 42h/bR4y3SURICgK2FItU+9S/gdxHqB6B4COjuQ2o2bKn9EqmW7KR8YLzfsOMZ+KYWP6T 6DfNG7VAh5XXQGTk1DlDBxhVkB4diJKWnr9dMQrSKy3J0BmYxzuY+CyIvDylnsEM+vw== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=kcPrKc2y; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; 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 F2ACB606A337; Sat, 21 Nov 2026 23:21:33 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=kcPrKc2y X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.21 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795303293; b=Yfsv4+FAo8kdnTFtTT6bL5J6o9gaxJfQbLnLMp/5jer9+aQWq3MKcOjpQI+UTw1KlksD FJc5mPV0gTy2Dm0Y+d2cfnfT1+0r8jI3HZqPn5lhGW+GlHw4dwfEXv9fZ2IriH99pC4Q6 KQLZpXY4QXrnXJdsurkhLnr/P3x1RVKtCwWDSjivQPIo/W62ZF01AVu4q7YAIsrhMs5V6 TQMMpeU77FgGgV1+zOfypJpHpSDayBvJBjMUCS/R4yD4PmLXcKssX3viwsJZrIeadu0Ll B6C0wU1rtTd5jm3w6uAh3pC7y9piKkzAS6TE6KrpmxwXstmrl/Gzb5mChpgXhSRR4rw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795303293; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:Subject:Date:Message-Id: MIME-Version:Content-Type:Content-Transfer-Encoding:X-B4-Tracking:To: Cc:X-Mailer; bh=Aj67hpSVfvyNeY2bYAHOKOCgXRNNXNasIUFLScoP+LQ=; b=Qyanwo7JiJvJmDqA9DeFZax2HqqY0wBqa2rZIKeAamo6WlMK/FvLlsOrU3MBS7mWFEKp cUp2lfFq4XinrjD1VNksk+KS/7GU58C7anjIY5j6QtyDJqCK4RuWCvOyZwm8zYH82CqvQ mtHTa9sdOV0voiWI9QILIIwt0zQv7LvJNcPCmKwBR/Yj8XX7YuypUDYmzVPRy0Jrn+Ph5 bSrRQTyejU3mNrLwe9+Yvq9/cGHas2j4wXJauM/qLoN0F20j9gn2QVDJnRooAwmYRzg/D BOfKW0F3pq8PXr6KuSDeUDHJVcVfpKNxgXM6FgDPpb1V0OMUXLWdEz7xroQK2Xrq7Jg== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=kcPrKc2y; arc=none smtp.remote-ip=91.218.175.21 X-Received: from mta0.migadu.com (out-21.mta0.migadu.com [91.218.175.21]) (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 D02BE606A330 for <netdev@vger.kernel.org>; Sat, 21 Nov 2026 23:21:31 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D02BE606A330 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Envelope-To: netdev@vger.kernel.org X-DKIM-Signature: a=rsa-sha256; bh=+1izkUncMumyUej9MQnzVY6Io8Kc1oNzUryCzKqQJWg=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1795303289; v=1; x=1795908089; b=kcPrKc2yaWA+PmvdP2c9E1Dy9Tjx4Iiq1ty3HHc7V5L07ELJzhqJrmtoau2PKjdINfQhg8g1 NROsykXOa5bVkxqYjitvdXhCjYEbPEwWnXeMzR0S+9uQiBvVypdRccucdP86963jBfcT+1XiLWU nRuHKfTSOS+cwgArdy1bNMpo= X-Envelope-To: netdev@vger.kernel.org X-Received: by smtp.migadu.com with ESMTPS id b4e59da960c162c4; Sat, 21 Nov 2026 23:21:29 +0000 X-Mizu-Trace-ID: b4e59da960c162c4 X-Migadu-Flow: FLOW_OUT 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-B4-Tracking: v=1; b=H4sIAG4nAmsC/43Py2rDMBAF0F8JWldBL+vRVf6jdCHJY0cQ20Wyh UPwv0dRFjXduItZXIY5l3mgBDFAQp+nB4qQQwrTWELzcUL+ascecGhLRowwSQmV2C09HmF+zZj wMGXA0S/Y2ViciFtjtJfcNJoTVJCfCF1Ya8EXet+tM/oum2tI8xTvtTnTuv9vSaaYYEEb1SqjZ aO7Sz/YcDv7aah0ZnvOHHKscE6CU0oTLwz7y/FfjpJjjhdOEi1c7Xf8cgvjsp5byG9O7DiqDjn xepYD9ZZY61W357ZtewK0fm6DwwEAAA== X-Cc: Kuniyuki Iwashima <kuniyu@google.com>, Ralf Lici <ralf@mandelbit.com>, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Qiliang Yuan <qiliang.yuan@linux.dev> X-Mailer: b4 0.13.0