net: page_pool: Expose size limit
Subsystems (6)
Tariq Toukan
maintainercover net: page_pool: Expose size limit
Hi,
This small series by Dragos has two patches.
Patch #1 exposes the page_pool internal size limit so that drivers can check against it before creating a page_pool.
Patch #2 adds usage of the exposed limit in mlx5e driver.
Regards,
Tariq
Dragos Tatulea (2):
net: page_pool: Expose internal limit
net/mlx5e: Clamp page_pool size to max
drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 2 ++ include/net/page_pool/types.h | 2 ++ net/core/page_pool.c | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-)
base-commit: 312e6f7676e63bbb9b81e5c68e580a9f776cc6f0
Signature · 1 line
2.31.1
Tariq Toukan
maintainerPATCH 1/2 net: page_pool: Expose internal limit
From: Dragos Tatulea <[email protected]>
page_pool_init() has a check for pool_size < 32K. But page_pool users have no access to this limit so there is no way to trim the pool_size in advance. The E2BIG error doesn't help much for retry as the driver has to guess the next size and retry.
This patch exposes this limit to in the page_pool header.
--- include/net/page_pool/types.h | 2 ++ net/core/page_pool.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
include/net/page_pool/types.h +2 -0
@@ -163,6 +163,8 @@ struct pp_memory_provider_params {const struct memory_provider_ops *mp_ops; }; +#define PAGE_POOL_SIZE_LIMIT 32768 +struct page_pool {struct page_pool_params_fast p;
net/core/page_pool.c +1 -1
@@ -214,7 +214,7 @@ static int page_pool_init(struct page_pool *pool, ring_qsize = pool->p.pool_size;/* Sanity limit mem that can be pinned down */ -if (ring_qsize >32768 ) +if (ring_qsize >PAGE_POOL_SIZE_LIMIT )return -E2BIG ;/* DMA direction is either DMA_FROM_DEVICE or DMA_BIDIRECTIONAL.
Signature · 1 line
2.31.1
Re: [PATCH net-next 1/2] net: page_pool: Expose internal limit
Quoted 8 lines · Tariq Toukan
From: Dragos Tatulea <[email protected]>
page_pool_init()has a check forpool_size< 32K. Butpage_poolusers have no access to this limit so there is no way to trim thepool_sizein advance. The E2BIG error doesn't help much for retry as the driver has to guess the next size and retry.
Quoted 4 lines
This patch exposes this limit to in the
page_poolheader.Signed-off-by Dragos Tatulea <[email protected]>Signed-off-by Tariq Toukan <[email protected]>
Quoted 34 lines
--- include/net/page_pool/types.h | 2 ++ net/core/page_pool.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)include/net/page_pool/types.h +2
-0@@ -163,6 +163,8 @@ struct pp_memory_provider_params {const struct memory_provider_ops *mp_ops; }; +#define PAGE_POOL_SIZE_LIMIT 32768 +struct page_pool {struct page_pool_params_fast p;net/core/page_pool.c +1
-2@@ -214,7 +214,7 @@ static int page_pool_init(struct page_pool *pool, ring_qsize = pool->p.pool_size;/* Sanity limit mem that can be pinned down */ -if (ring_qsize >32768 ) +if (ring_qsize >PAGE_POOL_SIZE_LIMIT )return -E2BIG ;/* DMA direction is either DMA_FROM_DEVICE or DMA_BIDIRECTIONAL. -- 2.31.1
Tariq Toukan
maintainerPATCH 2/2 net/mlx5e: Clamp page_pool size to max
In reply to Tariq ToukanFrom: Dragos Tatulea <[email protected]>
When the user configures a large ring size (8K) and a large MTU (9000) in HW-GRO mode, the queue will fail to allocate due to the size of the page_pool going above the limit.
This change clamps the pool_size to the limit.
--- drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +2 -0
@@ -989,6 +989,8 @@ static int mlx5e_alloc_rq(struct mlx5e_params *params,/* Create a page_pool and register it with rxq */ struct page_pool_params pp_params = {0 }; + pool_size =min_t (u32, pool_size,PAGE_POOL_SIZE_LIMIT ); + pp_params.order =0 ; pp_params.flags =PP_FLAG_DMA_MAP |PP_FLAG_DMA_SYNC_DEV ; pp_params.pool_size = pool_size;
Signature · 1 line
2.31.1
Simon Horman
reviewerRe: [PATCH net-next 2/2] net/mlx5e: Clamp page_pool size to max
Quoted 19 lines · Tariq Toukan
From: Dragos Tatulea <[email protected]>
When the user configures a large ring size (8K) and a large MTU (9000) in HW-GRO mode, the queue will fail to allocate due to the size of the
page_poolgoing above the limit.This change clamps the
pool_sizeto the limit.Signed-off-by Dragos Tatulea <[email protected]>Signed-off-by Tariq Toukan <[email protected]>--- drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 2 ++ 1 file changed, 2 insertions(+)drivers/net/ethernet/mellanox/mlx5/core/en_main.c +0
-0
drivers/net/ethernet/mellanox/mlx5/core/en_main.c static int mlx5e_alloc_rq(struct mlx5e_params *params, · line 992
Quoted 4 lines
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +1
-0@@ -989,6 +989,8 @@ static int mlx5e_alloc_rq(struct mlx5e_params *params,/* Create a page_pool and register it with rxq */ struct page_pool_params pp_params = {0 }; + pool_size =min_t (u32, pool_size,PAGE_POOL_SIZE_LIMIT );
pool_size is u32 and PAGE_POOL_SIZE_LIMIT is a constant. AFAIK min() would work just fine here.
Quoted 8 lines
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +1
-0+ pp_params.order =0 ; pp_params.flags =PP_FLAG_DMA_MAP |PP_FLAG_DMA_SYNC_DEV ; pp_params.pool_size = pool_size;Signature · 1 line
2.31.1
Jakub Kicinski
maintainerRe: [PATCH net-next 2/2] net/mlx5e: Clamp page_pool size to max
In reply to Tariq ToukanQuoted 3 lines · On Mon, 22 Sep 2025 12:18:35 +0300 Tariq Toukan wrote:
When the user configures a large ring size (8K) and a large MTU (9000) in HW-GRO mode, the queue will fail to allocate due to the size of the
page_poolgoing above the limit.
Please do some testing. A PP cache of 32k is just silly, you should probably use a smaller limit.
Re: [PATCH net-next 2/2] net/mlx5e: Clamp page_pool size to max
Quoted 7 lines · Jakub Kicinski
Quoted 3 lines · On Mon, 22 Sep 2025 12:18:35 +0300 Tariq Toukan wrote:
When the user configures a large ring size (8K) and a large MTU (9000) in HW-GRO mode, the queue will fail to allocate due to the size of the
page_poolgoing above the limit.Please do some testing. A PP cache of 32k is just silly, you should probably use a smaller limit.
You mean clamping the pool_size to a certain limit so that the page_pool ring size doesn't cover a full RQ when the RQ ring size is too large?
Thanks,
Dragos
Jakub Kicinski
maintainerRe: [PATCH net-next 2/2] net/mlx5e: Clamp page_pool size to max
Quoted 10 lines · On Tue, 23 Sep 2025 15:12:33 +0000 Dragos Tatulea wrote:
Quoted 7 lines · Jakub Kicinski
Quoted 3 lines · On Mon, 22 Sep 2025 12:18:35 +0300 Tariq Toukan wrote:
When the user configures a large ring size (8K) and a large MTU (9000) in HW-GRO mode, the queue will fail to allocate due to the size of the
page_poolgoing above the limit.Please do some testing. A PP cache of 32k is just silly, you should probably use a smaller limit.
You mean clamping the
pool_sizeto a certain limit so that thepage_poolring size doesn't cover a full RQ when the RQ ring size is too large?
Yes, 8k ring will take milliseconds to drain. We don't really need milliseconds of page cache. By the time the driver processed the full ring we must have gone thru 128 NAPI cycles, and the application most likely already stated freeing the pages.
If my math is right at 80Gbps per ring and 9k MTU it takes more than a 1usec to receive a frame. So 8msec to just _receive_ a full ring worth of data. At Meta we mostly use large rings to cover up scheduler and IRQ masking latency.
Jakub Kicinski
maintainerRe: [PATCH net-next 2/2] net/mlx5e: Clamp page_pool size to max
Quoted 12 lines · On Tue, 23 Sep 2025 08:23:10 -0700 Jakub Kicinski wrote:
Quoted 5 lines · On Tue, 23 Sep 2025 15:12:33 +0000 Dragos Tatulea wrote:
Quoted 2 lines · Jakub Kicinski
Please do some testing. A PP cache of 32k is just silly, you should probably use a smaller limit.
You mean clamping the
pool_sizeto a certain limit so that thepage_poolring size doesn't cover a full RQ when the RQ ring size is too large?Yes, 8k ring will take milliseconds to drain. We don't really need milliseconds of page cache. By the time the driver processed the full ring we must have gone thru 128 NAPI cycles, and the application most likely already stated freeing the pages.
Quoted 4 lines
If my math is right at 80Gbps per ring and 9k MTU it takes more than a 1usec to receive a frame. So 8msec to just _receive_ a full ring worth of data. At Meta we mostly use large rings to cover up scheduler and IRQ masking latency.
On second thought, let's just clamp it to 16k in the core and remove the error. Clearly the expectations of the API are too intricate, most drivers just use ring size as the cache size.
Re: [PATCH net-next 2/2] net/mlx5e: Clamp page_pool size to max
Quoted 13 lines · Jakub Kicinski
Quoted 12 lines · On Tue, 23 Sep 2025 08:23:10 -0700 Jakub Kicinski wrote:
Quoted 5 lines · On Tue, 23 Sep 2025 15:12:33 +0000 Dragos Tatulea wrote:
Quoted 2 lines · Jakub Kicinski
Please do some testing. A PP cache of 32k is just silly, you should probably use a smaller limit.
You mean clamping the
pool_sizeto a certain limit so that thepage_poolring size doesn't cover a full RQ when the RQ ring size is too large?Yes, 8k ring will take milliseconds to drain. We don't really need milliseconds of page cache. By the time the driver processed the full ring we must have gone thru 128 NAPI cycles, and the application most likely already stated freeing the pages.
Quoted 8 lines
Quoted 4 lines
If my math is right at 80Gbps per ring and 9k MTU it takes more than a 1usec to receive a frame. So 8msec to just _receive_ a full ring worth of data. At Meta we mostly use large rings to cover up scheduler and IRQ masking latency.
On second thought, let's just clamp it to 16k in the core and remove the error. Clearly the expectations of the API are too intricate, most drivers just use ring size as the cache size.
Makes sense. For my peace of mind I want to do some packet rate tests to see that there is no perf difference and compare the page_pool stats.
Should the page_pool should print a warning when it clamps?
Also, checking for size > 32K and clamping to 16K looks a bit weird... Should the limit be lowered to 16K alltogether?
Thanks,
Dragos
Jakub Kicinski
maintainerRe: [PATCH net-next 2/2] net/mlx5e: Clamp page_pool size to max
Quoted 1 line · On Thu, 25 Sep 2025 10:25:40 +0000 Dragos Tatulea wrote:
Should the
page_poolshould print a warning when it clamps?
I don't think so, goal is to avoid having all drivers copy the clamp on their side. So if we still warn drivers will still have to worry.
Quoted 2 lines
Also, checking for size > 32K and clamping to 16K looks a bit weird... Should the limit be lowered to 16K alltogether?
That's what I mean, replace the if (>32k) return E2BIG; with size = min(size, 16k).
Quoted 16 lines · Tariq Toukan
Hi,
This small series by Dragos has two patches.
Patch #1 exposes the
page_poolinternal size limit so that drivers can check against it before creating apage_pool.Patch #2 adds usage of the exposed limit in mlx5e driver.
Regards,
TariqDragos Tatulea (2):
net:page_pool: Expose internal limit
net/mlx5e: Clamppage_poolsize to max
Quoted 7 lines
drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 2 ++ include/net/page_pool/types.h | 2 ++ net/core/page_pool.c | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-)base-commit:
312e6f7676e63bbb9b81e5c68e580a9f776cc6f0
For the series:
Thanks,
Dawid