Netdev List
 help / color / mirror / Atom feed
From: Mina Almasry <almasrymina@google.com>
To: netdev@vger.kernel.org
Cc: Mina Almasry <almasrymina@google.com>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	 Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	"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>,
	Simon Horman <horms@kernel.org>
Subject: [PATCH net-next v1] page_pool: mark net_iov unlikely in __page_pool_page_can_be_recycled()
Date: Fri,  4 Dec 2026 21:11:15 +0000	[thread overview]
Message-ID: <20261204211115.3013261-1-almasrymina@google.com> (raw)

In __page_pool_page_can_be_recycled(), checking
netmem_is_net_iov(netmem) without branch hints causes the compiler to
emit taken branches on the common struct page recycling fast path
(refcnt == 1 and !page_is_pfmemalloc(page)), throttling the CPU
front-end in page_pool_put_unrefed_netmem(). Calling netmem_to_page()
twice also obscures that net_iov has already been ruled out.

Mark netmem_is_net_iov(netmem) as unlikely(), cache
netmem_to_page(netmem) in a local variable, and mark the recyclable
struct page predicate likely().

On x86_64 (GCC 15.2, CONFIG_DEBUG_NET=n), this turns the common struct
page check into a straight-line fall-through, allows GCC to eliminate
the redundant net_iov checks inside netmem_to_page(), and shrinks
page_pool_put_unrefed_netmem() (1344 -> 1222 bytes, -122 bytes),
page_pool_put_netmem_bulk() (1659 -> 1365 bytes, -294 bytes), and
page_pool_alloc_frag_netmem() (702 -> 571 bytes, -131 bytes).

Benchmarked with tools/testing/selftests/net/bench/page_pool
(bench_page_pool_simple.c: time_bench_page_pool01_fast_path,
time_bench_page_pool02_ptr_ring, and time_bench_page_pool03_slow) on an
Intel Xeon Platinum 8581C host under hardware KVM (cloud-hypervisor)
with vCPU 0 pinned to a dedicated physical core (SMT sibling offlined),
core clock locked to the nominal 2.1 GHz TSC clock (1 TSC tick = 1
exact core cycle, no HWP/Turbo stepping), guest memory bound to NUMA
node 0, nokaslr, CONFIG_DEBUG_NET=n, 2x10M warmup runs, and 3
interleaved passes (forward, reverse, forward) x 11 runs = 33 runs at
loops=20000000 (median [IQR], core cycles per element):

  Benchmark                   Before [IQR]    After [IQR]           Delta
  -----------------------------------------------------------------------
  fast_path (direct recycle)  25.45 [1.33]   17.20 [0.24]  -8.24 (-32.4%)
  ptr_ring (ring recycle)     49.56 [0.07]   47.88 [0.01]  -1.68 ( -3.4%)
  slow_path (page allocator) 175.42 [0.22]  175.74 [0.15]  +0.31 ( +0.2%)

perf stat on fast_path (50M loops): 79.1 -> 72.1 insns/iter (-7.0),
23.0 -> 22.0 branches/iter (-1.0), IPC 2.93 -> 4.25 (+45%).

Signed-off-by: Mina Almasry <almasrymina@google.com>
---
 net/core/page_pool.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/net/core/page_pool.c b/net/core/page_pool.c
index d7c88c0b67e5..83ead6a897e9 100644
--- a/net/core/page_pool.c
+++ b/net/core/page_pool.c
@@ -825,9 +825,13 @@ static bool page_pool_recycle_in_cache(netmem_ref netmem,
 
 static bool __page_pool_page_can_be_recycled(netmem_ref netmem)
 {
-	return netmem_is_net_iov(netmem) ||
-	       (page_ref_count(netmem_to_page(netmem)) == 1 &&
-		!page_is_pfmemalloc(netmem_to_page(netmem)));
+	struct page *page;
+
+	if (unlikely(netmem_is_net_iov(netmem)))
+		return true;
+
+	page = netmem_to_page(netmem);
+	return likely(page_ref_count(page) == 1 && !page_is_pfmemalloc(page));
 }
 
 /* If the page refcnt == 1, this will try to recycle the page.

base-commit: d5cf954cebe4f175dfd834e1dc471a3aa203ec7d
-- 
2.56.1.915.g69d5ec7298-goog


                 reply	other threads:[~2026-12-04 21:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261204211115.3013261-1-almasrymina@google.com \
    --to=almasrymina@google.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=hawk@kernel.org \
    --cc=horms@kernel.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemb@google.com \
    /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