Commit 0794935e authored by Patrick McHardy's avatar Patrick McHardy Committed by David S. Miller

[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: default avatarPatrick McHardy <kaber@trash.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 380517de
...@@ -73,15 +73,19 @@ static unsigned int nf_conntrack_hash_rnd; ...@@ -73,15 +73,19 @@ static unsigned int nf_conntrack_hash_rnd;
static u_int32_t __hash_conntrack(const struct nf_conntrack_tuple *tuple, static u_int32_t __hash_conntrack(const struct nf_conntrack_tuple *tuple,
unsigned int size, unsigned int rnd) unsigned int size, unsigned int rnd)
{ {
unsigned int a, b; unsigned int n;
u_int32_t h;
a = jhash2(tuple->src.u3.all, ARRAY_SIZE(tuple->src.u3.all), /* The direction must be ignored, so we hash everything up to the
(tuple->src.l3num << 16) | tuple->dst.protonum); * destination ports (which is a multiple of 4) and treat the last
b = jhash2(tuple->dst.u3.all, ARRAY_SIZE(tuple->dst.u3.all), * three bytes manually.
((__force __u16)tuple->src.u.all << 16) | */
(__force __u16)tuple->dst.u.all); n = (sizeof(tuple->src) + sizeof(tuple->dst.u3)) / sizeof(u32);
h = jhash2((u32 *)tuple, n,
rnd ^ (((__force __u16)tuple->dst.u.all << 16) |
tuple->dst.protonum));
return ((u64)jhash_2words(a, b, rnd) * size) >> 32; return ((u64)h * size) >> 32;
} }
static inline u_int32_t hash_conntrack(const struct nf_conntrack_tuple *tuple) static inline u_int32_t hash_conntrack(const struct nf_conntrack_tuple *tuple)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment