net: mana: reserve RX buffer headroom to fix forwarding performance
Subsystems (7)
PATCH v2 1/1 net: mana: reserve RX buffer headroom to fix forwarding performance
Commit 730ff06d3f5c ("net: mana: Use page pool fragments for RX buffers instead of full pages to improve memory efficiency.") started handing out RX buffers with zero headroom so that two buffers fit into one page at the default MTU.
The MANA TX path, however, stores the per scatter-gather entry DMA mappings in struct mana_skb_head at skb->head, and mana_start_xmit() therefore calls skb_cow_head(skb, MANA_HEADROOM). The port advertises this requirement as ndev->needed_headroom = MANA_HEADROOM.
As a result every packet that is received and then forwarded out of a MANA port fails the skb_cow() in ip_forward() and gets reallocated and copied by pskb_expand_head(). This is invisible to a plain RX or TX workload, but it puts a full skb reallocation plus memcpy on the hot path of every single forwarded packet, which is exactly what a router/NVA workload does.
Restore the headroom. Note that reserving MANA_HEADROOM (232) is not
enough: ip_forward() asks for LL_RESERVED_SPACE(dev), which rounds hard_header_len + needed_headroom up to HH_DATA_MOD and is 256 bytes on ethernet. Use LL_RESERVED_SPACE() directly so the value keeps tracking both constants. Also, since LL_RESERVED_SPACE() tracks MANA_HEADROOM, it grows with MAX_SKB_FRAGS and for MAX_SKB_FRAGS >= 19 it is greater than 256, so we have to account for that by using the headroom the RX queue actually uses (instead of assuming XDP_PACKET_HEADROOM) and turning MANA_XDP_MTU_MAX into MANA_XDP_MTU_MAX(ndev) (note that at the default CONFIG_MAX_SKB_FRAGS=17 they are equivalent).
At the default MTU on a 4K page this means a buffer no longer fits twice into a page (SKB_DATA_ALIGN(1500 + MANA_RXBUF_PAD + 256) = 2112), so the frag-vs-single decision is now made by computing the real buffer size instead of comparing the MTU against PAGE_SIZE / 2. The page_pool fragment path is still used wherever at least two buffers genuinely fit, e.g. on 16K and 64K page sizes.
Measured on an Azure VM with a MANA NIC acting as a forwarding NVA (UDP, 1400 byte payload, 4 streams, 8 Gbps offered, only the forwarding node's kernel differs), 8 runs each, median:
forwarded pps throughput
before 272,830 3.06 Gbps after 390,560 4.37 Gbps (+43%)
perf on the forwarding node, same workload:
memset_orig __pi_memcpy pskb_expand_head
before 10.07% 3.96% present after 0.94% 0.64% gone
---
v2:
- Fix the XDP headroom mismatch with CONFIG_MAX_SKB_FRAGS >= 19, by passing rxq->headroom to xdp_prepare_buff(). mana_build_skb() then picks up the correct offset via xdp->data - xdp->data_hard_start. Also, turn MANA_XDP_MTU_MAX into MANA_XDP_MTU_MAX(ndev) to account for the headroom, since it is no longer a constant. (Narcisa, Sashiko)
- Use the new mana_single_rxbuf_per_page_forced() helper in mana_set_priv_flags(). (Sashiko)
- Trim the comment above mana_get_rxbuf_headroom() and drop the stale "XDP headroom" wording from the comment above mana_get_rxbuf_cfg(). (Narcisa, Sashiko)
--- .../net/ethernet/microsoft/mana/mana_bpf.c | 8 +-- drivers/net/ethernet/microsoft/mana/mana_en.c | 63 ++++++++++++++----- .../ethernet/microsoft/mana/mana_ethtool.c | 10 +-- include/net/mana/mana.h | 14 ++++- 4 files changed, 68 insertions(+), 27 deletions(-)
drivers/net/ethernet/microsoft/mana/mana_bpf.c +4 -4
@@ -91,7 +91,7 @@ u32 mana_run_xdp(struct net_device *ndev, struct mana_rxq *rxq, goto out;xdp_init_buff (xdp,PAGE_SIZE , &rxq->xdp_rxq); -xdp_prepare_buff (xdp, buf_va,XDP_PACKET_HEADROOM , pkt_len, true); +xdp_prepare_buff (xdp, buf_va, rxq->headroom, pkt_len, true); act =bpf_prog_run_xdp (prog, xdp);
@@ -183,9 +183,9 @@ static int mana_xdp_set(struct net_device *ndev, struct bpf_prog *prog,if (!old_prog && !prog)return 0 ; -if (prog && ndev->mtu >MANA_XDP_MTU_MAX ) { +if (prog && ndev->mtu >MANA_XDP_MTU_MAX (ndev)) {netdev_err (ndev,"XDP: mtu:%u too large, mtu_max:%lu\n" , - ndev->mtu,MANA_XDP_MTU_MAX ); + ndev->mtu,MANA_XDP_MTU_MAX (ndev));NL_SET_ERR_MSG_MOD (extack,"XDP: mtu too large" );return -EOPNOTSUPP ;
@@ -238,7 +238,7 @@ static int mana_xdp_set(struct net_device *ndev, struct bpf_prog *prog,bpf_prog_put (old_prog);if (prog) - ndev->max_mtu = min_t(unsigned int, MANA_XDP_MTU_MAX, + ndev->max_mtu = min_t(unsigned int, MANA_XDP_MTU_MAX(ndev), gc->adapter_mtu -ETH_HLEN );else ndev->max_mtu = gc->adapter_mtu -ETH_HLEN ;
drivers/net/ethernet/microsoft/mana/mana_en.c +46 -17
95 lines not on this page · raw message
drivers/net/ethernet/microsoft/mana/mana_ethtool.c +5 -5
@@ -815,12 +815,12 @@ static int mana_set_priv_flags(struct net_device *ndev, u32 priv_flags)if (!apc->port_is_up)return 0 ; -/* If XDP is attached or MTU is jumbo, single-buffer-per-page -* is already forced regardless of this flag. Skip the -* expensive detach/attach cycle since nothing changes. +/* If XDP is attached or the MTU already forces one buffer per +* page, single-buffer-per-page is used regardless of this +* flag. Skip the expensive detach/attach cycle since nothing +* changes. */ -if (ndev->mtu +MANA_RXBUF_PAD >PAGE_SIZE /2 || -mana_xdp_get (apc)) +if (mana_single_rxbuf_per_page_forced (apc, ndev->mtu))return 0 ;/* Block RDMA from grabbing the vport during detach/attach */
include/net/mana/mana.h +13 -1
@@ -377,7 +377,18 @@ struct mana_recv_buf_oob {#define MANA_RXBUF_PAD (SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) \ + ETH_HLEN) -#define MANA_XDP_MTU_MAX (PAGE_SIZE - MANA_RXBUF_PAD - XDP_PACKET_HEADROOM) +/* Headroom an RX buffer has to reserve while XDP is attached: the XDP program +* needs XDP_PACKET_HEADROOM, and the TX path needs LL_RESERVED_SPACE() (see +* mana_get_rxbuf_headroom()). LL_RESERVED_SPACE() grows with MAX_SKB_FRAGS and +* exceeds XDP_PACKET_HEADROOM once CONFIG_MAX_SKB_FRAGS is 19 or more. +*/ +static inline u32 mana_xdp_headroom (struct net_device *ndev) +{ +return max_t (u32,LL_RESERVED_SPACE (ndev),XDP_PACKET_HEADROOM ); +} + +#define MANA_XDP_MTU_MAX (ndev) \ + (PAGE_SIZE - MANA_RXBUF_PAD - mana_xdp_headroom(ndev))struct mana_rxq {struct gdma_queue *gdma_rq;
@@ -691,6 +702,7 @@ int mana_query_link_cfg(struct mana_port_context *apc);int mana_set_bw_clamp (struct mana_port_context *apc,u32 speed,int enable_clamping);void mana_query_phy_stats (struct mana_port_context *apc); +bool mana_single_rxbuf_per_page_forced (struct mana_port_context *apc,u32 mtu);int mana_pre_alloc_rxbufs (struct mana_port_context *apc,int mtu,int num_queues);void mana_pre_dealloc_rxbufs (struct mana_port_context *apc);void mana_unmap_skb (struct sk_buff *skb,struct mana_port_context *apc);
Signature · 1 line
2.55.0
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 18 lines
Commit
730ff06d3f5c("net: mana: Use page pool fragments for RX buffers instead of full pages to improve memory efficiency.") started handing out RX buffers with zero headroom so that two buffers fit into one page at the default MTU.The MANA TX path, however, stores the per scatter-gather entry DMA mappings in
struct mana_skb_headatskb->head, andmana_start_xmit()therefore callsskb_cow_head(skb, MANA_HEADROOM). The port advertises this requirement asndev->needed_headroom=MANA_HEADROOM.As a result every packet that is received and then forwarded out of a MANA port fails the
skb_cow()inip_forward()and gets reallocated and copied bypskb_expand_head(). This is invisible to a plain RX or TX workload, but it puts a full skb reallocation plus memcpy on the hot path of every single forwarded packet, which is exactly what a [ ... ]
after 0.94% 0.64% gone
Quoted 3 lines
Fixes 730ff06d3f5c ("net: mana: Use page pool fragments for RX buffers instead of full pages to improve memory efficiency.")Signed-off-by Hamza Mahfooz <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 52 lines · Hamza Mahfooz
Commit
730ff06d3f5c("net: mana: Use page pool fragments for RX buffers instead of full pages to improve memory efficiency.") started handing out RX buffers with zero headroom so that two buffers fit into one page at the default MTU.The MANA TX path, however, stores the per scatter-gather entry DMA mappings in
struct mana_skb_headatskb->head, andmana_start_xmit()therefore callsskb_cow_head(skb, MANA_HEADROOM). The port advertises this requirement asndev->needed_headroom=MANA_HEADROOM.As a result every packet that is received and then forwarded out of a MANA port fails the
skb_cow()inip_forward()and gets reallocated and copied bypskb_expand_head(). This is invisible to a plain RX or TX workload, but it puts a full skb reallocation plus memcpy on the hot path of every single forwarded packet, which is exactly what a router/NVA workload does.Restore the headroom. Note that reserving
MANA_HEADROOM(232) is not
enough:ip_forward()asks forLL_RESERVED_SPACE(dev), which roundshard_header_len+needed_headroomup toHH_DATA_MODand is 256 bytes on ethernet. UseLL_RESERVED_SPACE()directly so the value keeps tracking both constants. Also, sinceLL_RESERVED_SPACE()tracksMANA_HEADROOM, it grows withMAX_SKB_FRAGSand forMAX_SKB_FRAGS>= 19 it is greater than 256, so we have to account for that by using the headroom the RX queue actually uses (instead of assumingXDP_PACKET_HEADROOM) and turningMANA_XDP_MTU_MAXintoMANA_XDP_MTU_MAX(ndev)(note that at the defaultCONFIG_MAX_SKB_FRAGS=17they are equivalent).At the default MTU on a 4K page this means a buffer no longer fits twice into a page (
SKB_DATA_ALIGN(1500 + MANA_RXBUF_PAD + 256)= 2112), so the frag-vs-single decision is now made by computing the real buffer size instead of comparing the MTU againstPAGE_SIZE/ 2. Thepage_poolfragment path is still used wherever at least two buffers genuinely fit, e.g. on 16K and 64K page sizes.Measured on an Azure VM with a MANA NIC acting as a forwarding NVA (UDP, 1400 byte payload, 4 streams, 8 Gbps offered, only the forwarding node's kernel differs), 8 runs each, median:
forwarded pps throughput
before 272,830 3.06 Gbps after 390,560 4.37 Gbps (+43%)perf on the forwarding node, same workload:
memset_orig__pi_memcpypskb_expand_headbefore 10.07% 3.96% present after 0.94% 0.64% goneFixes 730ff06d3f5c ("net: mana: Use page pool fragments for RX buffers instead of full pages to improve memory efficiency.")Signed-off-by Hamza Mahfooz <[email protected]>
Quoted 13 lines
---
v2:
- Fix the XDP headroom mismatch withCONFIG_MAX_SKB_FRAGS>= 19, by passingrxq->headroomtoxdp_prepare_buff().mana_build_skb()then picks up the correct offset viaxdp->data-xdp->data_hard_start. Also, turnMANA_XDP_MTU_MAXintoMANA_XDP_MTU_MAX(ndev)to account for the headroom, since it is no longer a constant. (Narcisa, Sashiko)
- Use the newmana_single_rxbuf_per_page_forced()helper inmana_set_priv_flags(). (Sashiko)
- Trim the comment abovemana_get_rxbuf_headroom()and drop the stale "XDP headroom" wording from the comment abovemana_get_rxbuf_cfg(). (Narcisa, Sashiko)
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 11 lines · On Fri, 2 Oct 2026 21:36:47 -0400 you wrote:
Commit
730ff06d3f5c("net: mana: Use page pool fragments for RX buffers instead of full pages to improve memory efficiency.") started handing out RX buffers with zero headroom so that two buffers fit into one page at the default MTU.The MANA TX path, however, stores the per scatter-gather entry DMA mappings in
struct mana_skb_headatskb->head, andmana_start_xmit()therefore callsskb_cow_head(skb, MANA_HEADROOM). The port advertises this requirement asndev->needed_headroom=MANA_HEADROOM.[...]
Here is the summary with links:
- [net,v2] net: mana: reserve RX buffer headroom to fix forwarding performance
https://git.kernel.org/netdev/net/c/259c4a519100
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html