Skip to content

Commit e54cfd7

Browse files
netoptimizerdavem330
authored andcommitted
page_pool: introduce page_pool_free and use in mlx5
In case driver fails to register the page_pool with XDP return API (via xdp_rxq_info_reg_mem_model()), then the driver can free the page_pool resources more directly than calling page_pool_destroy(), which does a unnecessarily RCU free procedure. This patch is preparing for removing page_pool_destroy(), from driver invocation. Signed-off-by: Jesper Dangaard Brouer <[email protected]> Reviewed-by: Tariq Toukan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent cbf3351 commit e54cfd7

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en_main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,10 @@ static int mlx5e_alloc_rq(struct mlx5e_channel *c,
545545
}
546546
err = xdp_rxq_info_reg_mem_model(&rq->xdp_rxq,
547547
MEM_TYPE_PAGE_POOL, rq->page_pool);
548-
if (err)
548+
if (err) {
549+
page_pool_free(rq->page_pool);
549550
goto err_free;
551+
}
550552

551553
for (i = 0; i < wq_sz; i++) {
552554
if (rq->wq_type == MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ) {
@@ -611,8 +613,6 @@ static int mlx5e_alloc_rq(struct mlx5e_channel *c,
611613
if (rq->xdp_prog)
612614
bpf_prog_put(rq->xdp_prog);
613615
xdp_rxq_info_unreg(&rq->xdp_rxq);
614-
if (rq->page_pool)
615-
page_pool_destroy(rq->page_pool);
616616
mlx5_wq_destroy(&rq->wq_ctrl);
617617

618618
return err;

include/net/page_pool.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,17 @@ struct page_pool *page_pool_create(const struct page_pool_params *params);
111111

112112
void page_pool_destroy(struct page_pool *pool);
113113

114+
void __page_pool_free(struct page_pool *pool);
115+
static inline void page_pool_free(struct page_pool *pool)
116+
{
117+
/* When page_pool isn't compiled-in, net/core/xdp.c doesn't
118+
* allow registering MEM_TYPE_PAGE_POOL, but shield linker.
119+
*/
120+
#ifdef CONFIG_PAGE_POOL
121+
__page_pool_free(pool);
122+
#endif
123+
}
124+
114125
/* Never call this directly, use helpers below */
115126
void __page_pool_put_page(struct page_pool *pool,
116127
struct page *page, bool allow_direct);

net/core/page_pool.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,17 +292,24 @@ static void __page_pool_empty_ring(struct page_pool *pool)
292292
}
293293
}
294294

295+
void __page_pool_free(struct page_pool *pool)
296+
{
297+
WARN(pool->alloc.count, "API usage violation");
298+
WARN(!ptr_ring_empty(&pool->ring), "ptr_ring is not empty");
299+
300+
ptr_ring_cleanup(&pool->ring, NULL);
301+
kfree(pool);
302+
}
303+
EXPORT_SYMBOL(__page_pool_free);
304+
295305
static void __page_pool_destroy_rcu(struct rcu_head *rcu)
296306
{
297307
struct page_pool *pool;
298308

299309
pool = container_of(rcu, struct page_pool, rcu);
300310

301-
WARN(pool->alloc.count, "API usage violation");
302-
303311
__page_pool_empty_ring(pool);
304-
ptr_ring_cleanup(&pool->ring, NULL);
305-
kfree(pool);
312+
__page_pool_free(pool);
306313
}
307314

308315
/* Cleanup and release resources */

0 commit comments

Comments
 (0)