Commit 4199bae1 authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

net: merge net->core.prot_inuse and net->core.sock_inuse

net->core.sock_inuse is a per cpu variable (int),
while net->core.prot_inuse is another per cpu variable
of 64 integers.

per cpu allocator tend to place them in very different places.

Grouping them together makes sense, since it makes
updates potentially faster, if hitting the same
cache line.
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d477eb90
...@@ -12,7 +12,6 @@ struct netns_core { ...@@ -12,7 +12,6 @@ struct netns_core {
int sysctl_somaxconn; int sysctl_somaxconn;
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
int __percpu *sock_inuse;
struct prot_inuse __percpu *prot_inuse; struct prot_inuse __percpu *prot_inuse;
#endif #endif
}; };
......
...@@ -1431,6 +1431,7 @@ proto_memory_pressure(struct proto *prot) ...@@ -1431,6 +1431,7 @@ proto_memory_pressure(struct proto *prot)
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
#define PROTO_INUSE_NR 64 /* should be enough for the first time */ #define PROTO_INUSE_NR 64 /* should be enough for the first time */
struct prot_inuse { struct prot_inuse {
int all;
int val[PROTO_INUSE_NR]; int val[PROTO_INUSE_NR];
}; };
/* Called with local bh disabled */ /* Called with local bh disabled */
...@@ -1442,7 +1443,7 @@ static inline void sock_prot_inuse_add(const struct net *net, ...@@ -1442,7 +1443,7 @@ static inline void sock_prot_inuse_add(const struct net *net,
static inline void sock_inuse_add(const struct net *net, int val) static inline void sock_inuse_add(const struct net *net, int val)
{ {
this_cpu_add(*net->core.sock_inuse, val); this_cpu_add(net->core.prot_inuse->all, val);
} }
int sock_prot_inuse_get(struct net *net, struct proto *proto); int sock_prot_inuse_get(struct net *net, struct proto *proto);
......
...@@ -3553,7 +3553,7 @@ int sock_inuse_get(struct net *net) ...@@ -3553,7 +3553,7 @@ int sock_inuse_get(struct net *net)
int cpu, res = 0; int cpu, res = 0;
for_each_possible_cpu(cpu) for_each_possible_cpu(cpu)
res += *per_cpu_ptr(net->core.sock_inuse, cpu); res += per_cpu_ptr(net->core.prot_inuse, cpu)->all;
return res; return res;
} }
...@@ -3565,22 +3565,12 @@ static int __net_init sock_inuse_init_net(struct net *net) ...@@ -3565,22 +3565,12 @@ static int __net_init sock_inuse_init_net(struct net *net)
net->core.prot_inuse = alloc_percpu(struct prot_inuse); net->core.prot_inuse = alloc_percpu(struct prot_inuse);
if (net->core.prot_inuse == NULL) if (net->core.prot_inuse == NULL)
return -ENOMEM; return -ENOMEM;
net->core.sock_inuse = alloc_percpu(int);
if (net->core.sock_inuse == NULL)
goto out;
return 0; return 0;
out:
free_percpu(net->core.prot_inuse);
return -ENOMEM;
} }
static void __net_exit sock_inuse_exit_net(struct net *net) static void __net_exit sock_inuse_exit_net(struct net *net)
{ {
free_percpu(net->core.prot_inuse); free_percpu(net->core.prot_inuse);
free_percpu(net->core.sock_inuse);
} }
static struct pernet_operations net_inuse_ops = { static struct pernet_operations net_inuse_ops = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment