🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: muc.lists.freebsd.bugs
3 messages
3 total messages Started by bugzilla-noreply Sat, 28 Nov 2026 15:02
[Bug 301235] sowakeup() calls selwakeuppri() without testing SB_SEL, so sockets ever polled lock mtxpool_select on every kqueue ...
#836
Author: bugzilla-noreply
Date: Sat, 28 Nov 2026 15:02
83 lines
5625 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301235

            Bug ID: 301235
           Summary: sowakeup() calls selwakeuppri() without testing
                    SB_SEL, so sockets ever polled lock mtxpool_select on
                    every kqueue or blocking wakeup
           Product: Base System
           Version: 16.0-CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: kern
          Assignee: bugs@FreeBSD.org
          Reporter: laamalif@proton.me

Once poll(2) or select(2) calls selrecord() on a socket buffer,
sb->sb_sel->si_mtx remains bound to a shared mtxpool_select mutex until
sofree(). In sys/kern/uipc_sockbuf.c (main 2534dcb233ad), sowakeup()
calls selwakeuppri() before checking or clearing SB_SEL:

        sb = sobuf(so, which);
        selwakeuppri(sb->sb_sel, PSOCK);
        if (!SEL_WAITING(sb->sb_sel))
                sb->sb_flags &= ~SB_SEL;

Unlike pipeselwakeup() (PIPE_SEL) and uipc_wakeup_writer()
(UXST_PEER_SEL), every subsequent sorwakeup_locked() or
sowwakeup_locked() entered via SB_KNOTE or SB_WAIT locks and unlocks
sb->sb_sel->si_mtx from the 128-entry global mtxpool_select while
holding SOCK_BUF_LOCK, even when SB_SEL is clear and si_tdlist is empty.

On FreeBSD 16.0-CURRENT amd64 GENERIC-NODEBUG (main 2534dcb233ad, Xeon
6975P-C, 8 vCPUs), running 8 kqueue(2) worker threads across 32
AF_UNIX datagram socket pairs per thread (3000 rounds after an initial
poll(2) readiness check, million messages/sec, 10 runs):

cc -O2 -Wall -Wextra -Werror -pthread -o sowakeup_kqueue_bench
sowakeup_kqueue_bench.c
for i in $(jot 10); do ./sowakeup_kqueue_bench 8 32 3000; done

x base_unix8.txt
+ patched_unix8.txt
+--------------------------------------------------------------------------+
|       x                                                    + +           |
|x   xxxxx  x x     x                                +   +   + +     + + ++|
|   |___MA____|                                          |_____MA______|   |
+--------------------------------------------------------------------------+
    N           Min           Max        Median           Avg        Stddev
x  10       11.2961       11.5676       11.3958      11.41055   0.075277077
+  10       12.0483       12.3514       12.1882      12.21142    0.10128089
Difference at 95.0% confidence
        0.80087 +/- 0.0838414
        7.01868% +/- 0.753527%
        (Student's t, pooled s = 0.0892313)

Pinned to a single CPU (cpuset -l 2 ./sowakeup_kqueue_bench 1 32 5000,
N=10), AF_UNIX datagram/kqueue throughput rises from 2.2855 to 2.3647
Mmsg/s (+3.46% +/- 0.34% at 95% confidence), and DTrace
fbt::doselwakeup:entry on ./sowakeup_kqueue_bench 1 4 500 drops from
2830 to 33 (zero during the 2000 timed wakeups). On the nopoll control
where si_mtx stays NULL (12.104 vs 12.149 Mmsg/s) and on 8-thread
loopback TCP where TCP stack work dominates (0.874 vs 0.883 Mmsg/s), no
difference is proven at 95% confidence, and Kyua kqueue, poll, select,
and unix socket tests pass under debug GENERIC (INVARIANTS and WITNESS).

Guarding selwakeuppri() and the SEL_WAITING() check in sowakeup() with
sb->sb_flags & SB_SEL skips doselwakeup() when no thread has recorded a
select or poll wait on sb.

Source inspection shows the same unguarded selwakeuppri() call in
sowakeup() on stable/15 and stable/14; I have only runtime-tested
16.0-CURRENT amd64.

-- 
You are receiving this mail because:
You are the assignee for the bug.

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 301235] sowakeup() calls selwakeuppri() without testing SB_SEL, so sockets ever polled lock mtxpool_select on every kqueue ...
#837
Author: bugzilla-noreply
Date: Sat, 28 Nov 2026 15:02
16 lines
2531 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301235

--- Comment #1 from laamalif@proton.me ---
Created attachment 277901
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277901&action=edit
guard selwakeuppri() on SB_SEL in sowakeup()

-- 
You are receiving this mail because:
You are the assignee for the bug.

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 301235] sowakeup() calls selwakeuppri() without testing SB_SEL, so sockets ever polled lock mtxpool_select on every kqueue ...
#838
Author: bugzilla-noreply
Date: Sat, 28 Nov 2026 15:02
17 lines
2580 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301235

--- Comment #2 from laamalif@proton.me ---
Created attachment 277902
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277902&action=edit
benchmark: multi-threaded kqueue(2) socket wakeup rate after initial poll(2)
readiness check

-- 
You are receiving this mail because:
You are the assignee for the bug.

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads