TRT
Sign in

Advanced · Module 8 · Lesson 7 of 11

Zero-Copy Data Pipelines: sendfile, splice, and Vectored I/O

Eliminate redundant CPU memory copies and context switches using Linux sendfile, stream kernel buffers via splice, and aggregate non-contiguous buffers with vectored writev.

Pro — members onlyAbout 16 minutes

By the end you can

  • Stream disk files directly to network sockets using Linux sendfile
  • Transfer byte streams between arbitrary file descriptors and pipes via splice and tee
  • Batch non-contiguous memory buffers into atomic transmissions using writev and readv
  • Trace DMA controller transfers, kernel page cache references, and scatter-gather sk_buff buffers

Builds on TCP State Machine and Socket Options: setsockopt, SO_REUSEADDR, and TIME_WAIT.

01 · A question first

Why does a traditional file-serving loop copy every byte four times and trigger four context switches, while Linux sendfile streams gigabytes directly from disk to the network card with zero CPU memory copies?

Make a guess before you read on.

02 · The idea

Members only

Unlock the full lesson

This lesson is part of the membership. Join to read it in full, along with every other premium deep dive.

What's inside

  • Start with the problem
  • How the idea works
  • Production Implementation: High-Performance Static File Server
  • Why it is correct
  • What it costs
  • Pitfalls and variations
  • Where it is used

03 · Practice

Something wrong with this lesson? Report a problem