From: Patrick McHardy <kaber@trash.net>
To: Yasuyuki KOZAKAI <yasuyuki.kozakai@toshiba.co.jp>
Cc: netfilter-devel@lists.netfilter.org
Subject: Re: [PATCH] nf_conntrack: optimize hash calculation of tuple
Date: Fri, 26 May 2006 15:34:42 +0200 [thread overview]
Message-ID: <447703F2.90401@trash.net> (raw)
In-Reply-To: <200605260015.k4Q0FpPC024839@toshiba.co.jp>
Yasuyuki KOZAKAI wrote:
> [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;
> }
That still looks pretty expensive. Is there a reason why you didn't
just add/xor/or/... the individual values until you get down to
three and then use jhash_3words? We could also get rid of the modula
operation by making sure the hash-size is always a power of 2.
next prev parent reply other threads:[~2006-05-26 13:34 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-05-26 0:15 [PATCH] nf_conntrack: optimize hash calculation of tuple Yasuyuki KOZAKAI
2006-05-26 13:34 ` Patrick McHardy [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=447703F2.90401@trash.net \
--to=kaber@trash.net \
--cc=netfilter-devel@lists.netfilter.org \
--cc=yasuyuki.kozakai@toshiba.co.jp \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.