git: 3ee596eeee19 - stable/15 - racct: Simplify skipping idle process in the throttling daemon
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 06 Nov 2025 03:38:05 UTC
The branch stable/15 has been updated by olce:
URL: https://cgit.FreeBSD.org/src/commit/?id=3ee596eeee198ede6860cf0c862fb5f8cfc81411
commit 3ee596eeee198ede6860cf0c862fb5f8cfc81411
Author: Olivier Certner <olce@FreeBSD.org>
AuthorDate: 2025-10-29 15:47:25 +0000
Commit: Olivier Certner <olce@FreeBSD.org>
CommitDate: 2025-11-06 03:36:28 +0000
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)
---
sys/kern/kern_racct.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/sys/kern/kern_racct.c b/sys/kern/kern_racct.c
index 7351e9cb6313..61e92678b54d 100644
--- a/sys/kern/kern_racct.c
+++ b/sys/kern/kern_racct.c
@@ -1236,16 +1236,20 @@ racct_updatepcpu_containers(void)
racct_updatepcpu_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)
{
struct proc *p;
- struct proc *idle;
ASSERT_RACCT_ENABLED();
- idle = STAILQ_FIRST(&cpuhead)->pc_idlethread->td_proc;
-
for (;;) {
racct_decay();
@@ -1253,12 +1257,7 @@ racctd(void)
FOREACH_PROC_IN_SYSTEM(p) {
PROC_LOCK(p);
- if (p == idle) {
- PROC_UNLOCK(p);
- continue;
- }
- if (p->p_state != PRS_NORMAL ||
- (p->p_flag & P_IDLEPROC) != 0) {
+ if (racct_proc_to_skip(p)) {
PROC_UNLOCK(p);
continue;
}
@@ -1284,7 +1283,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;
}