summaryrefslogtreecommitdiff
path: root/tools/include/uapi
diff options
context:
space:
mode:
authorMykyta Yatsenko <yatsenko@meta.com>2026-09-22 10:58:02 -0700
committerAlexei Starovoitov <ast@kernel.org>2026-09-22 19:19:25 +0000
commit63b13537e6b223699dabb60ec0009b0c976e7181 (patch)
treea20f3b7bb735c8291cef6b20adf54a48feb85228 /tools/include/uapi
parent79dc258c9392051420a26f1504c647bd3d27c66a (diff)
bpf: Speed up htab lookups for u32/u64 keys
Four- and eight-byte keys are common enough to warrant specialized htab lookups. Use jhash_1word() and jhash_2words() for these key sizes instead of the generic jhash2() path. For JITed BPF_MAP_TYPE_HASH lookups, htab_map_gen_lookup() also knows the map's fixed key size. Select u32- and u64-specific lookup entry points so the compiler can specialize both hashing and key comparison. Other key sizes continue to use the generic lookup entry point. This preserves the jhash2() result and lookup semantics while avoiding generic length handling. Measure this with six runs of: ./bench -w3 -d10 -a bpf-hashmap-lookup \ --key_size KEY_SIZE --max_entries MAX_ENTRIES \ --nr_entries NR_ENTRIES --nr_loops NR_LOOPS \ --map_flags 0x40 inside a vng guest with two vCPUs and 4 GiB of RAM. Run the baseline first and the optimized kernel second. Use these workloads: max_entries nr_entries nr_loops small 512 256 8,388,608 medium 10,000 5,000 8,000,000 large 100,000 50,000 8,000,000 Mean throughput in million lookups per second is: Baseline: key size (bytes) 1 4 8 10 small 89.45 91.21 103.40 91.74 medium 125.97 80.25 91.94 78.52 large 140.67 53.56 58.68 47.31 Optimized: key size (bytes) 1 4 8 10 small 86.95 197.77 168.65 90.88 medium 124.97 147.48 137.76 77.51 large 131.06 78.51 76.04 47.25 Change: key size (bytes) 1 4 8 10 small -2.79% +116.83% +63.11% -0.94% medium -0.79% +83.78% +49.83% -1.28% large -6.84% +46.58% +29.58% -0.12% The u32 specialization improves lookup throughput by 47-117%, and the u64 specialization improves it by 30-63%. Ten-byte controls remain within a 1.3% slowdown. One-byte controls range from -6.8% to -0.8%. Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Anton Protopopov <a.s.protopopov@gmail.com> Link: https://patch.msgid.link/20260922-hashtab_fast_hashfn-v3-1-b7b0e9bc33ac@meta.com
Diffstat (limited to 'tools/include/uapi')
0 files changed, 0 insertions, 0 deletions