Skip to content

Commit

Permalink
ipv4: icmp: use percpu allocation
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Eric Dumazet authored and David S. Miller committed Feb 1, 2015
1 parent 58c11b5 commit 349c9e3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
3 changes: 2 additions & 1 deletion include/net/netns/ipv4.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ struct netns_ipv4 {
struct hlist_head *fib_table_hash;
struct sock *fibnl;

struct sock **icmp_sk;
struct sock * __percpu *icmp_sk;

struct inet_peer_base *peers;
struct tcpm_hash_bucket *tcp_metrics_hash;
unsigned int tcp_metrics_hash_log;
Expand Down
17 changes: 8 additions & 9 deletions net/ipv4/icmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ static const struct icmp_control icmp_pointers[NR_ICMP_TYPES+1];
*/
static struct sock *icmp_sk(struct net *net)
{
return net->ipv4.icmp_sk[smp_processor_id()];
return *this_cpu_ptr(net->ipv4.icmp_sk);
}

static inline struct sock *icmp_xmit_lock(struct net *net)
Expand Down Expand Up @@ -1140,18 +1140,17 @@ static void __net_exit icmp_sk_exit(struct net *net)
int i;

for_each_possible_cpu(i)
inet_ctl_sock_destroy(net->ipv4.icmp_sk[i]);
kfree(net->ipv4.icmp_sk);
inet_ctl_sock_destroy(*per_cpu_ptr(net->ipv4.icmp_sk, i));
free_percpu(net->ipv4.icmp_sk);
net->ipv4.icmp_sk = NULL;
}

static int __net_init icmp_sk_init(struct net *net)
{
int i, err;

net->ipv4.icmp_sk =
kzalloc(nr_cpu_ids * sizeof(struct sock *), GFP_KERNEL);
if (net->ipv4.icmp_sk == NULL)
net->ipv4.icmp_sk = alloc_percpu(struct sock *);
if (!net->ipv4.icmp_sk)
return -ENOMEM;

for_each_possible_cpu(i) {
Expand All @@ -1162,7 +1161,7 @@ static int __net_init icmp_sk_init(struct net *net)
if (err < 0)
goto fail;

net->ipv4.icmp_sk[i] = sk;
*per_cpu_ptr(net->ipv4.icmp_sk, i) = sk;

/* Enough space for 2 64K ICMP packets, including
* sk_buff/skb_shared_info struct overhead.
Expand Down Expand Up @@ -1203,8 +1202,8 @@ static int __net_init icmp_sk_init(struct net *net)

fail:
for_each_possible_cpu(i)
inet_ctl_sock_destroy(net->ipv4.icmp_sk[i]);
kfree(net->ipv4.icmp_sk);
inet_ctl_sock_destroy(*per_cpu_ptr(net->ipv4.icmp_sk, i));
free_percpu(net->ipv4.icmp_sk);
return err;
}

Expand Down

0 comments on commit 349c9e3

Please sign in to comment.