From: Jakub Kicinski <kuba@kernel•org>
To: netdev@vger•kernel.org
Cc: hawk@kernel•org, ilias.apalodimas@linaro•org,
aleksander.lobakin@intel•com, linyunsheng@huawei•com,
almasrymina@google•com, Jakub Kicinski <kuba@kernel•org>
Subject: [RFC net-next 11/13] net: page_pool: report when page pool was destroyed
Date: Wed, 16 Aug 2023 16:43:00 -0700 [thread overview]
Message-ID: <20230816234303.3786178-12-kuba@kernel.org> (raw)
In-Reply-To: <20230816234303.3786178-1-kuba@kernel.org>
Report when page pool was destroyed and number of inflight
references. This allows user to proactively check for dead
page pools without waiting to see if errors messages will
be printed in dmesg.
Only provide inflight for pools which were already "destroyed".
inflight information could also be interesting for "live"
pools but we don't want to have to deal with the potential
negative values due to races.
Example output for a fake leaked page pool using some hacks
in netdevsim (one "live" pool, and one "leaked" on the same dev):
$ ./cli.py --no-schema --spec netlink/specs/netdev.yaml \
--dump page-pool-get
[{'id': 2, 'ifindex': 3},
{'id': 1, 'ifindex': 3, 'destroyed': 133, 'inflight': 1}]
Signed-off-by: Jakub Kicinski <kuba@kernel•org>
---
Documentation/netlink/specs/netdev.yaml | 16 ++++++++++++++++
include/net/page_pool/types.h | 1 +
include/uapi/linux/netdev.h | 2 ++
net/core/page_pool.c | 3 ++-
net/core/page_pool_priv.h | 3 +++
net/core/page_pool_user.c | 16 ++++++++++++++++
6 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/Documentation/netlink/specs/netdev.yaml b/Documentation/netlink/specs/netdev.yaml
index 47ae2a45daea..1fd3b4235251 100644
--- a/Documentation/netlink/specs/netdev.yaml
+++ b/Documentation/netlink/specs/netdev.yaml
@@ -92,6 +92,20 @@ name: netdev
name: napi-id
doc: Id of NAPI using this Page Pool instance.
type: u32
+ -
+ name: destroyed
+ type: u64
+ doc: |
+ Seconds in CLOCK_BOOTTIME of when Page Pool was destroyed.
+ Page Pools wait for all the memory allocated from them to be freed
+ before truly disappearing.
+ Absent if Page Pool hasn't been destroyed.
+ -
+ name: inflight
+ type: u32
+ doc: |
+ Number of outstanding references to this page pool (allocated
+ but yet to be freed pages).
operations:
list:
@@ -140,6 +154,8 @@ name: netdev
- id
- ifindex
- napi-id
+ - destroyed
+ - inflight
dump:
reply: *pp-reply
-
diff --git a/include/net/page_pool/types.h b/include/net/page_pool/types.h
index 3017557e0c59..490c7419a474 100644
--- a/include/net/page_pool/types.h
+++ b/include/net/page_pool/types.h
@@ -195,6 +195,7 @@ struct page_pool {
/* User-facing fields, protected by page_pools_lock */
struct {
struct hlist_node list;
+ u64 destroyed;
u32 napi_id;
u32 id;
} user;
diff --git a/include/uapi/linux/netdev.h b/include/uapi/linux/netdev.h
index 3c9818c1962a..aac840a3849b 100644
--- a/include/uapi/linux/netdev.h
+++ b/include/uapi/linux/netdev.h
@@ -53,6 +53,8 @@ enum {
NETDEV_A_PAGE_POOL_PAD,
NETDEV_A_PAGE_POOL_IFINDEX,
NETDEV_A_PAGE_POOL_NAPI_ID,
+ NETDEV_A_PAGE_POOL_DESTROYED,
+ NETDEV_A_PAGE_POOL_INFLIGHT,
__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 de199c356043..733ca2198d94 100644
--- a/net/core/page_pool.c
+++ b/net/core/page_pool.c
@@ -513,7 +513,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)
{
u32 release_cnt = atomic_read(&pool->pages_state_release_cnt);
u32 hold_cnt = READ_ONCE(pool->pages_state_hold_cnt);
@@ -933,6 +933,7 @@ void page_pool_destroy(struct page_pool *pool)
if (!page_pool_release(pool))
return;
+ page_pool_destroyed(pool);
pool->defer_start = jiffies;
pool->defer_warn = jiffies + DEFER_WARN_INTERVAL;
diff --git a/net/core/page_pool_priv.h b/net/core/page_pool_priv.h
index 6c4e4aeed02a..892e0cddc400 100644
--- a/net/core/page_pool_priv.h
+++ b/net/core/page_pool_priv.h
@@ -3,7 +3,10 @@
#ifndef __PAGE_POOL_PRIV_H
#define __PAGE_POOL_PRIV_H
+s32 page_pool_inflight(const struct page_pool *pool);
+
int page_pool_list(struct page_pool *pool);
+void page_pool_destroyed(struct page_pool *pool);
void page_pool_unlist(struct page_pool *pool);
#endif
diff --git a/net/core/page_pool_user.c b/net/core/page_pool_user.c
index ba2f27f15495..a74d6f18caac 100644
--- a/net/core/page_pool_user.c
+++ b/net/core/page_pool_user.c
@@ -126,6 +126,14 @@ page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool,
if (pool->user.napi_id &&
nla_put_u32(rsp, NETDEV_A_PAGE_POOL_NAPI_ID, pool->user.napi_id))
goto err_cancel;
+ if (pool->user.destroyed) {
+ if (nla_put_u64_64bit(rsp, NETDEV_A_PAGE_POOL_DESTROYED,
+ pool->user.destroyed,
+ NETDEV_A_PAGE_POOL_PAD) ||
+ nla_put_u32(rsp, NETDEV_A_PAGE_POOL_INFLIGHT,
+ page_pool_inflight(pool)))
+ goto err_cancel;
+ }
genlmsg_end(rsp, hdr);
@@ -211,6 +219,14 @@ int page_pool_list(struct page_pool *pool)
return err;
}
+void page_pool_destroyed(struct page_pool *pool)
+{
+ mutex_lock(&page_pools_lock);
+ pool->user.destroyed = ktime_get_boottime_seconds();
+ netdev_nl_page_pool_event(pool, NETDEV_CMD_PAGE_POOL_CHANGE_NTF);
+ mutex_unlock(&page_pools_lock);
+}
+
void page_pool_unlist(struct page_pool *pool)
{
mutex_lock(&page_pools_lock);
--
2.41.0
next prev parent reply other threads:[~2023-08-16 23:43 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-16 23:42 [RFC net-next 00/13] net: page_pool: add netlink-based introspection Jakub Kicinski
2023-08-16 23:42 ` [RFC net-next 01/13] net: page_pool: split the page_pool_params into fast and slow Jakub Kicinski
2023-08-17 9:31 ` Jesper Dangaard Brouer
2023-08-17 9:35 ` Ilias Apalodimas
2023-08-17 21:28 ` Mina Almasry
2023-08-16 23:42 ` [RFC net-next 02/13] net: page_pool: avoid touching slow on the fastpath Jakub Kicinski
2023-08-17 9:32 ` Jesper Dangaard Brouer
2023-08-17 9:38 ` Ilias Apalodimas
2023-08-17 21:31 ` Mina Almasry
2023-08-16 23:42 ` [RFC net-next 03/13] net: page_pool: factor out uninit Jakub Kicinski
2023-08-17 7:40 ` Ilias Apalodimas
2023-08-17 16:25 ` Jakub Kicinski
2023-08-17 16:53 ` Ilias Apalodimas
2023-08-16 23:42 ` [RFC net-next 04/13] net: page_pool: id the page pools Jakub Kicinski
2023-08-17 21:56 ` Mina Almasry
2023-08-18 0:08 ` Jakub Kicinski
2023-08-16 23:42 ` [RFC net-next 05/13] net: page_pool: record pools per netdev Jakub Kicinski
2023-08-17 7:26 ` Simon Horman
2023-08-17 16:22 ` Jakub Kicinski
2023-08-16 23:42 ` [RFC net-next 06/13] net: page_pool: stash the NAPI ID for easier access Jakub Kicinski
2023-08-16 23:42 ` [RFC net-next 07/13] eth: link netdev to pp Jakub Kicinski
2023-08-16 23:42 ` [RFC net-next 08/13] net: page_pool: add nlspec for basic access to page pools Jakub Kicinski
2023-08-16 23:42 ` [RFC net-next 09/13] net: page_pool: implement GET in the netlink API Jakub Kicinski
2023-08-16 23:42 ` [RFC net-next 10/13] net: page_pool: add netlink notifications for state changes Jakub Kicinski
2023-08-16 23:43 ` Jakub Kicinski [this message]
2023-08-16 23:43 ` [RFC net-next 12/13] net: page_pool: expose page pool stats via netlink Jakub Kicinski
2023-08-16 23:43 ` [RFC net-next 13/13] tools: netdev: regen after page pool changes Jakub Kicinski
2023-08-17 21:21 ` [RFC net-next 00/13] net: page_pool: add netlink-based introspection Mina Almasry
2023-08-18 0:13 ` Jakub Kicinski
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=20230816234303.3786178-12-kuba@kernel.org \
--to=kuba@kernel$(echo .)org \
--cc=aleksander.lobakin@intel$(echo .)com \
--cc=almasrymina@google$(echo .)com \
--cc=hawk@kernel$(echo .)org \
--cc=ilias.apalodimas@linaro$(echo .)org \
--cc=linyunsheng@huawei$(echo .)com \
--cc=netdev@vger$(echo .)kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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