Skip to contentSkip to conversation

ipv4: Add hash table of interface addresses.

PATCH In review David Miller 2 participants 3 messages Feb 18, 2011

Subsystems (3)
lore
Share & tools
lore

David Miller

author maintainer
#0 lore raw

PATCH 1/2 ipv4: Add hash table of interface addresses.

This will be used to optimize __ip_dev_find() and friends.

---
 include/linux/inetdevice.h |    1 +
 net/ipv4/devinet.c         |   44 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 0 deletions(-)
include/linux/inetdevice.h +1 -0
index ae8fdc5..5f81466 100644
@@ -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;
net/ipv4/devinet.c +44 -0

92 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#1 lore raw
Quoted 33 lines · David Miller

This will be used to optimize __ip_dev_find() and friends.

---
 include/linux/inetdevice.h |    1 +
 net/ipv4/devinet.c         |   44 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 0 deletions(-)
include/linux/inetdevice.h +1 -0
index ae8fdc5..5f81466 100644
@@ -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;
net/ipv4/devinet.c +5 -0
index 748cb5b..c1f2552 100644
@@ -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

net/ipv4/devinet.c static const struct nla_policy ifa_ipv4_policy[IFA_MAX+1] = { · line 109

Quoted 10 lines
net/ipv4/devinet.c +10 -0
+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

author maintainer
#2 lore raw

From: Eric Dumazet <[email protected]>
Date: Fri, 18 Feb 2011 07:22:30 +0100

Quoted 2 lines

Maybe you should take into account net pointer here, or machines with many net namespaces will hash collide for 127.0.0.1

Good idea. I'll post a new series with that fixed up later.

Thanks!