aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/icmp.c
diff options
context:
space:
mode:
authorEric Dumazet <edumazet@google.com>2015-01-29 18:58:09 -0500
committerDavid S. Miller <davem@davemloft.net>2015-01-31 20:48:18 -0500
commit349c9e3c7341bbab6efbea39acfadeba9ab19f61 (patch)
treef319fbf97b50c92a29c6bebd61878f8101da32bc /net/ipv4/icmp.c
parent58c11b5faed6913f73f2763d3a85e4a668e8ba2b (diff)
ipv4: icmp: use percpu allocation
Get rid of nr_cpu_ids and use modern percpu allocation. Note that the sockets themselves are not yet allocated using NUMA affinity. Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/icmp.c')
-rw-r--r--net/ipv4/icmp.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
index 36f5584d93c5..5e564014a0b7 100644
--- a/net/ipv4/icmp.c
+++ b/net/ipv4/icmp.c
@@ -205,7 +205,7 @@ static const struct icmp_control icmp_pointers[NR_ICMP_TYPES+1];
205 */ 205 */
206static struct sock *icmp_sk(struct net *net) 206static struct sock *icmp_sk(struct net *net)
207{ 207{
208 return net->ipv4.icmp_sk[smp_processor_id()]; 208 return *this_cpu_ptr(net->ipv4.icmp_sk);
209} 209}
210 210
211static inline struct sock *icmp_xmit_lock(struct net *net) 211static inline struct sock *icmp_xmit_lock(struct net *net)
@@ -1140,8 +1140,8 @@ static void __net_exit icmp_sk_exit(struct net *net)
1140 int i; 1140 int i;
1141 1141
1142 for_each_possible_cpu(i) 1142 for_each_possible_cpu(i)
1143 inet_ctl_sock_destroy(net->ipv4.icmp_sk[i]); 1143 inet_ctl_sock_destroy(*per_cpu_ptr(net->ipv4.icmp_sk, i));
1144 kfree(net->ipv4.icmp_sk); 1144 free_percpu(net->ipv4.icmp_sk);
1145 net->ipv4.icmp_sk = NULL; 1145 net->ipv4.icmp_sk = NULL;
1146} 1146}
1147 1147
@@ -1149,9 +1149,8 @@ static int __net_init icmp_sk_init(struct net *net)
1149{ 1149{
1150 int i, err; 1150 int i, err;
1151 1151
1152 net->ipv4.icmp_sk = 1152 net->ipv4.icmp_sk = alloc_percpu(struct sock *);
1153 kzalloc(nr_cpu_ids * sizeof(struct sock *), GFP_KERNEL); 1153 if (!net->ipv4.icmp_sk)
1154 if (net->ipv4.icmp_sk == NULL)
1155 return -ENOMEM; 1154 return -ENOMEM;
1156 1155
1157 for_each_possible_cpu(i) { 1156 for_each_possible_cpu(i) {
@@ -1162,7 +1161,7 @@ static int __net_init icmp_sk_init(struct net *net)
1162 if (err < 0) 1161 if (err < 0)
1163 goto fail; 1162 goto fail;
1164 1163
1165 net->ipv4.icmp_sk[i] = sk; 1164 *per_cpu_ptr(net->ipv4.icmp_sk, i) = sk;
1166 1165
1167 /* Enough space for 2 64K ICMP packets, including 1166 /* Enough space for 2 64K ICMP packets, including
1168 * sk_buff/skb_shared_info struct overhead. 1167 * sk_buff/skb_shared_info struct overhead.
@@ -1203,8 +1202,8 @@ static int __net_init icmp_sk_init(struct net *net)
1203 1202
1204fail: 1203fail:
1205 for_each_possible_cpu(i) 1204 for_each_possible_cpu(i)
1206 inet_ctl_sock_destroy(net->ipv4.icmp_sk[i]); 1205 inet_ctl_sock_destroy(*per_cpu_ptr(net->ipv4.icmp_sk, i));
1207 kfree(net->ipv4.icmp_sk); 1206 free_percpu(net->ipv4.icmp_sk);
1208 return err; 1207 return err;
1209} 1208}
1210 1209