Commit 49500ad
tcp_bpf: optimize splice_read with zero-copy for non-slab pages
The previous splice_read implementation copies all data through
intermediate pages (alloc_page + memcpy). This is wasteful for
skb fragment pages which are allocated from the page allocator
and can be safely referenced via get_page().
Optimize by checking PageSlab() to distinguish between linear
skb data (slab-backed) and fragment pages (page allocator-backed):
- For slab pages (skb linear data): copy to a page fragment via
sk_page_frag, matching what linear_to_page() does in the
standard TCP splice path (skb_splice_bits). get_page() is
invalid on slab pages so a copy is unavoidable here.
- For non-slab pages (skb frags): use get_page() directly for
true zero-copy, same as skb_splice_bits does for fragments.
Both paths use nosteal_pipe_buf_ops. The sk_page_frag approach
is more memory-efficient than alloc_page for small linear copies,
as multiple copies can share a single page fragment.
Benchmark results with rx-verdict-ingress mode (loopback, 8 CPUs):
splice(2) + always-copy: ~2770 MB/s (before this patch)
splice(2) + zero-copy: ~4270 MB/s (after this patch, +54%)
read(2): ~4292 MB/s (baseline for reference)
Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>1 parent 0eb3c1a commit 49500ad
1 file changed
+31
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
447 | 447 | | |
448 | 448 | | |
449 | 449 | | |
| 450 | + | |
450 | 451 | | |
451 | 452 | | |
452 | 453 | | |
| |||
458 | 459 | | |
459 | 460 | | |
460 | 461 | | |
461 | | - | |
462 | | - | |
463 | | - | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
464 | 474 | | |
465 | | - | |
466 | | - | |
467 | | - | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
468 | 489 | | |
469 | 490 | | |
470 | 491 | | |
| |||
481 | 502 | | |
482 | 503 | | |
483 | 504 | | |
484 | | - | |
485 | | - | |
486 | 505 | | |
| 506 | + | |
| 507 | + | |
487 | 508 | | |
488 | 509 | | |
489 | 510 | | |
| |||
508 | 529 | | |
509 | 530 | | |
510 | 531 | | |
511 | | - | |
512 | | - | |
513 | 532 | | |
| 533 | + | |
| 534 | + | |
514 | 535 | | |
515 | 536 | | |
516 | 537 | | |
| |||
0 commit comments