Re: [PATCH RFC net-next v4 6/9] iavf: switch to Page Pool

From: Yunsheng Lin
Date: Sun Jul 09 2023 - 01:17:03 EST


On 2023/7/7 0:38, Alexander Lobakin wrote:

...

>>
>>> /**
>>> @@ -766,13 +742,19 @@ void iavf_free_rx_resources(struct iavf_ring *rx_ring)
>>> **/
>>> int iavf_setup_rx_descriptors(struct iavf_ring *rx_ring)
>>> {
>>> - struct device *dev = rx_ring->dev;
>>> - int bi_size;
>>> + struct page_pool *pool;
>>> +
>>> + pool = libie_rx_page_pool_create(&rx_ring->q_vector->napi,
>>> + rx_ring->count);
>>
>> If a page is able to be spilt between more than one desc, perhaps the
>> prt_ring size does not need to be as big as rx_ring->count.
>
> But we doesn't know in advance, right? Esp. given that it's hidden in
> the lib. But anyway, you can only assume that in regular cases if you
> always allocate frags of the same size, PP will split pages when 2+
> frags can fit there or return the whole page otherwise, but who knows
> what might happen.

It seems intel driver is able to know the size of memory it needs when
creating the ring/queue/napi/pp, maybe the driver only tell the libie
how many descs does it use for queue, and libie can adjust it accordingly?

> BTW, with recent recycling optimization, most of recycling is done
> directly through cache, not ptr_ring. So I'd even say it's safe to start
> creating smaller ptr_rings in the drivers.

The problem is that we may use more memory than before for certain case
if we don't limit the size of ptr_ring, unless we can ensure all of
recycling is done directly through cache, not ptr_ring.

>
>>
>>> + if (IS_ERR(pool))
>>> + return PTR_ERR(pool);
>>> +
>>> + rx_ring->pp = pool;
>
> [...]
>
>>> /* build an skb around the page buffer */
>>> - skb = napi_build_skb(va - IAVF_SKB_PAD, truesize);
>>> - if (unlikely(!skb))
>>> + skb = napi_build_skb(va, rx_buffer->truesize);
>>> + if (unlikely(!skb)) {
>>> + page_pool_put_page(page->pp, page, size, true);
>>
>> Isn't it more correct to call page_pool_put_full_page() here?
>> as we do not know which frag is used for the rx_buffer, and depend
>> on the last released frag to do the syncing, maybe I should mention
>> that in Documentation/networking/page_pool.rst.
>
> Ooof, maybe. My first try with PP frags. So when we use frags, we always
> must use _full_page() / p.max_len instead of the actual frame size?

Currently, _full_page() / p.max_len must be used to ensure the correct
dma sync operation.
But as mentioned in the previous patch, it might be about what is the
semantics of dma sync operation for page split case.

>