All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nf_conntrack: optimize hash calculation of tuple
@ 2006-05-26  0:15 Yasuyuki KOZAKAI
  2006-05-26 13:34 ` Patrick McHardy
  0 siblings, 1 reply; 9+ messages in thread
From: Yasuyuki KOZAKAI @ 2006-05-26  0:15 UTC (permalink / raw)
  To: netfilter-devel

[-- Attachment #1: jhash.patch --]
[-- Type: Text/Plain, Size: 2033 bytes --]

[NETFILTER] nf_conntrack: optimize hash calculation of tuple

This reduces the number of calling __jhash_mix() and addition of
JHASH_GOLDEN_RATIO.

Signed-off-by: Yasuyuki Kozakai <yasuyuki.kozakai@toshiba.co.jp>
Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>

---
commit eac276f083c283360ed15571e8623463a8ace379
tree e7492317c9399f445bef061e76e01546f2517ef9
parent a54c9d30dbb06391ec4422aaf0e1dc2c8c53bd3e
author Yasuyuki Kozakai <yasuyuki.kozakai@toshiba.co.jp> Wed, 24 May 2006 21:16:51 +0900
committer Yasuyuki Kozakai <yasuyuki.kozakai@toshiba.co.jp> Wed, 24 May 2006 21:16:51 +0900

 net/netfilter/nf_conntrack_core.c |   30 ++++++++++++++++++++++++------
 1 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index f9b83f9..b24edc9 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -271,13 +271,31 @@ static unsigned int nf_conntrack_hash_rn
 static u_int32_t __hash_conntrack(const struct nf_conntrack_tuple *tuple,
 				  unsigned int size, unsigned int rnd)
 {
-	unsigned int a, b;
-	a = jhash((void *)tuple->src.u3.all, sizeof(tuple->src.u3.all),
-		  ((tuple->src.l3num) << 16) | tuple->dst.protonum);
-	b = jhash((void *)tuple->dst.u3.all, sizeof(tuple->dst.u3.all),
-			(tuple->src.u.all << 16) | tuple->dst.u.all);
+	u32 a, b, c;
 
-	return jhash_2words(a, b, rnd) % size;
+	a = JHASH_GOLDEN_RATIO;
+	b = JHASH_GOLDEN_RATIO;
+	c = rnd;
+
+	a += tuple->src.u3.all[0];
+	b += tuple->src.u3.all[1];
+	c += tuple->src.u3.all[2];
+	__jhash_mix(a, b, c);
+
+	a += tuple->src.u3.all[3],
+	b += (tuple->src.l3num << 16) | tuple->src.u.all;
+	c += tuple->dst.u3.all[0];
+	__jhash_mix(a, b, c);
+
+	a += tuple->dst.u3.all[1];
+	b += tuple->dst.u3.all[2];
+	c += tuple->dst.u3.all[3];
+	__jhash_mix(a, b, c);
+
+	a += (tuple->dst.protonum << 16) | tuple->dst.u.all;
+	__jhash_mix(a, b, c);
+
+	return c % size;
 }
 
 static inline u_int32_t hash_conntrack(const struct nf_conntrack_tuple *tuple)

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2006-05-29  1:27 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-26  0:15 [PATCH] nf_conntrack: optimize hash calculation of tuple Yasuyuki KOZAKAI
2006-05-26 13:34 ` Patrick McHardy
2006-05-26 13:45   ` YOSHIFUJI Hideaki / 吉藤英明
2006-05-26 13:51     ` Patrick McHardy
2006-05-26 14:17       ` YOSHIFUJI Hideaki / 吉藤英明
2006-05-26 15:04       ` Yasuyuki KOZAKAI
     [not found]       ` <200605261504.k4QF4InW014648@toshiba.co.jp>
2006-05-26 17:54         ` Patrick McHardy
2006-05-29  0:25           ` Yasuyuki KOZAKAI
     [not found]           ` <200605290025.k4T0PeSE014151@toshiba.co.jp>
2006-05-29  1:27             ` Patrick McHardy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.