Skip to contentSkip to conversation

net: avoid slow rcu synchronizations in cleanup_net()

PATCH Applied Eric Dumazet 4 participants 10 messages Feb 9, 2024 – Feb 12, 2024

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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.

Fixes f185de28d9ae ("mld: add new workqueues for process mld events")
Cc Taehee Yoo <[email protected]>
Cc Cong Wang <[email protected]>
Cc David Ahern <[email protected]>
---
 net/ipv6/mcast.c | 1 -
 1 file changed, 1 deletion(-)
net/ipv6/mcast.c +0 -1
index bc6e0a0bad3c12d641a1dc60a8c790a6e72b1b5f..76ee1615ff2a07e1dd496aada377a7feb4703e8c 100644
@@ -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
#2 lore raw

PATCH 2/6 net: use synchronize_net() in dev_change_name()

In reply to Eric Dumazet

dev_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
index e52e2888cccd37e0df794155004e77261c812ef9..cb0eaefa0aff79ddf009f0867b440200fa985e54 100644
@@ -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
#3 lore raw

PATCH 3/6 bridge: vlan: use synchronize_net() when holding RTNL

In reply to Eric Dumazet

br_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
index 15f44d026e75a8818f958703c5ec054eaafc4d94..9c2fffb827ab195cf9a01281e4790361e0b14bfe 100644
@@ -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
maintainer Acked-by on v1 3/6
#4 lore raw

Re: [PATCH net-next 3/6] bridge: vlan: use synchronize_net() when holding RTNL

Quoted 22 lines · Eric Dumazet

br_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 +1 -1
index 15f44d026e75a8818f958703c5ec054eaafc4d94..9c2fffb827ab195cf9a01281e4790361e0b14bfe 100644
@@ -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,

#5 lore raw

PATCH 4/6 ipv4/fib: use synchronize_net() when holding RTNL

In reply to Eric Dumazet

tnode_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
index 3ff35f811765591638c5e03d9211138ca6df3603..0fc7ab5832d1ae00e33fdf6fad4ef379c7d0bd4d 100644
@@ -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
maintainer Reviewed-by on v1 4/6
#6 lore raw

Re: [PATCH net-next 4/6] ipv4/fib: use synchronize_net() when holding RTNL

Quoted 8 lines · Eric Dumazet

tnode_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(-)
#7 lore raw

PATCH 5/6 net: use synchronize_rcu_expedited in cleanup_net()

In reply to Eric Dumazet

cleanup_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
index 233ec0cdd0111d5ca21c6f8a66f4c1f3fbc4657b..f0540c5575157135b1dc5dece2220f81a408fb7e 100644
@@ -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
#8 lore raw

PATCH 6/6 netfilter: conntrack: expedite rcu in nf_conntrack_cleanup_net_list

In reply to Eric Dumazet

nf_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.

Cc Pablo Neira Ayuso <[email protected]>
Cc Jozsef Kadlecsik <[email protected]>
Cc Florian Westphal <[email protected]>
---
 net/netfilter/nf_conntrack_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_conntrack_core.c +1 -1
index 2e5f3864d353a39cfde138b725e790d7290b82c9..90e6bd2c30002cbf45f417f014e8493c8d24984b 100644
@@ -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
#9 lore raw
In reply to Eric Dumazet
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 use synchronize_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