Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 29 Nov 2018 02:52:08 +0000 (UTC)
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r341176 - in head/sys: kern sys
Message-ID:  <201811290252.wAT2q8GQ004200@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mjg
Date: Thu Nov 29 02:52:08 2018
New Revision: 341176
URL: https://svnweb.freebsd.org/changeset/base/341176

Log:
  proc: create a dedicated lock for zombproc to ligthen the load on allproc_lock
  
  waitpid always takes proctree to evaluate the list, but only takes allproc
  if it can reap. With this patch allproc is no longer taken, which helps during
  poudriere -j 128.
  
  Discussed with: kib
  Sponsored by:	The FreeBSD Foundation

Modified:
  head/sys/kern/kern_exit.c
  head/sys/kern/kern_fork.c
  head/sys/kern/kern_proc.c
  head/sys/kern/kern_racct.c
  head/sys/sys/proc.h

Modified: head/sys/kern/kern_exit.c
==============================================================================
--- head/sys/kern/kern_exit.c	Thu Nov 29 01:31:12 2018	(r341175)
+++ head/sys/kern/kern_exit.c	Thu Nov 29 02:52:08 2018	(r341176)
@@ -432,8 +432,10 @@ exit1(struct thread *td, int rval, int signo)
 	 * Move proc from allproc queue to zombproc.
 	 */
 	sx_xlock(&allproc_lock);
+	sx_xlock(&zombproc_lock);
 	LIST_REMOVE(p, p_list);
 	LIST_INSERT_HEAD(&zombproc, p, p_list);
+	sx_xunlock(&zombproc_lock);
 	sx_xunlock(&allproc_lock);
 
 	/*
@@ -871,9 +873,9 @@ proc_reap(struct thread *td, struct proc *p, int *stat
 	 * Remove other references to this process to ensure we have an
 	 * exclusive reference.
 	 */
-	sx_xlock(&allproc_lock);
+	sx_xlock(&zombproc_lock);
 	LIST_REMOVE(p, p_list);	/* off zombproc */
-	sx_xunlock(&allproc_lock);
+	sx_xunlock(&zombproc_lock);
 	sx_xlock(PIDHASHLOCK(p->p_pid));
 	LIST_REMOVE(p, p_hash);
 	sx_xunlock(PIDHASHLOCK(p->p_pid));

Modified: head/sys/kern/kern_fork.c
==============================================================================
--- head/sys/kern/kern_fork.c	Thu Nov 29 01:31:12 2018	(r341175)
+++ head/sys/kern/kern_fork.c	Thu Nov 29 02:52:08 2018	(r341176)
@@ -238,6 +238,7 @@ fork_findpid(int flags)
 	struct proc *p;
 	int trypid;
 	static int pidchecked = 0;
+	bool locked_zomb = false;
 
 	/*
 	 * Requires allproc_lock in order to iterate over the list
@@ -318,6 +319,10 @@ again:
 		}
 		if (!doingzomb) {
 			doingzomb = 1;
+			if (!locked_zomb) {
+				sx_slock(&zombproc_lock);
+				locked_zomb = true;
+			}
 			p = LIST_FIRST(&zombproc);
 			goto again;
 		}
@@ -330,6 +335,9 @@ again:
 		pidchecked = 0;
 	else
 		lastpid = trypid;
+
+	if (locked_zomb)
+		sx_sunlock(&zombproc_lock);
 
 	return (trypid);
 }

Modified: head/sys/kern/kern_proc.c
==============================================================================
--- head/sys/kern/kern_proc.c	Thu Nov 29 01:31:12 2018	(r341175)
+++ head/sys/kern/kern_proc.c	Thu Nov 29 02:52:08 2018	(r341176)
@@ -125,6 +125,7 @@ u_long pgrphash;
 struct proclist allproc;
 struct proclist zombproc;
 struct sx __exclusive_cache_line allproc_lock;
+struct sx __exclusive_cache_line zombproc_lock;
 struct sx __exclusive_cache_line proctree_lock;
 struct mtx __exclusive_cache_line ppeers_lock;
 uma_zone_t proc_zone;
@@ -177,6 +178,7 @@ procinit(void)
 	u_long i;
 
 	sx_init(&allproc_lock, "allproc");
+	sx_init(&zombproc_lock, "zombproc");
 	sx_init(&proctree_lock, "proctree");
 	mtx_init(&ppeers_lock, "p_peers", NULL, MTX_DEF);
 	LIST_INIT(&allproc);
@@ -1194,14 +1196,14 @@ zpfind(pid_t pid)
 {
 	struct proc *p;
 
-	sx_slock(&allproc_lock);
+	sx_slock(&zombproc_lock);
 	LIST_FOREACH(p, &zombproc, p_list) {
 		if (p->p_pid == pid) {
 			PROC_LOCK(p);
 			break;
 		}
 	}
-	sx_sunlock(&allproc_lock);
+	sx_sunlock(&zombproc_lock);
 	return (p);
 }
 

Modified: head/sys/kern/kern_racct.c
==============================================================================
--- head/sys/kern/kern_racct.c	Thu Nov 29 01:31:12 2018	(r341175)
+++ head/sys/kern/kern_racct.c	Thu Nov 29 02:52:08 2018	(r341176)
@@ -1228,11 +1228,13 @@ racctd(void)
 
 		sx_slock(&allproc_lock);
 
+		sx_slock(&zombproc_lock);
 		LIST_FOREACH(p, &zombproc, p_list) {
 			PROC_LOCK(p);
 			racct_set(p, RACCT_PCTCPU, 0);
 			PROC_UNLOCK(p);
 		}
+		sx_sunlock(&zombproc_lock);
 
 		FOREACH_PROC_IN_SYSTEM(p) {
 			PROC_LOCK(p);

Modified: head/sys/sys/proc.h
==============================================================================
--- head/sys/sys/proc.h	Thu Nov 29 01:31:12 2018	(r341175)
+++ head/sys/sys/proc.h	Thu Nov 29 02:52:08 2018	(r341176)
@@ -959,6 +959,7 @@ extern u_long pgrphash;
 
 extern struct sx allproc_lock;
 extern int allproc_gen;
+extern struct sx zombproc_lock;
 extern struct sx proctree_lock;
 extern struct mtx ppeers_lock;
 extern struct proc proc0;		/* Process slot for swapper. */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201811290252.wAT2q8GQ004200>