From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 332E734D917; Fri, 21 Nov 2025 13:42:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763732536; cv=none; b=Cch5lpbu4M//UXxGSSRdutcbrs3j1pBEn6jKTQPMvMl5cRKWXFNCBhPgXSANk6B6dZKXMMn6CtWSmwjJo6iJmaqmM4P3uxfQrmQYtFS8JrQPck+TdpHeMR1TpIvWrLXpTli3dcGOXTSbjQKwo01O+9YoL9KOltm21rxnX22vjFg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763732536; c=relaxed/simple; bh=aYTLhdWFCJeAVS7FynrZuxt6NZmL9eLDfaU5qR/ZX3Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XakvGSj+aSKf+z0fH4e/VEl1meM7h6PmBhbyQPM+e3TZXTh8Fl4X5LkzdGAharXo6/tz2hPKNrewihljkne/Culged0Qk62NExyHiY2aJ8Ykaj8hLrFjTwC31yS2ov81K6ihBhqx9WDTJWo00+prin9Xk2wW/ySViBJ7Yn0ey2Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=WpkoFGnk; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="WpkoFGnk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3B4DC4CEF1; Fri, 21 Nov 2025 13:42:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1763732536; bh=aYTLhdWFCJeAVS7FynrZuxt6NZmL9eLDfaU5qR/ZX3Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WpkoFGnkEVsWUHGXI6pn9RGnCRJDqsHARYn1udCl4WY6n6uBa7UI6/7nSegzTUz6P 4wEfBgKgQAWl+RB7isht7NIjo7sRrIRLph/MHqwFV+2+C/XCZPpbT7XW1O2fZ4gwts EPkj7Aq1w3+6Z7lRnlQsm9dAJHdyqqbS7RpBYM6I= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Christoph Paasch , Ido Schimmel , Nikolay Aleksandrov , Eric Dumazet , David Ahern , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.6 155/529] net: When removing nexthops, dont call synchronize_net if it is not necessary Date: Fri, 21 Nov 2025 14:07:34 +0100 Message-ID: <20251121130236.534763832@linuxfoundation.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251121130230.985163914@linuxfoundation.org> References: <20251121130230.985163914@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Christoph Paasch [ Upstream commit b0ac6d3b56a2384db151696cfda2836a8a961b6d ] 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 Reviewed-by: Ido Schimmel Reviewed-by: Nikolay Aleksandrov Reviewed-by: Eric Dumazet Reviewed-by: David Ahern Link: https://patch.msgid.link/20250816-nexthop_dump-v2-2-491da3462118@openai.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/ipv4/nexthop.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index fab550633ec9f..99385fe34a1e5 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -1835,6 +1835,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); -- 2.51.0