Article View: linux.kernel.netdev
Article #4072Re: [PATCH net-next] veth: set the real number of queues before registering the devices
From: Eric Dumazet
Date: Fri, 16 Oct 2026 15:43
Date: Fri, 16 Oct 2026 15:43
94 lines
10232 bytes
10232 bytes
Le ven. 16 oct. 2026 ร 08:51, Qiliang Yuan <odys.yuan@gmail.com> a รฉcrit :
>
> Since commit 9d3684c24a52 ("veth: create by default nr_possible_cpus
> queues"), each veth device is allocated with one rx and one tx queue
> per possible CPU, and veth_newlink() reduces the real number of queues
> to one unless the user asked for a number.
>
> Both devices are already registered at that point, so
> netif_set_real_num_tx_queues() and netif_set_real_num_rx_queues()
> remove the sysfs objects of every extra queue that register_netdevice()
> has just created, each one emitting an add and a remove uevent, and the
> tx side also waits for an expedited RCU grace period. This happens with
> RTNL held, twice per pair, and grows with the number of possible CPUs:
> with 240 of them a veth pair emits about 1900 uevents, and udev
> processing them slows down later sysfs work such as deleting devices.
>
> Set the number of queues before registering each device. For a device
> that is not registered yet this only updates the counters, so the extra
> queues never appear in sysfs, and the error paths that undid a
> registration are no longer needed.
>
> Creating and then deleting 500 veth pairs, one ip -batch each, in a 16
> vCPU guest, median of 3 runs, per pair:
>
> before after
> 16 possible CPUs create 1644 us 520 us
> delete 11822 us 9750 us
> 240 possible CPUs create 17253 us 1339 us
> delete 17082 us 9941 us
> uevents 1918 6
>
> Signed-off-by: Qiliang Yuan <odys.yuan@gmail.com>
> ---
> drivers/net/veth.c | 20 ++++++++------------
> 1 file changed, 8 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/net/veth.c b/drivers/net/veth.c
> index 38f263d4f06b4..92ad064567327 100644
> --- a/drivers/net/veth.c
> +++ b/drivers/net/veth.c
> @@ -1875,6 +1875,10 @@ static int veth_newlink(struct net_device *dev,
>
> netif_inherit_tso_max(peer, dev);
>
> + err = veth_init_queues(peer, tb);
> + if (err)
> + goto err_register_peer;
> +
> err = register_netdevice(peer);
> if (err < 0)
> goto err_register_peer;
> @@ -1904,6 +1908,10 @@ static int veth_newlink(struct net_device *dev,
> else
> snprintf(dev->name, IFNAMSIZ, DRV_NAME "%%d");
>
> + err = veth_init_queues(dev, tb);
> + if (err)
> + goto err_register_dev;
> +
> err = register_netdevice(dev);
> if (err < 0)
> goto err_register_dev;
> @@ -1917,16 +1925,10 @@ static int veth_newlink(struct net_device *dev,
> priv = netdev_priv(dev);
> rcu_assign_pointer(priv->peer, peer);
> netdev_hold(peer, &priv->peer_tracker, GFP_KERNEL);
> - err = veth_init_queues(dev, tb);
> - if (err)
> - goto err_queues;
>
> priv = netdev_priv(peer);
> rcu_assign_pointer(priv->peer, dev);
> netdev_hold(dev, &priv->peer_tracker, GFP_KERNEL);
> - err = veth_init_queues(peer, tb);
Orthogonal to your patch, but here we should have used @tbp instead of @tb.
# ip link add va type veth peer vb numtxqueues 4
-> vb has 4 tx queues, but only 1 real tx queue, which is quite unexpected.
# ip -d link sh vb
13: vb@va: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN
mode DEFAULT group default qlen 1000
link/ether e2:53:93:f3:f4:f8 brd ff:ff:ff:ff:ff:ff promiscuity 0
allmulti 0 minmtu 68 maxmtu 65535
veth addrgenmode eui64 numtxqueues 4 numrxqueues 8 gso_max_size
65536 gso_max_segs 65535 tso_max_size 524280 tso_max_segs 65535
gro_max_size 65536 gso_ipv4_max_size 65536 gro_ipv4_max_size 65536
# ls /sys/class/net/vb/queues/
rx-0 tx-0
Technical Details
Message-ID:
<CAL4WiipGJT316aRQSMtyHo9s0qGoWGeZLxqnksyQTO9mioidQA@mail.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-347439-linux-kernel-netdev=dewy.ruReferences:
<20261016-bug-veth-init-queues-before-register-v1-1-f48eb2bb25a0@gmail.com>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-347439-linux-kernel-netdev=dewy.ru
From: edumazet@kernel.org (Eric Dumazet)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next] veth: set the real number of queues before
registering the devices
Date: Fri, 16 Oct 2026 17:43:54 +0200
Organization: Usenet Network
Message-ID: <CAL4WiipGJT316aRQSMtyHo9s0qGoWGeZLxqnksyQTO9mioidQA@mail.gmail.com>
References: <20261016-bug-veth-init-queues-before-register-v1-1-f48eb2bb25a0@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
logging-data="2818639"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:UIu6SFuygrxxcon1qREVMPhnc38= sha256:rENbSljePL1HEebQwyghn6N/TrDWkekvUWLqLqdzlkU=
sha1:+pdlCASWHo6qqu+YmFIaEZZtXkw= sha256:K/WlG57SFUVBIvi1uAnoEAKFz8jNnz0nEhw42UaJqHQ=
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 9198C110590; Fri, 16 Oct 2026 19:53:37 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -1.34
X-Spam-Status: No, score=-1.34 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1,
DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
MAILING_LIST_MULTI=-1, 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=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 vwT6q1O3vRn3;
Fri, 16 Oct 2026 19:53:34 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-347439-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id 4DAB1110574; Fri, 16 Oct 2026 19:53:26 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
by sea.lore.kernel.org (Postfix) with ESMTP id 8347063DC2; Fri, 16 Oct 2026 15:46:49 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 386D64EB84B;
Fri, 16 Oct 2026 15:44:08 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NWl7COJF"
X-Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0EBA632C94A
for <netdev@vger.kernel.org>; Fri, 16 Oct 2026 15:44:06 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1792165448; cv=none; b=XzLG+RHwURQWznAIpDJicPn2t8/trVh22FUlim14Ezi2Jj16wBiL0IbxemG6vYe5Flh+leEacHmq/bJ7H5Ed8SOZO/3Ka6VrqhYoGNxuGHktrp9EFt0hYqcgh95y9KeLqzgU643hYl0og0zQ859gUBZFBe6ct1pokvDl5V6e8Qo=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1792165448; c=relaxed/simple;
bh=Zz8i0lUTzRkuZgBP2+V7pWig14l8N8fd7W2Q0Mi/UCw=;
h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject:
To:Cc:Content-Type; b=dmbShe2isrTmWCvntzGp7Gc8+yZFFE1fLc5Rz5UShd+dLpZw1GUMXKdhIaf/IknK21C4mMs28Dsob8QipTqZnJOfrkzacLkiwvScDTuCKZYV/YugqeqVw+6pgdFJZslpwYw4F51pcNxrwqpgO7VcmsqQYNLXQvB4HanZCavgj8g=
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NWl7COJF; arc=none smtp.client-ip=100.103.45.18
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9EE641F000C4
for <netdev@vger.kernel.org>; Fri, 16 Oct 2026 15:44:06 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
s=k20260515; t=1792165446;
bh=x4BlVnBkdABSzxNkd7xtQc1KrHevTV+nHJUmN1WOF50=;
h=References:In-Reply-To:From:Date:Subject:To:Cc;
b=NWl7COJFN7Hf2rYjR08s5lUnWdyU60zFI9qWzWql2nZLxLwFDrOUuWaPtlZlEJCXf
k8HQ2guCGgRB450IeMTOxyhWfFQhO05ODS6uVNvGrehUbFykMXgPbVAwTDeiX6Xvf1
+sXx/gEJeltqf0VDI3BwB08CXxKGzx2LHRPe4qPXP+NoRKR0j0Cgj4YpApDJ9AdrLc
o+p29XbXvdplq512JPyDc7qGFzWLTorWk3hXmOdCW1MKV2cElO27KeSH5l39+z++5n
Zv50sIRji7pMPoHHTsw6CJkqOZ1/FXpBL26ojt3RPb0YMo9zvKdTqcTLzwfS4AXcgf
l7JQpzxGgEt1g==
X-Received: by mail-ot1-f45.google.com with SMTP id 46e09a7af769-833e671ee9fso4742138a34.0
for <netdev@vger.kernel.org>; Fri, 16 Oct 2026 08:44:06 -0700 (PDT)
X-Forwarded-Encrypted: i=1; AKwUvBzklj2dZy9hJmECzUhobKQ1pIRP+S9eb0hQK0MRvGlO3OQBDA9b9jwhWvs0dzgJ9a8DMfn5bjI=@vger.kernel.org
X-Gm-Message-State: AFq9FYKSXiDqY/3gMvdMU9EBAuxh7msmYuQvHRZBuyGtPuLcFxGmz7na
WtXUuM3F8jbCiQv1AqNXqOAXFFIeAwY3gQkSTGPpOehmgUYLGKvZ5X6yIEkClW2Oe5Px3yHe88i
4G7lJphQSbk09IXWPchaogf49rDfUybg=
X-Received: by 2002:a05:6808:6f8f:b0:4ea:686e:fe86 with SMTP id
5614622812f47-50c5b464a7emr20203589b6e.63.1792165446007; Fri, 16 Oct 2026
08:44:06 -0700 (PDT)
X-Precedence: bulk
X-Mailing-List: netdev@vger.kernel.org
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-In-Reply-To: <20261016-bug-veth-init-queues-before-register-v1-1-f48eb2bb25a0@gmail.com>
X-Gmail-Original-Message-ID: <CAL4WiipGJT316aRQSMtyHo9s0qGoWGeZLxqnksyQTO9mioidQA@mail.gmail.com>
X-Gm-Features: AclHuK-vfqoap1s0w_q-N6yPL7qX4SBSAmBMtMa8Gsw7Q-KmBm3I-033Cj2xIhU
X-Cc: Andrew Lunn <andrew+netdev@lunn.ch>, "David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org