#The Cost of Traditional System Calls
When a web server reads a file from disk and transmits it over a TCP socket using standard read() and write() routines:
// Standard two-step copy loop
char buffer[8192];
while ((bytes_read = read(file_fd, buffer, sizeof(buffer))) > 0) {
write(socket_fd, buffer, bytes_read);
}
This innocent loop triggers 4 context switches and 4 data copies per iteration:
1. read() syscall: Context switch User -> Kernel mode.
DMA engine copies file data from Disk -> Kernel Page Cache.
2. Kernel copies data from Page Cache -> User Space Buffer.
Context switch Kernel -> User mode.
3. write() syscall: Context switch User -> Kernel mode.
CPU copies data from User Space Buffer -> Socket Buffer.
4. DMA engine copies data from Socket Buffer -> Network Card (NIC).
Context switch Kernel -> User mode.
Notice that the application never actually inspected or modified the buffer! User space was merely an unnecessary transit stop.
#Zero-Copy with sendfile()
The sendfile() system call was designed specifically to eliminate user-space traversal:
#include <sys/sendfile.h>
ssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t count);
With SG-DMA (Scatter-Gather DMA) hardware support, data is copied directly from the Kernel Page Cache into the Network interface without passing through CPU registers or allocating user space memory.
#The Modern Frontier: io_uring
In modern high-concurrency Linux systems, Jens Axboe's io_uring provides asynchronous completion and submission queue rings shared between kernel and user space.
By eliminating system call overhead entirely via ring buffers, applications can execute hundreds of thousands of operations per second with near-zero latency jitter.