# HG changeset patch # User Maxim Dounin # Date 1323621042 0 # Node ID 1003326eccc556efffd69e55a43a795db023ec5c # Parent f8881d301d62fa5da8b53355316db4be7e6daf87 Microoptimization of sendfile(2) usage under FreeBSD. FreeBSD kernel checks headers/trailers pointer against NULL, not corresponding count. Passing NULL if there are no headers/trailers helps to avoid unneeded work in kernel, as well as unexpected 0 bytes GIO in traces. diff -r f8881d301d62 -r 1003326eccc5 src/os/unix/ngx_freebsd_sendfile_chain.c --- a/src/os/unix/ngx_freebsd_sendfile_chain.c Fri Dec 09 16:17:12 2011 +0000 +++ b/src/os/unix/ngx_freebsd_sendfile_chain.c Sun Dec 11 16:30:42 2011 +0000 @@ -246,9 +246,14 @@ } } - hdtr.headers = (struct iovec *) header.elts; + /* + * sendfile() does unneeded work if sf_hdtr's count is 0, + * but corresponding pointer is not NULL + */ + + hdtr.headers = header.nelts ? (struct iovec *) header.elts: NULL; hdtr.hdr_cnt = header.nelts; - hdtr.trailers = (struct iovec *) trailer.elts; + hdtr.trailers = trailer.nelts ? (struct iovec *) trailer.elts: NULL; hdtr.trl_cnt = trailer.nelts; /*