netfilter: nf_conntrack: Batch cleanup
Subsystems (3)
PATCH 1/1 netfilter: nf_conntrack: Batch cleanup
The patch introduces nf_conntrack_cleanup_net_list(), which cleanups nf_conntrack for a list of netns and calls synchronize_net() only once for them all. This should reduce netns destruction time.
--
I've measured cleanup time for 1k dummy net ns. Here are the results:
<without the patch>
# modprobe nf_conntrack # time modprobe -r nf_conntrack
real 0m10.337s
user 0m0.000s
sys 0m0.376s
<with the patch>
# modprobe nf_conntrack # time modprobe -r nf_conntrack
real 0m5.661s user 0m0.000s sys 0m0.216s
--- include/net/netfilter/nf_conntrack_core.h | 1 + net/netfilter/nf_conntrack_core.c | 46 ++++++++++++++++++++--------- net/netfilter/nf_conntrack_standalone.c | 16 ++++++---- 3 files changed, 43 insertions(+), 20 deletions(-)
include/net/netfilter/nf_conntrack_core.h +1 -0
@@ -27,6 +27,7 @@ extern unsigned int nf_conntrack_in(struct net *net,extern int nf_conntrack_init_net (struct net *net);extern void nf_conntrack_cleanup_net (struct net *net); +extern void nf_conntrack_cleanup_net_list (struct list_head *net_exit_list);extern int nf_conntrack_proto_pernet_init (struct net *net);extern void nf_conntrack_proto_pernet_fini (struct net *net);
net/netfilter/nf_conntrack_core.c +32 -14
62 lines not on this page · raw message
net/netfilter/nf_conntrack_standalone.c +10 -6
@@ -545,16 +545,20 @@ out_init:return ret; } -static void nf_conntrack_pernet_exit (struct net *net) +static void nf_conntrack_pernet_exit (struct list_head *net_exit_list) { -nf_conntrack_standalone_fini_sysctl (net); -nf_conntrack_standalone_fini_proc (net); -nf_conntrack_cleanup_net (net); +struct net *net; + +list_for_each_entry (net, net_exit_list, exit_list) { +nf_conntrack_standalone_fini_sysctl (net); +nf_conntrack_standalone_fini_proc (net); + } +nf_conntrack_cleanup_net_list (net_exit_list); }static struct pernet_operations nf_conntrack_net_ops = { - .init = nf_conntrack_pernet_init, - .exit = nf_conntrack_pernet_exit, + .init = nf_conntrack_pernet_init, + .exit_batch = nf_conntrack_pernet_exit, };static int __init nf_conntrack_standalone_init (void )
Signature · 1 line
1.7.1
Quoted 49 lines · Vladimir Davydov
The patch introduces
nf_conntrack_cleanup_net_list(), which cleanupsnf_conntrackfor a list of netns and callssynchronize_net()only once for them all. This should reduce netns destruction time.
--
I've measured cleanup time for 1k dummy net ns. Here are the results:<without the patch>
# modprobe nf_conntrack # time modprobe -r nf_conntrackreal 0m10.337s
user 0m0.000s
sys 0m0.376s<with the patch>
# modprobe nf_conntrack # time modprobe -r nf_conntrackreal 0m5.661s user 0m0.000s sys 0m0.216sSigned-off-by Vladimir Davydov <[email protected]>Cc Patrick McHardy <[email protected]>Cc "David S. Miller" <[email protected]>Cc "Eric W. Biederman" <[email protected]>--- include/net/netfilter/nf_conntrack_core.h | 1 + net/netfilter/nf_conntrack_core.c | 46 ++++++++++++++++++++--------- net/netfilter/nf_conntrack_standalone.c | 16 ++++++---- 3 files changed, 43 insertions(+), 20 deletions(-)include/net/netfilter/nf_conntrack_core.h +1
-0@@ -27,6 +27,7 @@ extern unsigned int nf_conntrack_in(struct net *net,extern int nf_conntrack_init_net (struct net *net);extern void nf_conntrack_cleanup_net (struct net *net); +extern void nf_conntrack_cleanup_net_list (struct list_head *net_exit_list);extern int nf_conntrack_proto_pernet_init (struct net *net);extern void nf_conntrack_proto_pernet_fini (struct net *net);net/netfilter/nf_conntrack_core.c +0
-0
net/netfilter/nf_conntrack_core.c void nf_conntrack_cleanup_end(void) · line 1372
Quoted 9 lines
net/netfilter/nf_conntrack_core.c +6
-0@@ -1364,30 +1364,48 @@ void nf_conntrack_cleanup_end(void)*/ void nf_conntrack_cleanup_net (struct net *net) { +LIST_HEAD (single); + +list_add (&net->exit_list, &single); +nf_conntrack_cleanup_net_list (&single); +} +
After adding net->exit_list to this single list,in setup_net we will re-add this net->exit_list to net_exit_list. So there has no invalid pointer problem.
This patch looks good to me.
Thanks!
Quoted 3 lines · Vladimir Davydov
The patch introduces
nf_conntrack_cleanup_net_list(), which cleanupsnf_conntrackfor a list of netns and callssynchronize_net()only once for them all. This should reduce netns destruction time.
Applied, thanks.