BPF List
 help / color / mirror / Atom feed
From: "Björn Töpel" <bjorn@kernel.org>
To: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Willem de Bruijn <willemb@google.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	John Fastabend <john.fastabend@gmail.com>,
	Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Nikolay Aleksandrov <razor@blackwall.org>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Magnus Karlsson <magnus.karlsson@intel.com>,
	Maciej Fijalkowski <maciej.fijalkowski@intel.com>,
	Donald Hunter <donald.hunter@gmail.com>,
	Alexander Duyck <alexanderduyck@fb.com>,
	Saeed Mahameed <saeedm@nvidia.com>,
	Tariq Toukan <tariqt@nvidia.com>, Mark Bloch <mbloch@nvidia.com>,
	Leon Romanovsky <leon@kernel.org>, Shuah Khan <shuah@kernel.org>,
	Jonathan Corbet <corbet@lwn.net>,
	netdev@vger.kernel.org, bpf@vger.kernel.org
Cc: "Björn Töpel" <bjorn@kernel.org>,
	"Simon Horman" <horms@kernel.org>,
	"Stanislav Fomichev" <sdf@fomichev.me>,
	"Martin KaFai Lau" <martin.lau@linux.dev>,
	"Song Liu" <song@kernel.org>,
	"Yonghong Song" <yonghong.song@linux.dev>,
	"Jiri Olsa" <jolsa@kernel.org>,
	"Emil Tsalapatis" <emil@etsalapatis.com>,
	"Ihor Solodrai" <ihor.solodrai@linux.dev>,
	"David Wei" <dw@davidwei.uk>, "Tao Cui" <cuitao@kylinos.cn>,
	linux-kernel@vger.kernel.org, kernel-team@meta.com,
	"Mike Marciniszyn (Meta)" <mike.marciniszyn@gmail.com>,
	linux-rdma@vger.kernel.org, linux-kselftest@vger.kernel.org,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"Randy Dunlap" <rdunlap@infradead.org>,
	linux-doc@vger.kernel.org
Subject: [PATCH net-next v2 12/15] net/mlx5e: Release XDP-only pages earlier
Date: Fri,  4 Dec 2026 17:27:17 +0100	[thread overview]
Message-ID: <20261204162723.755897-13-bjorn@kernel.org> (raw)
In-Reply-To: <20261204162723.755897-1-bjorn@kernel.org>

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 <bjorn@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


  parent reply	other threads:[~2026-12-04 16:29 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 16:27 [PATCH net-next v2 00/15] xsk: Return UMEM chunks explicitly Björn Töpel
2026-12-04 16:27 ` [PATCH net-next v2 01/15] xdp: Let memory providers expose net_iovs to XDP Björn Töpel
2026-12-04 16:27 ` [PATCH net-next v2 02/15] net: Add memory providers that only feed XDP Björn Töpel
2026-12-04 16:27 ` [PATCH net-next v2 03/15] page_pool: Let memory providers take back net_iovs Björn Töpel
2026-12-04 16:27 ` [PATCH net-next v2 04/15] xdp: Run programs on XDP-only buffers Björn Töpel
2026-12-04 16:27 ` [PATCH net-next v2 05/15] xsk: Back a queue's page pools with UMEM chunks Björn Töpel
2026-12-04 16:27 ` [PATCH net-next v2 06/15] xsk: Deliver packets and return chunks explicitly Björn Töpel
2026-12-04 16:27 ` [PATCH net-next v2 07/15] xsk: Receive with explicit chunk return Björn Töpel
2026-12-04 16:27 ` [PATCH net-next v2 08/15] xsk: Drop references of a run of buffers at once Björn Töpel
2026-12-04 16:27 ` [PATCH net-next v2 09/15] eth: fbnic: Receive into XDP-only memory providers Björn Töpel
2026-12-04 22:34   ` Alexander Duyck
2026-12-04 16:27 ` [PATCH net-next v2 10/15] net/mlx5e: Handle restarts with XDP-only providers Björn Töpel
2026-12-04 16:27 ` [PATCH net-next v2 11/15] net/mlx5e: Receive into XDP-only memory providers Björn Töpel
2026-12-04 16:27 ` Björn Töpel [this message]
2026-12-04 16:27 ` [PATCH net-next v2 13/15] net/mlx5e: Test for XDP-only pages per RQ Björn Töpel
2026-12-04 16:27 ` [PATCH net-next v2 14/15] selftests: net: xsk: Test explicit chunk return Björn Töpel
2026-12-04 16:27 ` [PATCH net-next v2 15/15] Documentation: xsk: Describe " Björn Töpel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204162723.755897-13-bjorn@kernel.org \
    --to=bjorn@kernel.org \
    --cc=alexanderduyck@fb.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=corbet@lwn.net \
    --cc=cuitao@kylinos.cn \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=donald.hunter@gmail.com \
    --cc=dw@davidwei.uk \
    --cc=eddyz87@gmail.com \
    --cc=edumazet@kernel.org \
    --cc=emil@etsalapatis.com \
    --cc=hawk@kernel.org \
    --cc=horms@kernel.org \
    --cc=ihor.solodrai@linux.dev \
    --cc=ilias.apalodimas@linaro.org \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kernel-team@meta.com \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=maciej.fijalkowski@intel.com \
    --cc=magnus.karlsson@intel.com \
    --cc=martin.lau@linux.dev \
    --cc=mbloch@nvidia.com \
    --cc=memxor@gmail.com \
    --cc=mike.marciniszyn@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=razor@blackwall.org \
    --cc=rdunlap@infradead.org \
    --cc=saeedm@nvidia.com \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=song@kernel.org \
    --cc=tariqt@nvidia.com \
    --cc=willemb@google.com \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox