aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/tcp.c
diff options
context:
space:
mode:
authorEric Dumazet <eric.dumazet@gmail.com>2011-09-12 16:28:37 -0400
committerDavid S. Miller <davem@davemloft.net>2011-09-17 01:15:46 -0400
commit765cf9976e937f1cfe9159bf4534967c8bf8eb6d (patch)
tree671d57668c3f10a22e76704ad6d2c9f0a2e1f9f1 /net/ipv4/tcp.c
parentb9fa1fbf98178c8bbda23ff1d3ed0731bb3c0bd1 (diff)
tcp: md5: remove one indirection level in tcp_md5sig_pool
tcp_md5sig_pool is currently an 'array' (a percpu object) of pointers to struct tcp_md5sig_pool. Only the pointers are NUMA aware, but objects themselves are all allocated on a single node. Remove this extra indirection to get proper percpu memory (NUMA aware) and make code simpler. Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/tcp.c')
-rw-r--r--net/ipv4/tcp.c41
1 files changed, 17 insertions, 24 deletions
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 5fe632c763f..cc0d5dead30 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -2857,26 +2857,25 @@ EXPORT_SYMBOL(tcp_gro_complete);
2857 2857
2858#ifdef CONFIG_TCP_MD5SIG 2858#ifdef CONFIG_TCP_MD5SIG
2859static unsigned long tcp_md5sig_users; 2859static unsigned long tcp_md5sig_users;
2860static struct tcp_md5sig_pool * __percpu *tcp_md5sig_pool; 2860static struct tcp_md5sig_pool __percpu *tcp_md5sig_pool;
2861static DEFINE_SPINLOCK(tcp_md5sig_pool_lock); 2861static DEFINE_SPINLOCK(tcp_md5sig_pool_lock);
2862 2862
2863static void __tcp_free_md5sig_pool(struct tcp_md5sig_pool * __percpu *pool) 2863static void __tcp_free_md5sig_pool(struct tcp_md5sig_pool __percpu *pool)
2864{ 2864{
2865 int cpu; 2865 int cpu;
2866
2866 for_each_possible_cpu(cpu) { 2867 for_each_possible_cpu(cpu) {
2867 struct tcp_md5sig_pool *p = *per_cpu_ptr(pool, cpu); 2868 struct tcp_md5sig_pool *p = per_cpu_ptr(pool, cpu);
2868 if (p) { 2869
2869 if (p->md5_desc.tfm) 2870 if (p->md5_desc.tfm)
2870 crypto_free_hash(p->md5_desc.tfm); 2871 crypto_free_hash(p->md5_desc.tfm);
2871 kfree(p);
2872 }
2873 } 2872 }
2874 free_percpu(pool); 2873 free_percpu(pool);
2875} 2874}
2876 2875
2877void tcp_free_md5sig_pool(void) 2876void tcp_free_md5sig_pool(void)
2878{ 2877{
2879 struct tcp_md5sig_pool * __percpu *pool = NULL; 2878 struct tcp_md5sig_pool __percpu *pool = NULL;
2880 2879
2881 spin_lock_bh(&tcp_md5sig_pool_lock); 2880 spin_lock_bh(&tcp_md5sig_pool_lock);
2882 if (--tcp_md5sig_users == 0) { 2881 if (--tcp_md5sig_users == 0) {
@@ -2889,30 +2888,24 @@ void tcp_free_md5sig_pool(void)
2889} 2888}
2890EXPORT_SYMBOL(tcp_free_md5sig_pool); 2889EXPORT_SYMBOL(tcp_free_md5sig_pool);
2891 2890
2892static struct tcp_md5sig_pool * __percpu * 2891static struct tcp_md5sig_pool __percpu *
2893__tcp_alloc_md5sig_pool(struct sock *sk) 2892__tcp_alloc_md5sig_pool(struct sock *sk)
2894{ 2893{
2895 int cpu; 2894 int cpu;
2896 struct tcp_md5sig_pool * __percpu *pool; 2895 struct tcp_md5sig_pool __percpu *pool;
2897 2896
2898 pool = alloc_percpu(struct tcp_md5sig_pool *); 2897 pool = alloc_percpu(struct tcp_md5sig_pool);
2899 if (!pool) 2898 if (!pool)
2900 return NULL; 2899 return NULL;
2901 2900
2902 for_each_possible_cpu(cpu) { 2901 for_each_possible_cpu(cpu) {
2903 struct tcp_md5sig_pool *p;
2904 struct crypto_hash *hash; 2902 struct crypto_hash *hash;
2905 2903
2906 p = kzalloc(sizeof(*p), sk->sk_allocation);
2907 if (!p)
2908 goto out_free;
2909 *per_cpu_ptr(pool, cpu) = p;
2910
2911 hash = crypto_alloc_hash("md5", 0, CRYPTO_ALG_ASYNC); 2904 hash = crypto_alloc_hash("md5", 0, CRYPTO_ALG_ASYNC);
2912 if (!hash || IS_ERR(hash)) 2905 if (!hash || IS_ERR(hash))
2913 goto out_free; 2906 goto out_free;
2914 2907
2915 p->md5_desc.tfm = hash; 2908 per_cpu_ptr(pool, cpu)->md5_desc.tfm = hash;
2916 } 2909 }
2917 return pool; 2910 return pool;
2918out_free: 2911out_free:
@@ -2920,9 +2913,9 @@ out_free:
2920 return NULL; 2913 return NULL;
2921} 2914}
2922 2915
2923struct tcp_md5sig_pool * __percpu *tcp_alloc_md5sig_pool(struct sock *sk) 2916struct tcp_md5sig_pool __percpu *tcp_alloc_md5sig_pool(struct sock *sk)
2924{ 2917{
2925 struct tcp_md5sig_pool * __percpu *pool; 2918 struct tcp_md5sig_pool __percpu *pool;
2926 int alloc = 0; 2919 int alloc = 0;
2927 2920
2928retry: 2921retry:
@@ -2941,7 +2934,7 @@ retry:
2941 2934
2942 if (alloc) { 2935 if (alloc) {
2943 /* we cannot hold spinlock here because this may sleep. */ 2936 /* we cannot hold spinlock here because this may sleep. */
2944 struct tcp_md5sig_pool * __percpu *p; 2937 struct tcp_md5sig_pool __percpu *p;
2945 2938
2946 p = __tcp_alloc_md5sig_pool(sk); 2939 p = __tcp_alloc_md5sig_pool(sk);
2947 spin_lock_bh(&tcp_md5sig_pool_lock); 2940 spin_lock_bh(&tcp_md5sig_pool_lock);
@@ -2974,7 +2967,7 @@ EXPORT_SYMBOL(tcp_alloc_md5sig_pool);
2974 */ 2967 */
2975struct tcp_md5sig_pool *tcp_get_md5sig_pool(void) 2968struct tcp_md5sig_pool *tcp_get_md5sig_pool(void)
2976{ 2969{
2977 struct tcp_md5sig_pool * __percpu *p; 2970 struct tcp_md5sig_pool __percpu *p;
2978 2971
2979 local_bh_disable(); 2972 local_bh_disable();
2980 2973
@@ -2985,7 +2978,7 @@ struct tcp_md5sig_pool *tcp_get_md5sig_pool(void)
2985 spin_unlock(&tcp_md5sig_pool_lock); 2978 spin_unlock(&tcp_md5sig_pool_lock);
2986 2979
2987 if (p) 2980 if (p)
2988 return *this_cpu_ptr(p); 2981 return this_cpu_ptr(p);
2989 2982
2990 local_bh_enable(); 2983 local_bh_enable();
2991 return NULL; 2984 return NULL;