mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yunsheng Lin <linyunsheng@huawei.com>
To: Jesper Dangaard Brouer <hawk@kernel.org>, <davem@davemloft.net>,
	<kuba@kernel.org>, <pabeni@redhat.com>
Cc: <zhangkun09@huawei.com>, <liuyonglong@huawei.com>,
	<fanghaiqing@huawei.com>, Robin Murphy <robin.murphy@arm.com>,
	Alexander Duyck <alexander.duyck@gmail.com>,
	IOMMU <iommu@lists.linux.dev>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Eric Dumazet <edumazet@google.com>,
	Simon Horman <horms@kernel.org>, <netdev@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH net-next v9 3/4] page_pool: support unlimited number of inflight pages
Date: Sat, 22 Feb 2025 16:11:51 +0800	[thread overview]
Message-ID: <24321916-549d-4b76-8ca5-a268432f54e7@huawei.com> (raw)
In-Reply-To: <640946c8-237d-40de-b64e-0f8fd8f1a600@kernel.org>

On 2025/2/21 18:12, Jesper Dangaard Brouer wrote:

...

>> @@ -513,10 +517,43 @@ static struct page_pool_item *page_pool_fast_item_alloc(struct page_pool *pool)
>>       return llist_entry(first, struct page_pool_item, lentry);
>>   }
>>   +#define PAGE_POOL_SLOW_ITEM_BLOCK_BIT            BIT(0)
>> +static struct page_pool_item *page_pool_slow_item_alloc(struct page_pool *pool)
>> +{
>> +    if (unlikely(!pool->slow_items.block ||
>> +             pool->slow_items.next_to_use >= ITEMS_PER_PAGE)) {
>> +        struct page_pool_item_block *block;
>> +        struct page *page;
>> +
>> +        page = alloc_pages_node(pool->p.nid, GFP_ATOMIC | __GFP_NOWARN |
>> +                    __GFP_ZERO, 0);
>> +        if (!page) {
>> +            alloc_stat_inc(pool, item_slow_failed);
>> +            return NULL;
>> +        }
> 
> We also need stats on how many pages we allocate for these item_blocks
> (and later free). This new scheme of keeping track of all pages
> allocated via page_pool, is obviously going to consume more memory.
> 
> I want to be able to find out how much memory a page_pool is consuming.
> (E.g. Kuba added a nice interface for querying inflight packets, even
> though this is kept as two different counters).

Does additional stats is needed? as I was thinking list_for_each_entry()
for pool->item_blocks might be used to tell how much memory it is used
for slow item, and how much each item_block is fragmented by looking at
the block->ref with the protection of pool->item_lock if needed.

> 
> What I worry about, is that fragmentation happens inside these
> item_blocks. (I hope you understand what I mean by fragmentation, else
> let me know).
> 
> Could you explain how code handles or avoids fragmentation?

Currently fragmentation is not handled or avoided yet.
For inflight pages which are using slow item, it seems there is hardly
anything we can do about that.

For pages which sit in the page_pool, it seems possible to change
the pages using slow item to use fast item when they are allocated
from or recycled back into page_pool if fast item is available, or
those pages are simply disconnected from page_pool by calling
page_pool_return_page() when page_pool_put_unrefed_netmem() is
called?

I am not sure how severe the fragmentation problem might become and
which way to handle it is better, maybe add interface to query the
fragmentation info as mentioned above first, and deal with it when
it does become a severe problem?

> 
> 
>> +
>> +        block = page_address(page);
>> +        block->pp = pool;
>> +        block->flags |= PAGE_POOL_SLOW_ITEM_BLOCK_BIT;
>> +        refcount_set(&block->ref, ITEMS_PER_PAGE);
>> +        pool->slow_items.block = block;
>> +        pool->slow_items.next_to_use = 0;
>> +
>> +        spin_lock_bh(&pool->item_lock);
>> +        list_add(&block->list, &pool->item_blocks);
>> +        spin_unlock_bh(&pool->item_lock);
>> +    }
>> +
>> +    return &pool->slow_items.block->items[pool->slow_items.next_to_use++];
>> +}
>> +

  reply	other threads:[~2025-02-22  8:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-12  9:25 [PATCH net-next v9 0/4] fix the DMA API misuse problem for page_pool Yunsheng Lin
2025-02-12  9:25 ` [PATCH net-next v9 1/4] page_pool: introduce page_pool_get_pp() API Yunsheng Lin
2025-02-12  9:25 ` [PATCH net-next v9 2/4] page_pool: fix IOMMU crash when driver has already unbound Yunsheng Lin
2025-02-14 20:58   ` Mina Almasry
2025-02-15 12:13     ` Yunsheng Lin
2025-02-12  9:25 ` [PATCH net-next v9 3/4] page_pool: support unlimited number of inflight pages Yunsheng Lin
2025-02-21 10:12   ` Jesper Dangaard Brouer
2025-02-22  8:11     ` Yunsheng Lin [this message]
2025-02-12  9:25 ` [PATCH net-next v9 4/4] page_pool: skip dma sync operation for " Yunsheng Lin
2025-02-12 18:53 ` [PATCH net-next v9 0/4] fix the DMA API misuse problem for page_pool Matthew Wilcox
2025-02-13 11:13   ` Yunsheng Lin

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=24321916-549d-4b76-8ca5-a268432f54e7@huawei.com \
    --to=linyunsheng@huawei.com \
    --cc=alexander.duyck@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=fanghaiqing@huawei.com \
    --cc=hawk@kernel.org \
    --cc=horms@kernel.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=iommu@lists.linux.dev \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liuyonglong@huawei.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=robin.murphy@arm.com \
    --cc=zhangkun09@huawei.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®