aboutsummaryrefslogtreecommitdiffstats
path: root/net/sctp
diff options
context:
space:
mode:
authorEric Dumazet <dada1@cosmosbay.com>2008-11-26 00:16:35 -0500
committerDavid S. Miller <davem@davemloft.net>2008-11-26 00:16:35 -0500
commit1748376b6626acf59c24e9592ac67b3fe2a0e026 (patch)
tree65a28205daf1ca92e31389440764fc407365014e /net/sctp
parentc1b56878fb68e9c14070939ea4537ad4db79ffae (diff)
net: Use a percpu_counter for sockets_allocated
Instead of using one atomic_t per protocol, use a percpu_counter for "sockets_allocated", to reduce cache line contention on heavy duty network servers. Note : We revert commit (248969ae31e1b3276fc4399d67ce29a5d81e6fd9 net: af_unix can make unix_nr_socks visbile in /proc), since it is not anymore used after sock_prot_inuse_add() addition Signed-off-by: Eric Dumazet <dada1@cosmosbay.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/sctp')
-rw-r--r--net/sctp/protocol.c6
-rw-r--r--net/sctp/socket.c6
2 files changed, 8 insertions, 4 deletions
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index a8ca743241ee..d5ea232c9126 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -102,6 +102,8 @@ struct sock *sctp_get_ctl_sock(void)
102/* Set up the proc fs entry for the SCTP protocol. */ 102/* Set up the proc fs entry for the SCTP protocol. */
103static __init int sctp_proc_init(void) 103static __init int sctp_proc_init(void)
104{ 104{
105 if (percpu_counter_init(&sctp_sockets_allocated, 0))
106 goto out_nomem;
105#ifdef CONFIG_PROC_FS 107#ifdef CONFIG_PROC_FS
106 if (!proc_net_sctp) { 108 if (!proc_net_sctp) {
107 struct proc_dir_entry *ent; 109 struct proc_dir_entry *ent;
@@ -110,7 +112,7 @@ static __init int sctp_proc_init(void)
110 ent->owner = THIS_MODULE; 112 ent->owner = THIS_MODULE;
111 proc_net_sctp = ent; 113 proc_net_sctp = ent;
112 } else 114 } else
113 goto out_nomem; 115 goto out_free_percpu;
114 } 116 }
115 117
116 if (sctp_snmp_proc_init()) 118 if (sctp_snmp_proc_init())
@@ -135,6 +137,8 @@ out_snmp_proc_init:
135 proc_net_sctp = NULL; 137 proc_net_sctp = NULL;
136 remove_proc_entry("sctp", init_net.proc_net); 138 remove_proc_entry("sctp", init_net.proc_net);
137 } 139 }
140out_free_percpu:
141 percpu_counter_destroy(&sctp_sockets_allocated);
138out_nomem: 142out_nomem:
139 return -ENOMEM; 143 return -ENOMEM;
140#else 144#else
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index ba81fe3ccab8..a2de585888d0 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -114,7 +114,7 @@ extern int sysctl_sctp_wmem[3];
114 114
115static int sctp_memory_pressure; 115static int sctp_memory_pressure;
116static atomic_t sctp_memory_allocated; 116static atomic_t sctp_memory_allocated;
117static atomic_t sctp_sockets_allocated; 117struct percpu_counter sctp_sockets_allocated;
118 118
119static void sctp_enter_memory_pressure(struct sock *sk) 119static void sctp_enter_memory_pressure(struct sock *sk)
120{ 120{
@@ -3613,7 +3613,7 @@ SCTP_STATIC int sctp_init_sock(struct sock *sk)
3613 sp->hmac = NULL; 3613 sp->hmac = NULL;
3614 3614
3615 SCTP_DBG_OBJCNT_INC(sock); 3615 SCTP_DBG_OBJCNT_INC(sock);
3616 atomic_inc(&sctp_sockets_allocated); 3616 percpu_counter_inc(&sctp_sockets_allocated);
3617 3617
3618 local_bh_disable(); 3618 local_bh_disable();
3619 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); 3619 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
@@ -3632,7 +3632,7 @@ SCTP_STATIC void sctp_destroy_sock(struct sock *sk)
3632 /* Release our hold on the endpoint. */ 3632 /* Release our hold on the endpoint. */
3633 ep = sctp_sk(sk)->ep; 3633 ep = sctp_sk(sk)->ep;
3634 sctp_endpoint_free(ep); 3634 sctp_endpoint_free(ep);
3635 atomic_dec(&sctp_sockets_allocated); 3635 percpu_counter_dec(&sctp_sockets_allocated);
3636 local_bh_disable(); 3636 local_bh_disable();
3637 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1); 3637 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
3638 local_bh_enable(); 3638 local_bh_enable();