HomeFreeBSD

racct: Improve handling of the pcpu resource

Description

racct: Improve handling of the pcpu resource

The previous scheme would inflate the CPU consumption of short-lived
processes. For containers (e.g., processes, jails), the total pcpu
usage was computed as a sum of the pcpu usage of all constituent
threads, which makes little sense for a decaying average.

Instead, aggregate wallclock time of all on-CPU threads and compute the
pcpu resource as a decaying average as the sum. This gives much more
reasonable and accurate values in various simple tests.

PR: 235556
Reviewed by: markj
MFC after: 1 month
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D30878

(cherry picked from commit c72188d85a793c7610208beafb83af544de6e3b7)

Changes for this MFC to stable/14:

  • Removal of process swap out (thread stacks swapped out) was done only in 'main' and stable/15 and prior to the original commit, causing a conflict with a test on P_INMEM. In this MFC, the %CPU is not forced to 0 anymore when P_INMEM is not set (contrary to what ps(1) explicitly does, which we find dubious). The %CPU decay will take care of that in a more accurate manner (for processes that have just been swapped out).
  • Commit 9530c6f082ada9e6 ("racct: Simplify skipping idle process in the throttling daemon") was MFCed before this one although it occurred after it. Consequently, adding the 'idle' variable in racctd() was removed from this MFC, as the other original commit removes it.

Details

Provenance
cyril_freebsdfoundation.orgAuthored on Aug 5 2025, 11:20 PM
olceCommitted on Jan 6 2026, 7:24 PM
Reviewer
markj
Differential Revision
D30878: racct: New scheme for calculating pctcpu
Parents
rG3690911c355a: mfi(4): Add subvendor and subdevice for Fujitsu RAID Controller SAS 6Gbit/s 1GB…
Branches
Unknown
Tags
Unknown