diff mbox series

[net-next,v2] ipv4: avoid quadratic behavior in FIB insertion of common address

Message ID 20241001231438.3855035-1-alexandre.ferrieux@orange.com (mailing list archive)
State Accepted
Commit 9b8ca04854fd1253a58aeb1bd089c191cb5a074c
Delegated to: Netdev Maintainers
Headers show
Series [net-next,v2] ipv4: avoid quadratic behavior in FIB insertion of common address | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 9 this patch: 9
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 3 maintainers not CCed: pabeni@redhat.com kuba@kernel.org dsahern@kernel.org
netdev/build_clang success Errors and warnings before: 9 this patch: 9
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 7 this patch: 7
netdev/checkpatch warning WARNING: From:/Signed-off-by: email address mismatch: 'From: Alexandre Ferrieux <alexandre.ferrieux@gmail.com>' != 'Signed-off-by: Alexandre Ferrieux <alexandre.ferrieux@orange.com>'
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-10-03--18-00 (tests: 772)

Commit Message

Alexandre Ferrieux Oct. 1, 2024, 11:14 p.m. UTC
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>
---
 net/ipv4/fib_semantics.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

Comments

Eric Dumazet Oct. 2, 2024, 8:38 a.m. UTC | #1
On Wed, Oct 2, 2024 at 1:14 AM Alexandre Ferrieux
<alexandre.ferrieux@gmail.com> wrote:
>
> 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>

I guess we will have to use per-netns hash tables soon anyway.
Kuniyuki Iwashima Oct. 2, 2024, 2:10 p.m. UTC | #2
From: Eric Dumazet <edumazet@google.com>
Date: Wed, 2 Oct 2024 10:38:11 +0200
> On Wed, Oct 2, 2024 at 1:14 AM Alexandre Ferrieux
> <alexandre.ferrieux@gmail.com> wrote:
> >
> > 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>
> 
> I guess we will have to use per-netns hash tables soon anyway.

Yes, it's on my stash :)

Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
patchwork-bot+netdevbpf@kernel.org Oct. 3, 2024, 11:20 p.m. UTC | #3
Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed,  2 Oct 2024 01:14:38 +0200 you wrote:
> 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>
> ---
>  net/ipv4/fib_semantics.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)

Here is the summary with links:
  - [net-next,v2] ipv4: avoid quadratic behavior in FIB insertion of common address
    https://git.kernel.org/netdev/net-next/c/9b8ca04854fd

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
index ba2df3d2ac15..1a847ba40458 100644
--- a/net/ipv4/fib_semantics.c
+++ b/net/ipv4/fib_semantics.c
@@ -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) {