Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Jakub Kicinski and committed by
Paolo Abeni
69cb4952 7aee8429

+29
+13
Documentation/netlink/specs/netdev.yaml
··· 127 127 type: uint 128 128 doc: | 129 129 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. 130 142 131 143 operations: 132 144 list: ··· 190 178 - napi-id 191 179 - inflight 192 180 - inflight-mem 181 + - detach-time 193 182 dump: 194 183 reply: *pp-reply 195 184 config-cond: page-pool
+1
include/net/page_pool/types.h
··· 193 193 /* User-facing fields, protected by page_pools_lock */ 194 194 struct { 195 195 struct hlist_node list; 196 + u64 detach_time; 196 197 u32 napi_id; 197 198 u32 id; 198 199 } user;
+1
include/uapi/linux/netdev.h
··· 70 70 NETDEV_A_PAGE_POOL_NAPI_ID, 71 71 NETDEV_A_PAGE_POOL_INFLIGHT, 72 72 NETDEV_A_PAGE_POOL_INFLIGHT_MEM, 73 + NETDEV_A_PAGE_POOL_DETACH_TIME, 73 74 74 75 __NETDEV_A_PAGE_POOL_MAX, 75 76 NETDEV_A_PAGE_POOL_MAX = (__NETDEV_A_PAGE_POOL_MAX - 1)
+1
net/core/page_pool.c
··· 953 953 if (!page_pool_release(pool)) 954 954 return; 955 955 956 + page_pool_detached(pool); 956 957 pool->defer_start = jiffies; 957 958 pool->defer_warn = jiffies + DEFER_WARN_INTERVAL; 958 959
+1
net/core/page_pool_priv.h
··· 6 6 s32 page_pool_inflight(const struct page_pool *pool, bool strict); 7 7 8 8 int page_pool_list(struct page_pool *pool); 9 + void page_pool_detached(struct page_pool *pool); 9 10 void page_pool_unlist(struct page_pool *pool); 10 11 11 12 #endif
+12
net/core/page_pool_user.c
··· 134 134 nla_put_uint(rsp, NETDEV_A_PAGE_POOL_INFLIGHT_MEM, 135 135 inflight * refsz)) 136 136 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; 137 141 138 142 genlmsg_end(rsp, hdr); 139 143 ··· 221 217 err_unlock: 222 218 mutex_unlock(&page_pools_lock); 223 219 return err; 220 + } 221 + 222 + void page_pool_detached(struct page_pool *pool) 223 + { 224 + mutex_lock(&page_pools_lock); 225 + pool->user.detach_time = ktime_get_boottime_seconds(); 226 + netdev_nl_page_pool_event(pool, NETDEV_CMD_PAGE_POOL_CHANGE_NTF); 227 + mutex_unlock(&page_pools_lock); 224 228 } 225 229 226 230 void page_pool_unlist(struct page_pool *pool)