aboutsummaryrefslogtreecommitdiffstats
path: root/net/core/sock.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/core/sock.c')
-rw-r--r--net/core/sock.c48
1 files changed, 47 insertions, 1 deletions
diff --git a/net/core/sock.c b/net/core/sock.c
index 12ad2067a9..e077f263b7 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1801,12 +1801,41 @@ EXPORT_SYMBOL(sk_common_release);
1801static DEFINE_RWLOCK(proto_list_lock); 1801static DEFINE_RWLOCK(proto_list_lock);
1802static LIST_HEAD(proto_list); 1802static LIST_HEAD(proto_list);
1803 1803
1804#ifdef CONFIG_SMP
1805/*
1806 * Define default functions to keep track of inuse sockets per protocol
1807 * Note that often used protocols use dedicated functions to get a speed increase.
1808 * (see DEFINE_PROTO_INUSE/REF_PROTO_INUSE)
1809 */
1810static void inuse_add(struct proto *prot, int inc)
1811{
1812 per_cpu_ptr(prot->inuse_ptr, smp_processor_id())[0] += inc;
1813}
1814
1815static int inuse_get(const struct proto *prot)
1816{
1817 int res = 0, cpu;
1818 for_each_possible_cpu(cpu)
1819 res += per_cpu_ptr(prot->inuse_ptr, cpu)[0];
1820 return res;
1821}
1822#endif
1823
1804int proto_register(struct proto *prot, int alloc_slab) 1824int proto_register(struct proto *prot, int alloc_slab)
1805{ 1825{
1806 char *request_sock_slab_name = NULL; 1826 char *request_sock_slab_name = NULL;
1807 char *timewait_sock_slab_name; 1827 char *timewait_sock_slab_name;
1808 int rc = -ENOBUFS; 1828 int rc = -ENOBUFS;
1809 1829
1830#ifdef CONFIG_SMP
1831 if (!prot->inuse_getval || !prot->inuse_add) {
1832 prot->inuse_ptr = alloc_percpu(int);
1833 if (prot->inuse_ptr == NULL)
1834 goto out;
1835 prot->inuse_getval = inuse_get;
1836 prot->inuse_add = inuse_add;
1837 }
1838#endif
1810 if (alloc_slab) { 1839 if (alloc_slab) {
1811 prot->slab = kmem_cache_create(prot->name, prot->obj_size, 0, 1840 prot->slab = kmem_cache_create(prot->name, prot->obj_size, 0,
1812 SLAB_HWCACHE_ALIGN, NULL); 1841 SLAB_HWCACHE_ALIGN, NULL);
@@ -1814,7 +1843,7 @@ int proto_register(struct proto *prot, int alloc_slab)
1814 if (prot->slab == NULL) { 1843 if (prot->slab == NULL) {
1815 printk(KERN_CRIT "%s: Can't create sock SLAB cache!\n", 1844 printk(KERN_CRIT "%s: Can't create sock SLAB cache!\n",
1816 prot->name); 1845 prot->name);
1817 goto out; 1846 goto out_free_inuse;
1818 } 1847 }
1819 1848
1820 if (prot->rsk_prot != NULL) { 1849 if (prot->rsk_prot != NULL) {
@@ -1873,6 +1902,15 @@ out_free_request_sock_slab_name:
1873out_free_sock_slab: 1902out_free_sock_slab:
1874 kmem_cache_destroy(prot->slab); 1903 kmem_cache_destroy(prot->slab);
1875 prot->slab = NULL; 1904 prot->slab = NULL;
1905out_free_inuse:
1906#ifdef CONFIG_SMP
1907 if (prot->inuse_ptr != NULL) {
1908 free_percpu(prot->inuse_ptr);
1909 prot->inuse_ptr = NULL;
1910 prot->inuse_getval = NULL;
1911 prot->inuse_add = NULL;
1912 }
1913#endif
1876 goto out; 1914 goto out;
1877} 1915}
1878 1916
@@ -1884,6 +1922,14 @@ void proto_unregister(struct proto *prot)
1884 list_del(&prot->node); 1922 list_del(&prot->node);
1885 write_unlock(&proto_list_lock); 1923 write_unlock(&proto_list_lock);
1886 1924
1925#ifdef CONFIG_SMP
1926 if (prot->inuse_ptr != NULL) {
1927 free_percpu(prot->inuse_ptr);
1928 prot->inuse_ptr = NULL;
1929 prot->inuse_getval = NULL;
1930 prot->inuse_add = NULL;
1931 }
1932#endif
1887 if (prot->slab != NULL) { 1933 if (prot->slab != NULL) {
1888 kmem_cache_destroy(prot->slab); 1934 kmem_cache_destroy(prot->slab);
1889 prot->slab = NULL; 1935 prot->slab = NULL;