[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5cb17491-d6a8-468b-b260-1b941a7f42e5@blackwall.org>
Date: Sun, 17 Aug 2025 12:40:58 +0300
From: Nikolay Aleksandrov <razor@...ckwall.org>
To: cpaasch@...nai.com, David Ahern <dsahern@...nel.org>,
"David S. Miller" <davem@...emloft.net>, Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
Simon Horman <horms@...nel.org>, Ido Schimmel <idosch@...sch.org>
Cc: netdev@...r.kernel.org
Subject: Re: [PATCH net-next v2 2/2] net: When removing nexthops, don't call
synchronize_net if it is not necessary
On 8/17/25 02:12, Christoph Paasch via B4 Relay wrote:
> From: Christoph Paasch <cpaasch@...nai.com>
>
> When removing a nexthop, commit
> 90f33bffa382 ("nexthops: don't modify published nexthop groups") added a
> call to synchronize_rcu() (later changed to _net()) to make sure
> everyone sees the new nexthop-group before the rtnl-lock is released.
>
> When one wants to delete a large number of groups and nexthops, it is
> fastest to first flush the groups (ip nexthop flush groups) and then
> flush the nexthops themselves (ip -6 nexthop flush). As that way the
> groups don't need to be rebalanced.
>
> However, `ip -6 nexthop flush` will still take a long time if there is
> a very large number of nexthops because of the call to
> synchronize_net(). Now, if there are no more groups, there is no point
> in calling synchronize_net(). So, let's skip that entirely by checking
> if nh->grp_list is empty.
>
> This gives us a nice speedup:
>
> BEFORE:
> =======
>
> $ time sudo ip -6 nexthop flush
> Dump was interrupted and may be inconsistent.
> Flushed 2097152 nexthops
>
> real 1m45.345s
> user 0m0.001s
> sys 0m0.005s
>
> $ time sudo ip -6 nexthop flush
> Dump was interrupted and may be inconsistent.
> Flushed 4194304 nexthops
>
> real 3m10.430s
> user 0m0.002s
> sys 0m0.004s
>
> AFTER:
> ======
>
> $ time sudo ip -6 nexthop flush
> Dump was interrupted and may be inconsistent.
> Flushed 2097152 nexthops
>
> real 0m17.545s
> user 0m0.003s
> sys 0m0.003s
>
> $ time sudo ip -6 nexthop flush
> Dump was interrupted and may be inconsistent.
> Flushed 4194304 nexthops
>
> real 0m35.823s
> user 0m0.002s
> sys 0m0.004s
>
> Signed-off-by: Christoph Paasch <cpaasch@...nai.com>
> ---
> net/ipv4/nexthop.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
> index 509004bfd08ec43de44c7ce4a540c983d0e70201..0a20625f5ffb471052d92b48802076b8295dd703 100644
> --- a/net/ipv4/nexthop.c
> +++ b/net/ipv4/nexthop.c
> @@ -2087,6 +2087,12 @@ static void remove_nexthop_from_groups(struct net *net, struct nexthop *nh,
> {
> struct nh_grp_entry *nhge, *tmp;
>
> + /* If there is nothing to do, let's avoid the costly call to
> + * synchronize_net()
> + */
> + if (list_empty(&nh->grp_list))
> + return;
> +
> list_for_each_entry_safe(nhge, tmp, &nh->grp_list, nh_list)
> remove_nh_grp_entry(net, nhge, nlinfo);
>
>
Reviewed-by: Nikolay Aleksandrov <razor@...ckwall.org>
Powered by blists - more mailing lists