mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-01 02:36:02 +00:00
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. Signed-off-by: Alexandre Ferrieux <alexandre.ferrieux@orange.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com> Link: https://patch.msgid.link/20241001231438.3855035-1-alexandre.ferrieux@orange.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
35d8471e24
commit
9b8ca04854
@ -347,11 +347,10 @@ 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(const struct net *net,
|
||||
unsigned int val)
|
||||
{
|
||||
unsigned int mask = (fib_info_hash_size - 1);
|
||||
|
||||
return (val ^ (val >> 7) ^ (val >> 12)) & mask;
|
||||
return hash_32(val ^ net_hash_mix(net), fib_info_hash_bits);
|
||||
}
|
||||
|
||||
static inline unsigned int fib_info_hashfn(struct fib_info *fi)
|
||||
@ -370,7 +369,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 +384,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) {
|
||||
|
Loading…
Reference in New Issue
Block a user