diff options
author | Eric Dumazet <edumazet@google.com> | 2012-11-30 04:49:27 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2012-11-30 15:02:56 -0500 |
commit | ce43b03e8889475817d427b1f3724c7e294b76eb (patch) | |
tree | 0cd6679992bd810371620fcab52c24ce39a89aa8 /include/net/inet_hashtables.h | |
parent | b02a80674ea3905926c1a942426008d732c47339 (diff) |
net: move inet_dport/inet_num in sock_common
commit 68835aba4d9b (net: optimize INET input path further)
moved some fields used for tcp/udp sockets lookup in the first cache
line of struct sock_common.
This patch moves inet_dport/inet_num as well, filling a 32bit hole
on 64 bit arches and reducing number of cache line misses in lookups.
Also change INET_MATCH()/INET_TW_MATCH() to perform the ports match
before addresses match, as this check is more discriminant.
Remove the hash check from MATCH() macros because we dont need to
re validate the hash value after taking a refcount on socket, and
use likely/unlikely compiler hints, as the sk_hash/hash check
makes the following conditional tests 100% predicted by cpu.
Introduce skc_addrpair/skc_portpair pair values to better
document the alignment requirements of the port/addr pairs
used in the various MATCH() macros, and remove some casts.
The namespace check can also be done at last.
This slightly improves TCP/UDP lookup times.
IP/TCP early demux needs inet->rx_dst_ifindex and
TCP needs inet->min_ttl, lets group them together in same cache line.
With help from Ben Hutchings & Joe Perches.
Idea of this patch came after Ling Ma proposal to move skc_hash
to the beginning of struct sock_common, and should allow him
to submit a final version of his patch. My tests show an improvement
doing so.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Ben Hutchings <bhutchings@solarflare.com>
Cc: Joe Perches <joe@perches.com>
Cc: Ling Ma <ling.ma.program@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net/inet_hashtables.h')
-rw-r--r-- | include/net/inet_hashtables.h | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/include/net/inet_hashtables.h b/include/net/inet_hashtables.h index 54be0287eb98..d1de4fbd45c2 100644 --- a/include/net/inet_hashtables.h +++ b/include/net/inet_hashtables.h | |||
@@ -299,30 +299,34 @@ typedef __u64 __bitwise __addrpair; | |||
299 | (((__force __u64)(__be32)(__daddr)) << 32) | \ | 299 | (((__force __u64)(__be32)(__daddr)) << 32) | \ |
300 | ((__force __u64)(__be32)(__saddr))); | 300 | ((__force __u64)(__be32)(__saddr))); |
301 | #endif /* __BIG_ENDIAN */ | 301 | #endif /* __BIG_ENDIAN */ |
302 | #define INET_MATCH(__sk, __net, __hash, __cookie, __saddr, __daddr, __ports, __dif)\ | 302 | #define INET_MATCH(__sk, __net, __cookie, __saddr, __daddr, __ports, __dif) \ |
303 | (((__sk)->sk_hash == (__hash)) && net_eq(sock_net(__sk), (__net)) && \ | 303 | ((inet_sk(__sk)->inet_portpair == (__ports)) && \ |
304 | ((*((__addrpair *)&(inet_sk(__sk)->inet_daddr))) == (__cookie)) && \ | 304 | (inet_sk(__sk)->inet_addrpair == (__cookie)) && \ |
305 | ((*((__portpair *)&(inet_sk(__sk)->inet_dport))) == (__ports)) && \ | 305 | (!(__sk)->sk_bound_dev_if || \ |
306 | (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif)))) | 306 | ((__sk)->sk_bound_dev_if == (__dif))) && \ |
307 | #define INET_TW_MATCH(__sk, __net, __hash, __cookie, __saddr, __daddr, __ports, __dif)\ | 307 | net_eq(sock_net(__sk), (__net))) |
308 | (((__sk)->sk_hash == (__hash)) && net_eq(sock_net(__sk), (__net)) && \ | 308 | #define INET_TW_MATCH(__sk, __net, __cookie, __saddr, __daddr, __ports, __dif)\ |
309 | ((*((__addrpair *)&(inet_twsk(__sk)->tw_daddr))) == (__cookie)) && \ | 309 | ((inet_twsk(__sk)->tw_portpair == (__ports)) && \ |
310 | ((*((__portpair *)&(inet_twsk(__sk)->tw_dport))) == (__ports)) && \ | 310 | (inet_twsk(__sk)->tw_addrpair == (__cookie)) && \ |
311 | (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif)))) | 311 | (!(__sk)->sk_bound_dev_if || \ |
312 | ((__sk)->sk_bound_dev_if == (__dif))) && \ | ||
313 | net_eq(sock_net(__sk), (__net))) | ||
312 | #else /* 32-bit arch */ | 314 | #else /* 32-bit arch */ |
313 | #define INET_ADDR_COOKIE(__name, __saddr, __daddr) | 315 | #define INET_ADDR_COOKIE(__name, __saddr, __daddr) |
314 | #define INET_MATCH(__sk, __net, __hash, __cookie, __saddr, __daddr, __ports, __dif) \ | 316 | #define INET_MATCH(__sk, __net, __cookie, __saddr, __daddr, __ports, __dif) \ |
315 | (((__sk)->sk_hash == (__hash)) && net_eq(sock_net(__sk), (__net)) && \ | 317 | ((inet_sk(__sk)->inet_portpair == (__ports)) && \ |
316 | (inet_sk(__sk)->inet_daddr == (__saddr)) && \ | 318 | (inet_sk(__sk)->inet_daddr == (__saddr)) && \ |
317 | (inet_sk(__sk)->inet_rcv_saddr == (__daddr)) && \ | 319 | (inet_sk(__sk)->inet_rcv_saddr == (__daddr)) && \ |
318 | ((*((__portpair *)&(inet_sk(__sk)->inet_dport))) == (__ports)) && \ | 320 | (!(__sk)->sk_bound_dev_if || \ |
319 | (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif)))) | 321 | ((__sk)->sk_bound_dev_if == (__dif))) && \ |
320 | #define INET_TW_MATCH(__sk, __net, __hash,__cookie, __saddr, __daddr, __ports, __dif) \ | 322 | net_eq(sock_net(__sk), (__net))) |
321 | (((__sk)->sk_hash == (__hash)) && net_eq(sock_net(__sk), (__net)) && \ | 323 | #define INET_TW_MATCH(__sk, __net, __cookie, __saddr, __daddr, __ports, __dif) \ |
322 | (inet_twsk(__sk)->tw_daddr == (__saddr)) && \ | 324 | ((inet_twsk(__sk)->tw_portpair == (__ports)) && \ |
323 | (inet_twsk(__sk)->tw_rcv_saddr == (__daddr)) && \ | 325 | (inet_twsk(__sk)->tw_daddr == (__saddr)) && \ |
324 | ((*((__portpair *)&(inet_twsk(__sk)->tw_dport))) == (__ports)) && \ | 326 | (inet_twsk(__sk)->tw_rcv_saddr == (__daddr)) && \ |
325 | (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif)))) | 327 | (!(__sk)->sk_bound_dev_if || \ |
328 | ((__sk)->sk_bound_dev_if == (__dif))) && \ | ||
329 | net_eq(sock_net(__sk), (__net))) | ||
326 | #endif /* 64-bit arch */ | 330 | #endif /* 64-bit arch */ |
327 | 331 | ||
328 | /* | 332 | /* |