diff mbox series

[net-next] net: Remove likely from l3mdev_master_ifindex_by_index

Message ID 20241008163205.3939629-1-leitao@debian.org (mailing list archive)
State Accepted
Commit 9e542ff8b79ae1871074d3a7dca7de9e7374eeda
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: Remove likely from l3mdev_master_ifindex_by_index | 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: 19 this patch: 19
netdev/build_tools success Errors and warnings before: 0 (+2) this patch: 0 (+2)
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 39 this patch: 39
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: 2620 this patch: 2620
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
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-10--09-00 (tests: 775)

Commit Message

Breno Leitao Oct. 8, 2024, 4:32 p.m. UTC
The likely() annotation in l3mdev_master_ifindex_by_index() has been
found to be incorrect 100% of the time in real-world workloads (e.g.,
web servers).

Annotated branches shows the following in these servers:

	correct incorrect  %        Function                  File              Line
	      0 169053813 100 l3mdev_master_ifindex_by_index l3mdev.h             81

This is happening because l3mdev_master_ifindex_by_index() is called
from __inet_check_established(), which calls
l3mdev_master_ifindex_by_index() passing the socked bounded interface.

	l3mdev_master_ifindex_by_index(net, sk->sk_bound_dev_if);

Since most sockets are not going to be bound to a network device,
the likely() is giving the wrong assumption.

Remove the likely() annotation to ensure more accurate branch
prediction.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 include/net/l3mdev.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

David Ahern Oct. 8, 2024, 6:25 p.m. UTC | #1
On 10/8/24 10:32 AM, Breno Leitao wrote:
> The likely() annotation in l3mdev_master_ifindex_by_index() has been
> found to be incorrect 100% of the time in real-world workloads (e.g.,
> web servers).
> 
> Annotated branches shows the following in these servers:
> 
> 	correct incorrect  %        Function                  File              Line
> 	      0 169053813 100 l3mdev_master_ifindex_by_index l3mdev.h             81
> 
> This is happening because l3mdev_master_ifindex_by_index() is called
> from __inet_check_established(), which calls
> l3mdev_master_ifindex_by_index() passing the socked bounded interface.
> 
> 	l3mdev_master_ifindex_by_index(net, sk->sk_bound_dev_if);
> 
> Since most sockets are not going to be bound to a network device,
> the likely() is giving the wrong assumption.
> 
> Remove the likely() annotation to ensure more accurate branch
> prediction.
> 
> Signed-off-by: Breno Leitao <leitao@debian.org>
> ---
>  include/net/l3mdev.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 

Reviewed-by: David Ahern <dsahern@kernel.org>
Eric Dumazet Oct. 9, 2024, 1:54 p.m. UTC | #2
On Tue, Oct 8, 2024 at 8:25 PM David Ahern <dsahern@kernel.org> wrote:
>
> On 10/8/24 10:32 AM, Breno Leitao wrote:
> > The likely() annotation in l3mdev_master_ifindex_by_index() has been
> > found to be incorrect 100% of the time in real-world workloads (e.g.,
> > web servers).
> >
> > Annotated branches shows the following in these servers:
> >
> >       correct incorrect  %        Function                  File              Line
> >             0 169053813 100 l3mdev_master_ifindex_by_index l3mdev.h             81
> >
> > This is happening because l3mdev_master_ifindex_by_index() is called
> > from __inet_check_established(), which calls
> > l3mdev_master_ifindex_by_index() passing the socked bounded interface.
> >
> >       l3mdev_master_ifindex_by_index(net, sk->sk_bound_dev_if);
> >
> > Since most sockets are not going to be bound to a network device,
> > the likely() is giving the wrong assumption.
> >
> > Remove the likely() annotation to ensure more accurate branch
> > prediction.
> >
> > Signed-off-by: Breno Leitao <leitao@debian.org>
> > ---
> >  include/net/l3mdev.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
>
> Reviewed-by: David Ahern <dsahern@kernel.org>

Reviewed-by: Eric Dumazet <edumazet@google.com>
patchwork-bot+netdevbpf@kernel.org Oct. 10, 2024, 10:20 a.m. UTC | #3
Hello:

This patch was applied to netdev/net-next.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Tue,  8 Oct 2024 09:32:04 -0700 you wrote:
> The likely() annotation in l3mdev_master_ifindex_by_index() has been
> found to be incorrect 100% of the time in real-world workloads (e.g.,
> web servers).
> 
> Annotated branches shows the following in these servers:
> 
> 	correct incorrect  %        Function                  File              Line
> 	      0 169053813 100 l3mdev_master_ifindex_by_index l3mdev.h             81
> 
> [...]

Here is the summary with links:
  - [net-next] net: Remove likely from l3mdev_master_ifindex_by_index
    https://git.kernel.org/netdev/net-next/c/9e542ff8b79a

You are awesome, thank you!
diff mbox series

Patch

diff --git a/include/net/l3mdev.h b/include/net/l3mdev.h
index 031c661aa14d..2d6141f28b53 100644
--- a/include/net/l3mdev.h
+++ b/include/net/l3mdev.h
@@ -78,7 +78,7 @@  static inline int l3mdev_master_ifindex_by_index(struct net *net, int ifindex)
 	struct net_device *dev;
 	int rc = 0;
 
-	if (likely(ifindex)) {
+	if (ifindex) {
 		rcu_read_lock();
 
 		dev = dev_get_by_index_rcu(net, ifindex);