diff options
author | Eric Dumazet <eric.dumazet@gmail.com> | 2010-04-08 19:03:29 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-04-13 04:41:33 -0400 |
commit | b6c6712a42ca3f9fa7f4a3d7c40e3a9dd1fd9e03 (patch) | |
tree | 42032b4978874e8ffcf6c851d13324b8c8c7c113 /net/core/sock.c | |
parent | 7a161ea92471087a1579239d7a58dd06eaa5601c (diff) |
net: sk_dst_cache RCUification
With latest CONFIG_PROVE_RCU stuff, I felt more comfortable to make this
work.
sk->sk_dst_cache is currently protected by a rwlock (sk_dst_lock)
This rwlock is readlocked for a very small amount of time, and dst
entries are already freed after RCU grace period. This calls for RCU
again :)
This patch converts sk_dst_lock to a spinlock, and use RCU for readers.
__sk_dst_get() is supposed to be called with rcu_read_lock() or if
socket locked by user, so use appropriate rcu_dereference_check()
condition (rcu_read_lock_held() || sock_owned_by_user(sk))
This patch avoids two atomic ops per tx packet on UDP connected sockets,
for example, and permits sk_dst_lock to be much less dirtied.
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core/sock.c')
-rw-r--r-- | net/core/sock.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/net/core/sock.c b/net/core/sock.c index c5812bbc2cc9..7effa1e689df 100644 --- a/net/core/sock.c +++ b/net/core/sock.c | |||
@@ -364,11 +364,11 @@ EXPORT_SYMBOL(sk_reset_txq); | |||
364 | 364 | ||
365 | struct dst_entry *__sk_dst_check(struct sock *sk, u32 cookie) | 365 | struct dst_entry *__sk_dst_check(struct sock *sk, u32 cookie) |
366 | { | 366 | { |
367 | struct dst_entry *dst = sk->sk_dst_cache; | 367 | struct dst_entry *dst = __sk_dst_get(sk); |
368 | 368 | ||
369 | if (dst && dst->obsolete && dst->ops->check(dst, cookie) == NULL) { | 369 | if (dst && dst->obsolete && dst->ops->check(dst, cookie) == NULL) { |
370 | sk_tx_queue_clear(sk); | 370 | sk_tx_queue_clear(sk); |
371 | sk->sk_dst_cache = NULL; | 371 | rcu_assign_pointer(sk->sk_dst_cache, NULL); |
372 | dst_release(dst); | 372 | dst_release(dst); |
373 | return NULL; | 373 | return NULL; |
374 | } | 374 | } |
@@ -1157,7 +1157,7 @@ struct sock *sk_clone(const struct sock *sk, const gfp_t priority) | |||
1157 | skb_queue_head_init(&newsk->sk_async_wait_queue); | 1157 | skb_queue_head_init(&newsk->sk_async_wait_queue); |
1158 | #endif | 1158 | #endif |
1159 | 1159 | ||
1160 | rwlock_init(&newsk->sk_dst_lock); | 1160 | spin_lock_init(&newsk->sk_dst_lock); |
1161 | rwlock_init(&newsk->sk_callback_lock); | 1161 | rwlock_init(&newsk->sk_callback_lock); |
1162 | lockdep_set_class_and_name(&newsk->sk_callback_lock, | 1162 | lockdep_set_class_and_name(&newsk->sk_callback_lock, |
1163 | af_callback_keys + newsk->sk_family, | 1163 | af_callback_keys + newsk->sk_family, |
@@ -1898,7 +1898,7 @@ void sock_init_data(struct socket *sock, struct sock *sk) | |||
1898 | } else | 1898 | } else |
1899 | sk->sk_sleep = NULL; | 1899 | sk->sk_sleep = NULL; |
1900 | 1900 | ||
1901 | rwlock_init(&sk->sk_dst_lock); | 1901 | spin_lock_init(&sk->sk_dst_lock); |
1902 | rwlock_init(&sk->sk_callback_lock); | 1902 | rwlock_init(&sk->sk_callback_lock); |
1903 | lockdep_set_class_and_name(&sk->sk_callback_lock, | 1903 | lockdep_set_class_and_name(&sk->sk_callback_lock, |
1904 | af_callback_keys + sk->sk_family, | 1904 | af_callback_keys + sk->sk_family, |