netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC net-next] net: page_pool: fix recycle stats for percpu page_pool allocator
@ 2024-02-14 18:08 Lorenzo Bianconi
  2024-02-14 21:42 ` Toke Høiland-Jørgensen
  2024-02-15 13:41 ` Alexander Lobakin
  0 siblings, 2 replies; 7+ messages in thread
From: Lorenzo Bianconi @ 2024-02-14 18:08 UTC (permalink / raw)
  To: netdev
  Cc: lorenzo.bianconi, kuba, davem, edumazet, pabeni, hawk,
	ilias.apalodimas, linyunsheng, toke

Use global page_pool_recycle_stats percpu counter for percpu page_pool
allocator.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 net/core/page_pool.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/net/core/page_pool.c b/net/core/page_pool.c
index 6e0753e6a95b..1bb83b6e7a61 100644
--- a/net/core/page_pool.c
+++ b/net/core/page_pool.c
@@ -31,6 +31,8 @@
 #define BIAS_MAX	(LONG_MAX >> 1)
 
 #ifdef CONFIG_PAGE_POOL_STATS
+static DEFINE_PER_CPU(struct page_pool_recycle_stats, pp_recycle_stats);
+
 /* alloc_stat_inc is intended to be used in softirq context */
 #define alloc_stat_inc(pool, __stat)	(pool->alloc_stats.__stat++)
 /* recycle_stat_inc is safe to use when preemption is possible. */
@@ -220,14 +222,19 @@ static int page_pool_init(struct page_pool *pool,
 	pool->has_init_callback = !!pool->slow.init_callback;
 
 #ifdef CONFIG_PAGE_POOL_STATS
-	pool->recycle_stats = alloc_percpu(struct page_pool_recycle_stats);
-	if (!pool->recycle_stats)
-		return -ENOMEM;
+	if (cpuid < 0) {
+		pool->recycle_stats = alloc_percpu(struct page_pool_recycle_stats);
+		if (!pool->recycle_stats)
+			return -ENOMEM;
+	} else {
+		pool->recycle_stats = &pp_recycle_stats;
+	}
 #endif
 
 	if (ptr_ring_init(&pool->ring, ring_qsize, GFP_KERNEL) < 0) {
 #ifdef CONFIG_PAGE_POOL_STATS
-		free_percpu(pool->recycle_stats);
+		if (cpuid < 0)
+			free_percpu(pool->recycle_stats);
 #endif
 		return -ENOMEM;
 	}
@@ -251,7 +258,8 @@ static void page_pool_uninit(struct page_pool *pool)
 		put_device(pool->p.dev);
 
 #ifdef CONFIG_PAGE_POOL_STATS
-	free_percpu(pool->recycle_stats);
+	if (pool->cpuid < 0)
+		free_percpu(pool->recycle_stats);
 #endif
 }
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-02-15 15:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-14 18:08 [RFC net-next] net: page_pool: fix recycle stats for percpu page_pool allocator Lorenzo Bianconi
2024-02-14 21:42 ` Toke Høiland-Jørgensen
2024-02-14 22:46   ` Lorenzo Bianconi
2024-02-15 13:41 ` Alexander Lobakin
2024-02-15 13:51   ` Lorenzo Bianconi
2024-02-15 15:04   ` Jakub Kicinski
2024-02-15 15:31     ` Lorenzo Bianconi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).