mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Pavel Begunkov <asml.silence@gmail.com>
To: Mina Almasry <almasrymina@google.com>, Byungchul Park <byungchul@sk.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org, hawk@kernel.org,
	toke@redhat.com
Subject: Re: [RFC net-next] netmem: replace __netmem_clear_lsb() with netmem_to_nmdesc()
Date: Mon, 28 Jul 2025 19:58:13 +0100	[thread overview]
Message-ID: <087ca43a-49b7-40c9-915d-558075181fd1@gmail.com> (raw)
In-Reply-To: <b239b40b-0abe-43a5-af41-346283a634f6@gmail.com>

On 7/28/25 19:46, Pavel Begunkov wrote:
> On 7/28/25 18:44, Mina Almasry wrote:
>> On Sun, Jul 27, 2025 at 9:21 PM Byungchul Park <byungchul@sk.com> wrote:
>>>
> 
> ...>> - * Return: the netmem_ref cast to net_iov* regardless of its underlying type.
>>> + * Return: the pointer to struct netmem_desc * regardless of its
>>> + * underlying type.
>>>    */
>>> -static inline struct net_iov *__netmem_clear_lsb(netmem_ref netmem)
>>> +static inline struct netmem_desc *netmem_to_nmdesc(netmem_ref netmem)
>>>   {
>>> -       return (struct net_iov *)((__force unsigned long)netmem & ~NET_IOV);
>>> +       if (netmem_is_net_iov(netmem))
>>> +               return &((struct net_iov *)((__force unsigned long)netmem &
>>> +                                           ~NET_IOV))->desc;
>>> +
>>> +       return __netmem_to_nmdesc(netmem);
>>
>> The if statement generates overhead. I'd rather avoid it. We can
>> implement netmem_to_nmdesc like this, no?
>>
>> netmem_to_nmdesc(netmem_ref netmem)
>> {
>>    return (struct netmem_desc)((__force unsigned long)netmem & ~NET_IOV);
>> }
>>
>> Because netmem_desc is the first element in both net_iov and page for
>> the moment. (yes I know that will change eventually, but we don't have
>> to incur overhead of an extra if statement until netmem_desc is
>> removed from page, right?)
> 
> Same concern, but I think the goal here should be to make enough

s/make/give/


> info to the compiler to optimise it out without assumptions on
> the layouts nor NET_IOV_ASSERT_OFFSET. Currently it's not so bad,
> but we should be able to remove this test+cmove.
> 
>      movq    %rdi, %rax    # netmem, tmp105
>      andq    $-2, %rax    #, tmp105
>      testb    $1, %dil    #, netmem
>      cmove    %rdi, %rax    # tmp105,, netmem, <retval>
>      jmp    __x86_return_thunk

struct netmem_desc *netmem_to_nmdesc(netmem_ref netmem)
{
	void *p = (void *)((__force unsigned long)netmem & ~NET_IOV);

	if (netmem_is_net_iov(netmem))
		return &((struct net_iov *)p)->desc;
	return __pp_page_to_nmdesc((struct page *)p);
}

movq	%rdi, %rax	# netmem, netmem
andq	$-2, %rax	#, netmem
jmp	__x86_return_thunk


This should do it, and if the layouts change, it'd still
remain correct.

-- 
Pavel Begunkov


  reply	other threads:[~2025-07-28 18:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-28  4:20 Byungchul Park
2025-07-28  5:35 ` Byungchul Park
2025-07-28 17:44 ` Mina Almasry
2025-07-28 18:46   ` Pavel Begunkov
2025-07-28 18:58     ` Pavel Begunkov [this message]
2025-07-29  1:17       ` Byungchul Park
2025-07-29  9:11         ` Pavel Begunkov
2025-07-29  1:10   ` Byungchul Park

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=087ca43a-49b7-40c9-915d-558075181fd1@gmail.com \
    --to=asml.silence@gmail.com \
    --cc=almasrymina@google.com \
    --cc=byungchul@sk.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hawk@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=toke@redhat.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®