Re: [PATCH net-next 1/4] tun: rcu_deference xdp_prog only once per batch

From: Jon Kohler
Date: Thu May 08 2025 - 09:41:31 EST




> On May 8, 2025, at 9:31 AM, Willem de Bruijn <willemdebruijn.kernel@xxxxxxxxx> wrote:
>
> !-------------------------------------------------------------------|
> CAUTION: External Email
>
> |-------------------------------------------------------------------!
>
> Jon Kohler wrote:
>>
>>
>>> On May 7, 2025, at 4:43 PM, Willem de Bruijn <willemdebruijn.kernel@xxxxxxxxx> wrote:
>>>
>>> !-------------------------------------------------------------------|
>>> CAUTION: External Email
>>>
>>> |-------------------------------------------------------------------!
>>>
>>> Jon Kohler wrote:
>>>> Hoist rcu_dereference(tun->xdp_prog) out of tun_xdp_one, so that
>>>> rcu_deference is called once during batch processing.
>>>
>>> I'm skeptical that this does anything.
>>>
>>> The compiler can inline tun_xdp_one and indeed seems to do so. And
>>> then it can cache the read in a register if that is the best use of
>>> a register.
>>
>> The thought here is that if a compiler decided to not-inline tun_xdp_one
>> (perhaps it grew to big, or the compiler was being sassy), that the intent
>> would simply be that this wants to be called once-and-only-once. This
>> change just makes that intent more clear, and is a nice little cleanup.
>>
>> I’ve got a series that stacks on top of this that enables multi-buffer support
>> and I can keep an eye on if that gets inlined or not.
>
> That will only give you one outcome with a specific compiler, platform
> and build configuration.
>
> I would just drop this and let the compiler handle such optimizations.

Ok, thanks for the feedback, will do