net: page_pool: fix recycle stats for system page_pool allocator
Subsystems (3)
PATCH 1/1 net: page_pool: fix recycle stats for system page_pool allocator
Use global percpu page_pool_recycle_stats counter for system page_pool allocator instead of allocating a separate percpu variable for each (also percpu) page pool instance.
--- include/net/page_pool/types.h | 5 +++-- net/core/dev.c | 1 + net/core/page_pool.c | 22 +++++++++++++++++----- 3 files changed, 21 insertions(+), 7 deletions(-)
include/net/page_pool/types.h +3 -2
@@ -18,8 +18,9 @@* Please note DMA-sync-for-CPU is still * device driver responsibility */ -#define PP_FLAG_ALL (PP_FLAG_DMA_MAP |\ - PP_FLAG_DMA_SYNC_DEV) +#define PP_FLAG_SYSTEM_POOL BIT(2)/* Global system page_pool */ +#define PP_FLAG_ALL (PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV | \ + PP_FLAG_SYSTEM_POOL)/* * Fast allocation side cache array/stack
net/core/dev.c +1 -0
@@ -11738,6 +11738,7 @@ static int net_page_pool_create(int cpuid)#if IS_ENABLED (CONFIG_PAGE_POOL )struct page_pool_params page_pool_params = { .pool_size =SYSTEM_PERCPU_PAGE_POOL_SIZE , + .flags =PP_FLAG_SYSTEM_POOL , .nid =NUMA_NO_NODE , };struct page_pool *pp_ptr;
net/core/page_pool.c +17 -5
@@ -31,6 +31,8 @@#define BIAS_MAX (LONG_MAX >> 1)#ifdef CONFIG_PAGE_POOL_STATS +static DEFINE_PER_CPU(struct page_pool_recycle_stats, pp_system_recycle_stats); +/* alloc_stat_inc is intended to be used in softirq context */ #define alloc_stat_inc (pool, __stat) (pool->alloc_stats.__stat++)/* recycle_stat_inc is safe to use when preemption is possible. */
@@ -220,14 +222,23 @@ 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) -return -ENOMEM ; +if (!(pool->p.flags &PP_FLAG_SYSTEM_POOL )) { + pool->recycle_stats = alloc_percpu(struct page_pool_recycle_stats); +if (!pool->recycle_stats) +return -ENOMEM ; + }else { +/* For system page pool instance we use a singular stats object +* instead of allocating a separate percpu variable for each +* (also percpu) page pool instance. +*/ + pool->recycle_stats = &pp_system_recycle_stats; + }#endif if (ptr_ring_init (&pool->ring, ring_qsize,GFP_KERNEL ) <0 ) {#ifdef CONFIG_PAGE_POOL_STATS -free_percpu (pool->recycle_stats); +if (!(pool->p.flags &PP_FLAG_SYSTEM_POOL )) +free_percpu (pool->recycle_stats);#endif return -ENOMEM ; }
@@ -251,7 +262,8 @@ static void page_pool_uninit(struct page_pool *pool)put_device (pool->p.dev);#ifdef CONFIG_PAGE_POOL_STATS -free_percpu (pool->recycle_stats); +if (!(pool->p.flags &PP_FLAG_SYSTEM_POOL )) +free_percpu (pool->recycle_stats);#endif }
Signature · 1 line
2.43.2
From: Lorenzo Bianconi <[email protected]>
Date: Fri, 16 Feb 2024 10:25:43 +0100
Quoted 5 lines
Use global percpu
page_pool_recycle_statscounter for systempage_poolallocator instead of allocating a separate percpu variable for each (also percpu) page pool instance.Reviewed-by Toke Hoiland-Jorgensen <[email protected]>
Quoted 6 lines
Signed-off-by Lorenzo Bianconi <[email protected]>--- include/net/page_pool/types.h | 5 +++-- net/core/dev.c | 1 + net/core/page_pool.c | 22 +++++++++++++++++----- 3 files changed, 21 insertions(+), 7 deletions(-)
Thanks,
Olek
Quoted 3 lines · Lorenzo Bianconi
Use global percpu
page_pool_recycle_statscounter for systempage_poolallocator instead of allocating a separate percpu variable for each (also percpu) page pool instance.
I may missed some obvious discussion in previous version due to spring holiday.
Quoted 57 lines
Reviewed-by Toke Hoiland-Jorgensen <[email protected]>Signed-off-by Lorenzo Bianconi <[email protected]>--- include/net/page_pool/types.h | 5 +++-- net/core/dev.c | 1 + net/core/page_pool.c | 22 +++++++++++++++++----- 3 files changed, 21 insertions(+), 7 deletions(-)include/net/page_pool/types.h +3
-2@@ -18,8 +18,9 @@* Please note DMA-sync-for-CPU is still * device driver responsibility */ -#define PP_FLAG_ALL (PP_FLAG_DMA_MAP |\ - PP_FLAG_DMA_SYNC_DEV) +#define PP_FLAG_SYSTEM_POOL BIT(2)/* Global system page_pool */ +#define PP_FLAG_ALL (PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV | \ + PP_FLAG_SYSTEM_POOL)/* * Fast allocation side cache array/stack net/core/dev.c +1
-0@@ -11738,6 +11738,7 @@ static int net_page_pool_create(int cpuid)#if IS_ENABLED (CONFIG_PAGE_POOL )struct page_pool_params page_pool_params = { .pool_size =SYSTEM_PERCPU_PAGE_POOL_SIZE , + .flags =PP_FLAG_SYSTEM_POOL , .nid =NUMA_NO_NODE , };struct page_pool *pp_ptr;net/core/page_pool.c +2
-3@@ -31,6 +31,8 @@#define BIAS_MAX (LONG_MAX >> 1)#ifdef CONFIG_PAGE_POOL_STATS +static DEFINE_PER_CPU(struct page_pool_recycle_stats, pp_system_recycle_stats); +/* alloc_stat_inc is intended to be used in softirq context */ #define alloc_stat_inc (pool, __stat) (pool->alloc_stats.__stat++)/* recycle_stat_inc is safe to use when preemption is possible. */ @@ -220,14 +222,23 @@ 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) -return -ENOMEM ;
net/core/page_pool.c static int page_pool_init(struct page_pool *pool, · line 234
Quoted 10 lines
net/core/page_pool.c +10
-0+if (!(pool->p.flags &PP_FLAG_SYSTEM_POOL )) { + pool->recycle_stats = alloc_percpu(struct page_pool_recycle_stats); +if (!pool->recycle_stats) +return -ENOMEM ; + }else { +/* For system page pool instance we use a singular stats object +* instead of allocating a separate percpu variable for each +* (also percpu) page pool instance. +*/ + pool->recycle_stats = &pp_system_recycle_stats;
Do we need to return -EINVAL here if page_pool_init() is called with pool->p.flags & PP_FLAG_SYSTEM_POOL being true and cpuid being a valid cpu?
If yes, it seems we may be able to use the cpuid to decide if we need to allocate a new pool->recycle_stats without adding a new flag.
If no, the API for page_pool_create_percpu() seems a litte weird as it relies on the user calling it correctly.
Also, do we need to enforce that page_pool_create_percpu() is only called once for the same cpu? if no, we may have two page_pool instance sharing the same stats.
Quoted 22 lines
net/core/page_pool.c +5
-2+ }#endif if (ptr_ring_init (&pool->ring, ring_qsize,GFP_KERNEL ) <0 ) {#ifdef CONFIG_PAGE_POOL_STATS -free_percpu (pool->recycle_stats); +if (!(pool->p.flags &PP_FLAG_SYSTEM_POOL )) +free_percpu (pool->recycle_stats);#endif return -ENOMEM ; }@@ -251,7 +262,8 @@ static void page_pool_uninit(struct page_pool *pool)put_device (pool->p.dev);#ifdef CONFIG_PAGE_POOL_STATS -free_percpu (pool->recycle_stats); +if (!(pool->p.flags &PP_FLAG_SYSTEM_POOL )) +free_percpu (pool->recycle_stats);#endif }
Quoted 9 lines · Lorenzo Bianconi
Quoted 3 lines
Use global percpu
page_pool_recycle_statscounter for systempage_poolallocator instead of allocating a separate percpu variable for each (also percpu) page pool instance.I may missed some obvious discussion in previous version due to spring holiday.
Quoted 1 line
[...]
Quoted 12 lines
Quoted 12 lines
#ifdef
CONFIG_PAGE_POOL_STATSnet/core/page_pool.c +8
-3- pool->recycle_stats = alloc_percpu(struct page_pool_recycle_stats); -if (!pool->recycle_stats) -return -ENOMEM ; +if (!(pool->p.flags &PP_FLAG_SYSTEM_POOL )) { + pool->recycle_stats = alloc_percpu(struct page_pool_recycle_stats); +if (!pool->recycle_stats) +return -ENOMEM ; + }else { +/* For system page pool instance we use a singular stats object +* instead of allocating a separate percpu variable for each +* (also percpu) page pool instance.
Quoted 8 lines
net/core/page_pool.c static int page_pool_init(struct page_pool *pool, · line 234
Quoted 2 lines
net/core/page_pool.c +2
-0+*/ + pool->recycle_stats = &pp_system_recycle_stats;Do we need to return
-EINVALhere ifpage_pool_init()is called withpool->p.flags&PP_FLAG_SYSTEM_POOLbeing true and cpuid being a valid cpu?
If yes, it seems we may be able to use the cpuid to decide if we need to allocate a newpool->recycle_statswithout adding a new flag.
for the current use-cases cpuid is set to a valid core id just for system page_pool but in the future probably there will not be a 1:1 relation (e.g. we would want to pin a per-cpu page_pool instance to a particular CPU?)
Quoted 7 lines
If no, the API for
page_pool_create_percpu()seems a litte weird as it relies on the user calling it correctly.Also, do we need to enforce that
page_pool_create_percpu()is only called once for the same cpu? if no, we may have twopage_poolinstance sharing the same stats.
do you mean for the same pp instance? I guess it is not allowed by the APIs.
Regards,
Lorenzo
Quoted 24 lines
Quoted 23 lines
net/core/page_pool.c +5
-2+ }#endif if (ptr_ring_init (&pool->ring, ring_qsize,GFP_KERNEL ) <0 ) {#ifdef CONFIG_PAGE_POOL_STATS -free_percpu (pool->recycle_stats); +if (!(pool->p.flags &PP_FLAG_SYSTEM_POOL )) +free_percpu (pool->recycle_stats);#endif return -ENOMEM ; }@@ -251,7 +262,8 @@ static void page_pool_uninit(struct page_pool *pool)put_device (pool->p.dev);#ifdef CONFIG_PAGE_POOL_STATS -free_percpu (pool->recycle_stats); +if (!(pool->p.flags &PP_FLAG_SYSTEM_POOL )) +free_percpu (pool->recycle_stats);#endif }
Quoted 10 lines · Lorenzo Bianconi
Quoted 10 lines
Quoted 10 lines
#ifdef
CONFIG_PAGE_POOL_STATSnet/core/page_pool.c +6
-3- pool->recycle_stats = alloc_percpu(struct page_pool_recycle_stats); -if (!pool->recycle_stats) -return -ENOMEM ; +if (!(pool->p.flags &PP_FLAG_SYSTEM_POOL )) { + pool->recycle_stats = alloc_percpu(struct page_pool_recycle_stats); +if (!pool->recycle_stats) +return -ENOMEM ; + }else { +/* For system page pool instance we use a singular stats object
Quoted 8 lines
Quoted 8 lines
net/core/page_pool.c static int page_pool_init(struct page_pool *pool, · line 234
Quoted 4 lines
net/core/page_pool.c +4
-0+* instead of allocating a separate percpu variable for each +* (also percpu) page pool instance. +*/ + pool->recycle_stats = &pp_system_recycle_stats;Do we need to return
-EINVALhere ifpage_pool_init()is called withpool->p.flags&PP_FLAG_SYSTEM_POOLbeing true and cpuid being a valid cpu?
My fault, the above "cpuid being a valid cpu" should be "cpuid not being a valid cpu".
In other word, do we need to protect user from calling page_pool_init() with PP_FLAG_SYSTEM_POOL flag and cpuid being -1?
Quoted 6 lines
Quoted 2 lines
If yes, it seems we may be able to use the cpuid to decide if we need to allocate a new
pool->recycle_statswithout adding a new flag.for the current use-cases cpuid is set to a valid core id just for system
page_poolbut in the future probably there will not be a 1:1 relation (e.g. we would want to pin a per-cpupage_poolinstance to a particular CPU?)
if it is a per-cpu page_pool instance, doesn't it run into the similar problem this patch is trying to fix?
Quoted 10 lines
Quoted 8 lines
If no, the API for
page_pool_create_percpu()seems a litte weird as it relies on the user calling it correctly.Also, do we need to enforce that
page_pool_create_percpu()is only called once for the same cpu? if no, we may have twopage_poolinstance sharing the same stats.do you mean for the same pp instance? I guess it is not allowed by the APIs.
As above comment, if the user is passing a valid cpuid, the PP_FLAG_SYSTEM_POOL flag need to be set too? if yes, doesn't the new flag seems somewhat redundant here?
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Fri, 16 Feb 2024 10:25:43 +0100 you wrote:
Use global percpu
page_pool_recycle_statscounter for systempage_poolallocator instead of allocating a separate percpu variable for each (also percpu) page pool instance.Reviewed-by Toke Hoiland-Jorgensen <[email protected]>Signed-off-by Lorenzo Bianconi <[email protected]>[...]
Here is the summary with links:
- [net-next] net: page_pool: fix recycle stats for system page_pool allocator
https://git.kernel.org/netdev/net-next/c/f853fa5c54e7
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html