Skip to content

Commit 69cb495

Browse files
kuba-mooPaolo Abeni
authored andcommitted
net: page_pool: report when page pool was destroyed
Report when page pool was destroyed. Together with the inflight / memory use reporting this can serve as a replacement for the warning about leaked page pools we currently print to dmesg. 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}] Tested-by: Dragos Tatulea <dtatulea@nvidia.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Acked-by: Jesper Dangaard Brouer <hawk@kernel.org> Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 7aee842 commit 69cb495

File tree

6 files changed

+29
-0
lines changed

6 files changed

+29
-0
lines changed

Documentation/netlink/specs/netdev.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,18 @@ attribute-sets:
127127
type: uint
128128
doc: |
129129
Amount of memory held by inflight pages.
130+
-
131+
name: detach-time
132+
type: uint
133+
doc: |
134+
Seconds in CLOCK_BOOTTIME of when Page Pool was detached by
135+
the driver. Once detached Page Pool can no longer be used to
136+
allocate memory.
137+
Page Pools wait for all the memory allocated from them to be freed
138+
before truly disappearing. "Detached" Page Pools cannot be
139+
"re-attached", they are just waiting to disappear.
140+
Attribute is absent if Page Pool has not been detached, and
141+
can still be used to allocate new memory.
130142
131143
operations:
132144
list:
@@ -178,6 +190,7 @@ operations:
178190
- napi-id
179191
- inflight
180192
- inflight-mem
193+
- detach-time
181194
dump:
182195
reply: *pp-reply
183196
config-cond: page-pool

include/net/page_pool/types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ struct page_pool {
193193
/* User-facing fields, protected by page_pools_lock */
194194
struct {
195195
struct hlist_node list;
196+
u64 detach_time;
196197
u32 napi_id;
197198
u32 id;
198199
} user;

include/uapi/linux/netdev.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ enum {
7070
NETDEV_A_PAGE_POOL_NAPI_ID,
7171
NETDEV_A_PAGE_POOL_INFLIGHT,
7272
NETDEV_A_PAGE_POOL_INFLIGHT_MEM,
73+
NETDEV_A_PAGE_POOL_DETACH_TIME,
7374

7475
__NETDEV_A_PAGE_POOL_MAX,
7576
NETDEV_A_PAGE_POOL_MAX = (__NETDEV_A_PAGE_POOL_MAX - 1)

net/core/page_pool.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,7 @@ void page_pool_destroy(struct page_pool *pool)
953953
if (!page_pool_release(pool))
954954
return;
955955

956+
page_pool_detached(pool);
956957
pool->defer_start = jiffies;
957958
pool->defer_warn = jiffies + DEFER_WARN_INTERVAL;
958959

net/core/page_pool_priv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
s32 page_pool_inflight(const struct page_pool *pool, bool strict);
77

88
int page_pool_list(struct page_pool *pool);
9+
void page_pool_detached(struct page_pool *pool);
910
void page_pool_unlist(struct page_pool *pool);
1011

1112
#endif

net/core/page_pool_user.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool,
134134
nla_put_uint(rsp, NETDEV_A_PAGE_POOL_INFLIGHT_MEM,
135135
inflight * refsz))
136136
goto err_cancel;
137+
if (pool->user.detach_time &&
138+
nla_put_uint(rsp, NETDEV_A_PAGE_POOL_DETACH_TIME,
139+
pool->user.detach_time))
140+
goto err_cancel;
137141

138142
genlmsg_end(rsp, hdr);
139143

@@ -219,6 +223,14 @@ int page_pool_list(struct page_pool *pool)
219223
return err;
220224
}
221225

226+
void page_pool_detached(struct page_pool *pool)
227+
{
228+
mutex_lock(&page_pools_lock);
229+
pool->user.detach_time = ktime_get_boottime_seconds();
230+
netdev_nl_page_pool_event(pool, NETDEV_CMD_PAGE_POOL_CHANGE_NTF);
231+
mutex_unlock(&page_pools_lock);
232+
}
233+
222234
void page_pool_unlist(struct page_pool *pool)
223235
{
224236
mutex_lock(&page_pools_lock);

0 commit comments

Comments
 (0)