HomeFreeBSD

sendfile: don't hack sb_lowat for sockets that manage the watermark

Description

sendfile: don't hack sb_lowat for sockets that manage the watermark

In the sendfile(2) we carry an old hack (originating from d99b0dd2c5297)
to help dumb benchmarks and applications to achieve higher performance. We
would modify low watermark on the socket send buffer to avoid socket being
reported as writable too early, which would result in lots of small
writes.

Skip that hack for applications that do setsockopt(SO_SNDLOWAT) or that
register the socket in kevent(2) with NOTE_LOWAT feature. First, we don't
want the hack to rewrite the watermark value explicitly specified by the
user. Second, in certain cases that can lead to real performance
regressions. A kevent(2) with NOTE_LOWAT would report socket as writable,
but then sendfile(2) would write 0 bytes and return EAGAIN.

The change also disables the hack for unix(4) sockets, leaving only TCP.

Reviewed by: rrs
Differential Revision: https://reviews.freebsd.org/D50581

Details

Provenance
glebiusAuthored on Jul 25 2025, 8:05 PM
Reviewer
rrs
Differential Revision
D50581: sendfile: don't hack sb_lowat for sockets that manage the watermark
Parents
rGee110941e35c: bsdinstall: Remove support for ZFS + MBR disk layouts
Branches
Unknown
Tags
Unknown