From: Eric Dumazet <eric.dumazet@gmail.com>
To: David Miller <davem@davemloft.net>
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH 1/2] ipv4: Add hash table of interface addresses.
Date: Fri, 18 Feb 2011 07:22:30 +0100 [thread overview]
Message-ID: <1298010150.2642.5.camel@edumazet-laptop> (raw)
In-Reply-To: <20110217.204638.104041410.davem@davemloft.net>
Le jeudi 17 février 2011 à 20:46 -0800, David Miller a écrit :
> This will be used to optimize __ip_dev_find() and friends.
>
> Signed-off-by: David S. Miller <davem@davemloft.net>
> ---
> include/linux/inetdevice.h | 1 +
> net/ipv4/devinet.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 45 insertions(+), 0 deletions(-)
>
> diff --git a/include/linux/inetdevice.h b/include/linux/inetdevice.h
> index ae8fdc5..5f81466 100644
> --- a/include/linux/inetdevice.h
> +++ b/include/linux/inetdevice.h
> @@ -144,6 +144,7 @@ static inline void ipv4_devconf_setall(struct in_device *in_dev)
> #define IN_DEV_ARP_NOTIFY(in_dev) IN_DEV_MAXCONF((in_dev), ARP_NOTIFY)
>
> struct in_ifaddr {
> + struct hlist_node hash;
> struct in_ifaddr *ifa_next;
> struct in_device *ifa_dev;
> struct rcu_head rcu_head;
> diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
> index 748cb5b..c1f2552 100644
> --- a/net/ipv4/devinet.c
> +++ b/net/ipv4/devinet.c
> @@ -92,6 +92,38 @@ static const struct nla_policy ifa_ipv4_policy[IFA_MAX+1] = {
> [IFA_LABEL] = { .type = NLA_STRING, .len = IFNAMSIZ - 1 },
> };
>
> +/* inet_addr_hash's shifting is dependent upon this IN4_ADDR_HSIZE
> + * value. So if you change this define, make appropriate changes to
> + * inet_addr_hash as well.
> + */
> +#define IN4_ADDR_HSIZE 256
> +static struct hlist_head inet_addr_lst[IN4_ADDR_HSIZE];
> +static DEFINE_SPINLOCK(inet_addr_hash_lock);
> +
> +static inline unsigned int inet_addr_hash(__be32 addr)
> +{
> + u32 val = (__force u32) addr;
> +
> + return ((val ^ (val >> 8) ^ (val >> 16) ^ (val >> 24)) &
> + (IN4_ADDR_HSIZE - 1));
> +}
Maybe you should take into account net pointer here, or machines with
many net namespaces will hash collide for 127.0.0.1
next prev parent reply other threads:[~2011-02-18 6:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-18 4:46 [PATCH 1/2] ipv4: Add hash table of interface addresses David Miller
2011-02-18 6:22 ` Eric Dumazet [this message]
2011-02-18 20:12 ` David 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=1298010150.2642.5.camel@edumazet-laptop \
--to=eric.dumazet@gmail.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
/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