OSDN Git Service

ipmr: introduce ipmr_net_exit_batch()
authorEric Dumazet <edumazet@google.com>
Tue, 8 Feb 2022 04:50:35 +0000 (20:50 -0800)
committerJakub Kicinski <kuba@kernel.org>
Wed, 9 Feb 2022 04:41:34 +0000 (20:41 -0800)
cleanup_net() is competing with other rtnl users.

Avoiding to acquire rtnl for each netns before calling
ipmr_rules_exit() gives chance for cleanup_net()
to progress much faster, holding rtnl a bit longer.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ipv4/ipmr.c

index 0727461..4a55a62 100644 (file)
@@ -266,13 +266,12 @@ static void __net_exit ipmr_rules_exit(struct net *net)
 {
        struct mr_table *mrt, *next;
 
-       rtnl_lock();
+       ASSERT_RTNL();
        list_for_each_entry_safe(mrt, next, &net->ipv4.mr_tables, list) {
                list_del(&mrt->list);
                ipmr_free_table(mrt);
        }
        fib_rules_unregister(net->ipv4.mr_rules_ops);
-       rtnl_unlock();
 }
 
 static int ipmr_rules_dump(struct net *net, struct notifier_block *nb,
@@ -328,10 +327,9 @@ static int __net_init ipmr_rules_init(struct net *net)
 
 static void __net_exit ipmr_rules_exit(struct net *net)
 {
-       rtnl_lock();
+       ASSERT_RTNL();
        ipmr_free_table(net->ipv4.mrt);
        net->ipv4.mrt = NULL;
-       rtnl_unlock();
 }
 
 static int ipmr_rules_dump(struct net *net, struct notifier_block *nb,
@@ -3075,7 +3073,9 @@ static int __net_init ipmr_net_init(struct net *net)
 proc_cache_fail:
        remove_proc_entry("ip_mr_vif", net->proc_net);
 proc_vif_fail:
+       rtnl_lock();
        ipmr_rules_exit(net);
+       rtnl_unlock();
 #endif
 ipmr_rules_fail:
        ipmr_notifier_exit(net);
@@ -3090,12 +3090,22 @@ static void __net_exit ipmr_net_exit(struct net *net)
        remove_proc_entry("ip_mr_vif", net->proc_net);
 #endif
        ipmr_notifier_exit(net);
-       ipmr_rules_exit(net);
+}
+
+static void __net_exit ipmr_net_exit_batch(struct list_head *net_list)
+{
+       struct net *net;
+
+       rtnl_lock();
+       list_for_each_entry(net, net_list, exit_list)
+               ipmr_rules_exit(net);
+       rtnl_unlock();
 }
 
 static struct pernet_operations ipmr_net_ops = {
        .init = ipmr_net_init,
        .exit = ipmr_net_exit,
+       .exit_batch = ipmr_net_exit_batch,
 };
 
 int __init ip_mr_init(void)