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