diff options
author | Eric Dumazet <dada1@cosmosbay.com> | 2008-11-26 00:17:14 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-11-26 00:17:14 -0500 |
commit | dd24c00191d5e4a1ae896aafe33c6b8095ab4bd1 (patch) | |
tree | e955c09e0b288e50c706b6ee409229d5a930c80c /net/ipv4/tcp.c | |
parent | 1748376b6626acf59c24e9592ac67b3fe2a0e026 (diff) |
net: Use a percpu_counter for orphan_count
Instead of using one atomic_t per protocol, use a percpu_counter
for "orphan_count", to reduce cache line contention on
heavy duty network servers.
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/tcp.c')
-rw-r--r-- | net/ipv4/tcp.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index e6fade9ebf62..019243408623 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c | |||
@@ -277,8 +277,7 @@ | |||
277 | 277 | ||
278 | int sysctl_tcp_fin_timeout __read_mostly = TCP_FIN_TIMEOUT; | 278 | int sysctl_tcp_fin_timeout __read_mostly = TCP_FIN_TIMEOUT; |
279 | 279 | ||
280 | atomic_t tcp_orphan_count = ATOMIC_INIT(0); | 280 | struct percpu_counter tcp_orphan_count; |
281 | |||
282 | EXPORT_SYMBOL_GPL(tcp_orphan_count); | 281 | EXPORT_SYMBOL_GPL(tcp_orphan_count); |
283 | 282 | ||
284 | int sysctl_tcp_mem[3] __read_mostly; | 283 | int sysctl_tcp_mem[3] __read_mostly; |
@@ -1837,7 +1836,7 @@ adjudge_to_death: | |||
1837 | state = sk->sk_state; | 1836 | state = sk->sk_state; |
1838 | sock_hold(sk); | 1837 | sock_hold(sk); |
1839 | sock_orphan(sk); | 1838 | sock_orphan(sk); |
1840 | atomic_inc(sk->sk_prot->orphan_count); | 1839 | percpu_counter_inc(sk->sk_prot->orphan_count); |
1841 | 1840 | ||
1842 | /* It is the last release_sock in its life. It will remove backlog. */ | 1841 | /* It is the last release_sock in its life. It will remove backlog. */ |
1843 | release_sock(sk); | 1842 | release_sock(sk); |
@@ -1888,9 +1887,11 @@ adjudge_to_death: | |||
1888 | } | 1887 | } |
1889 | } | 1888 | } |
1890 | if (sk->sk_state != TCP_CLOSE) { | 1889 | if (sk->sk_state != TCP_CLOSE) { |
1890 | int orphan_count = percpu_counter_read_positive( | ||
1891 | sk->sk_prot->orphan_count); | ||
1892 | |||
1891 | sk_mem_reclaim(sk); | 1893 | sk_mem_reclaim(sk); |
1892 | if (tcp_too_many_orphans(sk, | 1894 | if (tcp_too_many_orphans(sk, orphan_count)) { |
1893 | atomic_read(sk->sk_prot->orphan_count))) { | ||
1894 | if (net_ratelimit()) | 1895 | if (net_ratelimit()) |
1895 | printk(KERN_INFO "TCP: too many of orphaned " | 1896 | printk(KERN_INFO "TCP: too many of orphaned " |
1896 | "sockets\n"); | 1897 | "sockets\n"); |
@@ -2689,6 +2690,7 @@ void __init tcp_init(void) | |||
2689 | BUILD_BUG_ON(sizeof(struct tcp_skb_cb) > sizeof(skb->cb)); | 2690 | BUILD_BUG_ON(sizeof(struct tcp_skb_cb) > sizeof(skb->cb)); |
2690 | 2691 | ||
2691 | percpu_counter_init(&tcp_sockets_allocated, 0); | 2692 | percpu_counter_init(&tcp_sockets_allocated, 0); |
2693 | percpu_counter_init(&tcp_orphan_count, 0); | ||
2692 | tcp_hashinfo.bind_bucket_cachep = | 2694 | tcp_hashinfo.bind_bucket_cachep = |
2693 | kmem_cache_create("tcp_bind_bucket", | 2695 | kmem_cache_create("tcp_bind_bucket", |
2694 | sizeof(struct inet_bind_bucket), 0, | 2696 | sizeof(struct inet_bind_bucket), 0, |