aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4
diff options
context:
space:
mode:
authorEric Dumazet <dada1@cosmosbay.com>2008-11-26 00:17:14 -0500
committerDavid S. Miller <davem@davemloft.net>2008-11-26 00:17:14 -0500
commitdd24c00191d5e4a1ae896aafe33c6b8095ab4bd1 (patch)
treee955c09e0b288e50c706b6ee409229d5a930c80c /net/ipv4
parent1748376b6626acf59c24e9592ac67b3fe2a0e026 (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')
-rw-r--r--net/ipv4/inet_connection_sock.c4
-rw-r--r--net/ipv4/proc.c2
-rw-r--r--net/ipv4/tcp.c12
-rw-r--r--net/ipv4/tcp_timer.c2
4 files changed, 11 insertions, 9 deletions
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index 05af807ca9b9..1ccdbba528be 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -561,7 +561,7 @@ void inet_csk_destroy_sock(struct sock *sk)
561 561
562 sk_refcnt_debug_release(sk); 562 sk_refcnt_debug_release(sk);
563 563
564 atomic_dec(sk->sk_prot->orphan_count); 564 percpu_counter_dec(sk->sk_prot->orphan_count);
565 sock_put(sk); 565 sock_put(sk);
566} 566}
567 567
@@ -641,7 +641,7 @@ void inet_csk_listen_stop(struct sock *sk)
641 641
642 sock_orphan(child); 642 sock_orphan(child);
643 643
644 atomic_inc(sk->sk_prot->orphan_count); 644 percpu_counter_inc(sk->sk_prot->orphan_count);
645 645
646 inet_csk_destroy_sock(child); 646 inet_csk_destroy_sock(child);
647 647
diff --git a/net/ipv4/proc.c b/net/ipv4/proc.c
index 4944b47ad628..614958b7c276 100644
--- a/net/ipv4/proc.c
+++ b/net/ipv4/proc.c
@@ -54,7 +54,7 @@ static int sockstat_seq_show(struct seq_file *seq, void *v)
54 socket_seq_show(seq); 54 socket_seq_show(seq);
55 seq_printf(seq, "TCP: inuse %d orphan %d tw %d alloc %d mem %d\n", 55 seq_printf(seq, "TCP: inuse %d orphan %d tw %d alloc %d mem %d\n",
56 sock_prot_inuse_get(net, &tcp_prot), 56 sock_prot_inuse_get(net, &tcp_prot),
57 atomic_read(&tcp_orphan_count), 57 (int)percpu_counter_sum_positive(&tcp_orphan_count),
58 tcp_death_row.tw_count, 58 tcp_death_row.tw_count,
59 (int)percpu_counter_sum_positive(&tcp_sockets_allocated), 59 (int)percpu_counter_sum_positive(&tcp_sockets_allocated),
60 atomic_read(&tcp_memory_allocated)); 60 atomic_read(&tcp_memory_allocated));
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
278int sysctl_tcp_fin_timeout __read_mostly = TCP_FIN_TIMEOUT; 278int sysctl_tcp_fin_timeout __read_mostly = TCP_FIN_TIMEOUT;
279 279
280atomic_t tcp_orphan_count = ATOMIC_INIT(0); 280struct percpu_counter tcp_orphan_count;
281
282EXPORT_SYMBOL_GPL(tcp_orphan_count); 281EXPORT_SYMBOL_GPL(tcp_orphan_count);
283 282
284int sysctl_tcp_mem[3] __read_mostly; 283int 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,
diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
index 3df339e3e363..cc4e6d27dedc 100644
--- a/net/ipv4/tcp_timer.c
+++ b/net/ipv4/tcp_timer.c
@@ -65,7 +65,7 @@ static void tcp_write_err(struct sock *sk)
65static int tcp_out_of_resources(struct sock *sk, int do_reset) 65static int tcp_out_of_resources(struct sock *sk, int do_reset)
66{ 66{
67 struct tcp_sock *tp = tcp_sk(sk); 67 struct tcp_sock *tp = tcp_sk(sk);
68 int orphans = atomic_read(&tcp_orphan_count); 68 int orphans = percpu_counter_read_positive(&tcp_orphan_count);
69 69
70 /* If peer does not open window for long time, or did not transmit 70 /* If peer does not open window for long time, or did not transmit
71 * anything for long time, penalize it. */ 71 * anything for long time, penalize it. */