netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tim Gardner <timg@tpi.com>
To: netdev@oss.sgi.com
Cc: "linux-net" <linux-net@vger.kernel.org>
Subject: [PATCH] IPv4 ARP hash algorithm has poor distribution
Date: Mon, 15 Mar 2004 11:32:31 -0700	[thread overview]
Message-ID: <200403151132.31368.timg@tpi.com> (raw)

The current IPv4 ARP hash algorithm does not generate evenly distributed hash 
indices.

Included is a patch to fix the hash algorithm such that it will generate an 
even distribution of hash indices within a single subnet. It also uses the 
network bits of the address to attempt to avoid collisions with other 
subnets.

On my my router with 991 ARP entries, this algorithm utilized 669 out of 1024 
hash buckets. The old algorithm utilized 169.

rtg

<-Snip-->

diff -r -u --new-file linux-2.4.bk/net/ipv4/arp.c 
linux-2.4.bk-arp-hash/net/ipv4/arp.c
--- linux-2.4.bk/net/ipv4/arp.c	2004-03-15 11:24:07.000000000 -0700
+++ linux-2.4.bk-arp-hash/net/ipv4/arp.c	2004-03-15 10:15:48.000000000 -0700
@@ -215,11 +215,9 @@
 {
 	u32 hash_val;
 
-	hash_val = *(u32*)pkey;
+	hash_val = ntohl(*(u32*)pkey);
 	hash_val ^= (hash_val>>16);
-	hash_val ^= hash_val>>8;
-	hash_val ^= hash_val>>3;
-	hash_val = (hash_val^dev->ifindex)&(arp_tbl.num_hash_buckets-1);
+	hash_val &= (arp_tbl.num_hash_buckets-1);
 
 	return hash_val;
 }

-- 
Tim Gardner - timg@tpi.com
www.tpi.com 406-443-5357

             reply	other threads:[~2004-03-15 18:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-15 18:32 Tim Gardner [this message]
2004-03-15 21:44 ` [PATCH] IPv4 ARP hash algorithm has poor distribution David S. Miller

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=200403151132.31368.timg@tpi.com \
    --to=timg@tpi.com \
    --cc=linux-net@vger.kernel.org \
    --cc=netdev@oss.sgi.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).