|SF_NODISKIO. This flag causes any sendfile call which would block on disk I/O to instead return EBUSY. Busy servers may benefit by transferring requests that would block to a separate I/O worker thread.|
Do not wait for some kernel resource to become available,
.Vt mbuf and
.Vt sf_buf . The flag does not make the sendfile syscall truly non-blocking, since other resources are still allocated in a blocking fashion.
|SF_SYNC. sendfile sleeps until the network stack no longer references the VM pages of the file, making subsequent modifications to it safe. Please note that this is not a guarantee that the data has actually been sent.|
When using a socket marked for non-blocking I/O, sendfile may send fewer bytes than requested. In this case, the number of bytes successfully written is returned in *sbytes (if specified), and the error EAGAIN is returned.
.Fx implementation of sendfile is "zero-copy", meaning that it has been optimized so that copying of the file data is avoided.
On some architectures, this system call internally uses a special sendfile buffer (Vt struct sf_buf) to handle sending file data to the client. If the sending socket is blocking, and there are not enough sendfile buffers available, sendfile will block and report a state of "sfbufa". If the sending socket is non-blocking and there are not enough sendfile buffers available, the call will block and wait for the necessary buffers to become available before finishing the call.
The number of
.Vt sf_buf Ns s allocated should be proportional to the number of nmbclusters used to send data to a client via sendfile. Tune accordingly to avoid blocking! Busy installations that make extensive use of sendfile may want to increase these values to be inline with their kern.ipc.nmbclusters (see tuning(7) for details).
The number of sendfile buffers available is determined at boot time by either the kern.ipc.nsfbufs loader.conf(5) variable or the NSFBUFS kernel configuration tunable. The number of sendfile buffers scales with kern.maxusers. The kern.ipc.nsfbufsused and kern.ipc.nsfbufspeak read-only sysctl(8) variables show current and peak sendfile buffers usage respectively. These values may also be viewed through netstat-m .
If a value of zero is reported for kern.ipc.nsfbufs, your architecture does not need to use sendfile buffers because their task can be efficiently performed by the generic virtual memory structures.
.Rv -std sendfile
[EAGAIN] The socket is marked for non-blocking I/O and not all data was sent due to the socket buffer being filled. If specified, the number of bytes successfully sent will be returned in *sbytes. [EBADF] The fd argument is not a valid file descriptor. [EBADF] The s argument is not a valid socket descriptor. [EBUSY] Completing the entire transfer would have required disk I/O, so it was aborted. Partial data may have been sent. (This error can only occur when SF_NODISKIO is specified.) [EFAULT] An invalid address was specified for an argument. [EINTR] A signal interrupted sendfile before it could be completed. If specified, the number of bytes successfully sent will be returned in *sbytes. [EINVAL] The fd argument is not a regular file. [EINVAL] The s argument is not a SOCK_STREAM type socket. [EINVAL] The offset argument is negative. [EIO] An error occurred while reading from fd. [ENOBUFS] The system was unable to allocate an internal buffer. [ENOTCONN] The s argument points to an unconnected socket. [ENOTSOCK] The s argument is not a socket. [EOPNOTSUPP] The file system for descriptor fd does not support sendfile. [EPIPE] The socket peer has closed the connection.
netstat(1), open(2), send(2), socket(2), writev(2), tuning(7)
.Rs A Portable Kernel Abstraction for Low-Overhead Ephemeral Mapping Management
The sendfile system call first appeared in
.Fx 3.0 . This manual page first appeared in
.Fx 3.1 .
The sendfile system call and this manual page were written by
.An David G. Lawrence Aq email@example.com .