Commit 1338d466 authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by David S. Miller
Browse files

[SOCK]: Introduce a percpu inuse counters array (v2).

And redirect sock_prot_inuse_add and _get to use one.

As far as the dereferences are concerned. Before the patch we made
1 dereference to proto->inuse.add call, the call itself and then
called the __get_cpu_var() on a static variable. After the patch we 
make a direct call, then one dereference to proto->inuse_idx and 
then the same __get_cpu_var() on a still static variable. So this 
patch doesn't seem to produce performance penalty on SMP.

This is not per-net yet, but I will deliberately make NET_NS=y case
separated from NET_NS=n one, since it'll cost us one-or-two more 
dereferences to get the struct net and the inuse counter.
Signed-off-by: default avatarPavel Emelyanov <>
Acked-by: default avatarEric Dumazet <>
Signed-off-by: default avatarDavid S. Miller <>
parent 13ff3d6f
......@@ -639,18 +639,15 @@ static inline void sk_refcnt_debug_release(const struct sock *sk)
/* Called with local bh disabled */
static inline void sock_prot_inuse_add(struct proto *prot, int inc)
pcounter_add(&prot->inuse, inc);
extern void sock_prot_inuse_add(struct proto *prot, int inc);
static inline int sock_prot_inuse_init(struct proto *proto)
return pcounter_alloc(&proto->inuse);
static inline int sock_prot_inuse_get(struct proto *proto)
return pcounter_getval(&proto->inuse);
extern int sock_prot_inuse_get(struct proto *proto);
static inline void sock_prot_inuse_free(struct proto *proto)
......@@ -1942,8 +1942,30 @@ static LIST_HEAD(proto_list);
#define PROTO_INUSE_NR 64 /* should be enough for the first time */
struct prot_inuse {
int val[PROTO_INUSE_NR];
static DECLARE_BITMAP(proto_inuse_idx, PROTO_INUSE_NR);
static DEFINE_PER_CPU(struct prot_inuse, prot_inuse);
void sock_prot_inuse_add(struct proto *prot, int val)
__get_cpu_var(prot_inuse).val[prot->inuse_idx] += val;
int sock_prot_inuse_get(struct proto *prot)
int cpu, idx = prot->inuse_idx;
int res = 0;
res += per_cpu(prot_inuse, cpu).val[idx];
return res >= 0 ? res : 0;
static void assign_proto_idx(struct proto *prot)
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