Skip to contentSkip to conversation

ipv4: avoid quadratic behavior in FIB insertion of common address

PATCH In review Alexandre Ferrieux 2 participants 2 messages Sep 25, 2024 – Sep 26, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipv4: avoid quadratic behavior in FIB insertion of common address

Mix netns into all IPv4 FIB hashes to avoid massive collision when inserting the same address in many netns.

---
 net/ipv4/fib_semantics.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
net/ipv4/fib_semantics.c +5 -3
index ba2df3d2ac15..89fa8fd1a4a5 100644
@@ -347,10 +347,12 @@ static unsigned int fib_info_hashfn_1(int init_val, u8 protocol, u8 scope,
 	return val;
 }
 
-static unsigned int fib_info_hashfn_result(unsigned int val)
+static unsigned int fib_info_hashfn_result(struct net *net, unsigned int val)
 {
 	unsigned int mask = (fib_info_hash_size - 1);
 
+	val ^= net_hash_mix(net);
+
 	return (val ^ (val >> 7) ^ (val >> 12)) & mask;
 }
 
@@ -370,7 +372,7 @@ static inline unsigned int fib_info_hashfn(struct fib_info *fi)
 		} endfor_nexthops(fi)
 	}
 
-	return fib_info_hashfn_result(val);
+	return fib_info_hashfn_result(fi->fib_net, val);
 }
 
 /* no metrics, only nexthop id */
@@ -385,7 +387,7 @@ static struct fib_info *fib_find_info_nh(struct net *net,
 				 cfg->fc_protocol, cfg->fc_scope,
 				 (__force u32)cfg->fc_prefsrc,
 				 cfg->fc_priority);
-	hash = fib_info_hashfn_result(hash);
+	hash = fib_info_hashfn_result(net, hash);
 	head = &fib_info_hash[hash];
 
 	hlist_for_each_entry(fi, head, fib_hash) {
Signature · 1 line
2.30.2
#1 lore raw
Quoted 5 lines · Alexandre Ferrieux

Mix netns into all IPv4 FIB hashes to avoid massive collision when inserting the same address in many netns.

I think this targets net-next tree, which re-opens next week.

Quoted 9 lines
---
 net/ipv4/fib_semantics.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
net/ipv4/fib_semantics.c +0 -0
index ba2df3d2ac15..89fa8fd1a4a5 100644

net/ipv4/fib_semantics.c static unsigned int fib_info_hashfn_1(int init_val, u8 protocol, u8 scope, · line 350

Quoted 5 lines
net/ipv4/fib_semantics.c +1 -1
@@ -347,10 +347,12 @@ static unsigned int fib_info_hashfn_1(int init_val, u8 protocol, u8 scope,
        return val;
 }
 
-static unsigned int fib_info_hashfn_result(unsigned int val)
+static unsigned int fib_info_hashfn_result(struct net *net, unsigned int val)

This can be 'const struct net *net'

net/ipv4/fib_semantics.c static unsigned int fib_info_hashfn_1(int init_val, u8 protocol, u8 scope, · line 352

Quoted 2 lines
net/ipv4/fib_semantics.c +0 -0
 {
        unsigned int mask = (fib_info_hash_size - 1);

mask can be deleted, see below.

net/ipv4/fib_semantics.c static unsigned int fib_info_hashfn_1(int init_val, u8 protocol, u8 scope, · line 356

Quoted 4 lines
net/ipv4/fib_semantics.c +2 -0
+       val ^= net_hash_mix(net);
+
        return (val ^ (val >> 7) ^ (val >> 12)) & mask;

Please replace this legacy stuff with something more generic :

return hash_32(val ^ net_hash_mix(net), fib_info_hash_bits);

Quoted 6 lines
net/ipv4/fib_semantics.c +0 -0
 }
 
@@ -370,7 +372,7 @@ static inline unsigned int fib_info_hashfn(struct fib_info *fi)
                } endfor_nexthops(fi)
        }