Article View: muc.lists.freebsd.bugs
Article #829[Bug 301218] proc_to_reap() fills wrusage and siginfo before checking PRS_ZOMBIE, so wait4() and wait6() compute and discard rus...
From: bugzilla-noreply
Date: Sat, 28 Nov 2026 09:39
Date: Sat, 28 Nov 2026 09:39
90 lines
5930 bytes
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
Technical Details
Message-ID:
<bug-301218-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-mailShow 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 301218] proc_to_reap() fills wrusage and siginfo before checking PRS_ZOMBIE, so wait4() and wait6() compute and discard rusage on every running child Date: Sat, 28 Nov 2026 09:39:10 +0000 Organization: Newsgate at muc.de e.V. Approved: news-admin@muc.de Distribution: world Message-ID: <bug-301218-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="80212"; 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=1795858750; 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=vzU5Nf/4tU0NKIDsINRxD5I3qoKaR5MJLRutYPcYtZ0=; b=WvBZdXwLeWfHHgCdcWPjmgHitr4bgxxGG01jly7HXOd2RI9G7dLlEsWa2HxZfy/GM887s/ dekO98L+bbEigmB6ecLi9L9RLwjezTGRSp+CkLq6EtH7srG4W9YRmWDHsNgB07KtfB1aMj 1OU0F2x+PMovOzV1boAGA8ai0CXniRtX/T+xsEllUc6LDb8zFZ/na3Qw4me4QAkdMxe2OK K+DT2kDYjCzCCl7WAt0DG1PRsk7GTtQcKpHwqDisfM8kURQ/9FruGri9F6OSHhifUQHmL+ 7OMsTJN/pPQPm7VKiL8wiP10iGVJAtsHmkacpiTv8NlCptvE+bQ+h1fhSEsIhA== 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