▲ | commandersaki 5 days ago | |||||||
I'm sceptical of the efficiency gains with sendfile; seems marginal at best, even in the late 90s when it was at the height of popularity. | ||||||||
▲ | lossolo 5 days ago | parent | next [-] | |||||||
> seems marginal at best Depends on the workload. Normally you would go read() -> write() so: 1. Disk -> page cache (DMA) 2. Kernel -> user copy (read) 3. User -> kernel copy (write) 4. Kernel -> NIC (DMA) sendfile(): 1. Disk -> page cache (DMA) No user space copies, kernel wires those pages straight to the socket 2. Kernel -> NIC (DMA) So basically, it eliminates 1-2 memory copies along with the associated cache pollution and memory bandwidth overhead. If you are running high QPS web services where syscall and copy overheads dominate, for example CDNs/static file serving the gains can be really big. Based on my observations this can mean double digit reductions in CPU usage and up to ~2x higher throughput. | ||||||||
| ||||||||
▲ | kev009 5 days ago | parent | prev [-] | |||||||
Then you don't understand the memory and protection model of a modern system very well. sendfile effectively turns your user space file server into a control plane, and moves the data plane to where the data is eliminating copies between address spaces. This can be made congruent with I/O completions (i.e. Ethernet+IP and block) and made asynchronous so the entire thing is pumping data between completion events. Watch the Netflix video the author links in the post. There is an inverted approach where you move all this into a single user address space, i.e. DPDK, but it's the same overall concept just a different who. |