Skip to content

Commit 7aee842

Browse files
kuba-mooPaolo Abeni
authored andcommitted
net: page_pool: report amount of memory held by page pools
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. 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 d2ef6aa commit 7aee842

File tree

5 files changed

+36
-4
lines changed

5 files changed

+36
-4
lines changed

Documentation/netlink/specs/netdev.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,19 @@ attribute-sets:
114114
checks:
115115
min: 1
116116
max: u32-max
117+
-
118+
name: inflight
119+
type: uint
120+
doc: |
121+
Number of outstanding references to this page pool (allocated
122+
but yet to be freed pages). Allocated pages may be held in
123+
socket receive queues, driver receive ring, page pool recycling
124+
ring, the page pool cache, etc.
125+
-
126+
name: inflight-mem
127+
type: uint
128+
doc: |
129+
Amount of memory held by inflight pages.
117130
118131
operations:
119132
list:
@@ -163,6 +176,8 @@ operations:
163176
- id
164177
- ifindex
165178
- napi-id
179+
- inflight
180+
- inflight-mem
166181
dump:
167182
reply: *pp-reply
168183
config-cond: page-pool

include/uapi/linux/netdev.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ enum {
6868
NETDEV_A_PAGE_POOL_ID = 1,
6969
NETDEV_A_PAGE_POOL_IFINDEX,
7070
NETDEV_A_PAGE_POOL_NAPI_ID,
71+
NETDEV_A_PAGE_POOL_INFLIGHT,
72+
NETDEV_A_PAGE_POOL_INFLIGHT_MEM,
7173

7274
__NETDEV_A_PAGE_POOL_MAX,
7375
NETDEV_A_PAGE_POOL_MAX = (__NETDEV_A_PAGE_POOL_MAX - 1)

net/core/page_pool.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -529,16 +529,21 @@ EXPORT_SYMBOL(page_pool_alloc_pages);
529529
*/
530530
#define _distance(a, b) (s32)((a) - (b))
531531

532-
static s32 page_pool_inflight(struct page_pool *pool)
532+
s32 page_pool_inflight(const struct page_pool *pool, bool strict)
533533
{
534534
u32 release_cnt = atomic_read(&pool->pages_state_release_cnt);
535535
u32 hold_cnt = READ_ONCE(pool->pages_state_hold_cnt);
536536
s32 inflight;
537537

538538
inflight = _distance(hold_cnt, release_cnt);
539539

540-
trace_page_pool_release(pool, inflight, hold_cnt, release_cnt);
541-
WARN(inflight < 0, "Negative(%d) inflight packet-pages", inflight);
540+
if (strict) {
541+
trace_page_pool_release(pool, inflight, hold_cnt, release_cnt);
542+
WARN(inflight < 0, "Negative(%d) inflight packet-pages",
543+
inflight);
544+
} else {
545+
inflight = max(0, inflight);
546+
}
542547

543548
return inflight;
544549
}
@@ -881,7 +886,7 @@ static int page_pool_release(struct page_pool *pool)
881886
int inflight;
882887

883888
page_pool_scrub(pool);
884-
inflight = page_pool_inflight(pool);
889+
inflight = page_pool_inflight(pool, true);
885890
if (!inflight)
886891
__page_pool_destroy(pool);
887892

net/core/page_pool_priv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#ifndef __PAGE_POOL_PRIV_H
44
#define __PAGE_POOL_PRIV_H
55

6+
s32 page_pool_inflight(const struct page_pool *pool, bool strict);
7+
68
int page_pool_list(struct page_pool *pool);
79
void page_pool_unlist(struct page_pool *pool);
810

net/core/page_pool_user.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ static int
110110
page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool,
111111
const struct genl_info *info)
112112
{
113+
size_t inflight, refsz;
113114
void *hdr;
114115

115116
hdr = genlmsg_iput(rsp, info);
@@ -127,6 +128,13 @@ page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool,
127128
nla_put_uint(rsp, NETDEV_A_PAGE_POOL_NAPI_ID, pool->user.napi_id))
128129
goto err_cancel;
129130

131+
inflight = page_pool_inflight(pool, false);
132+
refsz = PAGE_SIZE << pool->p.order;
133+
if (nla_put_uint(rsp, NETDEV_A_PAGE_POOL_INFLIGHT, inflight) ||
134+
nla_put_uint(rsp, NETDEV_A_PAGE_POOL_INFLIGHT_MEM,
135+
inflight * refsz))
136+
goto err_cancel;
137+
130138
genlmsg_end(rsp, hdr);
131139

132140
return 0;

0 commit comments

Comments
 (0)