sendfile: Block or return EAGAIN, iff we are really short of space
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Sun, 22 Jan 2012 13:59:30 +0000 (21:59 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Sun, 22 Jan 2012 13:59:30 +0000 (21:59 +0800)
Send sockbuf's lowat could be quite "high" (hiwat/2), the originally
code actually only uses 1/2 of the send sockbuf space, thus poor
performance.

sys/kern/uipc_syscalls.c

index 76dcf5c..0aa5bc1 100644 (file)
@@ -1599,6 +1599,7 @@ kern_sendfile(struct vnode *vp, int sfd, off_t offset, size_t nbytes,
        for (off = offset; ; off += xfsize, *sbytes += xfsize + hbytes) {
                vm_pindex_t pindex;
                vm_offset_t pgoff;
+               int space;
 
                pindex = OFF_TO_IDX(off);
 retry_lookup:
@@ -1781,7 +1782,8 @@ retry_space:
                 * after checking the connection state above in order to avoid
                 * a race condition with ssb_wait().
                 */
-               if (ssb_space_prealloc(&so->so_snd) < so->so_snd.ssb_lowat) {
+               space = ssb_space_prealloc(&so->so_snd);
+               if (space < m->m_pkthdr.len && space < so->so_snd.ssb_lowat) {
                        if (fp->f_flag & FNONBLOCK) {
                                m_freem(m);
                                ssb_unlock(&so->so_snd);