netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
	almasrymina@google.com, hawk@kernel.org,
	ilias.apalodimas@linaro.org, dsahern@gmail.com,
	dtatulea@nvidia.com, Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next v2 11/15] net: page_pool: report amount of memory held by page pools
Date: Mon, 20 Nov 2023 16:00:44 -0800	[thread overview]
Message-ID: <20231121000048.789613-12-kuba@kernel.org> (raw)
In-Reply-To: <20231121000048.789613-1-kuba@kernel.org>

Advanced deployments need the ability to check memory use
of various system components. It makes it possible to make informed
decisions about memory allocation and to find regressions and leaks.

Report memory use of page pools. Report both number of references
and bytes held.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 Documentation/netlink/specs/netdev.yaml | 13 +++++++++++++
 include/uapi/linux/netdev.h             |  2 ++
 net/core/page_pool.c                    | 13 +++++++++----
 net/core/page_pool_priv.h               |  2 ++
 net/core/page_pool_user.c               |  8 ++++++++
 5 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/Documentation/netlink/specs/netdev.yaml b/Documentation/netlink/specs/netdev.yaml
index 82fbe81f7a49..85209e19dca9 100644
--- a/Documentation/netlink/specs/netdev.yaml
+++ b/Documentation/netlink/specs/netdev.yaml
@@ -114,6 +114,17 @@ name: netdev
         checks:
           min: 1
           max: u32-max
+      -
+        name: inflight
+        type: uint
+        doc: |
+          Number of outstanding references to this page pool (allocated
+          but yet to be freed pages).
+      -
+        name: inflight-mem
+        type: uint
+        doc: |
+          Amount of memory held by inflight pages.
 
 operations:
   list:
@@ -163,6 +174,8 @@ name: netdev
             - id
             - ifindex
             - napi-id
+            - inflight
+            - inflight-mem
       dump:
         reply: *pp-reply
       config-cond: page-pool
diff --git a/include/uapi/linux/netdev.h b/include/uapi/linux/netdev.h
index beb158872226..26ae5bdd3187 100644
--- a/include/uapi/linux/netdev.h
+++ b/include/uapi/linux/netdev.h
@@ -68,6 +68,8 @@ enum {
 	NETDEV_A_PAGE_POOL_ID = 1,
 	NETDEV_A_PAGE_POOL_IFINDEX,
 	NETDEV_A_PAGE_POOL_NAPI_ID,
+	NETDEV_A_PAGE_POOL_INFLIGHT,
+	NETDEV_A_PAGE_POOL_INFLIGHT_MEM,
 
 	__NETDEV_A_PAGE_POOL_MAX,
 	NETDEV_A_PAGE_POOL_MAX = (__NETDEV_A_PAGE_POOL_MAX - 1)
diff --git a/net/core/page_pool.c b/net/core/page_pool.c
index a8d96ea38d18..566390759294 100644
--- a/net/core/page_pool.c
+++ b/net/core/page_pool.c
@@ -529,7 +529,7 @@ EXPORT_SYMBOL(page_pool_alloc_pages);
  */
 #define _distance(a, b)	(s32)((a) - (b))
 
-static s32 page_pool_inflight(struct page_pool *pool)
+s32 page_pool_inflight(const struct page_pool *pool, bool strict)
 {
 	u32 release_cnt = atomic_read(&pool->pages_state_release_cnt);
 	u32 hold_cnt = READ_ONCE(pool->pages_state_hold_cnt);
@@ -537,8 +537,13 @@ static s32 page_pool_inflight(struct page_pool *pool)
 
 	inflight = _distance(hold_cnt, release_cnt);
 
-	trace_page_pool_release(pool, inflight, hold_cnt, release_cnt);
-	WARN(inflight < 0, "Negative(%d) inflight packet-pages", inflight);
+	if (strict) {
+		trace_page_pool_release(pool, inflight, hold_cnt, release_cnt);
+		WARN(inflight < 0, "Negative(%d) inflight packet-pages",
+		     inflight);
+	} else {
+		inflight = max(0, inflight);
+	}
 
 	return inflight;
 }
@@ -881,7 +886,7 @@ static int page_pool_release(struct page_pool *pool)
 	int inflight;
 
 	page_pool_scrub(pool);
-	inflight = page_pool_inflight(pool);
+	inflight = page_pool_inflight(pool, true);
 	if (!inflight)
 		__page_pool_destroy(pool);
 
diff --git a/net/core/page_pool_priv.h b/net/core/page_pool_priv.h
index c17ea092b4ab..72fb21ea1ddc 100644
--- a/net/core/page_pool_priv.h
+++ b/net/core/page_pool_priv.h
@@ -3,6 +3,8 @@
 #ifndef __PAGE_POOL_PRIV_H
 #define __PAGE_POOL_PRIV_H
 
+s32 page_pool_inflight(const struct page_pool *pool, bool strict);
+
 int page_pool_list(struct page_pool *pool);
 void page_pool_unlist(struct page_pool *pool);
 
diff --git a/net/core/page_pool_user.c b/net/core/page_pool_user.c
index 35c56fb41c46..d889b347f8f4 100644
--- a/net/core/page_pool_user.c
+++ b/net/core/page_pool_user.c
@@ -110,6 +110,7 @@ static int
 page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool,
 		  const struct genl_info *info)
 {
+	size_t inflight, refsz;
 	void *hdr;
 
 	hdr = genlmsg_iput(rsp, info);
@@ -127,6 +128,13 @@ page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool,
 	    nla_put_uint(rsp, NETDEV_A_PAGE_POOL_NAPI_ID, pool->user.napi_id))
 		goto err_cancel;
 
+	inflight = page_pool_inflight(pool, false);
+	refsz =	PAGE_SIZE << pool->p.order;
+	if (nla_put_uint(rsp, NETDEV_A_PAGE_POOL_INFLIGHT, inflight) ||
+	    nla_put_uint(rsp, NETDEV_A_PAGE_POOL_INFLIGHT_MEM,
+			 inflight * refsz))
+		goto err_cancel;
+
 	genlmsg_end(rsp, hdr);
 
 	return 0;
-- 
2.42.0


  parent reply	other threads:[~2023-11-21  0:01 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-21  0:00 [PATCH net-next v2 00/15] net: page_pool: add netlink-based introspection Jakub Kicinski
2023-11-21  0:00 ` [PATCH net-next v2 01/15] net: page_pool: split the page_pool_params into fast and slow Jakub Kicinski
2023-11-21  0:00 ` [PATCH net-next v2 02/15] net: page_pool: avoid touching slow on the fastpath Jakub Kicinski
2023-11-21  0:00 ` [PATCH net-next v2 03/15] net: page_pool: factor out uninit Jakub Kicinski
2023-11-21  0:00 ` [PATCH net-next v2 04/15] net: page_pool: id the page pools Jakub Kicinski
2023-11-21  0:00 ` [PATCH net-next v2 05/15] net: page_pool: record pools per netdev Jakub Kicinski
2023-11-21  0:00 ` [PATCH net-next v2 06/15] net: page_pool: stash the NAPI ID for easier access Jakub Kicinski
2023-11-21  0:00 ` [PATCH net-next v2 07/15] eth: link netdev to page_pools in drivers Jakub Kicinski
2023-11-21 13:13   ` kernel test robot
2023-11-21 21:25   ` kernel test robot
2023-11-21  0:00 ` [PATCH net-next v2 08/15] net: page_pool: add nlspec for basic access to page pools Jakub Kicinski
2023-11-21 18:24   ` Willem de Bruijn
2023-11-21 20:37     ` Jakub Kicinski
2023-11-21 21:33       ` Willem de Bruijn
2023-11-21 22:00         ` Jakub Kicinski
2023-11-21 22:49           ` David Ahern
2023-11-21 23:42             ` Jakub Kicinski
2023-11-21  0:00 ` [PATCH net-next v2 09/15] net: page_pool: implement GET in the netlink API Jakub Kicinski
2023-11-21  0:00 ` [PATCH net-next v2 10/15] net: page_pool: add netlink notifications for state changes Jakub Kicinski
2023-11-21  0:00 ` Jakub Kicinski [this message]
2023-11-21  0:00 ` [PATCH net-next v2 12/15] net: page_pool: report when page pool was destroyed Jakub Kicinski
2023-11-21 20:45   ` Jesper Dangaard Brouer
2023-11-21 21:49     ` Jakub Kicinski
2023-11-22  8:53       ` Jesper Dangaard Brouer
2023-11-21  0:00 ` [PATCH net-next v2 13/15] net: page_pool: expose page pool stats via netlink Jakub Kicinski
2023-11-21  0:00 ` [PATCH net-next v2 14/15] net: page_pool: mute the periodic warning for visible page pools Jakub Kicinski
2023-11-21  0:00 ` [PATCH net-next v2 15/15] tools: ynl: add sample for getting page-pool information Jakub Kicinski
2023-11-22  1:31 ` [PATCH net-next v2 00/15] net: page_pool: add netlink-based introspection Jakub Kicinski
2023-11-22  8:45   ` Jesper Dangaard Brouer
2023-11-22  1:40 ` patchwork-bot+netdevbpf

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=20231121000048.789613-12-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=almasrymina@google.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@gmail.com \
    --cc=dtatulea@nvidia.com \
    --cc=edumazet@google.com \
    --cc=hawk@kernel.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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;
as well as URLs for NNTP newsgroup(s).