🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: muc.lists.freebsd.bugs
2 messages
2 total messages Started by bugzilla-noreply Sat, 28 Nov 2026 09:39
[Bug 301218] proc_to_reap() fills wrusage and siginfo before checking PRS_ZOMBIE, so wait4() and wait6() compute and discard rus...
#829
Author: bugzilla-noreply
Date: Sat, 28 Nov 2026 09:39
90 lines
5930 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301218

            Bug ID: 301218
           Summary: proc_to_reap() fills wrusage and siginfo before
                    checking PRS_ZOMBIE, so wait4() and wait6() compute
                    and discard rusage on every running child
           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

When kern_wait6() scans q->p_children, proc_to_reap() in
sys/kern/kern_exit.c (main 2534dcb233ad) populates siginfo and wrusage
under proctree_lock before testing whether the child is a zombie or will
be reported:

        wait_fill_siginfo(p, siginfo);
        ...
        wait_fill_wrusage(p, wrusage);

        if (p->p_state == PRS_ZOMBIE) {
                proc_reap(td, p, status, options, PZOMBIEREF_PARENT);
                return (-1);
        }
        return (1);

kern_pdwait() likewise calls wait_fill_siginfo() and wait_fill_wrusage()
before wait6_check_alive(). When a parent calls wait4(-1, &status,
options, &ru) or wait6(), kern_wait6() walks q->p_children; for every
running child that is neither a zombie nor matching WTRAPPED, WUNTRACED,
or WCONTINUED, proc_to_reap() zeroes and fills siginfo, copies 288 bytes
of rusage, acquires PROC_STATLOCK(p), runs calcru() and calccru(), and
returns 1, after which kern_wait6() discards both structures.

On FreeBSD 16.0-CURRENT amd64 GENERIC-NODEBUG (main 2534dcb233ad, Xeon
6975P-C), timing 10000 wait4(-1, &status, WNOHANG, &ru) calls (us/call,
10 runs) in a parent with 128 live children:

cc -O2 -Wall -Wextra -Werror -o wait4_live_children wait4_live_children.c
for i in $(jot 10); do cpuset -l 2 ./wait4_live_children rusage 128 10000; done

x base_wait4_ru.txt
+ patched_wait4_ru.txt
+--------------------------------------------------------------------------+
|++                                                                       x|
|++                                                                       x|
|++                                                                       x|
|++                                                                       x|
|++                                                                       x|
|A|                                                                       A|
+--------------------------------------------------------------------------+
    N           Min           Max        Median           Avg        Stddev
x  10           9.4          9.43          9.41         9.414   0.010749677
+  10           2.9          2.99         2.935         2.941   0.035730473
Difference at 95.0% confidence
        -6.473 +/- 0.0247902
        -68.7593% +/- 0.25328%
        (Student's t, pooled s = 0.0263839)

Tracing fbt::wait_fill_wrusage:entry across ./wait4_live_children rusage
128 100 (200 warmup + 100 timed calls) drops from 38404 calls to 2 (the
single stopped-child and exited-child checks), while a NULL rusage
pointer (./wait4_live_children null) stays at 2.97 us vs 2.94 us. Under
debug GENERIC (INVARIANTS and WITNESS), wait4(), waitid(), pdwait()
(WNOHANG, WSTOPPED, WCONTINUED, WEXITED), ptrace(2) WTRAPPED, and Kyua's
procdesc and wait_test suites all pass.

Moving wait_fill_siginfo() and wait_fill_wrusage() into the PRS_ZOMBIE
branch of proc_to_reap() and into report_alive_proc() (after dropping
proctree_lock, with PROC_LOCK(p) still held) computes them only for
reported children.

Source inspection shows the same proc_to_reap() and kern_pdwait()
ordering on stable/15; 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 301218] proc_to_reap() fills wrusage and siginfo before checking PRS_ZOMBIE, so wait4() and wait6() compute and discard rus...
#830
Author: bugzilla-noreply
Date: Sat, 28 Nov 2026 09:39
17 lines
2606 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301218

--- Comment #3 from laamalif@proton.me ---
Created attachment 277866
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277866&action=edit
validation: pdwait() (WNOHANG/WSTOPPED/WCONTINUED/WEXITED) and ptrace(2)
WTRAPPED wrusage and siginfo checks

-- 
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