net: page_pool: add netlink-based introspection
Subsystems (10)
Jakub Kicinski
maintainerv2 cover net: page_pool: add netlink-based introspection
We recently started to deploy newer kernels / drivers at Meta, making significant use of page pools for the first time. We immediately run into page pool leaks both real and false positive warnings. As Eric pointed out/predicted there's no guarantee that applications will read / close their sockets so a page pool page may be stuck in a socket (but not leaked) forever. This happens a lot in our fleet. Most of these are obviously due to application bugs but we should not be printing kernel warnings due to minor application resource leaks.
Conversely the page pool memory may get leaked at runtime, and we have no way to detect / track that, unless someone reconfigures the NIC and destroys the page pools which leaked the pages.
The solution presented here is to expose the memory use of page pools via netlink. This allows for continuous monitoring of memory used by page pools, regardless if they were destroyed or not. Sample in patch 15 can print the memory use and recycling efficiency:
$ ./page-pool
eth0[2] page pools: 10 (zombies: 0)
refs: 41984 bytes: 171966464 (refs: 0 bytes: 0)
recycling: 90.3% (alloc: 656:397681 recycle: 89652:270201)v2:
- hopefully fix build with PAGE_POOL=n
v1: https://lore.kernel.org/all/[email protected]/
- The main change compared to the RFC is that the API now exposes outstanding references and byte counts even for "live" page pools. The warning is no longer printed if page pool is accessible via netlink.
RFC: https://lore.kernel.org/all/[email protected]/
Jakub Kicinski (15):
net: page_pool: split the page_pool_params into fast and slow
net: page_pool: avoid touching slow on the fastpath
net: page_pool: factor out uninit
net: page_pool: id the page pools
net: page_pool: record pools per netdev
net: page_pool: stash the NAPI ID for easier access
eth: link netdev to page_pools in drivers
net: page_pool: add nlspec for basic access to page pools
net: page_pool: implement GET in the netlink API
net: page_pool: add netlink notifications for state changes
net: page_pool: report amount of memory held by page pools
net: page_pool: report when page pool was destroyed
net: page_pool: expose page pool stats via netlink
net: page_pool: mute the periodic warning for visible page pools
tools: ynl: add sample for getting page-pool information
Documentation/netlink/specs/netdev.yaml | 166 +++++++ Documentation/networking/page_pool.rst | 10 +- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 1 + .../net/ethernet/mellanox/mlx5/core/en_main.c | 1 + drivers/net/ethernet/microsoft/mana/mana_en.c | 1 + drivers/net/ethernet/socionext/netsec.c | 2 + include/linux/list.h | 20 + include/linux/netdevice.h | 4 + include/linux/poison.h | 2 + include/net/page_pool/helpers.h | 8 +- include/net/page_pool/types.h | 43 +- include/uapi/linux/netdev.h | 36 ++ net/core/Makefile | 2 +- net/core/netdev-genl-gen.c | 60 +++ net/core/netdev-genl-gen.h | 11 + net/core/page_pool.c | 78 ++-- net/core/page_pool_priv.h | 12 + net/core/page_pool_user.c | 414 +++++++++++++++++ tools/include/uapi/linux/netdev.h | 36 ++ tools/net/ynl/generated/netdev-user.c | 419 ++++++++++++++++++ tools/net/ynl/generated/netdev-user.h | 171 +++++++ tools/net/ynl/lib/ynl.h | 2 +- tools/net/ynl/samples/.gitignore | 1 + tools/net/ynl/samples/Makefile | 2 +- tools/net/ynl/samples/page-pool.c | 147 ++++++ 25 files changed, 1601 insertions(+), 48 deletions(-) create mode 100644 net/core/page_pool_priv.h create mode 100644 net/core/page_pool_user.c create mode 100644 tools/net/ynl/samples/page-pool.c
Signature · 1 line
2.42.0
Jakub Kicinski
maintainerPATCH v2 1/15 net: page_pool: split the page_pool_params into fast and slow
struct page_pool is rather performance critical and we use 16B of the first cache line to store 2 pointers used only by test code. Future patches will add more informational (non-fast path) attributes.
It's convenient for the user of the API to not have to worry which fields are fast and which are slow path. Use struct groups to split the params into the two categories internally.
--- include/net/page_pool/types.h | 31 +++++++++++++++++++------------ net/core/page_pool.c | 7 ++++--- 2 files changed, 23 insertions(+), 15 deletions(-)
include/net/page_pool/types.h +19 -12
@@ -54,18 +54,22 @@ struct pp_alloc_cache {* @offset: DMA sync address offset for PP_FLAG_DMA_SYNC_DEV */ struct page_pool_params { -unsigned int flags; -unsigned int order; -unsigned int pool_size; -int nid; -struct device *dev; -struct napi_struct *napi; -enum dma_data_direction dma_dir; -unsigned int max_len; -unsigned int offset; + struct_group_tagged(page_pool_params_fast, fast, + unsigned int flags; +unsigned int order; +unsigned int pool_size; +int nid; +struct device *dev; +struct napi_struct *napi; +enum dma_data_direction dma_dir; +unsigned int max_len; +unsigned int offset; + ); + struct_group_tagged(page_pool_params_slow, slow,/* private: used by test code only */ -void (*init_callback)(struct page *page,void *arg); -void *init_arg; + void (*init_callback)(struct page *page, void *arg); +void *init_arg; + ); };#ifdef CONFIG_PAGE_POOL_STATS
@@ -119,7 +123,7 @@ struct page_pool_stats {#endif struct page_pool { -struct page_pool_params p; +struct page_pool_params_fast p;long frag_users;struct page *frag_page;
@@ -178,6 +182,9 @@ struct page_pool {refcount_t user_cnt;u64 destroy_cnt; + +/* Slow/Control-path information follows */ +struct page_pool_params_slow slow; };struct page *page_pool_alloc_pages (struct page_pool *pool,gfp_t gfp);
net/core/page_pool.c +4 -3
@@ -173,7 +173,8 @@ static int page_pool_init(struct page_pool *pool, {unsigned int ring_qsize =1024 ;/* Default */ -memcpy (&pool->p, params,sizeof (pool->p)); +memcpy (&pool->p, ¶ms->fast,sizeof (pool->p)); +memcpy (&pool->slow, ¶ms->slow,sizeof (pool->slow));/* Validate only known flags were used */ if (pool->p.flags & ~(PP_FLAG_ALL ))
@@ -388,8 +389,8 @@ static void page_pool_set_pp_info(struct page_pool *pool,* the overhead is negligible. */ page_pool_fragment_page (page,1 ); -if (pool->p.init_callback) - pool->p.init_callback (page, pool->p.init_arg); +if (pool->slow.init_callback) + pool->slow.init_callback (page, pool->slow.init_arg); }static void page_pool_clear_pp_info (struct page *page)
Signature · 1 line
2.42.0
Jakub Kicinski
maintainerPATCH v2 2/15 net: page_pool: avoid touching slow on the fastpath
In reply to Jakub KicinskiTo fully benefit from previous commit add one byte of state in the first cache line recording if we need to look at the slow part.
The packing isn't all that impressive right now, we create a 7B hole. I'm expecting Olek's rework will reshuffle this, anyway.
--- include/net/page_pool/types.h | 2 ++ net/core/page_pool.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-)
include/net/page_pool/types.h +2 -0
@@ -125,6 +125,8 @@ struct page_pool_stats {struct page_pool {struct page_pool_params_fast p; +bool has_init_callback; +long frag_users;struct page *frag_page;unsigned int frag_offset;
net/core/page_pool.c +3 -1
@@ -212,6 +212,8 @@ static int page_pool_init(struct page_pool *pool,*/ } + pool->has_init_callback = !!pool->slow.init_callback; +#ifdef CONFIG_PAGE_POOL_STATS pool->recycle_stats = alloc_percpu(struct page_pool_recycle_stats);if (!pool->recycle_stats)
@@ -389,7 +391,7 @@ static void page_pool_set_pp_info(struct page_pool *pool,* the overhead is negligible. */ page_pool_fragment_page (page,1 ); -if (pool->slow.init_callback) +if (pool->has_init_callback) pool->slow.init_callback (page, pool->slow.init_arg); }
Signature · 1 line
2.42.0
Jakub Kicinski
maintainerPATCH v2 3/15 net: page_pool: factor out uninit
In reply to Jakub KicinskiWe'll soon (next change in the series) need a fuller unwind path in page_pool_create() so create the inverse of page_pool_init().
--- net/core/page_pool.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
net/core/page_pool.c +13 -8
@@ -238,6 +238,18 @@ static int page_pool_init(struct page_pool *pool,return 0 ; } +static void page_pool_uninit (struct page_pool *pool) +{ +ptr_ring_cleanup (&pool->ring,NULL ); + +if (pool->p.flags &PP_FLAG_DMA_MAP ) +put_device (pool->p.dev); + +#ifdef CONFIG_PAGE_POOL_STATS +free_percpu (pool->recycle_stats); +#endif +} +/** * page_pool_create() - create a page pool. * @params: parameters, see struct page_pool_params
@@ -821,14 +833,7 @@ static void __page_pool_destroy(struct page_pool *pool)if (pool->disconnect) pool->disconnect (pool); -ptr_ring_cleanup (&pool->ring,NULL ); - -if (pool->p.flags &PP_FLAG_DMA_MAP ) -put_device (pool->p.dev); - -#ifdef CONFIG_PAGE_POOL_STATS -free_percpu (pool->recycle_stats); -#endif +page_pool_uninit (pool);kfree (pool); }
Signature · 1 line
2.42.0
Jakub Kicinski
maintainerPATCH v2 4/15 net: page_pool: id the page pools
In reply to Jakub KicinskiTo give ourselves the flexibility of creating netlink commands and ability to refer to page pool instances in uAPIs create IDs for page pools.
--- include/net/page_pool/types.h | 4 ++++ net/core/Makefile | 2 +- net/core/page_pool.c | 21 +++++++++++++++----- net/core/page_pool_priv.h | 9 +++++++++ net/core/page_pool_user.c | 36 +++++++++++++++++++++++++++++++++++ 5 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 net/core/page_pool_priv.h create mode 100644 net/core/page_pool_user.c
include/net/page_pool/types.h +4 -0
@@ -187,6 +187,10 @@ struct page_pool {/* Slow/Control-path information follows */ struct page_pool_params_slow slow; +/* User-facing fields, protected by page_pools_lock */ +struct { +u32 id; + } user; };struct page *page_pool_alloc_pages (struct page_pool *pool,gfp_t gfp);
net/core/Makefile +1 -1
@@ -18,7 +18,7 @@ obj-y += dev.o dev_addr_lists.o dst.o netevent.o \ obj-$(CONFIG_NETDEV_ADDR_LIST_TEST) += dev_addr_lists_test.o obj-y += net-sysfs.o -obj-$(CONFIG_PAGE_POOL) += page_pool.o +obj-$(CONFIG_PAGE_POOL) += page_pool.o page_pool_user.o obj-$(CONFIG_PROC_FS) += net-procfs.o obj-$(CONFIG_NET_PKTGEN) += pktgen.o obj-$(CONFIG_NETPOLL) += netpoll.o
net/core/page_pool.c +16 -5
@@ -23,6 +23,8 @@#include <trace/events/page_pool.h> +#include "page_pool_priv.h" +#define DEFER_TIME (msecs_to_jiffies(1000))#define DEFER_WARN_INTERVAL (60 * HZ)
@@ -264,13 +266,21 @@ struct page_pool *page_pool_create(const struct page_pool_params *params)return ERR_PTR (-ENOMEM ); err =page_pool_init (pool, params); -if (err <0 ) { -pr_warn ("%s() gave up with errno %d\n" , __func__, err); -kfree (pool); -return ERR_PTR (err); - } +if (err <0 ) + goto err_free; + + err =page_pool_list (pool); +if (err) + goto err_uninit;return pool; + +err_uninit: +page_pool_uninit (pool); +err_free: +pr_warn ("%s() gave up with errno %d\n" , __func__, err); +kfree (pool); +return ERR_PTR (err); }EXPORT_SYMBOL (page_pool_create);
@@ -833,6 +843,7 @@ static void __page_pool_destroy(struct page_pool *pool)if (pool->disconnect) pool->disconnect (pool); +page_pool_unlist (pool);page_pool_uninit (pool);kfree (pool); }
net/core/page_pool_priv.h new file +9 -0
@@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __PAGE_POOL_PRIV_H +#define __PAGE_POOL_PRIV_H + +int page_pool_list (struct page_pool *pool); +void page_pool_unlist (struct page_pool *pool); + +#endif
net/core/page_pool_user.c new file +36 -0
@@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <linux/mutex.h> +#include <linux/xarray.h> +#include <net/page_pool/types.h> + +#include "page_pool_priv.h" + +static DEFINE_XARRAY_FLAGS(page_pools, XA_FLAGS_ALLOC1); +static DEFINE_MUTEX (page_pools_lock); + +int page_pool_list (struct page_pool *pool) +{ +static u32 id_alloc_next; +int err; + +mutex_lock (&page_pools_lock); + err =xa_alloc_cyclic (&page_pools, &pool->user.id, pool, xa_limit_32b, + &id_alloc_next,GFP_KERNEL ); +if (err <0 ) + goto err_unlock; + +mutex_unlock (&page_pools_lock); +return 0 ; + +err_unlock: +mutex_unlock (&page_pools_lock); +return err; +} + +void page_pool_unlist (struct page_pool *pool) +{ +mutex_lock (&page_pools_lock); +xa_erase (&page_pools, pool->user.id); +mutex_unlock (&page_pools_lock); +}
Signature · 1 line
2.42.0
Jakub Kicinski
maintainerPATCH v2 5/15 net: page_pool: record pools per netdev
In reply to Jakub KicinskiLink the page pools with netdevs. This needs to be netns compatible so we have two options. Either we record the pools per netns and have to worry about moving them as the netdev gets moved. Or we record them directly on the netdev so they move with the netdev without any extra work.
Implement the latter option. Since pools may outlast netdev we need a place to store orphans. In time honored tradition use loopback for this purpose.
---
v1: fix race between page pool and netdev disappearing (Simon)
--- include/linux/list.h | 20 ++++++++ include/linux/netdevice.h | 4 ++ include/linux/poison.h | 2 + include/net/page_pool/types.h | 4 ++ net/core/page_pool_user.c | 90 +++++++++++++++++++++++++++++++++++ 5 files changed, 120 insertions(+)
include/linux/list.h +20 -0
@@ -1119,6 +1119,26 @@ static inline void hlist_move_list(struct hlist_head *old, old->first =NULL ; } +/** +* hlist_splice_init() - move all entries from one list to another +* @from: hlist_head from which entries will be moved +* @last: last entry on the @from list +* @to: hlist_head to which entries will be moved +* +* @to can be empty, @from must contain at least @last. +*/ +static inline void hlist_splice_init (struct hlist_head *from, +struct hlist_node *last, +struct hlist_head *to) +{ +if (to->first) + to->first->pprev = &last->next; + last->next = to->first; + to->first = from->first; + from->first->pprev = &to->first; + from->first =NULL ; +} +#define hlist_entry (ptr, type, member) container_of(ptr,type,member)#define hlist_for_each (pos, head) \
include/linux/netdevice.h +4 -0
@@ -2435,6 +2435,10 @@ struct net_device {#if IS_ENABLED (CONFIG_DPLL )struct dpll_pin *dpll_pin;#endif +#if IS_ENABLED (CONFIG_PAGE_POOL ) +/** @page_pools: page pools created for this netdevice */ +struct hlist_head page_pools; +#endif };#define to_net_dev (d) container_of(d, struct net_device, dev)
include/linux/poison.h +2 -0
@@ -83,6 +83,8 @@/********** net/core/skbuff.c **********/ #define SKB_LIST_POISON_NEXT ((void *)(0x800 + POISON_POINTER_DELTA)) +/********** net/ **********/ +#define NET_PTR_POISON ((void *)(0x801 + POISON_POINTER_DELTA))/********** kernel/bpf/ **********/ #define BPF_PTR_POISON ((void *)(0xeB9FUL + POISON_POINTER_DELTA))
include/net/page_pool/types.h +4 -0
@@ -5,6 +5,7 @@#include <linux/dma-direction.h> #include <linux/ptr_ring.h> +#include <linux/types.h> #define PP_FLAG_DMA_MAP BIT(0)/* Should page_pool do the DMA * map/unmap
@@ -48,6 +49,7 @@ struct pp_alloc_cache {* @pool_size: size of the ptr_ring * @nid: NUMA node id to allocate from pages from * @dev: device, for DMA pre-mapping purposes +* @netdev: netdev this pool will serve (leave as NULL if none or multiple) * @napi: NAPI which is the sole consumer of pages, otherwise NULL * @dma_dir: DMA mapping direction * @max_len: max DMA sync memory size for PP_FLAG_DMA_SYNC_DEV
@@ -66,6 +68,7 @@ struct page_pool_params {unsigned int offset; );struct_group_tagged (page_pool_params_slow, slow, + struct net_device *netdev;/* private: used by test code only */ void (*init_callback)(struct page *page,void *arg);void *init_arg;
@@ -189,6 +192,7 @@ struct page_pool {struct page_pool_params_slow slow;/* User-facing fields, protected by page_pools_lock */ struct { +struct hlist_node list;u32 id; } user; };
net/core/page_pool_user.c +90 -0
115 lines not on this page · raw message
Signature · 1 line
2.42.0
Jakub Kicinski
maintainerPATCH v2 6/15 net: page_pool: stash the NAPI ID for easier access
In reply to Jakub KicinskiTo avoid any issues with race conditions on accessing napi and having to think about the lifetime of NAPI objects in netlink GET - stash the napi_id to which page pool was linked at creation time.
--- include/net/page_pool/types.h | 1 + net/core/page_pool_user.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-)
include/net/page_pool/types.h +1 -0
@@ -193,6 +193,7 @@ struct page_pool {/* User-facing fields, protected by page_pools_lock */ struct {struct hlist_node list; +u32 napi_id;u32 id; } user; };
net/core/page_pool_user.c +3 -1
@@ -37,9 +37,11 @@ int page_pool_list(struct page_pool *pool)if (err <0 ) goto err_unlock; -if (pool->slow.netdev) +if (pool->slow.netdev) {hlist_add_head (&pool->user.list, &pool->slow.netdev->page_pools); + pool->user.napi_id = pool->p.napi ? pool->p.napi->napi_id :0 ; + }mutex_unlock (&page_pools_lock);return 0 ;
Signature · 1 line
2.42.0
Jakub Kicinski
maintainerPATCH v2 7/15 eth: link netdev to page_pools in drivers
In reply to Jakub KicinskiLink page pool instances to netdev for the drivers which already link to NAPI. Unless the driver is doing something very weird per-NAPI should imply per-netdev.
Add netsec as well, Ilias indicates that it fits the mold.
---
v2: add netsec
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 1 + drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 1 + drivers/net/ethernet/microsoft/mana/mana_en.c | 1 + drivers/net/ethernet/socionext/netsec.c | 2 ++ 4 files changed, 5 insertions(+)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -0
@@ -3322,6 +3322,7 @@ static int bnxt_alloc_rx_page_pool(struct bnxt *bp, pp.pool_size += bp->rx_ring_size; pp.nid =dev_to_node (&bp->pdev->dev); pp.napi = &rxr->bnapi->napi; + pp.netdev = bp->dev; pp.dev = &bp->pdev->dev; pp.dma_dir = bp->rx_dir; pp.max_len =PAGE_SIZE ;
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +1 -0
@@ -902,6 +902,7 @@ static int mlx5e_alloc_rq(struct mlx5e_params *params, pp_params.nid = node; pp_params.dev = rq->pdev; pp_params.napi = rq->cq.napi; + pp_params.netdev = rq->netdev; pp_params.dma_dir = rq->buff.map_dir; pp_params.max_len =PAGE_SIZE ;
drivers/net/ethernet/microsoft/mana/mana_en.c +1 -0
@@ -2137,6 +2137,7 @@ static int mana_create_page_pool(struct mana_rxq *rxq, struct gdma_context *gc) pprm.pool_size =RX_BUFFERS_PER_QUEUE ; pprm.nid = gc->numa_node; pprm.napi = &rxq->rx_cq.napi; + pprm.netdev = rxq->ndev; rxq->page_pool =page_pool_create (&pprm);
drivers/net/ethernet/socionext/netsec.c +2 -0
@@ -1302,6 +1302,8 @@ static int netsec_setup_rx_dring(struct netsec_priv *priv) .dma_dir = xdp_prog ? DMA_BIDIRECTIONAL : DMA_FROM_DEVICE, .offset = NETSEC_RXBUF_HEADROOM, .max_len = NETSEC_RX_BUF_SIZE, + .napi = priv->napi, + .netdev = priv->ndev, };int i, err;
Signature · 1 line
2.42.0
kernel test robot
build botRe: [PATCH net-next v2 07/15] eth: link netdev to page_pools in drivers
kernel test robot noticed the following build errors:
Hi Jakub,
kernel test robot noticed the following build errors:
[auto build test ERROR on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Jakub-Kicinski/net-page_pool-split-the-page_pool_params-into-fast-and-slow/20231121-092240 base: net-next/main patch link: https://lore.kernel.org/r/20231121000048.789613-8-kuba%40kernel.org patch subject: [PATCH net-next v2 07/15] eth: link netdev to page_pools in drivers config: openrisc-allmodconfig (https://download.01.org/0day-ci/archive/20231121/[email protected]/config) compiler: or1k-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231121/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
drivers/net/ethernet/socionext/netsec.c: In function 'netsec_setup_rx_dring':
>> drivers/net/ethernet/socionext/netsec.c:1305:25: error: incompatible types when initializing type 'struct napi_struct *' using type 'struct napi_struct'
1305 | .napi = priv->napi,
| ^~~~vim +1305 drivers/net/ethernet/socionext/netsec.c
1290
1291 static int netsec_setup_rx_dring(struct netsec_priv *priv)
1292 {
1293 struct netsec_desc_ring *dring = &priv->desc_ring[NETSEC_RING_RX];
1294 struct bpf_prog *xdp_prog = READ_ONCE(priv->xdp_prog);
1295 struct page_pool_params pp_params = {
1296 .order = 0,
1297 /* internal DMA mapping in page_pool */
1298 .flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV,
1299 .pool_size = DESC_NUM,
1300 .nid = NUMA_NO_NODE,
1301 .dev = priv->dev,
1302 .dma_dir = xdp_prog ? DMA_BIDIRECTIONAL : DMA_FROM_DEVICE,
1303 .offset = NETSEC_RXBUF_HEADROOM,
1304 .max_len = NETSEC_RX_BUF_SIZE,
> 1305 .napi = priv->napi,
1306 .netdev = priv->ndev,
1307 };
1308 int i, err;
1309
1310 dring->page_pool = page_pool_create(&pp_params);
1311 if (IS_ERR(dring->page_pool)) {
1312 err = PTR_ERR(dring->page_pool);
1313 dring->page_pool = NULL;
1314 goto err_out;
1315 }
1316
1317 err = xdp_rxq_info_reg(&dring->xdp_rxq, priv->ndev, 0, priv->napi.napi_id);
1318 if (err)
1319 goto err_out;
1320
1321 err = xdp_rxq_info_reg_mem_model(&dring->xdp_rxq, MEM_TYPE_PAGE_POOL,
1322 dring->page_pool);
1323 if (err)
1324 goto err_out;
1325
1326 for (i = 0; i < DESC_NUM; i++) {
1327 struct netsec_desc *desc = &dring->desc[i];
1328 dma_addr_t dma_handle;
1329 void *buf;
1330 u16 len;
1331
1332 buf = netsec_alloc_rx_data(priv, &dma_handle, &len);
1333
1334 if (!buf) {
1335 err = -ENOMEM;
1336 goto err_out;
1337 }
1338 desc->dma_addr = dma_handle;
1339 desc->addr = buf;
1340 desc->len = len;
1341 }
1342
1343 netsec_rx_fill(priv, 0, DESC_NUM);
1344
1345 return 0;
1346
1347 err_out:
1348 netsec_uninit_pkt_dring(priv, NETSEC_RING_RX);
1349 return err;
1350 }
1351
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH net-next v2 07/15] eth: link netdev to page_pools in drivers
In reply to Jakub Kicinskikernel test robot noticed the following build errors:
Hi Jakub,
kernel test robot noticed the following build errors:
[auto build test ERROR on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Jakub-Kicinski/net-page_pool-split-the-page_pool_params-into-fast-and-slow/20231121-092240 base: net-next/main patch link: https://lore.kernel.org/r/20231121000048.789613-8-kuba%40kernel.org patch subject: [PATCH net-next v2 07/15] eth: link netdev to page_pools in drivers config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20231122/[email protected]/config) compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231122/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> drivers/net/ethernet/socionext/netsec.c:1305:11: error: initializing 'struct napi_struct *' with an expression of incompatible type 'struct napi_struct'; take the address with &
.napi = priv->napi,
^~~~~~~~~~
&1 error generated.
vim +1305 drivers/net/ethernet/socionext/netsec.c
1290
1291 static int netsec_setup_rx_dring(struct netsec_priv *priv)
1292 {
1293 struct netsec_desc_ring *dring = &priv->desc_ring[NETSEC_RING_RX];
1294 struct bpf_prog *xdp_prog = READ_ONCE(priv->xdp_prog);
1295 struct page_pool_params pp_params = {
1296 .order = 0,
1297 /* internal DMA mapping in page_pool */
1298 .flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV,
1299 .pool_size = DESC_NUM,
1300 .nid = NUMA_NO_NODE,
1301 .dev = priv->dev,
1302 .dma_dir = xdp_prog ? DMA_BIDIRECTIONAL : DMA_FROM_DEVICE,
1303 .offset = NETSEC_RXBUF_HEADROOM,
1304 .max_len = NETSEC_RX_BUF_SIZE,
> 1305 .napi = priv->napi,
1306 .netdev = priv->ndev,
1307 };
1308 int i, err;
1309
1310 dring->page_pool = page_pool_create(&pp_params);
1311 if (IS_ERR(dring->page_pool)) {
1312 err = PTR_ERR(dring->page_pool);
1313 dring->page_pool = NULL;
1314 goto err_out;
1315 }
1316
1317 err = xdp_rxq_info_reg(&dring->xdp_rxq, priv->ndev, 0, priv->napi.napi_id);
1318 if (err)
1319 goto err_out;
1320
1321 err = xdp_rxq_info_reg_mem_model(&dring->xdp_rxq, MEM_TYPE_PAGE_POOL,
1322 dring->page_pool);
1323 if (err)
1324 goto err_out;
1325
1326 for (i = 0; i < DESC_NUM; i++) {
1327 struct netsec_desc *desc = &dring->desc[i];
1328 dma_addr_t dma_handle;
1329 void *buf;
1330 u16 len;
1331
1332 buf = netsec_alloc_rx_data(priv, &dma_handle, &len);
1333
1334 if (!buf) {
1335 err = -ENOMEM;
1336 goto err_out;
1337 }
1338 desc->dma_addr = dma_handle;
1339 desc->addr = buf;
1340 desc->len = len;
1341 }
1342
1343 netsec_rx_fill(priv, 0, DESC_NUM);
1344
1345 return 0;
1346
1347 err_out:
1348 netsec_uninit_pkt_dring(priv, NETSEC_RING_RX);
1349 return err;
1350 }
1351
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Jakub Kicinski
maintainerPATCH v2 8/15 net: page_pool: add nlspec for basic access to page pools
In reply to Jakub KicinskiAdd a Netlink spec in YAML for getting very basic information about page pools.
--- Documentation/netlink/specs/netdev.yaml | 46 +++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
Documentation/netlink/specs/netdev.yaml +46 -0
@@ -86,6 +86,34 @@ name: netdev See Documentation/networking/xdp-rx-metadata.rst for more details. type: u64 enum: xdp-rx-metadata + - + name: page-pool + attributes: + - + name: id + doc: Unique ID of a Page Pool instance. + type: uint + checks: + min: 1 + max: u32-max + - + name: ifindex + doc: | + ifindex of the netdev to which the pool belongs. + May be reported as 0 if the page pool was allocated for a netdev + which got destroyed already (page pools may outlast their netdevs + because they wait for all memory to be returned). + type: u32 + checks: + min: 1 + max: s32-max + - + name: napi-id + doc: Id of NAPI using this Page Pool instance. + type: uint + checks: + min: 1 + max: u32-max operations: list:
@@ -120,6 +148,24 @@ name: netdev doc: Notification about device configuration being changed. notify: dev-get mcgrp: mgmt + - + name: page-pool-get + doc: | + Get / dump information about Page Pools. + (Only Page Pools associated with a net_device can be listed.) + attribute-set: page-pool + do: + request: + attributes: + - id + reply: &pp-reply + attributes: + - id + - ifindex + - napi-id + dump: + reply: *pp-reply + config-cond: page-pool mcast-groups: list:
Signature · 1 line
2.42.0
Re: [PATCH net-next v2 08/15] net: page_pool: add nlspec for basic access to page pools
Quoted 34 lines · Jakub Kicinski
Add a Netlink spec in YAML for getting very basic information about page pools.
Signed-off-by Jakub Kicinski <[email protected]>--- Documentation/netlink/specs/netdev.yaml | 46 +++++++++++++++++++++++++ 1 file changed, 46 insertions(+)Documentation/netlink/specs/netdev.yaml +18
-0@@ -86,6 +86,34 @@ name: netdev See Documentation/networking/xdp-rx-metadata.rst for more details. type: u64 enum: xdp-rx-metadata + - + name: page-pool + attributes: + - + name: id + doc: Unique ID of a Page Pool instance. + type: uint + checks: + min: 1 + max: u32-max + - + name: ifindex + doc: | + ifindex of the netdev to which the pool belongs. + May be reported as 0 if the page pool was allocated for a netdev + which got destroyed already (page pools may outlast their netdevs + because they wait for all memory to be returned). + type: u32
Documentation/netlink/specs/netdev.yaml name: netdev · line 116
Quoted 10 lines
Documentation/netlink/specs/netdev.yaml +10
-0+ checks: + min: 1 + max: s32-max + - + name: napi-id + doc: Id of NAPI using this Page Pool instance. + type: uint + checks: + min: 1 + max: u32-max
Do you want to introduce a separate ID for page pools? That brings some issues regarding network namespace isolation.
As a user API, it is also possible (and intuitive?) to refer to a page_pool by (namespacified) ifindex plus netdev_rx_queue index, or napi_id.
In fairness, napi_id is also global, not per netns.
By iterating over "for_each_netdev(net, ..", dump already limits output to pools in the same netns and get only reports pools that match the netns.
So it's only a minor matter of visible numbering, and perhaps superfluous new id.
No technical comments to this series. Looks solid to me.
Jakub Kicinski
maintainerRe: [PATCH net-next v2 08/15] net: page_pool: add nlspec for basic access to page pools
Quoted 6 lines · On Tue, 21 Nov 2023 13:24:07 -0500 Willem de Bruijn wrote:
Do you want to introduce a separate ID for page pools? That brings some issues regarding network namespace isolation.
As a user API, it is also possible (and intuitive?) to refer to a
page_poolby (namespacified) ifindex plusnetdev_rx_queueindex, ornapi_id.
That does not work for "destroyed" pools. In general, there is no natural key for a page pool I can think of.
Quoted 8 lines
In fairness,
napi_idis also global, not per netns.By iterating over "for_each_netdev(net, ..", dump already limits output to pools in the same netns and get only reports pools that match the netns.
So it's only a minor matter of visible numbering, and perhaps superfluous new id.
The IDs are not stable. Any reconfiguration of a device will create a new page pool and therefore assign a new ID. So applications can't hold onto the ID long term.
That said the only use case for exposing the ID right now is to implement do/GET (since there is no other unique key). And manual debug with drgn, but that doesn't require uAPI. So if you prefer strongly I can drop the ID from the uAPI and do/GET support.
Re: [PATCH net-next v2 08/15] net: page_pool: add nlspec for basic access to page pools
Quoted 10 lines · Jakub Kicinski
Quoted 6 lines · On Tue, 21 Nov 2023 13:24:07 -0500 Willem de Bruijn wrote:
Do you want to introduce a separate ID for page pools? That brings some issues regarding network namespace isolation.
As a user API, it is also possible (and intuitive?) to refer to a
page_poolby (namespacified) ifindex plusnetdev_rx_queueindex, ornapi_id.That does not work for "destroyed" pools. In general, there is no natural key for a page pool I can think of.
Pools for destroyed devices are attached to the loopback device. If the netns is also destroyed, would it make sense to attach them to the loopback device in the init namespace?
Quoted 9 lines
Quoted 8 lines
In fairness,
napi_idis also global, not per netns.By iterating over "for_each_netdev(net, ..", dump already limits output to pools in the same netns and get only reports pools that match the netns.
So it's only a minor matter of visible numbering, and perhaps superfluous new id.
Quoted 8 lines
The IDs are not stable. Any reconfiguration of a device will create a new page pool and therefore assign a new ID. So applications can't hold onto the ID long term.
That said the only use case for exposing the ID right now is to implement do/GET (since there is no other unique key). And manual debug with drgn, but that doesn't require uAPI. So if you prefer strongly I can drop the ID from the uAPI and do/GET support.
No, this is fine. I just wanted to make sure that the alternative api and netns details were considered beforehand, since it's uapi.
Jakub Kicinski
maintainerRe: [PATCH net-next v2 08/15] net: page_pool: add nlspec for basic access to page pools
Quoted 6 lines · On Tue, 21 Nov 2023 16:33:25 -0500 Willem de Bruijn wrote:
Quoted 2 lines
That does not work for "destroyed" pools. In general, there is no natural key for a page pool I can think of.
Pools for destroyed devices are attached to the loopback device. If the netns is also destroyed, would it make sense to attach them to the loopback device in the init namespace?
I remember discussing this somewhere in person... netconf? I opted for only exposing the cases which are obvious now, we can extend the API later, once we get some production experience.
Quoted 11 lines
Quoted 8 lines
The IDs are not stable. Any reconfiguration of a device will create a new page pool and therefore assign a new ID. So applications can't hold onto the ID long term.
That said the only use case for exposing the ID right now is to implement do/GET (since there is no other unique key). And manual debug with drgn, but that doesn't require uAPI. So if you prefer strongly I can drop the ID from the uAPI and do/GET support.
No, this is fine. I just wanted to make sure that the alternative api and netns details were considered beforehand, since it's uapi.
Okay, let me ditch it for now, in the interest of making progress.. It's easily added later.
Re: [PATCH net-next v2 08/15] net: page_pool: add nlspec for basic access to page pools
Quoted 9 lines · Jakub Kicinski
Quoted 6 lines · On Tue, 21 Nov 2023 16:33:25 -0500 Willem de Bruijn wrote:
Quoted 2 lines
That does not work for "destroyed" pools. In general, there is no natural key for a page pool I can think of.
Pools for destroyed devices are attached to the loopback device. If the netns is also destroyed, would it make sense to attach them to the loopback device in the init namespace?
I remember discussing this somewhere in person... netconf?
I asked why not blackhole_dev for just that problem.
Jakub Kicinski
maintainerRe: [PATCH net-next v2 08/15] net: page_pool: add nlspec for basic access to page pools
Quoted 3 lines · On Tue, 21 Nov 2023 14:49:31 -0800 David Ahern wrote:
Quoted 1 line
I remember discussing this somewhere in person... netconf?
I asked why not
blackhole_devfor just that problem.
Ack, but I don't see myself blabbering about the hidden objects on that sub-thread now.
Jakub Kicinski
maintainerPATCH v2 9/15 net: page_pool: implement GET in the netlink API
In reply to Jakub KicinskiExpose the very basic page pool information via netlink.
Example using ynl-py for a system with 9 queues:
$ ./cli.py --no-schema --spec netlink/specs/netdev.yaml \
--dump page-pool-get
[{'id': 19, 'ifindex': 2, 'napi-id': 147},
{'id': 18, 'ifindex': 2, 'napi-id': 146},
{'id': 17, 'ifindex': 2, 'napi-id': 145},
{'id': 16, 'ifindex': 2, 'napi-id': 144},
{'id': 15, 'ifindex': 2, 'napi-id': 143},
{'id': 14, 'ifindex': 2, 'napi-id': 142},
{'id': 13, 'ifindex': 2, 'napi-id': 141},
{'id': 12, 'ifindex': 2, 'napi-id': 140},
{'id': 11, 'ifindex': 2, 'napi-id': 139},
{'id': 10, 'ifindex': 2, 'napi-id': 138}]--- include/uapi/linux/netdev.h | 10 +++ net/core/netdev-genl-gen.c | 27 ++++++++ net/core/netdev-genl-gen.h | 3 + net/core/page_pool_user.c | 127 ++++++++++++++++++++++++++++++++++++ 4 files changed, 167 insertions(+)
include/uapi/linux/netdev.h +10 -0
@@ -64,11 +64,21 @@ enum {NETDEV_A_DEV_MAX = (__NETDEV_A_DEV_MAX -1 ) }; +enum { +NETDEV_A_PAGE_POOL_ID =1 , +NETDEV_A_PAGE_POOL_IFINDEX , +NETDEV_A_PAGE_POOL_NAPI_ID , + + __NETDEV_A_PAGE_POOL_MAX, +NETDEV_A_PAGE_POOL_MAX = (__NETDEV_A_PAGE_POOL_MAX -1 ) +}; +enum {NETDEV_CMD_DEV_GET =1 ,NETDEV_CMD_DEV_ADD_NTF ,NETDEV_CMD_DEV_DEL_NTF ,NETDEV_CMD_DEV_CHANGE_NTF , +NETDEV_CMD_PAGE_POOL_GET , __NETDEV_CMD_MAX,NETDEV_CMD_MAX = (__NETDEV_CMD_MAX -1 )
net/core/netdev-genl-gen.c +27 -0
@@ -10,11 +10,24 @@#include <uapi/linux/netdev.h> +/* Integer value ranges */ +static const struct netlink_range_validation netdev_a_page_pool_id_range = { + .min =1 , + .max =4294967295 , +}; +/* NETDEV_CMD_DEV_GET - do */ static const struct nla_policy netdev_dev_get_nl_policy[NETDEV_A_DEV_IFINDEX +1 ] = { [NETDEV_A_DEV_IFINDEX ] =NLA_POLICY_MIN (NLA_U32 ,1 ), }; +/* NETDEV_CMD_PAGE_POOL_GET - do */ +#ifdef CONFIG_PAGE_POOL +static const struct nla_policy netdev_page_pool_get_nl_policy[NETDEV_A_PAGE_POOL_ID +1 ] = { + [NETDEV_A_PAGE_POOL_ID ] =NLA_POLICY_FULL_RANGE (NLA_UINT , &netdev_a_page_pool_id_range), +}; +#endif /* CONFIG_PAGE_POOL */ +/* Ops table for netdev */ static const struct genl_split_ops netdev_nl_ops[] = { {
@@ -29,6 +42,20 @@ static const struct genl_split_ops netdev_nl_ops[] = { .dumpit = netdev_nl_dev_get_dumpit, .flags = GENL_CMD_CAP_DUMP, }, +#ifdef CONFIG_PAGE_POOL + { + .cmd = NETDEV_CMD_PAGE_POOL_GET, + .doit = netdev_nl_page_pool_get_doit, + .policy = netdev_page_pool_get_nl_policy, + .maxattr = NETDEV_A_PAGE_POOL_ID, + .flags = GENL_CMD_CAP_DO, + }, + { + .cmd = NETDEV_CMD_PAGE_POOL_GET, + .dumpit = netdev_nl_page_pool_get_dumpit, + .flags = GENL_CMD_CAP_DUMP, + }, +#endif /* CONFIG_PAGE_POOL */ }; static const struct genl_multicast_group netdev_nl_mcgrps[] = {
net/core/netdev-genl-gen.h +3 -0
@@ -13,6 +13,9 @@int netdev_nl_dev_get_doit (struct sk_buff *skb,struct genl_info *info);int netdev_nl_dev_get_dumpit (struct sk_buff *skb,struct netlink_callback *cb); +int netdev_nl_page_pool_get_doit (struct sk_buff *skb,struct genl_info *info); +int netdev_nl_page_pool_get_dumpit (struct sk_buff *skb, +struct netlink_callback *cb);enum {NETDEV_NLGRP_MGMT ,
net/core/page_pool_user.c +127 -0
141 lines not on this page · raw message
Signature · 1 line
2.42.0
Jakub Kicinski
maintainerPATCH v2 10/15 net: page_pool: add netlink notifications for state changes
In reply to Jakub KicinskiGenerate netlink notifications about page pool state changes.
--- Documentation/netlink/specs/netdev.yaml | 20 ++++++++++++++ include/uapi/linux/netdev.h | 4 +++ net/core/netdev-genl-gen.c | 1 + net/core/netdev-genl-gen.h | 1 + net/core/page_pool_user.c | 36 +++++++++++++++++++++++++ 5 files changed, 62 insertions(+)
Documentation/netlink/specs/netdev.yaml +20 -0
@@ -166,8 +166,28 @@ name: netdev dump: reply: *pp-reply config-cond: page-pool + - + name: page-pool-add-ntf + doc: Notification about page pool appearing. + notify: page-pool-get + mcgrp: page-pool + config-cond: page-pool + - + name: page-pool-del-ntf + doc: Notification about page pool disappearing. + notify: page-pool-get + mcgrp: page-pool + config-cond: page-pool + - + name: page-pool-change-ntf + doc: Notification about page pool configuration being changed. + notify: page-pool-get + mcgrp: page-pool + config-cond: page-pool mcast-groups: list: - name: mgmt + - + name: page-pool
include/uapi/linux/netdev.h +4 -0
@@ -79,11 +79,15 @@ enum {NETDEV_CMD_DEV_DEL_NTF ,NETDEV_CMD_DEV_CHANGE_NTF ,NETDEV_CMD_PAGE_POOL_GET , +NETDEV_CMD_PAGE_POOL_ADD_NTF , +NETDEV_CMD_PAGE_POOL_DEL_NTF , +NETDEV_CMD_PAGE_POOL_CHANGE_NTF , __NETDEV_CMD_MAX,NETDEV_CMD_MAX = (__NETDEV_CMD_MAX -1 ) };#define NETDEV_MCGRP_MGMT "mgmt" +#define NETDEV_MCGRP_PAGE_POOL "page-pool"#endif /* _UAPI_LINUX_NETDEV_H */
net/core/netdev-genl-gen.c +1 -0
@@ -60,6 +60,7 @@ static const struct genl_split_ops netdev_nl_ops[] = {static const struct genl_multicast_group netdev_nl_mcgrps[] = { [NETDEV_NLGRP_MGMT ] = {"mgmt" , }, + [NETDEV_NLGRP_PAGE_POOL ] = {"page-pool" , }, };struct genl_family netdev_nl_family__ro_after_init = {
net/core/netdev-genl-gen.h +1 -0
@@ -19,6 +19,7 @@ int netdev_nl_page_pool_get_dumpit(struct sk_buff *skb,enum {NETDEV_NLGRP_MGMT , +NETDEV_NLGRP_PAGE_POOL , };extern struct genl_family netdev_nl_family;
net/core/page_pool_user.c +36 -0
@@ -135,6 +135,37 @@ page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool,return -EMSGSIZE ; } +static void netdev_nl_page_pool_event (const struct page_pool *pool,u32 cmd) +{ +struct genl_info info; +struct sk_buff *ntf; +struct net *net; + +lockdep_assert_held (&page_pools_lock); + +/* 'invisible' page pools don't matter */ +if (hlist_unhashed (&pool->user.list)) +return ; + net =dev_net (pool->slow.netdev); + +if (!genl_has_listeners (&netdev_nl_family, net,NETDEV_NLGRP_PAGE_POOL )) +return ; + +genl_info_init_ntf (&info, &netdev_nl_family, cmd); + + ntf =genlmsg_new (GENLMSG_DEFAULT_SIZE ,GFP_KERNEL ); +if (!ntf) +return ; + +if (page_pool_nl_fill (ntf, pool, &info)) { +nlmsg_free (ntf); +return ; + } + +genlmsg_multicast_netns (&netdev_nl_family, net, ntf, +0 ,NETDEV_NLGRP_PAGE_POOL ,GFP_KERNEL ); +} +int netdev_nl_page_pool_get_doit (struct sk_buff *skb,struct genl_info *info) {u32 id;
@@ -168,6 +199,8 @@ int page_pool_list(struct page_pool *pool)hlist_add_head (&pool->user.list, &pool->slow.netdev->page_pools); pool->user.napi_id = pool->p.napi ? pool->p.napi->napi_id :0 ; + +netdev_nl_page_pool_event (pool,NETDEV_CMD_PAGE_POOL_ADD_NTF ); }mutex_unlock (&page_pools_lock);
@@ -181,6 +214,7 @@ int page_pool_list(struct page_pool *pool)void page_pool_unlist (struct page_pool *pool) {mutex_lock (&page_pools_lock); +netdev_nl_page_pool_event (pool,NETDEV_CMD_PAGE_POOL_DEL_NTF );xa_erase (&page_pools, pool->user.id);hlist_del (&pool->user.list);mutex_unlock (&page_pools_lock);
@@ -216,6 +250,8 @@ static void page_pool_unreg_netdev(struct net_device *netdev) last =NULL ;hlist_for_each_entry (pool, &netdev->page_pools, user.list) { pool->slow.netdev = lo; +netdev_nl_page_pool_event (pool, +NETDEV_CMD_PAGE_POOL_CHANGE_NTF ); last = pool; }if (last)
Signature · 1 line
2.42.0
Jakub Kicinski
maintainerPATCH v2 11/15 net: page_pool: report amount of memory held by page pools
In reply to Jakub KicinskiAdvanced 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.
--- 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(-)
Documentation/netlink/specs/netdev.yaml +13 -0
@@ -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
include/uapi/linux/netdev.h +2 -0
@@ -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 )
net/core/page_pool.c +9 -4
@@ -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);
net/core/page_pool_priv.h +2 -0
@@ -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);
net/core/page_pool_user.c +8 -0
@@ -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 ;
Signature · 1 line
2.42.0
Jakub Kicinski
maintainerPATCH v2 12/15 net: page_pool: report when page pool was destroyed
In reply to Jakub KicinskiReport 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}]--- Documentation/netlink/specs/netdev.yaml | 9 +++++++++ include/net/page_pool/types.h | 1 + include/uapi/linux/netdev.h | 1 + net/core/page_pool.c | 1 + net/core/page_pool_priv.h | 1 + net/core/page_pool_user.c | 12 ++++++++++++ 6 files changed, 25 insertions(+)
Documentation/netlink/specs/netdev.yaml +9 -0
@@ -125,6 +125,14 @@ name: netdev type: uint doc: | Amount of memory held by inflight pages. + - + name: destroyed + type: uint + 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. operations: list:
@@ -176,6 +184,7 @@ name: netdev - napi-id - inflight - inflight-mem + - destroyed dump: reply: *pp-reply config-cond: page-pool
include/net/page_pool/types.h +1 -0
@@ -193,6 +193,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;
include/uapi/linux/netdev.h +1 -0
@@ -70,6 +70,7 @@ enum {NETDEV_A_PAGE_POOL_NAPI_ID ,NETDEV_A_PAGE_POOL_INFLIGHT ,NETDEV_A_PAGE_POOL_INFLIGHT_MEM , +NETDEV_A_PAGE_POOL_DESTROYED , __NETDEV_A_PAGE_POOL_MAX,NETDEV_A_PAGE_POOL_MAX = (__NETDEV_A_PAGE_POOL_MAX -1 )
net/core/page_pool.c +1 -0
@@ -953,6 +953,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 ;
net/core/page_pool_priv.h +1 -0
@@ -6,6 +6,7 @@s32 page_pool_inflight (const struct page_pool *pool,bool strict);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
net/core/page_pool_user.c +12 -0
@@ -134,6 +134,10 @@ page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool, nla_put_uint(rsp, NETDEV_A_PAGE_POOL_INFLIGHT_MEM, inflight * refsz)) goto err_cancel; +if (pool->user.destroyed && +nla_put_uint (rsp,NETDEV_A_PAGE_POOL_DESTROYED , + pool->user.destroyed)) + goto err_cancel;genlmsg_end (rsp, hdr);
@@ -219,6 +223,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);
Signature · 1 line
2.42.0
Jesper Dangaard Brouer
maintainerRe: [PATCH net-next v2 12/15] net: page_pool: report when page pool was destroyed
Quoted 79 lines · Jakub Kicinski
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 <[email protected]>Signed-off-by Jakub Kicinski <[email protected]>--- Documentation/netlink/specs/netdev.yaml | 9 +++++++++ include/net/page_pool/types.h | 1 + include/uapi/linux/netdev.h | 1 + net/core/page_pool.c | 1 + net/core/page_pool_priv.h | 1 + net/core/page_pool_user.c | 12 ++++++++++++ 6 files changed, 25 insertions(+)Documentation/netlink/specs/netdev.yaml +9
-0@@ -125,6 +125,14 @@ name: netdev type: uint doc: | Amount of memory held by inflight pages. + - + name: destroyed + type: uint + 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. operations: list:@@ -176,6 +184,7 @@ name: netdev - napi-id - inflight - inflight-mem + - destroyed dump: reply: *pp-reply config-cond: page-poolinclude/net/page_pool/types.h +1
-0@@ -193,6 +193,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;include/uapi/linux/netdev.h +1
-0@@ -70,6 +70,7 @@ enum {NETDEV_A_PAGE_POOL_NAPI_ID ,NETDEV_A_PAGE_POOL_INFLIGHT ,NETDEV_A_PAGE_POOL_INFLIGHT_MEM , +NETDEV_A_PAGE_POOL_DESTROYED , __NETDEV_A_PAGE_POOL_MAX,NETDEV_A_PAGE_POOL_MAX = (__NETDEV_A_PAGE_POOL_MAX -1 )net/core/page_pool.c +0
-0
net/core/page_pool.c void page_pool_destroy(struct page_pool *pool) · line 956
Quoted 4 lines
net/core/page_pool.c +1
-0@@ -953,6 +953,7 @@ void page_pool_destroy(struct page_pool *pool)if (!page_pool_release (pool))return ; +page_pool_destroyed (pool);
Hmm, this is called when kernel could *NOT* destroy the PP, but have to start a work-queue that will retry deleting this. Thus, I think naming this "destroyed" is confusing as I then assumed was successfully destroyed, but it is not, instead it is on "deathrow".
Quoted 31 lines
net/core/page_pool.c +0
-0pool->defer_start = jiffies; pool->defer_warn = jiffies +DEFER_WARN_INTERVAL ;net/core/page_pool_priv.h +1
-0@@ -6,6 +6,7 @@s32 page_pool_inflight (const struct page_pool *pool,bool strict);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 net/core/page_pool_user.c +4
-0@@ -134,6 +134,10 @@ page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool, nla_put_uint(rsp, NETDEV_A_PAGE_POOL_INFLIGHT_MEM, inflight * refsz)) goto err_cancel; +if (pool->user.destroyed && +nla_put_uint (rsp,NETDEV_A_PAGE_POOL_DESTROYED , + pool->user.destroyed)) + goto err_cancel;genlmsg_end (rsp, hdr);
net/core/page_pool_user.c int page_pool_list(struct page_pool *pool) · line 230
Quoted 8 lines
net/core/page_pool_user.c +5
-0@@ -219,6 +223,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 );
Could we place this PP instance on another list of PP instances about to be deleted?
(e.g. a deathrow or sched_destroy list)
Perhaps this could also allow us to list those PP instances that no-longer have a netdev associated?
Quoted 2 lines
net/core/page_pool_user.c +2
-0+mutex_unlock (&page_pools_lock); +}
Jakub Kicinski
maintainerRe: [PATCH net-next v2 12/15] net: page_pool: report when page pool was destroyed
Quoted 4 lines · On Tue, 21 Nov 2023 21:45:57 +0100 Jesper Dangaard Brouer wrote:
Hmm, this is called when kernel could *NOT* destroy the PP, but have to start a work-queue that will retry deleting this. Thus, I think naming this "destroyed" is confusing as I then assumed was successfully destroyed, but it is not, instead it is on "deathrow".
I wasn't sure what to call it so I called what the driver API is called...
"deathrow" does not sound very intuitive to me. How about "detached" or "removed"?
Quoted 4 lines
Could we place this PP instance on another list of PP instances about to be deleted?
(e.g. a deathrow or
sched_destroylist)
Is there a need for that?
I mean - many interesting extensions to this API are possible. I don't think they should all can all be here from day 1..
Quoted 2 lines
Perhaps this could also allow us to list those PP instances that no-longer have a netdev associated?
The current implementation uses loopback for that, since it's naturally tied to a name space.
Jesper Dangaard Brouer
maintainerRe: [PATCH net-next v2 12/15] net: page_pool: report when page pool was destroyed
Quoted 11 lines · Jakub Kicinski
Quoted 4 lines · On Tue, 21 Nov 2023 21:45:57 +0100 Jesper Dangaard Brouer wrote:
Hmm, this is called when kernel could *NOT* destroy the PP, but have to start a work-queue that will retry deleting this. Thus, I think naming this "destroyed" is confusing as I then assumed was successfully destroyed, but it is not, instead it is on "deathrow".
I wasn't sure what to call it so I called what the driver API is called...
"deathrow" does not sound very intuitive to me. How about "detached" or "removed"?
I like "detached".
Quoted 8 lines
Quoted 5 lines
Could we place this PP instance on another list of PP instances about to be deleted?
(e.g. a deathrow or
sched_destroylist)Is there a need for that?
Quoted 8 lines
I mean - many interesting extensions to this API are possible. I don't think they should all can all be here from day 1..
Quoted 2 lines
Perhaps this could also allow us to list those PP instances that no-longer have a netdev associated?
The current implementation uses loopback for that, since it's naturally tied to a name space.
Okay, guess it makes sense to tie this to loopback.
--Jesper
Jakub Kicinski
maintainerPATCH v2 13/15 net: page_pool: expose page pool stats via netlink
In reply to Jakub KicinskiDump the stats into netlink. More clever approaches like dumping the stats per-CPU for each CPU individually to see where the packets get consumed can be implemented in the future.
A trimmed example from a real (but recently booted system):
$ ./cli.py --no-schema --spec netlink/specs/netdev.yaml \
--dump page-pool-stats-get
[{'info': {'id': 19, 'ifindex': 2},
'alloc-empty': 48,
'alloc-fast': 3024,
'alloc-refill': 0,
'alloc-slow': 48,
'alloc-slow-high-order': 0,
'alloc-waive': 0,
'recycle-cache-full': 0,
'recycle-cached': 0,
'recycle-released-refcnt': 0,
'recycle-ring': 0,
'recycle-ring-full': 0},
{'info': {'id': 18, 'ifindex': 2},
'alloc-empty': 66,
'alloc-fast': 11811,
'alloc-refill': 35,
'alloc-slow': 66,
'alloc-slow-high-order': 0,
'alloc-waive': 0,
'recycle-cache-full': 1145,
'recycle-cached': 6541,
'recycle-released-refcnt': 0,
'recycle-ring': 1275,
'recycle-ring-full': 0},
{'info': {'id': 17, 'ifindex': 2},
'alloc-empty': 73,
'alloc-fast': 62099,
'alloc-refill': 413,
...--- Documentation/netlink/specs/netdev.yaml | 78 ++++++++++++++++++ Documentation/networking/page_pool.rst | 10 ++- include/net/page_pool/helpers.h | 8 +- include/uapi/linux/netdev.h | 19 +++++ net/core/netdev-genl-gen.c | 32 ++++++++ net/core/netdev-genl-gen.h | 7 ++ net/core/page_pool.c | 2 +- net/core/page_pool_user.c | 103 ++++++++++++++++++++++++ 8 files changed, 250 insertions(+), 9 deletions(-)
Documentation/netlink/specs/netdev.yaml +78 -0
@@ -133,6 +133,59 @@ name: netdev 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: page-pool-info + subset-of: page-pool + attributes: + - + name: id + - + name: ifindex + - + name: page-pool-stats + doc: | + Page pool statistics, see docs for struct page_pool_stats + for information about individual statistics. + attributes: + - + name: info + doc: Page pool identifying information. + type: nest + nested-attributes: page-pool-info + - + name: alloc-fast + type: uint + value: 8 # reserve some attr ids in case we need more metadata later + - + name: alloc-slow + type: uint + - + name: alloc-slow-high-order + type: uint + - + name: alloc-empty + type: uint + - + name: alloc-refill + type: uint + - + name: alloc-waive + type: uint + - + name: recycle-cached + type: uint + - + name: recycle-cache-full + type: uint + - + name: recycle-ring + type: uint + - + name: recycle-ring-full + type: uint + - + name: recycle-released-refcnt + type: uint operations: list:
@@ -206,6 +259,31 @@ name: netdev notify: page-pool-get mcgrp: page-pool config-cond: page-pool + - + name: page-pool-stats-get + doc: Get page pool statistics. + attribute-set: page-pool-stats + do: + request: + attributes: + - info + reply: &pp-stats-reply + attributes: + - info + - alloc-fast + - alloc-slow + - alloc-slow-high-order + - alloc-empty + - alloc-refill + - alloc-waive + - recycle-cached + - recycle-cache-full + - recycle-ring + - recycle-ring-full + - recycle-released-refcnt + dump: + reply: *pp-stats-reply + config-cond: page-pool-stats mcast-groups: list:
Documentation/networking/page_pool.rst +8 -2
@@ -41,6 +41,11 @@ Architecture overview | Fast cache | | ptr-ring cache | +-----------------+ +------------------+ +Monitoring +========== +Information about page pools on the system can be accessed via the netdev +genetlink family (see Documentation/netlink/specs/netdev.yaml). + API interface ============= The number of pools created **must** match the number of hardware queues
@@ -107,8 +112,9 @@ page_pool_get_stats() and structures described below are available. It takes a pointer to a ``struct page_pool`` and a pointer to a struct page_pool_stats allocated by the caller. -The API will fill in the provided struct page_pool_stats with -statistics about the page_pool. +Older drivers expose page pool statistics via ethtool or debugfs. +The same statistics are accessible via the netlink netdev family +in a driver-independent fashion. .. kernel-doc:: include/net/page_pool/types.h :identifiers: struct page_pool_recycle_stats
include/net/page_pool/helpers.h +2 -6
@@ -55,16 +55,12 @@#include <net/page_pool/types.h> #ifdef CONFIG_PAGE_POOL_STATS +/* Deprecated driver-facing API, use netlink instead */ int page_pool_ethtool_stats_get_count (void );u8 *page_pool_ethtool_stats_get_strings (u8 *data);u64 *page_pool_ethtool_stats_get (u64 *data,void *stats); -/* -* Drivers that wish to harvest page pool stats and report them to users -* (perhaps via ethtool, debugfs, or another mechanism) can allocate a -* struct page_pool_stats call page_pool_get_stats to get stats for the specified pool. -*/ -bool page_pool_get_stats (struct page_pool *pool, +bool page_pool_get_stats (const struct page_pool *pool,struct page_pool_stats *stats);#else static inline int page_pool_ethtool_stats_get_count (void )
include/uapi/linux/netdev.h +19 -0
@@ -76,6 +76,24 @@ enum {NETDEV_A_PAGE_POOL_MAX = (__NETDEV_A_PAGE_POOL_MAX -1 ) }; +enum { +NETDEV_A_PAGE_POOL_STATS_INFO =1 , +NETDEV_A_PAGE_POOL_STATS_ALLOC_FAST =8 , +NETDEV_A_PAGE_POOL_STATS_ALLOC_SLOW , +NETDEV_A_PAGE_POOL_STATS_ALLOC_SLOW_HIGH_ORDER , +NETDEV_A_PAGE_POOL_STATS_ALLOC_EMPTY , +NETDEV_A_PAGE_POOL_STATS_ALLOC_REFILL , +NETDEV_A_PAGE_POOL_STATS_ALLOC_WAIVE , +NETDEV_A_PAGE_POOL_STATS_RECYCLE_CACHED , +NETDEV_A_PAGE_POOL_STATS_RECYCLE_CACHE_FULL , +NETDEV_A_PAGE_POOL_STATS_RECYCLE_RING , +NETDEV_A_PAGE_POOL_STATS_RECYCLE_RING_FULL , +NETDEV_A_PAGE_POOL_STATS_RECYCLE_RELEASED_REFCNT , + + __NETDEV_A_PAGE_POOL_STATS_MAX, +NETDEV_A_PAGE_POOL_STATS_MAX = (__NETDEV_A_PAGE_POOL_STATS_MAX -1 ) +}; +enum {NETDEV_CMD_DEV_GET =1 ,NETDEV_CMD_DEV_ADD_NTF ,
@@ -85,6 +103,7 @@ enum {NETDEV_CMD_PAGE_POOL_ADD_NTF ,NETDEV_CMD_PAGE_POOL_DEL_NTF ,NETDEV_CMD_PAGE_POOL_CHANGE_NTF , +NETDEV_CMD_PAGE_POOL_STATS_GET , __NETDEV_CMD_MAX,NETDEV_CMD_MAX = (__NETDEV_CMD_MAX -1 )
net/core/netdev-genl-gen.c +32 -0
@@ -16,6 +16,17 @@ static const struct netlink_range_validation netdev_a_page_pool_id_range = { .max = 4294967295, }; +static const struct netlink_range_validation netdev_a_page_pool_ifindex_range = { + .min =1 , + .max =2147483647 , +}; + +/* Common nested types */ +const struct nla_policy netdev_page_pool_info_nl_policy[NETDEV_A_PAGE_POOL_IFINDEX +1 ] = { + [NETDEV_A_PAGE_POOL_ID ] =NLA_POLICY_FULL_RANGE (NLA_UINT , &netdev_a_page_pool_id_range), + [NETDEV_A_PAGE_POOL_IFINDEX ] =NLA_POLICY_FULL_RANGE (NLA_U32 , &netdev_a_page_pool_ifindex_range), +}; +/* NETDEV_CMD_DEV_GET - do */ static const struct nla_policy netdev_dev_get_nl_policy[NETDEV_A_DEV_IFINDEX +1 ] = { [NETDEV_A_DEV_IFINDEX ] =NLA_POLICY_MIN (NLA_U32 ,1 ),
@@ -28,6 +39,13 @@ static const struct nla_policy netdev_page_pool_get_nl_policy[NETDEV_A_PAGE_POOL };#endif /* CONFIG_PAGE_POOL */ +/* NETDEV_CMD_PAGE_POOL_STATS_GET - do */ +#ifdef CONFIG_PAGE_POOL_STATS +static const struct nla_policy netdev_page_pool_stats_get_nl_policy[NETDEV_A_PAGE_POOL_STATS_INFO +1 ] = { + [NETDEV_A_PAGE_POOL_STATS_INFO ] =NLA_POLICY_NESTED (netdev_page_pool_info_nl_policy), +}; +#endif /* CONFIG_PAGE_POOL_STATS */ +/* Ops table for netdev */ static const struct genl_split_ops netdev_nl_ops[] = { {
@@ -56,6 +74,20 @@ static const struct genl_split_ops netdev_nl_ops[] = { .flags = GENL_CMD_CAP_DUMP, },#endif /* CONFIG_PAGE_POOL */ +#ifdef CONFIG_PAGE_POOL_STATS + { + .cmd = NETDEV_CMD_PAGE_POOL_STATS_GET, + .doit = netdev_nl_page_pool_stats_get_doit, + .policy = netdev_page_pool_stats_get_nl_policy, + .maxattr = NETDEV_A_PAGE_POOL_STATS_INFO, + .flags = GENL_CMD_CAP_DO, + }, + { + .cmd = NETDEV_CMD_PAGE_POOL_STATS_GET, + .dumpit = netdev_nl_page_pool_stats_get_dumpit, + .flags = GENL_CMD_CAP_DUMP, + }, +#endif /* CONFIG_PAGE_POOL_STATS */ }; static const struct genl_multicast_group netdev_nl_mcgrps[] = {
net/core/netdev-genl-gen.h +7 -0
@@ -11,11 +11,18 @@#include <uapi/linux/netdev.h> +/* Common nested types */ +extern const struct nla_policy netdev_page_pool_info_nl_policy[NETDEV_A_PAGE_POOL_IFINDEX +1 ]; +int netdev_nl_dev_get_doit (struct sk_buff *skb,struct genl_info *info);int netdev_nl_dev_get_dumpit (struct sk_buff *skb,struct netlink_callback *cb);int netdev_nl_page_pool_get_doit (struct sk_buff *skb,struct genl_info *info);int netdev_nl_page_pool_get_dumpit (struct sk_buff *skb,struct netlink_callback *cb); +int netdev_nl_page_pool_stats_get_doit (struct sk_buff *skb, +struct genl_info *info); +int netdev_nl_page_pool_stats_get_dumpit (struct sk_buff *skb, +struct netlink_callback *cb);enum {NETDEV_NLGRP_MGMT ,
net/core/page_pool.c +1 -1
@@ -71,7 +71,7 @@ static const char pp_stats[][ETH_GSTRING_LEN] = {* is passed to this API which is filled in. The caller can then report * those stats to the user (perhaps via ethtool, debugfs, etc.). */ -bool page_pool_get_stats (struct page_pool *pool, +bool page_pool_get_stats (const struct page_pool *pool,struct page_pool_stats *stats) {int cpu =0 ;
net/core/page_pool_user.c +103 -0
115 lines not on this page · raw message
Signature · 1 line
2.42.0
Jakub Kicinski
maintainerPATCH v2 14/15 net: page_pool: mute the periodic warning for visible page pools
In reply to Jakub KicinskiMute the periodic "stalled pool shutdown" warning if the page pool is visible to user space. Rolling out a driver using page pools to just a few hundred hosts at Meta surfaces applications which fail to reap their broken sockets. Obviously it's best if the applications are fixed, but we don't generally print warnings for application resource leaks. Admins can now depend on the netlink interface for getting page pool info to detect buggy apps.
While at it throw in the ID of the pool into the message, in rare cases (pools from destroyed netns) this will make finding the pool with a debugger easier.
--- net/core/page_pool.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
net/core/page_pool.c +7 -4
@@ -897,18 +897,21 @@ static void page_pool_release_retry(struct work_struct *wq) {struct delayed_work *dwq =to_delayed_work (wq);struct page_pool *pool =container_of (dwq,typeof (*pool), release_dw); +void *netdev;int inflight; inflight =page_pool_release (pool);if (!inflight)return ; -/* Periodic warning */ -if (time_after_eq (jiffies, pool->defer_warn)) { +/* Periodic warning for page pools the user can't see */ + netdev =READ_ONCE (pool->slow.netdev); +if (time_after_eq (jiffies, pool->defer_warn) && + (!netdev || netdev ==NET_PTR_POISON )) {int sec = (s32)((u32 )jiffies - (u32 )pool->defer_start) /HZ ; -pr_warn ("%s() stalled pool shutdown %d inflight %d sec\n" , - __func__, inflight, sec); +pr_warn ("%s() stalled pool shutdown: id %u, %d inflight %d sec\n" , + __func__, pool->user.id, inflight, sec); pool->defer_warn = jiffies +DEFER_WARN_INTERVAL ; }
Signature · 1 line
2.42.0
Jakub Kicinski
maintainerPATCH v2 15/15 tools: ynl: add sample for getting page-pool information
In reply to Jakub KicinskiRegenerate the tools/ code after netdev spec changes.
Add sample to query page-pool info in a concise fashion:
$ ./page-pool
eth0[2] page pools: 10 (zombies: 0)
refs: 41984 bytes: 171966464 (refs: 0 bytes: 0)
recycling: 90.3% (alloc: 656:397681 recycle: 89652:270201)--- tools/include/uapi/linux/netdev.h | 36 +++ tools/net/ynl/generated/netdev-user.c | 419 ++++++++++++++++++++++++++ tools/net/ynl/generated/netdev-user.h | 171 +++++++++++ tools/net/ynl/lib/ynl.h | 2 +- tools/net/ynl/samples/.gitignore | 1 + tools/net/ynl/samples/Makefile | 2 +- tools/net/ynl/samples/page-pool.c | 147 +++++++++ 7 files changed, 776 insertions(+), 2 deletions(-) create mode 100644 tools/net/ynl/samples/page-pool.c
tools/include/uapi/linux/netdev.h +36 -0
@@ -64,16 +64,52 @@ enum {NETDEV_A_DEV_MAX = (__NETDEV_A_DEV_MAX -1 ) }; +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_DESTROYED , + + __NETDEV_A_PAGE_POOL_MAX, +NETDEV_A_PAGE_POOL_MAX = (__NETDEV_A_PAGE_POOL_MAX -1 ) +}; + +enum { +NETDEV_A_PAGE_POOL_STATS_INFO =1 , +NETDEV_A_PAGE_POOL_STATS_ALLOC_FAST =8 , +NETDEV_A_PAGE_POOL_STATS_ALLOC_SLOW , +NETDEV_A_PAGE_POOL_STATS_ALLOC_SLOW_HIGH_ORDER , +NETDEV_A_PAGE_POOL_STATS_ALLOC_EMPTY , +NETDEV_A_PAGE_POOL_STATS_ALLOC_REFILL , +NETDEV_A_PAGE_POOL_STATS_ALLOC_WAIVE , +NETDEV_A_PAGE_POOL_STATS_RECYCLE_CACHED , +NETDEV_A_PAGE_POOL_STATS_RECYCLE_CACHE_FULL , +NETDEV_A_PAGE_POOL_STATS_RECYCLE_RING , +NETDEV_A_PAGE_POOL_STATS_RECYCLE_RING_FULL , +NETDEV_A_PAGE_POOL_STATS_RECYCLE_RELEASED_REFCNT , + + __NETDEV_A_PAGE_POOL_STATS_MAX, +NETDEV_A_PAGE_POOL_STATS_MAX = (__NETDEV_A_PAGE_POOL_STATS_MAX -1 ) +}; +enum {NETDEV_CMD_DEV_GET =1 ,NETDEV_CMD_DEV_ADD_NTF ,NETDEV_CMD_DEV_DEL_NTF ,NETDEV_CMD_DEV_CHANGE_NTF , +NETDEV_CMD_PAGE_POOL_GET , +NETDEV_CMD_PAGE_POOL_ADD_NTF , +NETDEV_CMD_PAGE_POOL_DEL_NTF , +NETDEV_CMD_PAGE_POOL_CHANGE_NTF , +NETDEV_CMD_PAGE_POOL_STATS_GET , __NETDEV_CMD_MAX,NETDEV_CMD_MAX = (__NETDEV_CMD_MAX -1 ) };#define NETDEV_MCGRP_MGMT "mgmt" +#define NETDEV_MCGRP_PAGE_POOL "page-pool"#endif /* _UAPI_LINUX_NETDEV_H */
tools/net/ynl/generated/netdev-user.c +419 -0
450 lines not on this page · raw message
tools/net/ynl/generated/netdev-user.h +171 -0
181 lines not on this page · raw message
tools/net/ynl/lib/ynl.h +1 -1
@@ -239,7 +239,7 @@ int ynl_error_parse(struct ynl_parse_arg *yarg, const char *msg);#ifndef MNL_HAS_AUTO_SCALARS static inline uint64_t mnl_attr_get_uint (const struct nlattr *attr) { -if (mnl_attr_get_len (attr) ==4 ) +if (mnl_attr_get_payload_len (attr) ==4 )return mnl_attr_get_u32 (attr);return mnl_attr_get_u64 (attr); }
tools/net/ynl/samples/.gitignore +1 -0
@@ -1,3 +1,4 @@ ethtool devlink netdev +page-pool
tools/net/ynl/samples/Makefile +1 -1
@@ -18,7 +18,7 @@ include $(wildcard *.d) all: $(BINS) -$(BINS): ../lib/ynl.a ../generated/protos.a +$(BINS): ../lib/ynl.a ../generated/protos.a $(SRCS) @echo -e '\tCC sample $@' @$(COMPILE.c) $(CFLAGS_$@) [email protected] -o [email protected] @$(LINK.c) [email protected] -o $@ $(LDLIBS)
tools/net/ynl/samples/page-pool.c new file +147 -0
147 lines not on this page · raw message
Signature · 1 line
2.42.0
Jakub Kicinski
maintainerQuoted 2 lines · On Mon, 20 Nov 2023 16:00:33 -0800 Jakub Kicinski wrote:
net:
page_pool: split thepage_pool_paramsinto fast and slow
net:page_pool: avoid touching slow on the fastpath
To relieve some of the pain and suffering this series causes to our build tester I'm going to apply the first 2 patches already. I hope that's fine. They are pretty stand-alone and have broad acks/review tags.
Jesper Dangaard Brouer
maintainerQuoted 8 lines · Jakub Kicinski
Quoted 2 lines · On Mon, 20 Nov 2023 16:00:33 -0800 Jakub Kicinski wrote:
net:
page_pool: split thepage_pool_paramsinto fast and slow
net:page_pool: avoid touching slow on the fastpathTo relieve some of the pain and suffering this series causes to our build tester I'm going to apply the first 2 patches already. I hope that's fine. They are pretty stand-alone and have broad acks/review tags.
Fine by me to apply the first 2 patches. Thanks for communicating this as I did get confused seeing patchwork-bot reporting this was applied and seeing a V3 on the list.
Keep up the good work. Overall I like this netlink-based introspection. I'll try to get some opinions from Cloudflare people how this can be integrated into existing monitoring systems.
--Jesper
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 11 lines · On Mon, 20 Nov 2023 16:00:33 -0800 you wrote:
We recently started to deploy newer kernels / drivers at Meta, making significant use of page pools for the first time. We immediately run into page pool leaks both real and false positive warnings. As Eric pointed out/predicted there's no guarantee that applications will read / close their sockets so a page pool page may be stuck in a socket (but not leaked) forever. This happens a lot in our fleet. Most of these are obviously due to application bugs but we should not be printing kernel warnings due to minor application resource leaks.
[...]
Here is the summary with links:
- [net-next,v2,01/15] net: page_pool: split the page_pool_params into fast and slow
https://git.kernel.org/netdev/net-next/c/5027ec19f104 - [net-next,v2,02/15] net: page_pool: avoid touching slow on the fastpath https://git.kernel.org/netdev/net-next/c/2da0cac1e949
- [net-next,v2,03/15] net: page_pool: factor out uninit
(no matching commit)
- [net-next,v2,04/15] net: page_pool: id the page pools
(no matching commit)
- [net-next,v2,05/15] net: page_pool: record pools per netdev
(no matching commit)
- [net-next,v2,06/15] net: page_pool: stash the NAPI ID for easier access (no matching commit)
- [net-next,v2,07/15] eth: link netdev to page_pools in drivers
(no matching commit)
- [net-next,v2,08/15] net: page_pool: add nlspec for basic access to page pools (no matching commit)
- [net-next,v2,09/15] net: page_pool: implement GET in the netlink API (no matching commit)
- [net-next,v2,10/15] net: page_pool: add netlink notifications for state changes (no matching commit)
- [net-next,v2,11/15] net: page_pool: report amount of memory held by page pools (no matching commit)
- [net-next,v2,12/15] net: page_pool: report when page pool was destroyed (no matching commit)
- [net-next,v2,13/15] net: page_pool: expose page pool stats via netlink (no matching commit)
- [net-next,v2,14/15] net: page_pool: mute the periodic warning for visible page pools (no matching commit)
- [net-next,v2,15/15] tools: ynl: add sample for getting page-pool information (no matching commit)
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html