sendfile: keep the lowat hack more conservative

First, record the original lowat value and later in the wait/EAGAIN loop
look at the original value, rather than on the value that we just faked.
This eliminates some blank syscalls, where socket was reported as writable
and immediate write instantly fails.  In my testing the ratio of such
syscalls was really small, under 2%, however in a different scenario this
negative effect can be more profound.

Second, cap the lowat growth to 1/2 of original socket buffer size, rather
than to current size.  The problem was there before, but it became more
profound after 587c6c1215.

Note: we are considering to evaluate if the lowat hack is needed at all.

Reviewed by:		tuexen
Differential Revision:	https://reviews.freebsd.org/D60106
This commit is contained in:
Gleb Smirnoff committed 2026-10-01 19:53:40 -07:00
1 parent e65b7079db
commit 6948f4d5e2
1 file changed
+6 -3
+6 -3
View File
@@ -637,6 +637,7 @@ sendfile_getsock(struct thread *td, int s, struct file **sock_fp,
int
sendfile_wait_generic(struct socket *so, off_t need, int *space)
{
u_int lowat, newlowat;
int error;
MPASS(need > 0);
@@ -657,9 +658,11 @@ sendfile_wait_generic(struct socket *so, off_t need, int *space)
*/
error = 0;
SOCK_SENDBUF_LOCK(so);
lowat = so->so_snd.sb_lowat;
if (so->so_snd.sb_flags & SB_AUTOLOWAT) {
if (so->so_snd.sb_lowat < so->so_snd.sb_hiwat / 2)
so->so_snd.sb_lowat = so->so_snd.sb_hiwat / 2;
newlowat = min(V_tcp_sendspace, so->so_snd.sb_hiwat) / 2;
if (so->so_snd.sb_lowat < newlowat)
so->so_snd.sb_lowat = newlowat;
if (so->so_snd.sb_lowat < PAGE_SIZE &&
so->so_snd.sb_hiwat >= PAGE_SIZE)
so->so_snd.sb_lowat = PAGE_SIZE;
@@ -679,7 +682,7 @@ retry_space:
}
*space = sbspace(&so->so_snd);
if (*space < need && (*space <= 0 || *space < so->so_snd.sb_lowat)) {
if (*space < need && (*space <= 0 || *space < lowat)) {
if (so->so_state & SS_NBIO) {
error = EAGAIN;
goto done;