[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <fe952ad5-b0f3-4547-95c8-1126411c21d7@intel.com>
Date: Mon, 21 Oct 2024 16:10:30 +0200
From: Alexander Lobakin <aleksander.lobakin@...el.com>
To: Maciej Fijalkowski <maciej.fijalkowski@...el.com>
CC: "David S. Miller" <davem@...emloft.net>, Eric Dumazet
<edumazet@...gle.com>, Jakub Kicinski <kuba@...nel.org>, Paolo Abeni
<pabeni@...hat.com>, Toke Høiland-Jørgensen
<toke@...hat.com>, Alexei Starovoitov <ast@...nel.org>, Daniel Borkmann
<daniel@...earbox.net>, John Fastabend <john.fastabend@...il.com>, "Andrii
Nakryiko" <andrii@...nel.org>, Stanislav Fomichev <sdf@...ichev.me>, "Magnus
Karlsson" <magnus.karlsson@...el.com>,
<nex.sw.ncis.osdt.itp.upstreaming@...el.com>, <bpf@...r.kernel.org>,
<netdev@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH net-next v2 11/18] xdp: add generic xdp_buff_add_frag()
From: Maciej Fijalkowski <maciej.fijalkowski@...el.com>
Date: Thu, 17 Oct 2024 14:26:48 +0200
> On Tue, Oct 15, 2024 at 04:53:43PM +0200, Alexander Lobakin wrote:
>> The code piece which would attach a frag to &xdp_buff is almost
>> identical across the drivers supporting XDP multi-buffer on Rx.
>> Make it a generic elegant onelner.
>
> oneliner
>
>> Also, I see lots of drivers calculating frags_truesize as
>> `xdp->frame_sz * nr_frags`. I can't say this is fully correct, since
>> frags might be backed by chunks of different sizes, especially with
>> stuff like the header split. Even page_pool_alloc() can give you two
>> different truesizes on two subsequent requests to allocate the same
>> buffer size. Add a field to &skb_shared_info (unionized as there's no
>> free slot currently on x6_64) to track the "true" truesize. It can be
>
> x86_64
What a shame from these two typos >_<
>
>> used later when updating an skb.
[...]
>> +
>> + prev = &sinfo->frags[nr_frags - 1];
>> + if (try_coalesce && page == skb_frag_page(prev) &&
>> + offset == skb_frag_off(prev) + skb_frag_size(prev))
>> + skb_frag_size_add(prev, size);
>> + else
>> +fill:
>> + __skb_fill_page_desc_noacc(sinfo, nr_frags++, page,
>> + offset, size);
>> +
>> + sinfo->nr_frags = nr_frags;
>
> is it really necessary to work on local nr_frags instead of directly
> update it from sinfo?
I think you remember the difference when you started to work on ntu and
ntc locally instead of accessing the ring struct all the time? :>
>
>> + sinfo->xdp_frags_size += size;
>> + sinfo->xdp_frags_truesize += truesize;
>> +
>> + return true;
>> +}
[...]
>> @@ -230,7 +312,13 @@ xdp_update_skb_shared_info(struct sk_buff *skb, u8 nr_frags,
>> unsigned int size, unsigned int truesize,
>> bool pfmemalloc)
>> {
>> - skb_shinfo(skb)->nr_frags = nr_frags;
>> + struct skb_shared_info *sinfo = skb_shinfo(skb);
>> +
>> + sinfo->nr_frags = nr_frags;
>> + /* ``destructor_arg`` is unionized with ``xdp_frags_{,true}size``,
>> + * reset it after that these fields aren't used anymore.
>> + */
>> + sinfo->destructor_arg = NULL;
>
> wouldn't clearing size and truesize from union be more obvious?
But here we actually need to reset the destructor arg pointer.
size/truesize are not needed at this point anymore, but the arg can be
used/tested later, so I thought clearing it here is more clear to the
readers?
> OTOH it's one write vs two :)
Sometimes the compiler can optimize two subsequent writes (e.g. to addr
and addr + 4) into one bigger, but I wouldn't rely on it (that's why in
patch #18 I intensively use casts to u64).
>
>>
>> skb->len += size;
>> skb->data_len += size;
>> --
>> 2.46.2
Thanks,
Olek
Powered by blists - more mailing lists