fix(libkernel): fire EVFILT_WRITE on a socket once free send space reaches NOTE_LOWAT #8596
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8596"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by ebarr24 on 2026-10-20T17:48:23Z.
What
kevent threw NotImplemented for EVFILT_WRITE with NOTE_LOWAT above 1 on a socket, although the socket readiness check already reports free send-buffer space (SO_SNDBUF less SIOCOUTQ on Linux). The write event now fires once that space reaches the mark, as FreeBSD 11's filt_sowrite compares sbspace with kn_sdata, and stays silent while the space is below it. The debt entry no longer says a write mark is limited to 1. Reference: https://github.com/freebsd/freebsd-src/blob/release/11.0.0/sys/kern/uipc_socket.c
Tested
Windows 11, MinGW-w64 GCC 15.2, Release build with tests.
guest_kqueuepasses with this change; the new test fails onmain.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T18:15:21Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/libkernel.mdL119-120docs/dev/debt/libkernel.mdL120Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
docs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/tests/GuestKqueue.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Equeue/src/Kqueue.cppcore/libs/tests/GuestKqueue.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Equeue/src/Kqueue.cppcore/libs/tests/GuestKqueue.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Equeue/src/Kqueue.cppcore/libs/tests/GuestKqueue.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Equeue/src/Kqueue.cppcore/libs/tests/GuestKqueue.cppdocs/dev/debt/libkernel.mdImported from boykopovar/AnyPS5. Originally posted by nikowolf123 on 2026-10-20T19:04:36Z.
I checked these against
084dcf8and replayedGuestSockets::Ready,PollEdgeand the epoll wait in a standalone program on Linux 6.18 (WSL2). I did not build this branch.1. An
EV_CLEARwrite knote withNOTE_LOWATabove 1 on a Linux TCP socket can wait foreverWithout the throw,
AddDescriptorKnotegives the mark to anEPOLLET | EPOLLOUTedge knote.PollEdgedisarms that knote while the free space is below the mark. Only a new hostEPOLLOUTwakeup or a later change of the knote arms it again.Linux TCP sends that wakeup only after a send or a poll found the socket not writable.
tcp_check_spacecallstcp_new_spaceonly whileSOCK_NOSPACEis set (tcp_input.c#L5639-L5649; the flag is set in tcp.c#L565-L570).sk_stream_write_spacethen clears the flag on the one wakeup it sends (stream.c#L35-L42).FreeBSD 11.0 calls
sowwakeupon every ACK that frees send space (tcp_input.c#L1808, #L2836-L2844). ThroughKNOTE_LOCKED(uipc_sockbuf.c#L324) that runs thekn_data >= kn_sdatacheck infilt_sowrite(uipc_socket.c#L3338-L3339). So on FreeBSD the knote fires oncesbspacereaches the mark.Example: a loopback TCP writer has
SO_SNDBUF32768 and 5120 bytes unacknowledged (POLLOUTset, 27648 free). It addsEV_ADD | EV_CLEARwithNOTE_LOWAT32768, and the first scan disarms the knote. After the peer has read everything (SIOCOUTQ0, 32768 free), a 3 s wait still returns nothing in 3 of 3 runs, while a level knote with the same mark fires. In a second run the writer filled the buffer toEAGAIN. The one wakeup came at 16384 free, so a mark of 24576 never fired either, and the same happened with default buffer sizes.On
mainthis input threw. Nowkeventwith a NULL timeout hangs without a message, which is what #7092 avoided by keeping the throw for datagram read marks. The new tests useAF_UNIXand never combineEV_CLEARwith a write mark, so they don't reach this. Keeping the throw for this combination would cover it, together with a Linux case inGuestKqueue.cppthat requires the throw:2. The rewritten debt sentence drops two gaps that are still open
libkernel.md#L117 now says a write event fires once the free space reaches the mark, as
filt_sowritedoes. The first gap it drops: the mark is only compared after the host reportsPOLLOUT(Udp.cpp#L822). Linux reportsPOLLOUTfor anAF_UNIXstream socket only while at most a quarter ofSO_SNDBUFis in use (af_unix.c#L535-L539). For TCP it needs about a third of the buffer free (sock.h#L1373-L1377). For example, on anAF_UNIXpair withSO_SNDBUF212992 and 45056 bytes queued unread,SO_SNDBUFlessSIOCOUTQis 159488 butPOLLOUTis clear, so a mark of 2 does not fire. The old text stated this gate ("the host's writability stands in for one free byte").The second gap: a write mark above 1 still throws on a socket that is not a stream, because the check at Kqueue.cpp#L137 now applies to
EVFILT_WRITEtoo, but the entry no longer says so.CONTRIBUTING.md asks an entry to state what differs and what throws, and asks a PR to cut an entry to what is still open rather than describe the corrected behaviour. For example:
AI-assisted: yes (Claude Code).