Commit 13ff3d6f authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by David S. Miller
Browse files

[SOCK]: Enumerate struct proto-s to facilitate percpu inuse accounting (v2).

The inuse counters are going to become a per-cpu array.  Introduce an
index for this array on the struct proto.

To handle the case of proto register-unregister-register loop the
bitmap is used. All its bits manipulations are protected with
proto_list_lock and a sanity check for the bitmap being exhausted is
also added.

Signed-off-by: default avatarPavel Emelyanov <>
Acked-by: default avatarEric Dumazet <>
Signed-off-by: default avatarDavid S. Miller <>
parent bc578a54
......@@ -562,6 +562,7 @@ struct proto {
/* Keeping track of sockets in use */
unsigned int inuse_idx;
struct pcounter inuse;
......@@ -1940,6 +1940,38 @@ EXPORT_SYMBOL(sk_common_release);
static DEFINE_RWLOCK(proto_list_lock);
static LIST_HEAD(proto_list);
#define PROTO_INUSE_NR 64 /* should be enough for the first time */
static DECLARE_BITMAP(proto_inuse_idx, PROTO_INUSE_NR);
static void assign_proto_idx(struct proto *prot)
prot->inuse_idx = find_first_zero_bit(proto_inuse_idx, PROTO_INUSE_NR);
if (unlikely(prot->inuse_idx == PROTO_INUSE_NR - 1)) {
printk(KERN_ERR "PROTO_INUSE_NR exhausted\n");
set_bit(prot->inuse_idx, proto_inuse_idx);
static void release_proto_idx(struct proto *prot)
if (prot->inuse_idx != PROTO_INUSE_NR - 1)
clear_bit(prot->inuse_idx, proto_inuse_idx);
static inline void assign_proto_idx(struct proto *prot)
static inline void release_proto_idx(struct proto *prot)
int proto_register(struct proto *prot, int alloc_slab)
char *request_sock_slab_name = NULL;
......@@ -2000,6 +2032,7 @@ int proto_register(struct proto *prot, int alloc_slab)
list_add(&prot->node, &proto_list);
return 0;
......@@ -2026,6 +2059,7 @@ EXPORT_SYMBOL(proto_register);
void proto_unregister(struct proto *prot)
Supports Markdown
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