diff options
author | Eric Dumazet <dada1@cosmosbay.com> | 2007-02-08 17:16:46 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2007-02-08 17:16:46 -0500 |
commit | dbca9b2750e3b1ee6f56a616160ccfc12e8b161f (patch) | |
tree | bf84c0acb5495fc95bc616d32b8af946f2e3bca9 /include | |
parent | eac3731bd04c7131478722a3c148b78774553116 (diff) |
[NET]: change layout of ehash table
ehash table layout is currently this one :
First half of this table is used by sockets not in TIME_WAIT state
Second half of it is used by sockets in TIME_WAIT state.
This is non optimal because of for a given hash or socket, the two chain heads
are located in separate cache lines.
Moreover the locks of the second half are never used.
If instead of this halving, we use two list heads in inet_ehash_bucket instead
of only one, we probably can avoid one cache miss, and reduce ram usage,
particularly if sizeof(rwlock_t) is big (various CONFIG_DEBUG_SPINLOCK,
CONFIG_DEBUG_LOCK_ALLOC settings). So we still halves the table but we keep
together related chains to speedup lookups and socket state change.
In this patch I did not try to align struct inet_ehash_bucket, but a future
patch could try to make this structure have a convenient size (a power of two
or a multiple of L1_CACHE_SIZE).
I guess rwlock will just vanish as soon as RCU is plugged into ehash :) , so
maybe we dont need to scratch our heads to align the bucket...
Note : In case struct inet_ehash_bucket is not a power of two, we could
probably change alloc_large_system_hash() (in case it use __get_free_pages())
to free the unused space. It currently allocates a big zone, but the last
quarter of it could be freed. Again, this should be a temporary 'problem'.
Patch tested on ipv4 tcp only, but should be OK for IPV6 and DCCP.
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include')
-rw-r--r-- | include/net/inet_hashtables.h | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/include/net/inet_hashtables.h b/include/net/inet_hashtables.h index 34cc76e3ddb4..d27ee8c0da3f 100644 --- a/include/net/inet_hashtables.h +++ b/include/net/inet_hashtables.h | |||
@@ -34,12 +34,13 @@ | |||
34 | #include <asm/byteorder.h> | 34 | #include <asm/byteorder.h> |
35 | 35 | ||
36 | /* This is for all connections with a full identity, no wildcards. | 36 | /* This is for all connections with a full identity, no wildcards. |
37 | * New scheme, half the table is for TIME_WAIT, the other half is | 37 | * One chain is dedicated to TIME_WAIT sockets. |
38 | * for the rest. I'll experiment with dynamic table growth later. | 38 | * I'll experiment with dynamic table growth later. |
39 | */ | 39 | */ |
40 | struct inet_ehash_bucket { | 40 | struct inet_ehash_bucket { |
41 | rwlock_t lock; | 41 | rwlock_t lock; |
42 | struct hlist_head chain; | 42 | struct hlist_head chain; |
43 | struct hlist_head twchain; | ||
43 | }; | 44 | }; |
44 | 45 | ||
45 | /* There are a few simple rules, which allow for local port reuse by | 46 | /* There are a few simple rules, which allow for local port reuse by |
@@ -97,8 +98,7 @@ struct inet_hashinfo { | |||
97 | * | 98 | * |
98 | * TCP_ESTABLISHED <= sk->sk_state < TCP_CLOSE | 99 | * TCP_ESTABLISHED <= sk->sk_state < TCP_CLOSE |
99 | * | 100 | * |
100 | * First half of the table is for sockets not in TIME_WAIT, second half | 101 | * TIME_WAIT sockets use a separate chain (twchain). |
101 | * is for TIME_WAIT sockets only. | ||
102 | */ | 102 | */ |
103 | struct inet_ehash_bucket *ehash; | 103 | struct inet_ehash_bucket *ehash; |
104 | 104 | ||
@@ -369,7 +369,7 @@ static inline struct sock * | |||
369 | } | 369 | } |
370 | 370 | ||
371 | /* Must check for a TIME_WAIT'er before going to listener hash. */ | 371 | /* Must check for a TIME_WAIT'er before going to listener hash. */ |
372 | sk_for_each(sk, node, &(head + hashinfo->ehash_size)->chain) { | 372 | sk_for_each(sk, node, &head->twchain) { |
373 | if (INET_TW_MATCH(sk, hash, acookie, saddr, daddr, ports, dif)) | 373 | if (INET_TW_MATCH(sk, hash, acookie, saddr, daddr, ports, dif)) |
374 | goto hit; | 374 | goto hit; |
375 | } | 375 | } |