3 ms·
It's unwise to go against Rob Pike and Keith Adams, but I'm going to give it a try... The read(2)/write(2) solution from userspace would involve no copying as
by wmf 16y ago
It's unwise to go against Rob Pike and Keith Adams, but I'm going to give it a try...
The read(2)/write(2) solution from userspace would involve no copying as well, assuming a competent kernel implementation.
AFAIK that was tried and it's slower than sendfile; sometimes it's even slower than copying data.
software may well outlive any existing hardware and its quirks.
Virtual memory operations like modifying page tables appear to be consistently getting slower relative to other operations, so I would expect that sendfile/splice will always be faster.
- kmavm 16y agoModifying page tables is just a store on x86; since you would be reducing protections (going from unmapped, to mapped read-only), there is no need for TLB flush or shootdown (both of which are, admittedly, getting relatively more costly).
- wmf 16y agoApps tend to reuse buffers, so if you zero-copy read() into a buffer that's already populated you'd have to drop the existing pages and replace them with new ones. Then a zero-copy write() has to mark the pages as COW. Would this require a TLB flush? It seems like it would.
- kmavm 16y agoI initially thought that was a killer point, but on second thought, if the memory is already mapped writably the kernel can avoid remappings entirely by directing the I/O into the already-mapped pages.
- aliguori 16y agoProblem is you don't know which recv() a packet is destined for until you actually receive it and can parse the header and apply all of the filtering rules. But what you describe is exactly how O_DIRECT achieves zero/copy for read/write. Of course, if you assume multiple receive queues that are programmable, you can short cut the netfilter code. That was roughly the idea behind VJ channels.