Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: avoid quadratic behavior in netdev_wait_allrefs_any()

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")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Link: https://lore.kernel.org/r/20220218065430.2613262-1-eric.dumazet@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Eric Dumazet and committed by
Jakub Kicinski
86213f80 086d4905

+1 -3
+1 -3
net/core/dev.c
··· 9828 9828 struct net_device *dev; 9829 9829 int wait = 0; 9830 9830 9831 - list_for_each_entry(dev, list, todo_list) 9832 - linkwatch_forget_dev(dev); 9833 - 9834 9831 rebroadcast_time = warning_time = jiffies; 9835 9832 9836 9833 list_for_each_entry(dev, list, todo_list) ··· 9948 9951 } 9949 9952 9950 9953 dev->reg_state = NETREG_UNREGISTERED; 9954 + linkwatch_forget_dev(dev); 9951 9955 } 9952 9956 9953 9957 while (!list_empty(&list)) {