Linux Documentation
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: nashuiliang@gmail.com
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org, corbet@lwn.net,
	skhan@linuxfoundation.org, sdf.kernel@gmail.com,
	daniel@iogearbox.net, kuniyu@google.com, netdev@vger.kernel.org,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next v13] net: reduce ARFS flow updates by checking LLC affinity
Date: Tue, 17 Nov 2026 13:24:18 +0000	[thread overview]
Message-ID: <179492185829.3136.8645050662806185449@kernel.org> (raw)
In-Reply-To: <20261113125643.2255-1-nashuiliang@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] With net.core.arfs_llc_affinity enabled, the new early `goto
  out` in set_rps_cpu() (net/core/dev.c:5301-5305) can skip…
- [Low] Commit message / documentation completeness (baseline: not
  confirmed as a defect).

--

net: reduce ARFS flow updates by checking LLC affinity

This patch adds a default-off sysctl, net.core.arfs_llc_affinity. When it
is enabled, set_rps_cpu() does not call ndo_rx_flow_steer() if the flow's
previous RFS target CPU and the new one share an LLC. The per-queue
rflow->cpu is still updated, so software RFS keeps following the
application.

> diff --git a/Documentation/networking/scaling.rst b/Documentation/networking/scaling.rst
> index 6c9836000a8d1..d85fe7a9e9bfb 100644
> --- a/Documentation/networking/scaling.rst
> +++ b/Documentation/networking/scaling.rst
> @@ -468,6 +468,15 @@ of CPU to queues is automatically deduced from the IRQ affinities
>  configured for each receive queue by the driver, so no additional
>  configuration should be necessary.
>  
> +When the flow's previous target CPU and the new target CPU share the
> +last level cache (LLC), the hardware steering update can be skipped,
> +since the application's cache locality is preserved either way. This
> +reduces contention on driver-internal locks when application threads
> +migrate frequently between CPUs sharing an LLC. The functionality
> +remains disabled until explicitly enabled through::
> +
> +  /proc/sys/net/core/arfs_llc_affinity
> +

[Severity: Low]

This isn't a bug, but the text gives the condition only as the previous
and new target CPU sharing the LLC. The code in set_rps_cpu() has two more
requirements: old_cpu must be online, and rflow->filter must not be
RPS_NO_FILTER.

Could the documentation mention these? It could also say that after a
skip, packets keep arriving on the old queue and are RPS-forwarded to the
application CPU.

[ ... ]

> diff --git a/net/core/dev.c b/net/core/dev.c
> index a230ecce9327d..15a5c7caaf8e8 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c

[ ... ]

> @@ -5274,7 +5278,7 @@ static bool rps_flow_is_active(struct rps_dev_flow *rflow,
>  
>  static struct rps_dev_flow *
>  set_rps_cpu(struct net_device *dev, struct sk_buff *skb,
> -	    struct rps_dev_flow *rflow, u16 next_cpu, u32 hash)
> +	    struct rps_dev_flow *rflow, u16 old_cpu, u16 next_cpu, u32 hash)
>  {
>  	if (next_cpu < nr_cpu_ids) {
>  		u32 head;
> @@ -5293,6 +5297,13 @@ set_rps_cpu(struct net_device *dev, struct sk_buff *skb,
>  		if (!skb_rx_queue_recorded(skb) || !dev->rx_cpu_rmap ||
>  		    !(dev->features & NETIF_F_NTUPLE))
>  			goto out;
> +
> +		if (static_branch_unlikely(&arfs_llc_affinity) &&
> +		    old_cpu < nr_cpu_ids && cpu_online(old_cpu) &&
> +		    cpus_share_cache(old_cpu, next_cpu) &&
> +		    READ_ONCE(rflow->filter) != RPS_NO_FILTER)
> +			goto out;
> +

[Severity: Medium]

Can this skip ndo_rx_flow_steer() even when the NIC is not delivering the
flow anywhere near next_cpu?

old_cpu is tcpu from get_rps_cpu(), which is rflow->cpu, the last software
RFS target. That is not necessarily the CPU that services the queue the
hardware filter delivers to.

The rflow->filter != RPS_NO_FILTER test is also not checked against
rflow->hash or rps_flow_is_active(). The existing tmp_rflow check further
down in set_rps_cpu() does both.

set_rps_cpu() writes rflow->cpu on every exit, including the paths where
no hardware steering happened:

    q_tag_ptr = READ_ONCE(rxqueue->rps_flow_table);
    if (!q_tag_ptr)
        goto out;
    ...
        if (hash != READ_ONCE(tmp_rflow->hash) ||
            next_cpu == tmp_cpu)
            goto out;
    ...
    rc = dev->netdev_ops->ndo_rx_flow_steer(dev, skb,
                                            rxq_index, flow_id);
    if (rc < 0)
        goto out;
    ...
out:
    ...
    WRITE_ONCE(rflow->cpu, next_cpu);

On those paths rflow is still the arrival queue's entry. Its filter keeps
the old filter id, but its cpu moves to the new CPU. For example,
mlx5e_rx_flow_steer() can return -ENOMEM, -EPERM or -EPROTONOSUPPORT.

Consider this sequence:

1. Flow F has filter f steering it to queue Q near LLC-A. Q's entry is
   {filter = f, cpu = cA}.

2. The application moves to cB in LLC-B. cpus_share_cache(cA, cB) is
   false, so steering towards rmap(cB) is attempted, but it fails on one
   of the paths above. Q's entry becomes {filter = f, cpu = cB}, while
   the NIC still delivers F to Q.

3. The application moves to cB' in LLC-B. cpus_share_cache(cB, cB') is
   true and filter == f, so steering is skipped.

4. get_rps_cpu() only calls set_rps_cpu() when rflow->cpu != next_cpu, so
   every later move inside LLC-B is skipped as well.

After that, would every packet be RPS-forwarded from Q's CPU in LLC-A to
the application in LLC-B, with the hardware filter never retried? Before
this patch, each migration retried steering. A retry could succeed once
the colliding filter had expired or memory was available again.

The filter id can also be stale or belong to another flow:

- RPS_NO_FILTER is only written at table allocation and when
  old_rflow->filter == rc.
- rps_may_expire_flow() only reports expiry to the driver. Nothing clears
  rflow->filter after the driver deletes the rule.
- A colliding flow's filter in the same rfs_slot() would also pass this
  check.

Changing IRQ affinity also changes the queue-to-CPU mapping without
touching rflow->cpu.

This seems to conflict with the claim in the commit message and
scaling.rst that "cache locality for the application is preserved either
way".

Would it make sense to also require READ_ONCE(rflow->hash) == hash and an
activity check? Another option is to compare next_cpu with the CPU that
services the arrival queue (skb_get_rx_queue(skb)), or with
smp_processor_id(), instead of rflow->cpu.

>  		rxq_index = cpu_rmap_lookup_index(dev->rx_cpu_rmap, next_cpu);
>  		if (rxq_index == skb_get_rx_queue(skb))
>  			goto out;

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113125643.2255-1-nashuiliang%40gmail.com

      reply	other threads:[~2026-11-17 13:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13 12:56 [PATCH net-next v13] net: reduce ARFS flow updates by checking LLC affinity Chuang Wang
2026-11-17 13:24 ` netdev-bot+sashiko [this message]

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=179492185829.3136.8645050662806185449@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=corbet@lwn.net \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nashuiliang@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf.kernel@gmail.com \
    --cc=skhan@linuxfoundation.org \
    /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