net: avoid slow rcu synchronizations in cleanup_net()
Subsystems (5)
cover net: avoid slow rcu synchronizations in cleanup_net()
RTNL is a contended mutex, we prefer to expedite rcu synchronizations in contexts we hold RTNL.
Similarly, cleanup_net() is a single threaded critical component and should also use synchronize_rcu_expedited() even when not holding RTNL.
First patch removes a barrier with no clear purpose in ipv6_mc_down()
Eric Dumazet (6):
ipv6: mcast: remove one synchronize_net() barrier in ipv6_mc_down()
net: use synchronize_net() in dev_change_name()
bridge: vlan: use synchronize_net() when holding RTNL ipv4/fib: use synchronize_net() when holding RTNL
net: use synchronize_rcu_expedited in cleanup_net()
netfilter: conntrack: expedite rcu in nf_conntrack_cleanup_net_list
net/bridge/br_vlan.c | 4 ++-- net/core/dev.c | 2 +- net/core/net_namespace.c | 2 +- net/ipv4/fib_trie.c | 2 +- net/ipv6/mcast.c | 1 - net/netfilter/nf_conntrack_core.c | 2 +- 6 files changed, 6 insertions(+), 7 deletions(-)
Signature · 1 line
2.43.0.687.g38aa6559b0-goog
PATCH 1/6 ipv6: mcast: remove one synchronize_net() barrier in ipv6_mc_down()
As discussed in the past (commit 2d3916f31891 ("ipv6: fix skb drops in igmp6_event_query() and igmp6_event_report()")) I think the synchronize_net() call in ipv6_mc_down() is not needed.
Under load, synchronize_net() can last between 200 usec and 5 ms.
KASAN seems to agree as well.
--- net/ipv6/mcast.c | 1 - 1 file changed, 1 deletion(-)
net/ipv6/mcast.c +0 -1
@@ -2719,7 +2719,6 @@ void ipv6_mc_down(struct inet6_dev *idev)/* Should stop work after group drop. or we will * start work again in mld_ifc_event() */ -synchronize_net ();mld_query_stop_work (idev);mld_report_stop_work (idev);
Signature · 1 line
2.43.0.687.g38aa6559b0-goog
PATCH 2/6 net: use synchronize_net() in dev_change_name()
In reply to Eric Dumazetdev_change_name() holds RTNL, we better use synchronize_net() instead of plain synchronize_rcu().
--- net/core/dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/dev.c +1 -1
@@ -1239,7 +1239,7 @@ int dev_change_name(struct net_device *dev, const char *newname)netdev_name_node_del (dev->name_node);write_unlock (&dev_base_lock); -synchronize_rcu (); +synchronize_net ();write_lock (&dev_base_lock);netdev_name_node_add (net, dev->name_node);
Signature · 1 line
2.43.0.687.g38aa6559b0-goog
PATCH 3/6 bridge: vlan: use synchronize_net() when holding RTNL
In reply to Eric Dumazetbr_vlan_flush() and nbp_vlan_flush() should use synchronize_net() instead of syncronize_rcu() to release RTNL sooner.
--- net/bridge/br_vlan.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/bridge/br_vlan.c +2 -2
@@ -841,7 +841,7 @@ void br_vlan_flush(struct net_bridge *br) vg =br_vlan_group (br);__vlan_flush (br,NULL , vg);RCU_INIT_POINTER (br->vlgrp,NULL ); -synchronize_rcu (); +synchronize_net ();__vlan_group_free (vg); }
@@ -1372,7 +1372,7 @@ void nbp_vlan_flush(struct net_bridge_port *port) vg =nbp_vlan_group (port);__vlan_flush (port->br, port, vg);RCU_INIT_POINTER (port->vlgrp,NULL ); -synchronize_rcu (); +synchronize_net ();__vlan_group_free (vg); }
Signature · 1 line
2.43.0.687.g38aa6559b0-goog
Re: [PATCH net-next 3/6] bridge: vlan: use synchronize_net() when holding RTNL
Quoted 22 lines · Eric Dumazet
br_vlan_flush()andnbp_vlan_flush()should usesynchronize_net()instead ofsyncronize_rcu()to release RTNL sooner.Signed-off-by Eric Dumazet <[email protected]>--- net/bridge/br_vlan.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)net/bridge/br_vlan.c +1
-1@@ -841,7 +841,7 @@ void br_vlan_flush(struct net_bridge *br) vg =br_vlan_group (br);__vlan_flush (br,NULL , vg);RCU_INIT_POINTER (br->vlgrp,NULL ); -synchronize_rcu (); +synchronize_net ();__vlan_group_free (vg); }
net/bridge/br_vlan.c void nbp_vlan_flush(struct net_bridge_port *port) · line 1378
Quoted 8 lines
net/bridge/br_vlan.c +1
-1@@ -1372,7 +1372,7 @@ void nbp_vlan_flush(struct net_bridge_port *port) vg =nbp_vlan_group (port);__vlan_flush (port->br, port, vg);RCU_INIT_POINTER (port->vlgrp,NULL ); -synchronize_rcu (); +synchronize_net ();__vlan_group_free (vg); }
Also CCed Roopa. Thanks,
PATCH 4/6 ipv4/fib: use synchronize_net() when holding RTNL
In reply to Eric Dumazettnode_free() should use synchronize_net() instead of syncronize_rcu() to release RTNL sooner.
--- net/ipv4/fib_trie.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/fib_trie.c +1 -1
@@ -501,7 +501,7 @@ static void tnode_free(struct key_vector *tn)if (tnode_free_size >=READ_ONCE (sysctl_fib_sync_mem)) { tnode_free_size =0 ; -synchronize_rcu (); +synchronize_net (); } }
Signature · 1 line
2.43.0.687.g38aa6559b0-goog
Re: [PATCH net-next 4/6] ipv4/fib: use synchronize_net() when holding RTNL
Quoted 8 lines · Eric Dumazet
tnode_free()should usesynchronize_net()instead ofsyncronize_rcu()to release RTNL sooner.Signed-off-by Eric Dumazet <[email protected]>--- net/ipv4/fib_trie.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
PATCH 5/6 net: use synchronize_rcu_expedited in cleanup_net()
In reply to Eric Dumazetcleanup_net() is calling synchronize_rcu() right before acquiring RTNL.
synchronize_rcu() is much slower than synchronize_rcu_expedited(), and cleanup_net() is currently single threaded. In many workloads we want cleanup_net() to be fast, in order to free memory and various sysfs and procfs entries as fast as possible.
--- net/core/net_namespace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/net_namespace.c +1 -1
@@ -622,7 +622,7 @@ static void cleanup_net(struct work_struct *work)* the rcu_barrier() below isn't sufficient alone. * Also the pre_exit() and exit() methods need this barrier. */ -synchronize_rcu (); +synchronize_rcu_expedited ();rtnl_lock ();list_for_each_entry_reverse (ops, &pernet_list, list) {
Signature · 1 line
2.43.0.687.g38aa6559b0-goog
PATCH 6/6 netfilter: conntrack: expedite rcu in nf_conntrack_cleanup_net_list
In reply to Eric Dumazetnf_conntrack_cleanup_net_list() is calling synchronize_net() while RTNL is not held. This effectively calls synchronize_rcu().
synchronize_rcu() is much slower than synchronize_rcu_expedited(), and cleanup_net() is currently single threaded. In many workloads we want cleanup_net() to be faster, in order to free memory and various sysfs and procfs entries as fast as possible.
--- net/netfilter/nf_conntrack_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_conntrack_core.c +1 -1
@@ -2530,7 +2530,7 @@ void nf_conntrack_cleanup_net_list(struct list_head *net_exit_list)* netfilter framework. Roll on, two-stage module * delete... */ -synchronize_net (); +synchronize_rcu_expedited (); i_see_dead_people: busy =0 ;list_for_each_entry (net, net_exit_list, exit_list) {
Signature · 1 line
2.43.0.687.g38aa6559b0-goog
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Quoted 9 lines · On Fri, 9 Feb 2024 15:30:55 +0000 you wrote:
RTNL is a contended mutex, we prefer to expedite rcu synchronizations in contexts we hold RTNL.
Similarly,
cleanup_net()is a single threaded critical component and should also usesynchronize_rcu_expedited()even when not holding RTNL.First patch removes a barrier with no clear purpose in
ipv6_mc_down()[...]
Here is the summary with links:
- [net-next,1/6] ipv6: mcast: remove one synchronize_net() barrier in ipv6_mc_down()
https://git.kernel.org/netdev/net-next/c/17ef8efc00b3 - [net-next,2/6] net: use synchronize_net() in dev_change_name() https://git.kernel.org/netdev/net-next/c/4cd582ffa5a9 - [net-next,3/6] bridge: vlan: use synchronize_net() when holding RTNL https://git.kernel.org/netdev/net-next/c/48ebf6ebbc91 - [net-next,4/6] ipv4/fib: use synchronize_net() when holding RTNL https://git.kernel.org/netdev/net-next/c/2cd0c51e3baf - [net-next,5/6] net: use synchronize_rcu_expedited in cleanup_net() https://git.kernel.org/netdev/net-next/c/78c3253f27e5 - [net-next,6/6] netfilter: conntrack: expedite rcu in nf_conntrack_cleanup_net_list https://git.kernel.org/netdev/net-next/c/1ebb85f9c03d
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html