|
@@ -1801,12 +1801,41 @@ EXPORT_SYMBOL(sk_common_release);
|
|
static DEFINE_RWLOCK(proto_list_lock);
|
|
static DEFINE_RWLOCK(proto_list_lock);
|
|
static LIST_HEAD(proto_list);
|
|
static LIST_HEAD(proto_list);
|
|
|
|
|
|
|
|
+#ifdef CONFIG_SMP
|
|
|
|
+/*
|
|
|
|
+ * Define default functions to keep track of inuse sockets per protocol
|
|
|
|
+ * Note that often used protocols use dedicated functions to get a speed increase.
|
|
|
|
+ * (see DEFINE_PROTO_INUSE/REF_PROTO_INUSE)
|
|
|
|
+ */
|
|
|
|
+static void inuse_add(struct proto *prot, int inc)
|
|
|
|
+{
|
|
|
|
+ per_cpu_ptr(prot->inuse_ptr, smp_processor_id())[0] += inc;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static int inuse_get(const struct proto *prot)
|
|
|
|
+{
|
|
|
|
+ int res = 0, cpu;
|
|
|
|
+ for_each_possible_cpu(cpu)
|
|
|
|
+ res += per_cpu_ptr(prot->inuse_ptr, cpu)[0];
|
|
|
|
+ return res;
|
|
|
|
+}
|
|
|
|
+#endif
|
|
|
|
+
|
|
int proto_register(struct proto *prot, int alloc_slab)
|
|
int proto_register(struct proto *prot, int alloc_slab)
|
|
{
|
|
{
|
|
char *request_sock_slab_name = NULL;
|
|
char *request_sock_slab_name = NULL;
|
|
char *timewait_sock_slab_name;
|
|
char *timewait_sock_slab_name;
|
|
int rc = -ENOBUFS;
|
|
int rc = -ENOBUFS;
|
|
|
|
|
|
|
|
+#ifdef CONFIG_SMP
|
|
|
|
+ if (!prot->inuse_getval || !prot->inuse_add) {
|
|
|
|
+ prot->inuse_ptr = alloc_percpu(int);
|
|
|
|
+ if (prot->inuse_ptr == NULL)
|
|
|
|
+ goto out;
|
|
|
|
+ prot->inuse_getval = inuse_get;
|
|
|
|
+ prot->inuse_add = inuse_add;
|
|
|
|
+ }
|
|
|
|
+#endif
|
|
if (alloc_slab) {
|
|
if (alloc_slab) {
|
|
prot->slab = kmem_cache_create(prot->name, prot->obj_size, 0,
|
|
prot->slab = kmem_cache_create(prot->name, prot->obj_size, 0,
|
|
SLAB_HWCACHE_ALIGN, NULL);
|
|
SLAB_HWCACHE_ALIGN, NULL);
|
|
@@ -1814,7 +1843,7 @@ int proto_register(struct proto *prot, int alloc_slab)
|
|
if (prot->slab == NULL) {
|
|
if (prot->slab == NULL) {
|
|
printk(KERN_CRIT "%s: Can't create sock SLAB cache!\n",
|
|
printk(KERN_CRIT "%s: Can't create sock SLAB cache!\n",
|
|
prot->name);
|
|
prot->name);
|
|
- goto out;
|
|
|
|
|
|
+ goto out_free_inuse;
|
|
}
|
|
}
|
|
|
|
|
|
if (prot->rsk_prot != NULL) {
|
|
if (prot->rsk_prot != NULL) {
|
|
@@ -1873,6 +1902,15 @@ out_free_request_sock_slab_name:
|
|
out_free_sock_slab:
|
|
out_free_sock_slab:
|
|
kmem_cache_destroy(prot->slab);
|
|
kmem_cache_destroy(prot->slab);
|
|
prot->slab = NULL;
|
|
prot->slab = NULL;
|
|
|
|
+out_free_inuse:
|
|
|
|
+#ifdef CONFIG_SMP
|
|
|
|
+ if (prot->inuse_ptr != NULL) {
|
|
|
|
+ free_percpu(prot->inuse_ptr);
|
|
|
|
+ prot->inuse_ptr = NULL;
|
|
|
|
+ prot->inuse_getval = NULL;
|
|
|
|
+ prot->inuse_add = NULL;
|
|
|
|
+ }
|
|
|
|
+#endif
|
|
goto out;
|
|
goto out;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1884,6 +1922,14 @@ void proto_unregister(struct proto *prot)
|
|
list_del(&prot->node);
|
|
list_del(&prot->node);
|
|
write_unlock(&proto_list_lock);
|
|
write_unlock(&proto_list_lock);
|
|
|
|
|
|
|
|
+#ifdef CONFIG_SMP
|
|
|
|
+ if (prot->inuse_ptr != NULL) {
|
|
|
|
+ free_percpu(prot->inuse_ptr);
|
|
|
|
+ prot->inuse_ptr = NULL;
|
|
|
|
+ prot->inuse_getval = NULL;
|
|
|
|
+ prot->inuse_add = NULL;
|
|
|
|
+ }
|
|
|
|
+#endif
|
|
if (prot->slab != NULL) {
|
|
if (prot->slab != NULL) {
|
|
kmem_cache_destroy(prot->slab);
|
|
kmem_cache_destroy(prot->slab);
|
|
prot->slab = NULL;
|
|
prot->slab = NULL;
|