ipvs: batch __ip_vs_cleanup
authorHaishuang Yan <yanhaishuang@cmss.chinamobile.com>
Fri, 27 Sep 2019 04:54:50 +0000 (12:54 +0800)
committerSimon Horman <horms@verge.net.au>
Tue, 8 Oct 2019 09:28:33 +0000 (11:28 +0200)
It's better to batch __ip_vs_cleanup to speedup ipvs
connections dismantle.

Signed-off-by: Haishuang Yan <yanhaishuang@cmss.chinamobile.com>
Acked-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Simon Horman <horms@verge.net.au>
include/net/ip_vs.h
net/netfilter/ipvs/ip_vs_core.c
net/netfilter/ipvs/ip_vs_ctl.c

index 3759167f91f5643ea5a192eb7e82ce3a34e9e91b..93e7a252993d87df8d094ddd1add431cc485bc7a 100644 (file)
@@ -1324,7 +1324,7 @@ void ip_vs_protocol_net_cleanup(struct netns_ipvs *ipvs);
 void ip_vs_control_net_cleanup(struct netns_ipvs *ipvs);
 void ip_vs_estimator_net_cleanup(struct netns_ipvs *ipvs);
 void ip_vs_sync_net_cleanup(struct netns_ipvs *ipvs);
-void ip_vs_service_net_cleanup(struct netns_ipvs *ipvs);
+void ip_vs_service_nets_cleanup(struct list_head *net_list);
 
 /* IPVS application functions
  * (from ip_vs_app.c)
index 8b80ab794a92ba3f0827151861ec630ea0af512a..93cfb47823d1a8e4be7d1f7bf7f6e403c3feb8ff 100644 (file)
@@ -2402,18 +2402,22 @@ estimator_fail:
        return -ENOMEM;
 }
 
-static void __net_exit __ip_vs_cleanup(struct net *net)
+static void __net_exit __ip_vs_cleanup_batch(struct list_head *net_list)
 {
-       struct netns_ipvs *ipvs = net_ipvs(net);
-
-       ip_vs_service_net_cleanup(ipvs);        /* ip_vs_flush() with locks */
-       ip_vs_conn_net_cleanup(ipvs);
-       ip_vs_app_net_cleanup(ipvs);
-       ip_vs_protocol_net_cleanup(ipvs);
-       ip_vs_control_net_cleanup(ipvs);
-       ip_vs_estimator_net_cleanup(ipvs);
-       IP_VS_DBG(2, "ipvs netns %d released\n", ipvs->gen);
-       net->ipvs = NULL;
+       struct netns_ipvs *ipvs;
+       struct net *net;
+
+       ip_vs_service_nets_cleanup(net_list);   /* ip_vs_flush() with locks */
+       list_for_each_entry(net, net_list, exit_list) {
+               ipvs = net_ipvs(net);
+               ip_vs_conn_net_cleanup(ipvs);
+               ip_vs_app_net_cleanup(ipvs);
+               ip_vs_protocol_net_cleanup(ipvs);
+               ip_vs_control_net_cleanup(ipvs);
+               ip_vs_estimator_net_cleanup(ipvs);
+               IP_VS_DBG(2, "ipvs netns %d released\n", ipvs->gen);
+               net->ipvs = NULL;
+       }
 }
 
 static int __net_init __ip_vs_dev_init(struct net *net)
@@ -2442,7 +2446,7 @@ static void __net_exit __ip_vs_dev_cleanup(struct net *net)
 
 static struct pernet_operations ipvs_core_ops = {
        .init = __ip_vs_init,
-       .exit = __ip_vs_cleanup,
+       .exit_batch = __ip_vs_cleanup_batch,
        .id   = &ip_vs_net_id,
        .size = sizeof(struct netns_ipvs),
 };
index 8b48e7ce1c2c2243bbdc8c4e43e4e484f3e52df6..153c77b5c4f54b78bd8bdc6f989b3c18b38c8a3e 100644 (file)
@@ -1607,14 +1607,20 @@ static int ip_vs_flush(struct netns_ipvs *ipvs, bool cleanup)
 
 /*
  *     Delete service by {netns} in the service table.
- *     Called by __ip_vs_cleanup()
+ *     Called by __ip_vs_batch_cleanup()
  */
-void ip_vs_service_net_cleanup(struct netns_ipvs *ipvs)
+void ip_vs_service_nets_cleanup(struct list_head *net_list)
 {
+       struct netns_ipvs *ipvs;
+       struct net *net;
+
        EnterFunction(2);
        /* Check for "full" addressed entries */
        mutex_lock(&__ip_vs_mutex);
-       ip_vs_flush(ipvs, true);
+       list_for_each_entry(net, net_list, exit_list) {
+               ipvs = net_ipvs(net);
+               ip_vs_flush(ipvs, true);
+       }
        mutex_unlock(&__ip_vs_mutex);
        LeaveFunction(2);
 }