Zero-Copy Networking: How Linux Achieves Millions of Requests Per Second
In standard POSIX network programming, serving a file over HTTP requires copying data 4 times and context-switching 4 times across the user/kernel boundary.
1. The Standard 4-Copy Overhead
read()syscall: Disk $\rightarrow$ Kernel Page Cache (DMA)- Kernel Page Cache $\rightarrow$ User-space Application Buffer (CPU Copy)
write()syscall: User-space $\rightarrow$ Socket Buffer (CPU Copy)- Socket Buffer $\rightarrow$ Network Card (DMA)
2. The Zero-Copy Revolution (sendfile & splice)
With zero-copy sendfile(), the kernel transfers DMA descriptors directly from the file page cache to the network interface card without user-space buffer hops.
Explore networking layers in our OSI Model Target!