From: Paolo Abeni <pabeni@redhat.com>
To: Breno Leitao <leitao@debian.org>, David Ahern <dsahern@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
rmikey@meta.com, kernel-team@meta.com, horms@kernel.org,
"open list:NETWORKING [IPv4/IPv6]" <netdev@vger.kernel.org>,
open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH net-next] net: Optimize IPv6 path in ip_neigh_for_gw()
Date: Tue, 8 Oct 2024 12:51:05 +0200 [thread overview]
Message-ID: <759f82f0-0498-466c-a4c2-a87a86e06315@redhat.com> (raw)
In-Reply-To: <20241004-straight-prompt-auk-ada09a@leitao>
On 10/4/24 19:37, Breno Leitao wrote:
> On Fri, Oct 04, 2024 at 11:01:29AM -0600, David Ahern wrote:
>> On 10/4/24 10:27 AM, Breno Leitao wrote:
>>> Branch annotation traces from approximately 200 IPv6-enabled hosts
>>> revealed that the 'likely' branch in ip_neigh_for_gw() was consistently
>>> mispredicted. Given the increasing prevalence of IPv6 in modern networks,
>>> this commit adjusts the function to favor the IPv6 path.
>>>
>>> Swap the order of the conditional statements and move the 'likely'
>>> annotation to the IPv6 case. This change aims to improve performance in
>>> IPv6-dominant environments by reducing branch mispredictions.
>>>
>>> This optimization aligns with the trend of IPv6 becoming the default IP
>>> version in many deployments, and should benefit modern network
>>> configurations.
>>>
>>> Signed-off-by: Breno Leitao <leitao@debian.org>
>>> ---
>>> include/net/route.h | 6 +++---
>>> 1 file changed, 3 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/include/net/route.h b/include/net/route.h
>>> index 1789f1e6640b..b90b7b1effb8 100644
>>> --- a/include/net/route.h
>>> +++ b/include/net/route.h
>>> @@ -389,11 +389,11 @@ static inline struct neighbour *ip_neigh_for_gw(struct rtable *rt,
>>> struct net_device *dev = rt->dst.dev;
>>> struct neighbour *neigh;
>>>
>>> - if (likely(rt->rt_gw_family == AF_INET)) {
>>> - neigh = ip_neigh_gw4(dev, rt->rt_gw4);
>>> - } else if (rt->rt_gw_family == AF_INET6) {
>>> + if (likely(rt->rt_gw_family == AF_INET6)) {
>>> neigh = ip_neigh_gw6(dev, &rt->rt_gw6);
>>> *is_v6gw = true;
>>> + } else if (rt->rt_gw_family == AF_INET) {
>>> + neigh = ip_neigh_gw4(dev, rt->rt_gw4);
>>> } else {
>>> neigh = ip_neigh_gw4(dev, ip_hdr(skb)->daddr);
>>> }
>>
>> This is an IPv4 function allowing support for IPv6 addresses as a
>> nexthop. It is appropriate for IPv4 family checks to be first.
>
> Right. In which case is this called on IPv6 only systems?
>
> On my IPv6-only 200 systems, the annotated branch predictor is showing
> it is mispredicted 100% of the time.
perf probe -a ip_neigh_for_gw; perf record -e probe:ip_neigh_for_gw -ag;
perf script
should give you an hint.
Cheers,
Paolo
next prev parent reply other threads:[~2024-10-08 10:51 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-04 16:27 Breno Leitao
2024-10-04 17:01 ` David Ahern
2024-10-04 17:37 ` Breno Leitao
2024-10-08 10:51 ` Paolo Abeni [this message]
2024-10-08 14:07 ` Breno Leitao
2024-10-08 14:15 ` Eric Dumazet
2024-10-08 14:48 ` Breno Leitao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=759f82f0-0498-466c-a4c2-a87a86e06315@redhat.com \
--to=pabeni@redhat.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kernel-team@meta.com \
--cc=kuba@kernel.org \
--cc=leitao@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=rmikey@meta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®