git: a15f2c5cc58f - main - proc: perform P_CONTROLT check on fork without SESS_LOCK
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 25 Sep 2025 11:51:06 UTC
The branch main has been updated by mjg:
URL: https://cgit.FreeBSD.org/src/commit/?id=a15f2c5cc58f403407daf797a2e6963adffa6c2c
commit a15f2c5cc58f403407daf797a2e6963adffa6c2c
Author: Mateusz Guzik <mjg@FreeBSD.org>
AuthorDate: 2025-09-25 11:50:01 +0000
Commit: Mateusz Guzik <mjg@FreeBSD.org>
CommitDate: 2025-09-25 11:50:55 +0000
proc: perform P_CONTROLT check on fork without SESS_LOCK
The flag is guarded by proc lock which is already held.
After tracing poudriere for over 4 hours like so:
dtrace -n 'fbt::do_fork:entry { @[curthread->td_proc->p_flag & 0x2] = count(); }':
2 15605151
0 20074116
Over 56% of cases did not have P_CONTROLT set and could have avoided the
lock.
This reduces hold time of the proctree lock.
---
sys/kern/kern_fork.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index 2ab9b363f8b5..7f6abae187b3 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -610,10 +610,12 @@ do_fork(struct thread *td, struct fork_req *fr, struct proc *p2, struct thread *
p2->p_flag |= p1->p_flag & P_SUGID;
td2->td_pflags |= td->td_pflags & (TDP_ALTSTACK | TDP_SIGFASTBLOCK);
td2->td_pflags2 |= td->td_pflags2 & TDP2_UEXTERR;
- SESS_LOCK(p1->p_session);
- if (p1->p_session->s_ttyvp != NULL && p1->p_flag & P_CONTROLT)
- p2->p_flag |= P_CONTROLT;
- SESS_UNLOCK(p1->p_session);
+ if (p1->p_flag & P_CONTROLT) {
+ SESS_LOCK(p1->p_session);
+ if (p1->p_session->s_ttyvp != NULL)
+ p2->p_flag |= P_CONTROLT;
+ SESS_UNLOCK(p1->p_session);
+ }
if (fr->fr_flags & RFPPWAIT)
p2->p_flag |= P_PPWAIT;