netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] ipv6: avoid taking locks at socket dismantle
@ 2012-12-05 19:18 Eric Dumazet
  2012-12-05 21:07 ` David Stevens
  2012-12-05 21:26 ` David Miller
  0 siblings, 2 replies; 4+ messages in thread
From: Eric Dumazet @ 2012-12-05 19:18 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

From: Eric Dumazet <edumazet@google.com>

ipv6_sock_mc_close() is called for ipv6 sockets at close time, and most
of them don't use multicast.

Add a test to avoid contention on a shared spinlock.

Same heuristic applies for ipv6_sock_ac_close(), to avoid contention
on a shared rwlock.

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/ipv6/anycast.c |    3 +++
 net/ipv6/mcast.c   |    3 +++
 2 files changed, 6 insertions(+)

diff --git a/net/ipv6/anycast.c b/net/ipv6/anycast.c
index 2f4f584..757a810 100644
--- a/net/ipv6/anycast.c
+++ b/net/ipv6/anycast.c
@@ -189,6 +189,9 @@ void ipv6_sock_ac_close(struct sock *sk)
 	struct net *net = sock_net(sk);
 	int	prev_index;
 
+	if (!np->ipv6_ac_list)
+		return;
+
 	write_lock_bh(&ipv6_sk_ac_lock);
 	pac = np->ipv6_ac_list;
 	np->ipv6_ac_list = NULL;
diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c
index b19ed51..28dfa5f 100644
--- a/net/ipv6/mcast.c
+++ b/net/ipv6/mcast.c
@@ -284,6 +284,9 @@ void ipv6_sock_mc_close(struct sock *sk)
 	struct ipv6_mc_socklist *mc_lst;
 	struct net *net = sock_net(sk);
 
+	if (!rcu_access_pointer(np->ipv6_mc_list))
+		return;
+
 	spin_lock(&ipv6_sk_mc_lock);
 	while ((mc_lst = rcu_dereference_protected(np->ipv6_mc_list,
 				lockdep_is_held(&ipv6_sk_mc_lock))) != NULL) {

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next] ipv6: avoid taking locks at socket dismantle
  2012-12-05 19:18 [PATCH net-next] ipv6: avoid taking locks at socket dismantle Eric Dumazet
@ 2012-12-05 21:07 ` David Stevens
  2012-12-05 21:21   ` David Miller
  2012-12-05 21:26 ` David Miller
  1 sibling, 1 reply; 4+ messages in thread
From: David Stevens @ 2012-12-05 21:07 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: David Miller, netdev, netdev-owner

> From: Eric Dumazet <edumazet@google.com>
> 
> ipv6_sock_mc_close() is called for ipv6 sockets at close time, and most
> of them don't use multicast.
> 
> Add a test to avoid contention on a shared spinlock.
> 
> Same heuristic applies for ipv6_sock_ac_close(), to avoid contention
> on a shared rwlock.

        What prevents a different thread from racing with the
tests for NULL on these?

                                                +-DLS

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next] ipv6: avoid taking locks at socket dismantle
  2012-12-05 21:07 ` David Stevens
@ 2012-12-05 21:21   ` David Miller
  0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2012-12-05 21:21 UTC (permalink / raw)
  To: dlstevens; +Cc: eric.dumazet, netdev, netdev-owner

From: David Stevens <dlstevens@us.ibm.com>
Date: Wed, 5 Dec 2012 16:07:16 -0500

>> From: Eric Dumazet <edumazet@google.com>
>> 
>> ipv6_sock_mc_close() is called for ipv6 sockets at close time, and most
>> of them don't use multicast.
>> 
>> Add a test to avoid contention on a shared spinlock.
>> 
>> Same heuristic applies for ipv6_sock_ac_close(), to avoid contention
>> on a shared rwlock.
> 
>         What prevents a different thread from racing with the
> tests for NULL on these?

The socket is being torn apart, which means that operations on it's
FD are no longer possible, which means that no other thread can add
entries to these lists.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next] ipv6: avoid taking locks at socket dismantle
  2012-12-05 19:18 [PATCH net-next] ipv6: avoid taking locks at socket dismantle Eric Dumazet
  2012-12-05 21:07 ` David Stevens
@ 2012-12-05 21:26 ` David Miller
  1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2012-12-05 21:26 UTC (permalink / raw)
  To: eric.dumazet; +Cc: netdev

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Wed, 05 Dec 2012 11:18:10 -0800

> From: Eric Dumazet <edumazet@google.com>
> 
> ipv6_sock_mc_close() is called for ipv6 sockets at close time, and most
> of them don't use multicast.
> 
> Add a test to avoid contention on a shared spinlock.
> 
> Same heuristic applies for ipv6_sock_ac_close(), to avoid contention
> on a shared rwlock.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>

Applied.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-12-05 21:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-05 19:18 [PATCH net-next] ipv6: avoid taking locks at socket dismantle Eric Dumazet
2012-12-05 21:07 ` David Stevens
2012-12-05 21:21   ` David Miller
2012-12-05 21:26 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).