aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Dumazet <eric.dumazet@gmail.com>2009-10-08 20:16:19 -0400
committerDavid S. Miller <davem@davemloft.net>2009-10-13 06:44:02 -0400
commitf373b53b5fe67aa4a6f28f921a529cc90f88e79b (patch)
treeb2cae9152aed2e30b7a39c114678b9355ab5c14f
parentc3faca053d0a9c877597935b434150b422dbc6fb (diff)
tcp: replace ehash_size by ehash_mask
Storing the mask (size - 1) instead of the size allows fast path to be a bit faster. Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/inet_hashtables.h4
-rw-r--r--net/dccp/proto.c13
-rw-r--r--net/ipv4/inet_diag.c2
-rw-r--r--net/ipv4/inet_hashtables.c2
-rw-r--r--net/ipv4/inet_timewait_sock.c2
-rw-r--r--net/ipv4/tcp.c11
-rw-r--r--net/ipv4/tcp_ipv4.c6
-rw-r--r--net/ipv6/inet6_hashtables.c2
8 files changed, 21 insertions, 21 deletions
diff --git a/include/net/inet_hashtables.h b/include/net/inet_hashtables.h
index d522dcf3031a..5f11c4a0daca 100644
--- a/include/net/inet_hashtables.h
+++ b/include/net/inet_hashtables.h
@@ -125,7 +125,7 @@ struct inet_hashinfo {
125 */ 125 */
126 struct inet_ehash_bucket *ehash; 126 struct inet_ehash_bucket *ehash;
127 spinlock_t *ehash_locks; 127 spinlock_t *ehash_locks;
128 unsigned int ehash_size; 128 unsigned int ehash_mask;
129 unsigned int ehash_locks_mask; 129 unsigned int ehash_locks_mask;
130 130
131 /* Ok, let's try this, I give up, we do need a local binding 131 /* Ok, let's try this, I give up, we do need a local binding
@@ -158,7 +158,7 @@ static inline struct inet_ehash_bucket *inet_ehash_bucket(
158 struct inet_hashinfo *hashinfo, 158 struct inet_hashinfo *hashinfo,
159 unsigned int hash) 159 unsigned int hash)
160{ 160{
161 return &hashinfo->ehash[hash & (hashinfo->ehash_size - 1)]; 161 return &hashinfo->ehash[hash & hashinfo->ehash_mask];
162} 162}
163 163
164static inline spinlock_t *inet_ehash_lockp( 164static inline spinlock_t *inet_ehash_lockp(
diff --git a/net/dccp/proto.c b/net/dccp/proto.c
index a156319fd0ac..ecb203fff501 100644
--- a/net/dccp/proto.c
+++ b/net/dccp/proto.c
@@ -1060,11 +1060,12 @@ static int __init dccp_init(void)
1060 for (ehash_order = 0; (1UL << ehash_order) < goal; ehash_order++) 1060 for (ehash_order = 0; (1UL << ehash_order) < goal; ehash_order++)
1061 ; 1061 ;
1062 do { 1062 do {
1063 dccp_hashinfo.ehash_size = (1UL << ehash_order) * PAGE_SIZE / 1063 unsigned long hash_size = (1UL << ehash_order) * PAGE_SIZE /
1064 sizeof(struct inet_ehash_bucket); 1064 sizeof(struct inet_ehash_bucket);
1065 while (dccp_hashinfo.ehash_size & 1065
1066 (dccp_hashinfo.ehash_size - 1)) 1066 while (hash_size & (hash_size - 1))
1067 dccp_hashinfo.ehash_size--; 1067 hash_size--;
1068 dccp_hashinfo.ehash_mask = hash_size - 1;
1068 dccp_hashinfo.ehash = (struct inet_ehash_bucket *) 1069 dccp_hashinfo.ehash = (struct inet_ehash_bucket *)
1069 __get_free_pages(GFP_ATOMIC|__GFP_NOWARN, ehash_order); 1070 __get_free_pages(GFP_ATOMIC|__GFP_NOWARN, ehash_order);
1070 } while (!dccp_hashinfo.ehash && --ehash_order > 0); 1071 } while (!dccp_hashinfo.ehash && --ehash_order > 0);
@@ -1074,7 +1075,7 @@ static int __init dccp_init(void)
1074 goto out_free_bind_bucket_cachep; 1075 goto out_free_bind_bucket_cachep;
1075 } 1076 }
1076 1077
1077 for (i = 0; i < dccp_hashinfo.ehash_size; i++) { 1078 for (i = 0; i <= dccp_hashinfo.ehash_mask; i++) {
1078 INIT_HLIST_NULLS_HEAD(&dccp_hashinfo.ehash[i].chain, i); 1079 INIT_HLIST_NULLS_HEAD(&dccp_hashinfo.ehash[i].chain, i);
1079 INIT_HLIST_NULLS_HEAD(&dccp_hashinfo.ehash[i].twchain, i); 1080 INIT_HLIST_NULLS_HEAD(&dccp_hashinfo.ehash[i].twchain, i);
1080 } 1081 }
@@ -1153,7 +1154,7 @@ static void __exit dccp_fini(void)
1153 get_order(dccp_hashinfo.bhash_size * 1154 get_order(dccp_hashinfo.bhash_size *
1154 sizeof(struct inet_bind_hashbucket))); 1155 sizeof(struct inet_bind_hashbucket)));
1155 free_pages((unsigned long)dccp_hashinfo.ehash, 1156 free_pages((unsigned long)dccp_hashinfo.ehash,
1156 get_order(dccp_hashinfo.ehash_size * 1157 get_order((dccp_hashinfo.ehash_mask + 1) *
1157 sizeof(struct inet_ehash_bucket))); 1158 sizeof(struct inet_ehash_bucket)));
1158 inet_ehash_locks_free(&dccp_hashinfo); 1159 inet_ehash_locks_free(&dccp_hashinfo);
1159 kmem_cache_destroy(dccp_hashinfo.bind_bucket_cachep); 1160 kmem_cache_destroy(dccp_hashinfo.bind_bucket_cachep);
diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
index a706a47f4dbb..cb73fdefba91 100644
--- a/net/ipv4/inet_diag.c
+++ b/net/ipv4/inet_diag.c
@@ -774,7 +774,7 @@ skip_listen_ht:
774 if (!(r->idiag_states & ~(TCPF_LISTEN | TCPF_SYN_RECV))) 774 if (!(r->idiag_states & ~(TCPF_LISTEN | TCPF_SYN_RECV)))
775 goto unlock; 775 goto unlock;
776 776
777 for (i = s_i; i < hashinfo->ehash_size; i++) { 777 for (i = s_i; i <= hashinfo->ehash_mask; i++) {
778 struct inet_ehash_bucket *head = &hashinfo->ehash[i]; 778 struct inet_ehash_bucket *head = &hashinfo->ehash[i];
779 spinlock_t *lock = inet_ehash_lockp(hashinfo, i); 779 spinlock_t *lock = inet_ehash_lockp(hashinfo, i);
780 struct sock *sk; 780 struct sock *sk;
diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
index 625cc5f64c94..a45aaf3d48b1 100644
--- a/net/ipv4/inet_hashtables.c
+++ b/net/ipv4/inet_hashtables.c
@@ -209,7 +209,7 @@ struct sock * __inet_lookup_established(struct net *net,
209 * have wildcards anyways. 209 * have wildcards anyways.
210 */ 210 */
211 unsigned int hash = inet_ehashfn(net, daddr, hnum, saddr, sport); 211 unsigned int hash = inet_ehashfn(net, daddr, hnum, saddr, sport);
212 unsigned int slot = hash & (hashinfo->ehash_size - 1); 212 unsigned int slot = hash & hashinfo->ehash_mask;
213 struct inet_ehash_bucket *head = &hashinfo->ehash[slot]; 213 struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
214 214
215 rcu_read_lock(); 215 rcu_read_lock();
diff --git a/net/ipv4/inet_timewait_sock.c b/net/ipv4/inet_timewait_sock.c
index 13f0781f35cd..2fe571155b22 100644
--- a/net/ipv4/inet_timewait_sock.c
+++ b/net/ipv4/inet_timewait_sock.c
@@ -430,7 +430,7 @@ void inet_twsk_purge(struct net *net, struct inet_hashinfo *hashinfo,
430 int h; 430 int h;
431 431
432 local_bh_disable(); 432 local_bh_disable();
433 for (h = 0; h < (hashinfo->ehash_size); h++) { 433 for (h = 0; h <= hashinfo->ehash_mask; h++) {
434 struct inet_ehash_bucket *head = 434 struct inet_ehash_bucket *head =
435 inet_ehash_bucket(hashinfo, h); 435 inet_ehash_bucket(hashinfo, h);
436 spinlock_t *lock = inet_ehash_lockp(hashinfo, h); 436 spinlock_t *lock = inet_ehash_lockp(hashinfo, h);
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 64d0af675823..cf13726259cd 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -2865,11 +2865,10 @@ void __init tcp_init(void)
2865 (totalram_pages >= 128 * 1024) ? 2865 (totalram_pages >= 128 * 1024) ?
2866 13 : 15, 2866 13 : 15,
2867 0, 2867 0,
2868 &tcp_hashinfo.ehash_size,
2869 NULL, 2868 NULL,
2869 &tcp_hashinfo.ehash_mask,
2870 thash_entries ? 0 : 512 * 1024); 2870 thash_entries ? 0 : 512 * 1024);
2871 tcp_hashinfo.ehash_size = 1 << tcp_hashinfo.ehash_size; 2871 for (i = 0; i <= tcp_hashinfo.ehash_mask; i++) {
2872 for (i = 0; i < tcp_hashinfo.ehash_size; i++) {
2873 INIT_HLIST_NULLS_HEAD(&tcp_hashinfo.ehash[i].chain, i); 2872 INIT_HLIST_NULLS_HEAD(&tcp_hashinfo.ehash[i].chain, i);
2874 INIT_HLIST_NULLS_HEAD(&tcp_hashinfo.ehash[i].twchain, i); 2873 INIT_HLIST_NULLS_HEAD(&tcp_hashinfo.ehash[i].twchain, i);
2875 } 2874 }
@@ -2878,7 +2877,7 @@ void __init tcp_init(void)
2878 tcp_hashinfo.bhash = 2877 tcp_hashinfo.bhash =
2879 alloc_large_system_hash("TCP bind", 2878 alloc_large_system_hash("TCP bind",
2880 sizeof(struct inet_bind_hashbucket), 2879 sizeof(struct inet_bind_hashbucket),
2881 tcp_hashinfo.ehash_size, 2880 tcp_hashinfo.ehash_mask + 1,
2882 (totalram_pages >= 128 * 1024) ? 2881 (totalram_pages >= 128 * 1024) ?
2883 13 : 15, 2882 13 : 15,
2884 0, 2883 0,
@@ -2933,8 +2932,8 @@ void __init tcp_init(void)
2933 sysctl_tcp_rmem[2] = max(87380, max_share); 2932 sysctl_tcp_rmem[2] = max(87380, max_share);
2934 2933
2935 printk(KERN_INFO "TCP: Hash tables configured " 2934 printk(KERN_INFO "TCP: Hash tables configured "
2936 "(established %d bind %d)\n", 2935 "(established %u bind %u)\n",
2937 tcp_hashinfo.ehash_size, tcp_hashinfo.bhash_size); 2936 tcp_hashinfo.ehash_mask + 1, tcp_hashinfo.bhash_size);
2938 2937
2939 tcp_register_congestion_control(&tcp_reno); 2938 tcp_register_congestion_control(&tcp_reno);
2940} 2939}
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 7cda24b53f61..99718703d040 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -2000,7 +2000,7 @@ static void *established_get_first(struct seq_file *seq)
2000 struct net *net = seq_file_net(seq); 2000 struct net *net = seq_file_net(seq);
2001 void *rc = NULL; 2001 void *rc = NULL;
2002 2002
2003 for (st->bucket = 0; st->bucket < tcp_hashinfo.ehash_size; ++st->bucket) { 2003 for (st->bucket = 0; st->bucket <= tcp_hashinfo.ehash_mask; ++st->bucket) {
2004 struct sock *sk; 2004 struct sock *sk;
2005 struct hlist_nulls_node *node; 2005 struct hlist_nulls_node *node;
2006 struct inet_timewait_sock *tw; 2006 struct inet_timewait_sock *tw;
@@ -2061,10 +2061,10 @@ get_tw:
2061 st->state = TCP_SEQ_STATE_ESTABLISHED; 2061 st->state = TCP_SEQ_STATE_ESTABLISHED;
2062 2062
2063 /* Look for next non empty bucket */ 2063 /* Look for next non empty bucket */
2064 while (++st->bucket < tcp_hashinfo.ehash_size && 2064 while (++st->bucket <= tcp_hashinfo.ehash_mask &&
2065 empty_bucket(st)) 2065 empty_bucket(st))
2066 ; 2066 ;
2067 if (st->bucket >= tcp_hashinfo.ehash_size) 2067 if (st->bucket > tcp_hashinfo.ehash_mask)
2068 return NULL; 2068 return NULL;
2069 2069
2070 spin_lock_bh(inet_ehash_lockp(&tcp_hashinfo, st->bucket)); 2070 spin_lock_bh(inet_ehash_lockp(&tcp_hashinfo, st->bucket));
diff --git a/net/ipv6/inet6_hashtables.c b/net/ipv6/inet6_hashtables.c
index 1bcc3431859e..874aed86e1a2 100644
--- a/net/ipv6/inet6_hashtables.c
+++ b/net/ipv6/inet6_hashtables.c
@@ -73,7 +73,7 @@ struct sock *__inet6_lookup_established(struct net *net,
73 * have wildcards anyways. 73 * have wildcards anyways.
74 */ 74 */
75 unsigned int hash = inet6_ehashfn(net, daddr, hnum, saddr, sport); 75 unsigned int hash = inet6_ehashfn(net, daddr, hnum, saddr, sport);
76 unsigned int slot = hash & (hashinfo->ehash_size - 1); 76 unsigned int slot = hash & hashinfo->ehash_mask;
77 struct inet_ehash_bucket *head = &hashinfo->ehash[slot]; 77 struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
78 78
79 79