Skip to contentSkip to conversation

net: avoid quadratic behavior in netdev_wait_allrefs_any()

PATCH Applied Eric Dumazet 3 participants 3 messages Feb 18, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: avoid quadratic behavior in netdev_wait_allrefs_any()

From: Eric Dumazet <[email protected]>

If the list of devices has N elements, netdev_wait_allrefs_any() is called N times, and linkwatch_forget_dev() is called N*(N-1)/2 times.

Fix this by calling linkwatch_forget_dev() only once per device.

Fixes faab39f63c1f ("net: allow out-of-order netdev unregistration")
---
 net/core/dev.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
net/core/dev.c +1 -3
index 05fa867f18787e709dcaccfea1df350c424eff80..acd884910e12a040841e1e0525e0d4bc5e3ee799 100644
@@ -9828,9 +9828,6 @@ static struct net_device *netdev_wait_allrefs_any(struct list_head *list)
 	struct net_device *dev;
 	int wait = 0;
 
-	list_for_each_entry(dev, list, todo_list)
-		linkwatch_forget_dev(dev);
-
 	rebroadcast_time = warning_time = jiffies;
 
 	list_for_each_entry(dev, list, todo_list)
@@ -9951,6 +9948,7 @@ void netdev_run_todo(void)
 		}
 
 		dev->reg_state = NETREG_UNREGISTERED;
+		linkwatch_forget_dev(dev);
 	}
 
 	while (!list_empty(&list)) {
Signature · 1 line
2.35.1.265.g69c8d7142f-goog
maintainer
#1 lore raw
Quoted 9 lines · On Thu, 17 Feb 2022 22:54:30 -0800 Eric Dumazet wrote:

From: Eric Dumazet <[email protected]>

If the list of devices has N elements, netdev_wait_allrefs_any() is called N times, and linkwatch_forget_dev() is called N*(N-1)/2 times.

Fix this by calling linkwatch_forget_dev() only once per device.

Fixes faab39f63c1f ("net: allow out-of-order netdev unregistration")

Yup, I was on the fence on this one, I went for keeping all linkwatch stuff in one function and minimal changes. Clearly underestimated the number of netdevs your cases are destroying at once :)

#2 lore raw
In reply to Eric Dumazet
This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Thu, 17 Feb 2022 22:54:30 -0800 you wrote:

From: Eric Dumazet <[email protected]>

If the list of devices has N elements, netdev_wait_allrefs_any() is called N times, and linkwatch_forget_dev() is called N*(N-1)/2 times.

Fix this by calling linkwatch_forget_dev() only once per device.

[...]

Here is the summary with links:
- [net-next] net: avoid quadratic behavior in netdev_wait_allrefs_any()

    https://git.kernel.org/netdev/net-next/c/86213f80da1b

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html