net/mlx5e: Reuse per-RQ XDP buffer to avoid stack zeroing overhead
Subsystems (7)
Tariq Toukan
maintainerPATCH 1/1 net/mlx5e: Reuse per-RQ XDP buffer to avoid stack zeroing overhead
From: Carolina Jubran <[email protected]>
CONFIG_INIT_STACK_ALL_ZERO introduces a performance cost by zero-initializing all stack variables on function entry. The mlx5 XDP RX path previously allocated a struct mlx5e_xdp_buff on the stack per received CQE, resulting in measurable performance degradation under this config.
This patch reuses a mlx5e_xdp_buff stored in the mlx5e_rq struct, avoiding per-CQE stack allocations and repeated zeroing.
With this change, XDP_DROP and XDP_TX performance matches that of kernels built without CONFIG_INIT_STACK_ALL_ZERO.
Performance was measured on a ConnectX-6Dx using a single RX channel (1 CPU at 100% usage) at ~50 Mpps. The baseline results were taken from net-next-6.15.
Stack zeroing disabled:
- XDP_DROP:
* baseline: 31.47 Mpps
* baseline + per-RQ allocation: 32.31 Mpps (+2.68%)
- XDP_TX:
* baseline: 12.41 Mpps
* baseline + per-RQ allocation: 12.95 Mpps (+4.30%)
Stack zeroing enabled:
- XDP_DROP:
* baseline: 24.32 Mpps
* baseline + per-RQ allocation: 32.27 Mpps (+32.7%)
- XDP_TX:
* baseline: 11.80 Mpps
* baseline + per-RQ allocation: 12.24 Mpps (+3.72%)
--- drivers/net/ethernet/mellanox/mlx5/core/en.h | 7 ++ .../net/ethernet/mellanox/mlx5/core/en/xdp.h | 6 -- .../net/ethernet/mellanox/mlx5/core/en_rx.c | 81 ++++++++++--------- 3 files changed, 51 insertions(+), 43 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en.h +7 -0
@@ -520,6 +520,12 @@ struct mlx5e_xdpsq {struct mlx5e_channel *channel; }____cacheline_aligned_in_smp ; +struct mlx5e_xdp_buff { +struct xdp_buff xdp; +struct mlx5_cqe64 *cqe; +struct mlx5e_rq *rq; +}; +struct mlx5e_ktls_resync_resp ;struct mlx5e_icosq {
@@ -716,6 +722,7 @@ struct mlx5e_rq {struct mlx5e_xdpsq *xdpsq;DECLARE_BITMAP (flags,8 );struct page_pool *page_pool; +struct mlx5e_xdp_buff mxbuf;/* AF_XDP zero-copy */ struct xsk_buff_pool *xsk_pool;
drivers/net/ethernet/mellanox/mlx5/core/en/xdp.h +0 -6
@@ -45,12 +45,6 @@ (MLX5E_XDP_INLINE_WQE_MAX_DS_CNT *MLX5_SEND_WQE_DS - \sizeof (struct mlx5_wqe_inline_seg )) -struct mlx5e_xdp_buff { -struct xdp_buff xdp; -struct mlx5_cqe64 *cqe; -struct mlx5e_rq *rq; -}; -/* XDP packets can be transmitted in different ways. On completion, we need to * distinguish between them to clean up things in a proper way. */
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +44 -37
204 lines not on this page · raw message
base-commit: 664bf117a30804b442a88a8462591bb23f5a0f22
Signature · 1 line
2.31.1
Quoted 19 lines · Tariq Toukan
From: Carolina Jubran <[email protected]>
CONFIG_INIT_STACK_ALL_ZEROintroduces a performance cost by zero-initializing all stack variables on function entry. The mlx5 XDP RX path previously allocated a structmlx5e_xdp_buffon the stack per received CQE, resulting in measurable performance degradation under this config.This patch reuses a
mlx5e_xdp_buffstored in themlx5e_rqstruct, avoiding per-CQE stack allocations and repeated zeroing.With this change,
XDP_DROPandXDP_TXperformance matches that of kernels built withoutCONFIG_INIT_STACK_ALL_ZERO.Performance was measured on a ConnectX-6Dx using a single RX channel (1 CPU at 100% usage) at ~50 Mpps. The baseline results were taken from net-next-6.15.
Quoted 8 lines
Stack zeroing disabled:
-XDP_DROP:
* baseline: 31.47 Mpps
* baseline + per-RQ allocation: 32.31 Mpps (+2.68%)-
XDP_TX:
* baseline: 12.41 Mpps
* baseline + per-RQ allocation: 12.95 Mpps (+4.30%)
Looks good, but where are these gains coming from ? The patch just moves mxbuf from stack to rq. The number of operations should really be the same.
Quoted 4 lines
Stack zeroing enabled:
-XDP_DROP:
* baseline: 24.32 Mpps
* baseline + per-RQ allocation: 32.27 Mpps (+32.7%)
This part makes sense.
Quoted 25 lines · Alexei Starovoitov
Quoted 24 lines · Tariq Toukan
From: Carolina Jubran <[email protected]>
CONFIG_INIT_STACK_ALL_ZEROintroduces a performance cost by zero-initializing all stack variables on function entry. The mlx5 XDP RX path previously allocated a structmlx5e_xdp_buffon the stack per received CQE, resulting in measurable performance degradation under this config.This patch reuses a
mlx5e_xdp_buffstored in themlx5e_rqstruct, avoiding per-CQE stack allocations and repeated zeroing.With this change,
XDP_DROPandXDP_TXperformance matches that of kernels built withoutCONFIG_INIT_STACK_ALL_ZERO.Performance was measured on a ConnectX-6Dx using a single RX channel (1 CPU at 100% usage) at ~50 Mpps. The baseline results were taken from net-next-6.15.
Stack zeroing disabled:
-XDP_DROP:
* baseline: 31.47 Mpps
* baseline + per-RQ allocation: 32.31 Mpps (+2.68%)
Quoted 8 lines
Quoted 3 lines
-
XDP_TX:
* baseline: 12.41 Mpps
* baseline + per-RQ allocation: 12.95 Mpps (+4.30%)Looks good, but where are these gains coming from ? The patch just moves mxbuf from stack to rq. The number of operations should really be the same.
I guess it's cache related. Hot/cold areas, alignments, movement of other fields in the mlx5e_rq structure...
Quoted 6 lines
Quoted 4 lines
Stack zeroing enabled:
-XDP_DROP:
* baseline: 24.32 Mpps
* baseline + per-RQ allocation: 32.27 Mpps (+32.7%)This part makes sense.
Quoted 23 lines · Tariq Toukan
Quoted 20 lines · Alexei Starovoitov
Quoted 19 lines · Tariq Toukan
From: Carolina Jubran <[email protected]>
CONFIG_INIT_STACK_ALL_ZEROintroduces a performance cost by zero-initializing all stack variables on function entry. The mlx5 XDP RX path previously allocated a structmlx5e_xdp_buffon the stack per received CQE, resulting in measurable performance degradation under this config.This patch reuses a
mlx5e_xdp_buffstored in themlx5e_rqstruct, avoiding per-CQE stack allocations and repeated zeroing.With this change,
XDP_DROPandXDP_TXperformance matches that of kernels built withoutCONFIG_INIT_STACK_ALL_ZERO.Performance was measured on a ConnectX-6Dx using a single RX channel (1 CPU at 100% usage) at ~50 Mpps. The baseline results were taken from net-next-6.15.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Stack zeroing disabled:
-XDP_DROP:
* baseline: 31.47 Mpps
* baseline + per-RQ allocation: 32.31 Mpps (+2.68%)
31.47 Mpps = 31.77 nanosec per packet
32.31 Mpps = 30.95 nanosec per packet
Improvement: 0.82 nanosec faster
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
-
XDP_TX:
* baseline: 12.41 Mpps
* baseline + per-RQ allocation: 12.95 Mpps (+4.30%)
The XDP_TX number are actually lower than I expected. Hmm... I wonder if we regressed here(?)
12.41 Mpps = 80.58 nanosec per packet
12.95 Mpps = 77.22 nanosec per packet
Improvement: 3.36 nanosec faster
Quoted 6 lines
Quoted 4 lines
Looks good, but where are these gains coming from ? The patch just moves mxbuf from stack to rq. The number of operations should really be the same.
I guess it's cache related. Hot/cold areas, alignments, movement of other fields in the
mlx5e_rqstructure...
The improvements for XDP_DROP (see calc above) in nanosec is so small that it is hard to measure accurately/stable on any system.
The improvement for XDP_TX is above 2 nanosec, which looks like an actual improvement...
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
Stack zeroing enabled:
-XDP_DROP:
* baseline: 24.32 Mpps
* baseline + per-RQ allocation: 32.27 Mpps (+32.7%)This part makes sense.
Yes, this makes sense as it is a measurable improvement.
24.32 Mpps = 41.12 nanosec per packet
32.27 Mpps = 30.99 nanosec per packet
Improvement: 10.13 nanosec faster
--Jesper
Hey,
I ran tests just on stack zeroing kernel.
Quoted 2 lines
The
XDP_TXnumber are actually lower than I expected. Hmm... I wonder if we regressed here(?)
The absolute numbers look more or less the same, so I would say no. The first results we have for TX is from 6.13.0-0.rc1.20241202gite70140ba0d2b.14.eln144 comparing it to 6.15.0-0.rc5.250509g9c69f8884904.47.eln148 there is actually 1% improvement. But that might be a random fluctuation (numbers are based on 1 iteration). We don't have data for earlier kernels...
However, for TX I get better results:
XDP_TX: DPA, swap macs:
- baseline: 9.75 Mpps
- patched 10.78 Mpps (+10%)
Maybe just different test configuration? We use xdp-bench in dpa mode+swapping macs.
XDP_DROP:
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Stack zeroing enabled:
-XDP_DROP:
* baseline: 24.32 Mpps
* baseline + per-RQ allocation: 32.27 Mpps (+32.7%)
Same results on my side:
- baseline 16.6 Mpps
- patched 24.6 Mpps (+32.5%)
Seems to be fixed :)
Sam.
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 9 lines · On Wed, 14 May 2025 23:03:52 +0300 you wrote:
From: Carolina Jubran <[email protected]>
CONFIG_INIT_STACK_ALL_ZEROintroduces a performance cost by zero-initializing all stack variables on function entry. The mlx5 XDP RX path previously allocated a structmlx5e_xdp_buffon the stack per received CQE, resulting in measurable performance degradation under this config.[...]
Here is the summary with links:
- [net-next] net/mlx5e: Reuse per-RQ XDP buffer to avoid stack zeroing overhead
https://git.kernel.org/netdev/net-next/c/b66b76a82c88
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html