Commit e72ffac
selftests/bpf: add splice option to sockmap benchmark
Add --splice option to bench_sockmap that uses splice(2) instead of
read(2) in the consumer path. A global pipe is created once during
setup and reused across iterations to avoid per-call pipe creation
overhead.
When --splice is enabled, the consumer splices data from the socket
into the pipe, then reads from the pipe into the user buffer. The
socket is set to O_NONBLOCK to prevent tcp_splice_read() from
blocking indefinitely, as it only checks sock->file->f_flags for
non-blocking mode, ignoring SPLICE_F_NONBLOCK.
Also increase SO_RCVBUF to 16MB to avoid sk_psock_backlog being
throttled by the default sk_rcvbuf limit, and add --verify option
to optionally enable data correctness checking (disabled by default
for benchmark accuracy).
Benchmark results with rx-verdict-ingress mode (loopback, 8 CPUs):
read(2): ~4292 MB/s
splice(2) + zero-copy: ~4270 MB/s
splice(2) + always-copy: ~2770 MB/s
Zero-copy splice achieves near-parity with read(2), while the
always-copy fallback is ~35% slower.
Usage:
# Steer softirqs to CPU 7 to avoid contending with the producer CPU
echo 80 > /sys/class/net/lo/queues/rx-0/rps_cpus
# Raise the receive buffer ceiling so the benchmark can set 16MB rcvbuf
sysctl -w net.core.rmem_max=16777216
# Run the benchmark
./bench sockmap --rx-verdict-ingress --splice -c 2 -p 1 -a -d 30
Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>1 parent 0c98595 commit e72ffac
1 file changed
+56
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
10 | 13 | | |
11 | 14 | | |
12 | 15 | | |
| |||
46 | 49 | | |
47 | 50 | | |
48 | 51 | | |
| 52 | + | |
| 53 | + | |
49 | 54 | | |
50 | 55 | | |
51 | 56 | | |
| |||
110 | 115 | | |
111 | 116 | | |
112 | 117 | | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
113 | 121 | | |
114 | 122 | | |
115 | 123 | | |
| |||
119 | 127 | | |
120 | 128 | | |
121 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
122 | 133 | | |
123 | 134 | | |
124 | 135 | | |
| |||
130 | 141 | | |
131 | 142 | | |
132 | 143 | | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
133 | 149 | | |
134 | 150 | | |
135 | 151 | | |
| |||
320 | 336 | | |
321 | 337 | | |
322 | 338 | | |
| 339 | + | |
323 | 340 | | |
324 | 341 | | |
325 | 342 | | |
| |||
350 | 367 | | |
351 | 368 | | |
352 | 369 | | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
353 | 382 | | |
354 | 383 | | |
355 | 384 | | |
| |||
368 | 397 | | |
369 | 398 | | |
370 | 399 | | |
| 400 | + | |
| 401 | + | |
371 | 402 | | |
372 | 403 | | |
373 | 404 | | |
| |||
388 | 419 | | |
389 | 420 | | |
390 | 421 | | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
391 | 425 | | |
392 | 426 | | |
393 | 427 | | |
| |||
419 | 453 | | |
420 | 454 | | |
421 | 455 | | |
422 | | - | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
423 | 465 | | |
424 | 466 | | |
425 | 467 | | |
| |||
440 | 482 | | |
441 | 483 | | |
442 | 484 | | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
443 | 488 | | |
444 | 489 | | |
445 | 490 | | |
| |||
554 | 599 | | |
555 | 600 | | |
556 | 601 | | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
557 | 606 | | |
558 | 607 | | |
559 | 608 | | |
| |||
572 | 621 | | |
573 | 622 | | |
574 | 623 | | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
575 | 630 | | |
576 | 631 | | |
577 | 632 | | |
| |||
0 commit comments