🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: muc.lists.freebsd.bugs
Article #836

[Bug 301235] sowakeup() calls selwakeuppri() without testing SB_SEL, so sockets ever polled lock mtxpool_select on every kqueue ...

#836
From: 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
Technical Details
Message-ID: <bug-301235-227@https.bugs.freebsd.org/bugzilla/>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news.szaf.org!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news.szaf.org!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mail
From: bugzilla-noreply@freebsd.org
Newsgroups: muc.lists.freebsd.bugs
Subject: [Bug 301235] sowakeup() calls selwakeuppri() without testing SB_SEL,
 so sockets ever polled lock mtxpool_select on every kqueue or blocking wakeup
Date: Sat, 28 Nov 2026 15:02:54 +0000
Organization: Newsgate at muc.de e.V.
Approved: news-admin@muc.de
Distribution: world
Message-ID: <bug-301235-227@https.bugs.freebsd.org/bugzilla/>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2";
	logging-data="14077"; mail-complaints-to="news-admin@muc.de"
X-Original-To: bugs@mlmmj.nyi.freebsd.org
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1795878174;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=/Z25dwlIwT5UwwIBn2ADeLO/JaVcYSdH2uoK0vgZkiY=;
	b=YeBg/KU5ETtQBzFS48Byw2rOSskiaT6NirxhKEIggdGXopznLg7wR9/ZJikz0S2zG7ohmm
	IlwJSnW8xejv0Uvw69V+FcSa5XgzQ3+W3s8Tq8LKTgTY5ql5meIYKGzQOtMADiZfBlMUNI
	+KLbNU2QONXo7XLqQ05rwZnjy4lB0Noo/TB848lPjPf5QG5FDXdvXGlHKFapV+wB80vvnw
	PKUgoKKWCMmRmW3RTAjLi77iJ3cHNlbz7pV7+hqy/C4eBzTCmH9/Tpp1Tp97O2M2ZK8Z6/
	p1hU79VFv/w+n0kb2Fa5Ssm8ljOmE8vSyYyT+lO1R4JCCUpsrqVGWLn37sOfxw==
X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f
Auto-Submitted: auto-generated
Precedence: list
X-Newsgate-Id: f02c70b8849f+
X-No-Archive: Yes