diff options
author | Patrick McHardy <kaber@trash.net> | 2008-01-31 07:40:52 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-01-31 22:27:57 -0500 |
commit | 0794935e21a18e7c171b604c31219b60ad9749a9 (patch) | |
tree | 1d34141abf0c88601d79e3913f3b61fb32dea656 | |
parent | 380517dead6ab86d7249a1723f07f2f1b10af5f6 (diff) |
[NETFILTER]: nf_conntrack: optimize hash_conntrack()
Avoid calling jhash three times and hash the entire tuple in one go.
__hash_conntrack | -485 # 760 -> 275, # inlines: 3 -> 1, size inlines: 717 -> 252
1 function changed, 485 bytes removed
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | net/netfilter/nf_conntrack_core.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c index ce4c4ba31cb1..4a2cce1e1ced 100644 --- a/net/netfilter/nf_conntrack_core.c +++ b/net/netfilter/nf_conntrack_core.c | |||
@@ -73,15 +73,19 @@ static unsigned int nf_conntrack_hash_rnd; | |||
73 | static u_int32_t __hash_conntrack(const struct nf_conntrack_tuple *tuple, | 73 | static u_int32_t __hash_conntrack(const struct nf_conntrack_tuple *tuple, |
74 | unsigned int size, unsigned int rnd) | 74 | unsigned int size, unsigned int rnd) |
75 | { | 75 | { |
76 | unsigned int a, b; | 76 | unsigned int n; |
77 | u_int32_t h; | ||
77 | 78 | ||
78 | a = jhash2(tuple->src.u3.all, ARRAY_SIZE(tuple->src.u3.all), | 79 | /* The direction must be ignored, so we hash everything up to the |
79 | (tuple->src.l3num << 16) | tuple->dst.protonum); | 80 | * destination ports (which is a multiple of 4) and treat the last |
80 | b = jhash2(tuple->dst.u3.all, ARRAY_SIZE(tuple->dst.u3.all), | 81 | * three bytes manually. |
81 | ((__force __u16)tuple->src.u.all << 16) | | 82 | */ |
82 | (__force __u16)tuple->dst.u.all); | 83 | n = (sizeof(tuple->src) + sizeof(tuple->dst.u3)) / sizeof(u32); |
84 | h = jhash2((u32 *)tuple, n, | ||
85 | rnd ^ (((__force __u16)tuple->dst.u.all << 16) | | ||
86 | tuple->dst.protonum)); | ||
83 | 87 | ||
84 | return ((u64)jhash_2words(a, b, rnd) * size) >> 32; | 88 | return ((u64)h * size) >> 32; |
85 | } | 89 | } |
86 | 90 | ||
87 | static inline u_int32_t hash_conntrack(const struct nf_conntrack_tuple *tuple) | 91 | static inline u_int32_t hash_conntrack(const struct nf_conntrack_tuple *tuple) |