Before this patch, a striding RQ released pages only when reposting their WQE, so a provider page returned its chunk late, on an extra empty descriptor. The chunks come back without this patch; it only saves that descriptor. On the linear path, release a provider page once XDP took the buffer in its last stride, and let the WQE skip it, also at close. The chunk then comes back on the packet's descriptor, as the socket drops its references last. The device writes nothing to a page after its last stride, so this cannot race with DMA. Also skip the head and xdp_frame prefetches of XDP-only pages. Only the program reads them, and after the early release each packet lands in an untouched page, where a prefetch may cost a page walk. On ConnectX-7, one core, 66-byte frames offered at 61 Mpps, a program that parses headers and an application that reads the payload, this and the batched reference drops took a 4 KiB-chunk queue from 12.40-12.66 to 15.65-15.92 Mpps. Signed-off-by: Björn Töpel <bjo…@kernel.org> --- Notes (v2changes): Changes in v2: - New in v2, from "eth: mlx5e: Let go of XDP-only pages after their last stride" and "eth: mlx5e: Skip head prefetches for XDP-only buffers" of the v1 full series. A striding RQ let go of a page only when it reposted its WQE, so its chunk came back on an extra empty descriptor, and the head prefetch of a page that the CPU had not touched cost a page walk. The message has the numbers. .../net/ethernet/mellanox/mlx5/core/en_rx.c | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c index 43a382fcd3ad..a93eefa581c0 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c @@ -2107,6 +2107,7 @@ mlx5e_skb_from_cqe_mpwrq_linear(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi, void *va, *data; dma_addr_t addr; u32 frag_size; + bool xdp_only; /* Check packet size. Note LRO doesn't use linear SKB */ if (unlikely(cqe_bcnt > rq->hw_mtu)) { @@ -2121,18 +2122,36 @@ mlx5e_skb_from_cqe_mpwrq_linear(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi, addr = page_pool_get_dma_addr_netmem(frag_page->netmem); dma_sync_single_range_for_cpu(rq->pdev, addr, head_offset, frag_size, rq->buff.map_dir); - net_prefetch(data); + /* The kernel reads an XDP-only head only if the program does, and a + * prefetch may cost a page walk + */ + xdp_only = netmem_is_net_iov(frag_page->netmem); + if (!xdp_only) + net_prefetch(data); prog = rcu_dereference(rq->xdp_prog); if (prog) { struct mlx5e_xdp_buff *mxbuf = &rq->mxbuf; - net_prefetchw(va); /* xdp_frame data area */ + if (!xdp_only) + net_prefetchw(va); /* xdp_frame data area */ mlx5e_fill_mxbuf(rq, cqe, va, rx_headroom, rq->buff.frame0_sz, cqe_bcnt, mxbuf); if (mlx5e_xdp_handle(rq, prog, mxbuf)) { if (__test_and_clear_bit(MLX5E_RQ_FLAG_XDP_XMIT, rq->flags)) frag_page->frags++; + /* The device is done with a provider page after its + * last stride. Letting go of it now, before the socket + * drops its references, gives the chunk back on the + * packet's descriptor rather than an empty one. + */ + if (xdp_only && + head_offset + BIT(rq->mpwqe.log_stride_sz) >= + BIT(rq->mpwqe.page_shift)) { + mlx5e_page_release_fragmented(rq->page_pool, + frag_page); + __set_bit(page_idx, wi->skip_release_bitmap); + } return NULL; /* page/packet was consumed by XDP */ }
-- 2.56.1