[RFC v3 03/18] page_pool: use netmem alloc/put APIs in __page_pool_alloc_page_order()

Byungchul Park
2025-05-29T03:11:05Z

Use netmem alloc/put APIs instead of page alloc/put APIs and make it
return netmem_ref instead of struct page * in
__page_pool_alloc_page_order().

Signed-off-by: Byungchul Park <byungchul@sk.com>
Reviewed-by: Mina Almasry <almasrymina@google.com>
---
net/core/page_pool.c | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/net/core/page_pool.c b/net/core/page_pool.c
index 974f3eef2efa..e101c39d65c7 100644
--- a/net/core/page_pool.c
+++ b/net/core/page_pool.c
@@ -518,29 +518,29 @@ static bool page_pool_dma_map(struct page_pool *pool, netmem_ref netmem, gfp_t g
return false;
}

-static struct page *__page_pool_alloc_page_order(struct page_pool *pool,
- gfp_t gfp)
+static netmem_ref __page_pool_alloc_page_order(struct page_pool *pool,
+ gfp_t gfp)
{
- struct page *page;
+ netmem_ref netmem;

gfp |= __GFP_COMP;
- page = alloc_pages_node(pool->p.nid, gfp, pool->p.order);
- if (unlikely(!page))
- return NULL;
+ netmem = alloc_netmems_node(pool->p.nid, gfp, pool->p.order);
+ if (unlikely(!netmem))
+ return 0;

- if (pool->dma_map && unlikely(!page_pool_dma_map(pool, page_to_netmem(page), gfp))) {
- put_page(page);
- return NULL;
+ if (pool->dma_map && unlikely(!page_pool_dma_map(pool, netmem, gfp))) {
+ put_netmem(netmem);
+ return 0;
}

alloc_stat_inc(pool, slow_high_order);
- page_pool_set_pp_info(pool, page_to_netmem(page));
+ page_pool_set_pp_info(pool, netmem);

/* Track how many pages are held 'in-flight' */
pool->pages_state_hold_cnt++;
- trace_page_pool_state_hold(pool, page_to_netmem(page),
+ trace_page_pool_state_hold(pool, netmem,
pool->pages_state_hold_cnt);
- return page;
+ return netmem;
}

/* slow path */
@@ -555,7 +555,7 @@ static noinline netmem_ref __page_pool_alloc_pages_slow(struct page_pool *pool,

/* Don't support bulk alloc for high-order pages */
if (unlikely(pp_order))
- return page_to_netmem(__page_pool_alloc_page_order(pool, gfp));
+ return __page_pool_alloc_page_order(pool, gfp);

/* Unnecessary as alloc cache is empty, but guarantees zero count */
if (unlikely(pool->alloc.count > 0))
--
2.17.1