Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.224.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796414684; b=qwUDuHAXtuLvZGASGke/Mb4ms2w90igHTBlUhA/P7973JmQkwKMFkJq/cbjLTORtfs+U METJ0sa5HwwW5/MQO2MVmV960Hyoi28yBK/kk/Z3xYDm9QcLsJ0XDJyMv0vAXJDWtQzrd NswOaD+IyU9CVn7L7MBhHTta81sGUTYMO0clZXGPxOLn6l8UY8RJ+vynqSWpz1uulrzIx QCM/Mnla6h8W2T6nKMelaRMM+GI1jTWNb1KOQNwixylFlUK2/7xtt8Cx9CpUq0rC/C5gO WDiG4RSwMovJl7fGvUSg+NRJQr2P5mjrVl5q23FWf0bX1w4JRMVYtiZOALIQuw5O2aQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796414684; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:Subject:Date: Message-Id:MIME-Version:Content-Type:Content-Transfer-Encoding: X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer:X-Developer-Signature: X-Developer-Key; bh=tWDxbEDZ/upNSdTDzvKHhR82VIVHAOhFG+Ix4tjKClw=; b=anCr7MdiDIS8HRqjNaolva1M9n1tYVuhYQN3oMF1bQzgNMkH/2ONdS64m6XfV1AZI1gy Z9jxnDWUgRZQuu3XtCk7WG1AiIYoZNNvz3+EFYV8u756sLUCj9+8km1ld4xv6LMHc/C61 c01+L+1RD8Z3SUzY5Iv1cbpWm4/pnWAxVYmMtJOSObmRvuSDGDAeLQynMEJUAF+hsUtei DIua+haderJhlyL1QGSKoB0BUxk5VuNWnaj6th1F7VOowOaN3i8K0Mju7n65naPh2u0G4 OSIWR6Wh7BctdCJvAPRMzUTVkh4dna1427eZNRPNK44ZAVZnOo2TRtoWn/qobuemEmQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=I0oPb235; arc=none smtp.remote-ip=74.125.224.42 Received: from mail-yx1-f42.google.com (mail-yx1-f42.google.com [74.125.224.42]) (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 8BDBB606A322 for ; Fri, 4 Dec 2026 20:04:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8BDBB606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=I0oPb235 Received: by mail-yx1-f42.google.com with SMTP id 956f58d0204a3-67dc7eb1442so1246617d50.0 for ; Fri, 04 Dec 2026 12:04:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796414683; x=1797019483; darn=vger.kernel.org; h=cc:to:content-transfer-encoding:content-type:mime-version :message-id:date:subject:from:from:to:cc:subject:date:message-id :reply-to:content-type; bh=tWDxbEDZ/upNSdTDzvKHhR82VIVHAOhFG+Ix4tjKClw=; b=I0oPb235eQeIWTOvtAbijTKENMhDOaYXJmm8SsCHs1+yo7ADXAfroT538+J8TkrYcq Upkkth1InePo2Fx+9fF4BGCrnMCAeeM8AX7yZs1RpvT3e4ci1/v8hqz1KSAtOF3J4QJD tdeiiGO+vv3ElsSRziwOWrLYbxY7bsCzVL1E8jaW0ao8SuxKldr7jHh2G8C5V8dkSl1n avtaZe1CCExCzdwGKYpPckPou1RAA8GqtfRSDA0/3evaMhvhcnsuJMVaalm6SnybYkLz zq/v3ObTY4GsPueC3FqvTsuSiXc5fD0mJvV4s29ycOa/HYFag8+Iwq21xyV4IgO68L38 LfNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796414683; x=1797019483; h=cc:to:content-transfer-encoding:content-type:mime-version :message-id:date:subject:from:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=tWDxbEDZ/upNSdTDzvKHhR82VIVHAOhFG+Ix4tjKClw=; b=E/i7S9OssPnSptwswg2LtoJ+I7IYzIETVGLIdLV5u6ruQSrBJBnaqxqB8hNeDb+/Pa XBY6dKiopcMLxjZJ6TNJkBXZIvigd6VEEPU8oQNIoGJhbGgqXdnrBZH/dJFx1L6VO407 Opxc/ykVqS2PsJLeF4AVcF1bQoK4szPPVz4WNRZPF9keZdqeiZaVCiEF8/HaOeFi7KZ8 tZ2cu/M/xRUqW8mHFOrCrNXTCduJ2Rm0weYnIPjvb8w2GuSZkfwwDZe7HnJYV8y+xeV4 Fi6J6M/4IC6qUe/NJ6+XJLIAn4iV7369XJEJdZ96a5aX000ky4zvb+okSHfvbdQvPN/U oX0A== X-Gm-Message-State: AB4q+uHUfDTTX/LpqlhmGbU0Moyx3qwLPwf2+bSHviogh/iDKbnSt7PW /ifFJ5WCn2RViXgl/k4+1x4VNXpwUYuIcuIUJ1WpKvpmL/sIlGlBaZNi X-Gm-Gg: AZFdTZcNdX6GM+3NFacMe4zNkqU9EWfnI8XZH//Qs0YpW8HpW/vCECgd5AXjGdXGrOc n48sJa8Gpz0Com/lD1Vgx8Zp2QK3VOT5KT5+/H2i/F0NXgqmH8AQlatl6ZL6U3YM6LaNg96Ujoz +I2fCnGPjT3UUxH9NLmiQ6NglADRo48P6dX6o+4AwzD28CpL24G87FqAJYBUvfcOBvDCeA6XyjA zJr0QylKp7K/HPBz3MwMQNncrJTU+42XnVM8d8kIrUk6DCVbuUlLROStOTlg77UqmSo2UvDi3cH pkTxIiuhyuUsNMgDKBDMhycpw4jZoZvmxEepLlZMWr4aKAfF+8jry+nQfWbBhQq4hkE1z4Ezg2T KoYNSBktl1L33hmuQ6cPfQQ16rg9uEpj1amjiIXo3Av4zSz0pN8JYo8ZLmi05NpDDLQRHQnDdPy 654OwqcVHJXQFdZ2KAgBC+ERB8V5qXpLJnCScx4YaPijdFm7P8FuDOLRRn3c6IBpom0bPDZCEZu 1BdLa7DyXcWLPUY5bLBIMZXYnh2rEO74FR7HShOU+DTZLKVUprLlTeLEstWjrZRsgPIuKG+aNxK 8ZLR1BlbJxOLv8r1n2DdBzFp3YUnjRx5DEDqEVttwQ== X-Received: by 2002:a53:ea8e:0:b0:676:7f47:5e19 with SMTP id 956f58d0204a3-67f724721a4mr1252237d50.93.1796414681686; Fri, 04 Dec 2026 12:04:41 -0800 (PST) Received: from localhost ([2a03:2880:30ff:42::]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-67f0cd0378dsm1545575d50.9.2026.12.04.12.04.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 12:04:41 -0800 (PST) From: Mykyta Yatsenko Subject: [PATCH bpf-next 0/5] bpf: tcp: Prefetch sk storage before TCP transmit Date: Fri, 04 Dec 2026 12:03:51 -0800 Message-Id: <20261204-sk_storage_prefetch-v1-0-ea52fb48b52b@meta.com> X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-B4-Tracking: v=1; b=H4sIAKccE2sC/x3MQQqDMBAF0KsMf23ARGxoriIiVic6FKJkggji3 aVdP3gXlLOwItCFzIeobAmBbEWY1jEtbGRGILjavaxtaqPfQcuWx4WHPXPkMq2m9S37OTpn/Rs V4Qdy/tcOnz2axGdBf98PSLUbW28AAAA= X-Change-ID: 20261130-sk_storage_prefetch-575e7df22179 To: bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org, daniel@iogearbox.net, kernel-team@meta.com, eddyz87@gmail.com, memxor@gmail.com Cc: Mykyta Yatsenko X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1796414679; l=5098; i=yatsenko@meta.com; s=20260324; h=from:subject:message-id; bh=As7590Jvksy+7oU5jim1pX/W1wJTyzBLD9G+DMu9b8k=; b=3lujM8VnziHejPiw38EGeML5p5Xe3+YwKayi18ytYMROVd85f/E8dnp9MPvRBJBT5eDOmT2Jl u/qRFfhR1gZDdfSKWQQp0iZ7F489BlDt5eqjEt+vNL4UGP61PrPlTUI X-Developer-Key: i=yatsenko@meta.com; a=ed25519; pk=1zCUBXUa66KmzfjNsG8YNlMj2ckPdqBPvFq2ww3/YaA= An egress program that looks up the sk storage of a cold socket waits for two cache misses in a row. The first miss is on cache[] of the storage, and the second miss is on the element. A lookup of a value that the socket does not have is worse: it walks the whole list of the storage, with one miss for each element. With many connections, these misses are a large part of the program cost. This series replaces the BPF_F_INLINE_VALUE series [1] with the design that Alexei proposed [2], [3]: - Patch 1 makes a NULL cache[] slot mean that the storage has no value for the slot, so that a lookup of an absent value stops at the first load [3]. This patch is generic: task, inode and cgroup storage get it too. Patch 2 tests maps that share slots. - Patch 3 prefetches cache[] when sendmsg starts and when a transmit starts, because TCP knows the socket before the egress programs run. - Patch 4 learns on each CPU which cache[] slots the programs look up, and prefetches the elements of these slots just before ->queue_xmit(). Patch 5 tests the hooks under traffic. Patches 1-2 do not need patches 3-5. There is no UAPI change and no new limit. Changes from the prototype in [2]: - A work item changes the static key from a count of the maps. Map create can run, and map free always runs, with migration disabled, and a change of a static key takes cpus_read_lock(). This can deadlock with a CPU offline: the key code of the prototype hung in a CPU hotplug and light skeleton stress test. - Only bpf_sk_storage_get() marks a slot, for any socket. The prototype marked the lookups of the last socket that sent on the CPU. - One mask of marked slots, cleared every 256 transmits. The prototype kept a second mask with the slots of the last round. - The cache[] prefetch runs only on a CPU that has a marked slot. - The sendmsg prefetch is in tcp_sendmsg_locked(), so that kTLS, sockmap and espintcp get it too. - this_cpu operations, because the hooks can run in preemptible process context. Limits: - Patches 3-4 cover only TCP transmit and sk storage. The lookups of all programs mark slots, so a map that only ingress or sock_ops programs use also gets a prefetch on each transmit. - The static key is on while any sk storage map exists. While a CPU has a hot slot, each transmit on that CPU loads sk->sk_bpf_storage. A gate for each socket can come later, if a workload needs it. - With more than 16 maps, maps share cache[] slots, and a lookup of an absent value in a shared slot can still walk the list. On x86-64, clang emits no instruction for prefetch(), because the kernel builds with -mno-sse [4], [5]. Thus the hooks use prefetchw(). Results: AMD Zen 5 KVM guest, 4 server vCPUs, IPv6 over veth, 131072 connections, 9 sk storage maps for each socket, bpf-next 2bf3351c5f89. 2 tc egress programs do 2 sk storage lookups on each packet. The change of the time in each lookup against base, from perf profiles, mean of 3 runs: lookup 1 lookup 2 both values present -95.7% -93.7% lookup 2 finds no value -96.4% -99.5% With patch 1 alone, the lookup that finds no value takes 98.7% less time, and the other lookups change by less than 4%. The local storage benchmarks in selftests show no change larger than the noise between runs. Signed-off-by: Mykyta Yatsenko [1] https://lore.kernel.org/bpf/20261123-sls_f1-v2-0-76474de9b052@meta.com/ [2] https://lore.kernel.org/bpf/DN8A36W906WG.1BTUYRC2FIIR@gmail.com/ [3] https://lore.kernel.org/bpf/DN92BUAQMX7H.3NKLFY0FRORT7@gmail.com/ [4] https://lore.kernel.org/all/20261103060658.696994-1-martin.ankerl@gmail.com/ [5] https://github.com/llvm/llvm-project/pull/248194 [6] https://lore.kernel.org/bpf/DNAPOYTT6B0G.2RZJJ80T3HFKU@gmail.com/ --- Mykyta Yatsenko (5): bpf: Make a NULL cache slot mean that local storage has no value selftests/bpf: Test sk storage maps that share cache slots bpf: tcp: Prefetch sk storage cache[] before TCP transmit bpf: tcp: Prefetch values of hot sk storage maps before transmit selftests/bpf: Test sk storage lookups during TCP transmit include/linux/bpf_local_storage.h | 14 +- include/net/bpf_sk_storage.h | 53 +++++++ kernel/bpf/bpf_local_storage.c | 23 +++- net/core/bpf_sk_storage.c | 69 +++++++++- net/ipv4/tcp.c | 2 + net/ipv4/tcp_output.c | 3 + .../bpf/prog_tests/sk_storage_shared_slots.c | 57 ++++++++ .../selftests/bpf/prog_tests/sk_storage_xmit.c | 153 +++++++++++++++++++++ .../testing/selftests/bpf/progs/sk_storage_xmit.c | 46 +++++++ 9 files changed, 415 insertions(+), 5 deletions(-) --- base-commit: 94299e4ad749bd5b361498b97b59f326bedac6fe change-id: 20261130-sk_storage_prefetch-575e7df22179 Best regards, -- Mykyta Yatsenko