3 ms·
Probably the most common example is sendfile() for writing file contents out to a socket without reading them into userspace: https://man7.org/linux/man-pages/
by kentonv 3y ago
Probably the most common example is sendfile() for writing file contents out to a socket without reading them into userspace:
https://man7.org/linux/man-pages/man2/sendfile.2.html https://man7.org/linux/man-pages/man2/sendfile.2.html
- arter4 3y agoYes, I knew about sendfile() but I wasnt't aware of any web server using that (though I know Kafka uses it). Then I found out Apache supports it via the EnableSendfile directive. Nice. >This directive controls whether httpd may use the sendfile support from the kernel to transmit file contents to the client. By default, when the handling of a request requires no access to the data within a file -- for example, when delivering a static file -- Apache httpd uses sendfile to deliver the file contents without ever reading the file if the OS supports it.
- kentonv 3y agoI'd expect most serious web servers support it. I've written one that does (workerd), it's not too hard. That said, it's tricky to use if the server also does TLS termination... then you need kTLS, which is a much bigger can of worms.
- nh2 3y agoPretty much all modern Linux web servers support sendfile(). Examples: * nginx: [1] * Haskell webserver module: [2] * caddy: [3] [1]: https://nginx.org/en/docs/http/ngx_http_core_module.html#sendfile https://nginx.org/en/docs/http/ngx_http_core_module.html#sen... [2]: https://hackage.haskell.org/package/warp-3.3.28/docs/Network-Wai-Handler-Warp-Internal.html#g:6 https://hackage.haskell.org/package/warp-3.3.28/docs/Network... [3]: https://github.com/caddyserver/caddy/pull/5022 https://github.com/caddyserver/caddy/pull/5022
- mrfox321 3y agoIsn't that the opposite? That is, bypassing user space, not kernel space?
- kentonv 3y agoOh, hmm, yeah, perhaps OP meant something more like using raw sockets to get packets directly into userspace without relying on the kernel to arrange them into streams? I'm not very familiar with that though.
- loeg 3y agoSendfile isn’t kernel bypass.