From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.71 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796418678; b=E6ItRF9Pt1c64ej2DOfRXv/ykw7+KDnAL4WP1wjh3uz/INBQEA96VQP/RDYMEB9pDF8D 3h8EPsQZ85G1a/X43GljBX2H8xoDjOR7aZO0h93mS3kQDdGDAZNfb97n0ejcgjSZrpNx3 3tlWtBYAbDQFXghp4JpBqgWzuP5UO0aOu+1O4bbrfLywEo6kErzz4jRcbslBNvuYlypqA Z5nzMGFB0FPhlfjHWy2bS3nf0yPKUl23gHBEP/3DArmDswnrNSWD5ryGTrovzmcR0PPM3 kf5kIu2WXYa4MhFnfGeog/G/Ystk3pUESzdY3aAnwO+iHlGf6quOI9vplKyFVV78D9g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796418678; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Received:Date:Mime-Version:X-Mailer:Message-ID: Subject:From:To:Cc:Content-Type; bh=+BMaYIwBw6LTW3QavGX8y5r5RfBlIBAOWS7/nNFfOd4=; b=5osMBfi0Np2VF3zqfSyDSBsFkXuZHyZZLa0q/WJACiaHvDpwFFvoorOr5KNZiLS71DWq bZ352SEECtdXSmimQmZRpcoq7zICIvzyeQRpqB2DS4PdfFlhHLVONxEnGfNvnh3ScnyGP gYU5D+ZDJ6SNMZmRKNm+KIKNN7T04u0rqxq7Vekzm5azlIVWQuz6/RFHR2WGk9uBlR+nb ZXb3vq5HwdYuhhzVX865Tggq4IW+pWbPw5EPYks1MrcRFVwL/X1lzewEuTH3ZTzmPC4mg yLPNQwMgMZHiSFo3T13l3o2zvbvFowp9+9KIj8HcI9c5xjZoSrYzqMmJkAC6SkSfTpA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--almasrymina.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=bEozPty6; arc=none smtp.remote-ip=74.125.82.71 Received: from mail-dl1-f71.google.com (mail-dl1-f71.google.com [74.125.82.71]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A046606A322 for ; Fri, 4 Dec 2026 21:11:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8A046606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--almasrymina.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=bEozPty6 Received: by mail-dl1-f71.google.com with SMTP id a92af1059eb24-1b5d5f81059so1700009c88.1 for ; Fri, 04 Dec 2026 13:11:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796418676; x=1797023476; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=+BMaYIwBw6LTW3QavGX8y5r5RfBlIBAOWS7/nNFfOd4=; b=bEozPty61p/0/M7KadmDCfPrgcPHGd+56+Tv24fdtek2wB+30LYyezsUwQuio3qc2W hyM4F5vwxTHGlIQoliuoytZo30jO9dDgMsPEN/qAqe49cNtRX95X63uZuaRpTMGespgo 9dYj/OOZVCsolxxxyXHpvQfYOvknittElSLF7KY6AZwymzSo8PYYwbUEbTCLUc+wKDkg n65j0/JZCAhqukqlpzCpHgPNDJdFOKTbs0aq/1aH6dQ6aWLEEKe4e63TzVktnRUlJKw+ 2HKcxJEJwZ6fFaZ+IJFKg8r7J53vGCetmdQBPp78/PeEjmYQgqSjv3FZKfr29sLVBWjP Ymfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796418676; x=1797023476; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=+BMaYIwBw6LTW3QavGX8y5r5RfBlIBAOWS7/nNFfOd4=; b=rKHCn16tlylj64T9ZurXsCSJN6/qZ/H5D7Jx2SyBn4KeB2wa7l/XQl/9DzzW6Bbz05 UPl8zcgd9yKkd387gNvubQoVcifxVecFhI2w2V/ZBhOSC7xUs2tVpGA/LJdxDMaUjimu xt0h0vXD0bJtHwCBX4DIh5qETjnYyZDYW1unfPh3XYrpYjKZeBMjtyfILkKxrDlDf9wF hYQquDQQSylGCrAQdgGdatym0MTXAnPzeOOAGtO31lRcuKAWTwu/g7G7Rc9lM0Q//yKs MigCSA+9yWUpyR7aX9r1m72Y7S4gpttyUGwuNh99qHeBxjvfKTDjgy0/Ww/0M5RrWOpE 6alA== X-Gm-Message-State: APuU4Z9Gn43/m2mCXEncsztzGaaSk4NxOFHvcT6hQ/2ZEyCusgQtrsDe EgU4uPSHpENOcw9v6qdkmxUWdj50rZO1YeCezLEqJxeFArQxuQEswxZy+QcpZgc63+WPQPRB3Fq 685ZdjzsdvVc/Sn8+jownCKy6YEdeA6GR/K3e4dZipwj3sLHJrsIEJDnRlEQyzA33vH+UzjKnD9 oEqJytS6vWqXar2GFj7ecmxHEr8cMNFup5QeOscK0Hbrg6LtLpoA6cVbyFxo3657A= X-Received: from dled10-n1.prod.google.com ([2002:a05:701b:42ca:10b0:1b5:b9d1:d712]) (user=almasrymina job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7023:e44:10b0:1b5:4aba:b087 with SMTP id a92af1059eb24-1b5d7061cb7mr2756704c88.3.1796418676222; Fri, 04 Dec 2026 13:11:16 -0800 (PST) Date: Fri, 4 Dec 2026 21:11:15 +0000 X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog Message-ID: <20261204211115.3013261-1-almasrymina@google.com> Subject: [PATCH net-next v1] page_pool: mark net_iov unlikely in __page_pool_page_can_be_recycled() From: Mina Almasry To: netdev@vger.kernel.org Cc: Mina Almasry , Jesper Dangaard Brouer , Ilias Apalodimas , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman Content-Type: text/plain; charset="UTF-8" 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