netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] net: page_pool: add pages and released_pages counters
@ 2023-04-13 21:46 Lorenzo Bianconi
  2023-04-15  1:46 ` Jakub Kicinski
  0 siblings, 1 reply; 7+ messages in thread
From: Lorenzo Bianconi @ 2023-04-13 21:46 UTC (permalink / raw)
  To: netdev
  Cc: hawk, ilias.apalodimas, davem, edumazet, kuba, pabeni,
	lorenzo.bianconi, jdamato

Introduce pages and released_pages counters to page_pool ethtool stats
in order to track the number of allocated and released pages from the
pool.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 Documentation/networking/page_pool.rst | 2 ++
 include/net/page_pool.h                | 2 ++
 net/core/page_pool.c                   | 8 ++++++++
 3 files changed, 12 insertions(+)

diff --git a/Documentation/networking/page_pool.rst b/Documentation/networking/page_pool.rst
index 30f1344e7cca..71b3eb4555f1 100644
--- a/Documentation/networking/page_pool.rst
+++ b/Documentation/networking/page_pool.rst
@@ -138,6 +138,7 @@ The ``struct page_pool_alloc_stats`` has the following fields:
   * ``refill``: an allocation which triggered a refill of the cache
   * ``waive``: pages obtained from the ptr ring that cannot be added to
     the cache due to a NUMA mismatch.
+  * ``pages``: number of allocated pages to the pool
 
 The ``struct page_pool_recycle_stats`` has the following fields:
   * ``cached``: recycling placed page in the page pool cache
@@ -145,6 +146,7 @@ The ``struct page_pool_recycle_stats`` has the following fields:
   * ``ring``: page placed into the ptr ring
   * ``ring_full``: page released from page pool because the ptr ring was full
   * ``released_refcnt``: page released (and not recycled) because refcnt > 1
+  * ``released_pages``: number of released pages from the pool
 
 Coding examples
 ===============
diff --git a/include/net/page_pool.h b/include/net/page_pool.h
index ddfa0b328677..b16d5320d963 100644
--- a/include/net/page_pool.h
+++ b/include/net/page_pool.h
@@ -94,6 +94,7 @@ struct page_pool_alloc_stats {
 		    */
 	u64 refill; /* allocations via successful refill */
 	u64 waive;  /* failed refills due to numa zone mismatch */
+	u64 pages; /* number of allocated pages to the pool */
 };
 
 struct page_pool_recycle_stats {
@@ -106,6 +107,7 @@ struct page_pool_recycle_stats {
 	u64 released_refcnt; /* page released because of elevated
 			      * refcnt
 			      */
+	u64 released_pages; /* number of released pages from the pool */
 };
 
 /* This struct wraps the above stats structs so users of the
diff --git a/net/core/page_pool.c b/net/core/page_pool.c
index 193c18799865..418d443d7e7c 100644
--- a/net/core/page_pool.c
+++ b/net/core/page_pool.c
@@ -50,11 +50,13 @@ static const char pp_stats[][ETH_GSTRING_LEN] = {
 	"rx_pp_alloc_empty",
 	"rx_pp_alloc_refill",
 	"rx_pp_alloc_waive",
+	"rx_pp_alloc_pages",
 	"rx_pp_recycle_cached",
 	"rx_pp_recycle_cache_full",
 	"rx_pp_recycle_ring",
 	"rx_pp_recycle_ring_full",
 	"rx_pp_recycle_released_ref",
+	"rx_pp_released_pages",
 };
 
 bool page_pool_get_stats(struct page_pool *pool,
@@ -72,6 +74,7 @@ bool page_pool_get_stats(struct page_pool *pool,
 	stats->alloc_stats.empty += pool->alloc_stats.empty;
 	stats->alloc_stats.refill += pool->alloc_stats.refill;
 	stats->alloc_stats.waive += pool->alloc_stats.waive;
+	stats->alloc_stats.pages += pool->alloc_stats.pages;
 
 	for_each_possible_cpu(cpu) {
 		const struct page_pool_recycle_stats *pcpu =
@@ -82,6 +85,7 @@ bool page_pool_get_stats(struct page_pool *pool,
 		stats->recycle_stats.ring += pcpu->ring;
 		stats->recycle_stats.ring_full += pcpu->ring_full;
 		stats->recycle_stats.released_refcnt += pcpu->released_refcnt;
+		stats->recycle_stats.released_pages += pcpu->released_pages;
 	}
 
 	return true;
@@ -117,11 +121,13 @@ u64 *page_pool_ethtool_stats_get(u64 *data, void *stats)
 	*data++ = pool_stats->alloc_stats.empty;
 	*data++ = pool_stats->alloc_stats.refill;
 	*data++ = pool_stats->alloc_stats.waive;
+	*data++ = pool_stats->alloc_stats.pages;
 	*data++ = pool_stats->recycle_stats.cached;
 	*data++ = pool_stats->recycle_stats.cache_full;
 	*data++ = pool_stats->recycle_stats.ring;
 	*data++ = pool_stats->recycle_stats.ring_full;
 	*data++ = pool_stats->recycle_stats.released_refcnt;
+	*data++ = pool_stats->recycle_stats.released_pages;
 
 	return data;
 }
@@ -411,6 +417,7 @@ static struct page *__page_pool_alloc_pages_slow(struct page_pool *pool,
 		pool->pages_state_hold_cnt++;
 		trace_page_pool_state_hold(pool, page,
 					   pool->pages_state_hold_cnt);
+		alloc_stat_inc(pool, pages);
 	}
 
 	/* Return last page */
@@ -493,6 +500,7 @@ void page_pool_release_page(struct page_pool *pool, struct page *page)
 	 */
 	count = atomic_inc_return_relaxed(&pool->pages_state_release_cnt);
 	trace_page_pool_state_release(pool, page, count);
+	recycle_stat_inc(pool, released_pages);
 }
 EXPORT_SYMBOL(page_pool_release_page);
 
-- 
2.39.2


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

end of thread, other threads:[~2023-04-18  7:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-13 21:46 [PATCH net-next] net: page_pool: add pages and released_pages counters Lorenzo Bianconi
2023-04-15  1:46 ` Jakub Kicinski
2023-04-15 11:16   ` Lorenzo Bianconi
2023-04-17 18:12     ` Jakub Kicinski
2023-04-17 21:39       ` Lorenzo Bianconi
2023-04-17 23:36         ` Jakub Kicinski
2023-04-18  7:23           ` 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).