aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Certner <olce@FreeBSD.org>2025-10-29 15:47:25 +0000
committerOlivier Certner <olce@FreeBSD.org>2025-12-19 09:16:47 +0000
commitbd26c99b688e4f9dabfc477d6e89ead587f923f4 (patch)
tree48297d983c0780618ef9a03ebaa955494ca1eb08
parentfd404e957dd93d0e8525e4bc37df3f66610ca19d (diff)
racct: Simplify skipping idle process in the throttling daemon
In racctd(), commit c72188d85a79 ("racct: Improve handling of the pcpu resource") added a superfluous test to skip the idle process when computing the resource usage and checking for limits, consisting of a comparison of the considered process' pointer with that of the process of the first CPU's idle thread. The P_IDLEPROC flag introduced in commit 33be1632047c ("racct: Fix accounting of CPU time for the system idle process") is sufficient and simpler for this purpose. In the second loop throttling processes based on their %CPU usage, the test excluding processes not in PRS_NORMAL was not consistent with that of the first loop (which tests for the idle process also). This had no practical consequences except a superfluous call to racct_pcpu_available() as the RACCT_PCTCPU counter stays at 0 on the idle process (because of the first loop). Factor out the test in the new racct_proc_to_skip() function. No functional change intended. Reviewed by: markj MFC after: 3 days Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D53455 (cherry picked from commit 9530c6f082ada9e6d0323f36697ce53997ab2326)
-rw-r--r--sys/kern/kern_racct.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/sys/kern/kern_racct.c b/sys/kern/kern_racct.c
index 13df4724f860..0e359dfe85cf 100644
--- a/sys/kern/kern_racct.c
+++ b/sys/kern/kern_racct.c
@@ -1226,6 +1226,13 @@ racct_decay(void)
racct_decay_post, NULL, NULL);
}
+static bool
+racct_proc_to_skip(const struct proc *p)
+{
+ PROC_LOCK_ASSERT(p, MA_OWNED);
+ return (p->p_state != PRS_NORMAL || (p->p_flag & P_IDLEPROC) != 0);
+}
+
static void
racctd(void)
{
@@ -1243,8 +1250,7 @@ racctd(void)
FOREACH_PROC_IN_SYSTEM(p) {
PROC_LOCK(p);
- if (p->p_state != PRS_NORMAL ||
- (p->p_flag & P_IDLEPROC) != 0) {
+ if (racct_proc_to_skip(p)) {
if (p->p_state == PRS_ZOMBIE)
racct_set(p, RACCT_PCTCPU, 0);
PROC_UNLOCK(p);
@@ -1297,7 +1303,7 @@ racctd(void)
*/
FOREACH_PROC_IN_SYSTEM(p) {
PROC_LOCK(p);
- if (p->p_state != PRS_NORMAL) {
+ if (racct_proc_to_skip(p)) {
PROC_UNLOCK(p);
continue;
}