svn commit: r340785 - head/sys/kern

Mateusz Guzik mjg at FreeBSD.org
Thu Nov 22 21:29:37 UTC 2018


Author: mjg
Date: Thu Nov 22 21:29:36 2018
New Revision: 340785
URL: https://svnweb.freebsd.org/changeset/base/340785

Log:
  fork: remove avoidable proc lock/unlock pair
  
  We don't have to access the process after making it runnable, so there
  is no need to hold it either.
  
  Sponsored by:	The FreeBSD Foundation

Modified:
  head/sys/kern/kern_fork.c
  head/sys/kern/kern_racct.c

Modified: head/sys/kern/kern_fork.c
==============================================================================
--- head/sys/kern/kern_fork.c	Thu Nov 22 21:08:37 2018	(r340784)
+++ head/sys/kern/kern_fork.c	Thu Nov 22 21:29:36 2018	(r340785)
@@ -719,11 +719,6 @@ do_fork(struct thread *td, struct fork_req *fr, struct
 	if ((fr->fr_flags & RFMEM) == 0 && dtrace_fasttrap_fork)
 		dtrace_fasttrap_fork(p1, p2);
 #endif
-	/*
-	 * Hold the process so that it cannot exit after we make it runnable,
-	 * but before we wait for the debugger.
-	 */
-	_PHOLD(p2);
 	if (fr->fr_flags & RFPPWAIT) {
 		_PHOLD(p2);
 		td->td_pflags |= TDP_RFPPWAIT;
@@ -783,8 +778,12 @@ do_fork(struct thread *td, struct fork_req *fr, struct
 		PROC_UNLOCK(p2);
 		sx_xunlock(&proctree_lock);
 	}
-	
+
+	racct_proc_fork_done(p2);
+
 	if ((fr->fr_flags & RFSTOPPED) == 0) {
+		if (fr->fr_pidp != NULL)
+			*fr->fr_pidp = p2->p_pid;
 		/*
 		 * If RFSTOPPED not requested, make child runnable and
 		 * add to run queue.
@@ -793,16 +792,9 @@ do_fork(struct thread *td, struct fork_req *fr, struct
 		TD_SET_CAN_RUN(td2);
 		sched_add(td2, SRQ_BORING);
 		thread_unlock(td2);
-		if (fr->fr_pidp != NULL)
-			*fr->fr_pidp = p2->p_pid;
 	} else {
 		*fr->fr_procp = p2;
 	}
-
-	PROC_LOCK(p2);
-	_PRELE(p2);
-	racct_proc_fork_done(p2);
-	PROC_UNLOCK(p2);
 }
 
 int

Modified: head/sys/kern/kern_racct.c
==============================================================================
--- head/sys/kern/kern_racct.c	Thu Nov 22 21:08:37 2018	(r340784)
+++ head/sys/kern/kern_racct.c	Thu Nov 22 21:29:36 2018	(r340785)
@@ -967,13 +967,13 @@ racct_proc_fork_done(struct proc *child)
 	if (!racct_enable)
 		return;
 
-	PROC_LOCK_ASSERT(child, MA_OWNED);
-
 #ifdef RCTL
+	PROC_LOCK(child);
 	RACCT_LOCK();
 	rctl_enforce(child, RACCT_NPROC, 0);
 	rctl_enforce(child, RACCT_NTHR, 0);
 	RACCT_UNLOCK();
+	PROC_UNLOCK(child);
 #endif
 }
 


More information about the svn-src-head mailing list