Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 22 Apr 2003 13:14:43 -0700 (PDT)
From:      John Baldwin <jhb@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 29426 for review
Message-ID:  <200304222014.h3MKEho7052099@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=29426

Change 29426 by jhb@jhb_laptop on 2003/04/22 13:14:36

	IFC @29424 (loop back proc locking).

Affected files ...

.. //depot/projects/smpng/sys/dev/vinum/vinumdaemon.c#6 integrate
.. //depot/projects/smpng/sys/fs/procfs/procfs_ctl.c#18 integrate
.. //depot/projects/smpng/sys/geom/geom_ctl.c#8 integrate
.. //depot/projects/smpng/sys/geom/geom_ctl.h#3 integrate
.. //depot/projects/smpng/sys/i386/linux/linux_ptrace.c#7 integrate
.. //depot/projects/smpng/sys/kern/kern_thread.c#28 integrate
.. //depot/projects/smpng/sys/kern/sched_ule.c#7 integrate
.. //depot/projects/smpng/sys/kern/sys_process.c#27 integrate
.. //depot/projects/smpng/sys/sys/proc.h#81 integrate
.. //depot/projects/smpng/sys/vm/vm_fault.c#25 integrate
.. //depot/projects/smpng/sys/vm/vm_glue.c#23 integrate
.. //depot/projects/smpng/sys/vm/vm_pageout.c#27 integrate

Differences ...

==== //depot/projects/smpng/sys/dev/vinum/vinumdaemon.c#6 (text+ko) ====

@@ -35,7 +35,7 @@
  * advised of the possibility of such damage.
  *
  * $Id: vinumdaemon.c,v 1.8 2000/01/03 05:22:03 grog Exp grog $
- * $FreeBSD: src/sys/dev/vinum/vinumdaemon.c,v 1.24 2003/01/03 05:57:34 phk Exp $
+ * $FreeBSD: src/sys/dev/vinum/vinumdaemon.c,v 1.25 2003/04/22 19:45:26 jhb Exp $
  */
 
 #include <dev/vinum/vinumhdr.h>
@@ -71,10 +71,10 @@
 
     PROC_LOCK(curproc);
     curproc->p_flag |= P_SYSTEM;			    /* we're a system process */
-    PROC_UNLOCK(curproc);
     mtx_lock_spin(&sched_lock);
     curproc->p_sflag |= PS_INMEM;
     mtx_unlock_spin(&sched_lock);
+    PROC_UNLOCK(curproc);
     daemon_save_config();				    /* start by saving the configuration */
     daemonpid = curproc->p_pid;				    /* mark our territory */
     while (1) {

==== //depot/projects/smpng/sys/fs/procfs/procfs_ctl.c#18 (text+ko) ====

@@ -38,7 +38,7 @@
  *
  * From:
  *	$Id: procfs_ctl.c,v 3.2 1993/12/15 09:40:17 jsp Exp $
- * $FreeBSD: src/sys/fs/procfs/procfs_ctl.c,v 1.49 2003/04/17 22:14:30 jhb Exp $
+ * $FreeBSD: src/sys/fs/procfs/procfs_ctl.c,v 1.50 2003/04/22 20:00:25 jhb Exp $
  */
 
 #include <sys/param.h>
@@ -144,9 +144,7 @@
 		 * Stop the target.
 		 */
 		p->p_flag |= P_TRACED;
-		mtx_lock_spin(&sched_lock);
 		faultin(p);
-		mtx_unlock_spin(&sched_lock);
 		p->p_xstat = 0;		/* XXX ? */
 		if (p->p_pptr != td->td_proc) {
 			p->p_oppid = p->p_pptr->p_pid;

==== //depot/projects/smpng/sys/geom/geom_ctl.c#8 (text+ko) ====

@@ -32,7 +32,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/geom/geom_ctl.c,v 1.14 2003/04/03 11:19:24 phk Exp $
+ * $FreeBSD: src/sys/geom/geom_ctl.c,v 1.15 2003/04/22 19:42:05 phk Exp $
  */
 
 #include "opt_geom.h"
@@ -151,13 +151,8 @@
 		    !useracc(ap[i].value, ap[i].len, 
 		    ap[i].flag & GCTL_PARAM_RW))
 			error = gctl_error(req, "no access to param data");
-		if (ap[i].name == NULL) {
-			if (req->reqt->meta)
-				continue;
-			error = gctl_error(req,
-			    "request does not take metadata arguments");
+		if (error)
 			break;
-		}
 		p = NULL;
 		if (ap[i].nlen < 1 || ap[i].nlen > SPECNAMELEN) {
 			error = gctl_error(req, "wrong param name length");
@@ -205,10 +200,7 @@
 	}
 	for (i = 0; i < req->narg; i++) {
 		ap = &req->arg[i];
-		if (ap->name != NULL)
-			printf("  param:\t\"%s\"", ap->name);
-		else
-			printf("  meta:\t@%jd", (intmax_t)ap->offset);
+		printf("  param:\t\"%s\"", ap->name);
 		printf(" [%s%s%d] = ",
 		    ap->flag & GCTL_PARAM_RD ? "R" : "",
 		    ap->flag & GCTL_PARAM_WR ? "W" : "",

==== //depot/projects/smpng/sys/geom/geom_ctl.h#3 (text+ko) ====

@@ -26,7 +26,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/geom/geom_ctl.h,v 1.2 2003/03/27 14:34:59 phk Exp $
+ * $FreeBSD: src/sys/geom/geom_ctl.h,v 1.3 2003/04/22 19:42:05 phk Exp $
  */
 
 #ifndef _GEOM_GEOM_CTL_H_
@@ -50,8 +50,6 @@
 	GCTL_DESTROY_PROVIDER,
 	GCTL_INSERT_GEOM,
 	GCTL_ELIMINATE_GEOM,
-	GCTL_WRITE_META,
-	GCTL_READ_META
 };
 
 #ifdef GCTL_TABLE
@@ -61,24 +59,21 @@
 	int             	provider;
 	int             	consumer;
 	int             	params;
-	int             	meta;
 	char			*name;
 	enum gctl_request	request;
 } gcrt[] = {
-/*        Cl Ge Pr Co Pa Me Name                Request			*/
-	{ 1, 0, 1, 0, 1, 0, "create geom",	GCTL_CREATE_GEOM            },
-	{ 0, 1, 0, 0, 1, 0, "destroy geom",	GCTL_DESTROY_GEOM           },
-	{ 0, 1, 1, 0, 1, 0, "attach",		GCTL_ATTACH                 },
-	{ 0, 1, 1, 0, 1, 0, "detach",		GCTL_DETACH                 },
-	{ 0, 1, 0, 0, 1, 0, "create provider",	GCTL_CREATE_PROVIDER        },
-	{ 0, 1, 1, 0, 1, 0, "destroy provider",	GCTL_DESTROY_PROVIDER       },
-	{ 1, 1, 1, 0, 1, 0, "insert geom",	GCTL_INSERT_GEOM            },
-	{ 0, 1, 0, 0, 1, 0, "eliminate geom",	GCTL_ELIMINATE_GEOM         },
-	{ 0, 1, 0, 0, 1, 1, "write meta",	GCTL_WRITE_META             },
-	{ 0, 1, 0, 0, 1, 1, "read meta",	GCTL_READ_META              },
+/*        Cl Ge Pr Co Pa Name                Request			*/
+	{ 1, 0, 1, 0, 1, "create geom",		GCTL_CREATE_GEOM            },
+	{ 0, 1, 0, 0, 1, "destroy geom",	GCTL_DESTROY_GEOM           },
+	{ 0, 1, 1, 0, 1, "attach",		GCTL_ATTACH                 },
+	{ 0, 1, 1, 0, 1, "detach",		GCTL_DETACH                 },
+	{ 0, 1, 0, 0, 1, "create provider",	GCTL_CREATE_PROVIDER        },
+	{ 0, 1, 1, 0, 1, "destroy provider",	GCTL_DESTROY_PROVIDER       },
+	{ 1, 1, 1, 0, 1, "insert geom",		GCTL_INSERT_GEOM            },
+	{ 0, 1, 0, 0, 1, "eliminate geom",	GCTL_ELIMINATE_GEOM         },
 
 	/* Terminator entry */
-	{ 1, 1, 1, 1, 1, 1, "*INVALID*",	GCTL_INVALID_REQUEST        }
+	{ 1, 1, 1, 1, 1, "*INVALID*",		GCTL_INVALID_REQUEST        }
 };
 
 #endif /* GCTL_TABLE */

==== //depot/projects/smpng/sys/i386/linux/linux_ptrace.c#7 (text+ko) ====

@@ -25,7 +25,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/i386/linux/linux_ptrace.c,v 1.10 2003/04/15 16:29:39 jhb Exp $
+ * $FreeBSD: src/sys/i386/linux/linux_ptrace.c,v 1.11 2003/04/22 20:01:56 jhb Exp $
  */
 
 #include "opt_cpu.h"
@@ -222,31 +222,23 @@
 static int
 linux_proc_read_fpxregs(struct thread *td, struct linux_pt_fpxreg *fpxregs)
 {
-	int error;
 
-	error = 0;
-	mtx_lock_spin(&sched_lock);
+	PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
 	if (cpu_fxsr == 0 || (td->td_proc->p_sflag & PS_INMEM) == 0)
-		error = EIO;
-	else
-		bcopy(&td->td_pcb->pcb_save.sv_xmm, fpxregs, sizeof(*fpxregs));
-	mtx_unlock_spin(&sched_lock);
-	return (error);
+		return (EIO);
+	bcopy(&td->td_pcb->pcb_save.sv_xmm, fpxregs, sizeof(*fpxregs));
+	return (0);
 }
 
 static int
 linux_proc_write_fpxregs(struct thread *td, struct linux_pt_fpxreg *fpxregs)
 {
-	int error;
 
-	error = 0;
-	mtx_lock_spin(&sched_lock);
+	PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
 	if (cpu_fxsr == 0 || (td->td_proc->p_sflag & PS_INMEM) == 0)
-		error = EIO;
-	else
-		bcopy(fpxregs, &td->td_pcb->pcb_save.sv_xmm, sizeof(*fpxregs));
-	mtx_unlock_spin(&sched_lock);
-	return (error);
+		return (EIO);
+	bcopy(fpxregs, &td->td_pcb->pcb_save.sv_xmm, sizeof(*fpxregs));
+	return (0);
 }
 #endif
 

==== //depot/projects/smpng/sys/kern/kern_thread.c#28 (text+ko) ====

@@ -25,7 +25,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  * DAMAGE.
  *
- * $FreeBSD: src/sys/kern/kern_thread.c,v 1.121 2003/04/21 14:42:04 davidxu Exp $
+ * $FreeBSD: src/sys/kern/kern_thread.c,v 1.122 2003/04/22 19:47:55 jhb Exp $
  */
 
 #include <sys/param.h>
@@ -1311,7 +1311,7 @@
  * Purge a ksegrp resource. When a ksegrp is preparing to
  * exit, it calls this function. 
  */
-void
+static void
 kse_purge_group(struct thread *td)
 {
 	struct ksegrp *kg;
@@ -1336,14 +1336,13 @@
  * exit, it calls kse_purge to release any extra KSE resources in 
  * the process.
  */
-void
+static void
 kse_purge(struct proc *p, struct thread *td)
 {
 	struct ksegrp *kg;
 	struct kse *ke;
 
  	KASSERT(p->p_numthreads == 1, ("bad thread number"));
-	mtx_lock_spin(&sched_lock);
 	while ((kg = TAILQ_FIRST(&p->p_ksegrps)) != NULL) {
 		TAILQ_REMOVE(&p->p_ksegrps, kg, kg_ksegrp);
 		p->p_numksegrps--;
@@ -1373,7 +1372,6 @@
 	}
 	TAILQ_INSERT_HEAD(&p->p_ksegrps, td->td_ksegrp, kg_ksegrp);
 	p->p_numksegrps++;
-	mtx_unlock_spin(&sched_lock);
 }
 
 /*
@@ -1969,12 +1967,12 @@
 		 * and stays there.
 		 */
 		thread_suspend_one(td);
-		PROC_UNLOCK(p);
 		if (P_SHOULDSTOP(p) == P_STOPPED_SINGLE) {
 			if (p->p_numthreads == p->p_suspcount) {
 				thread_unsuspend_one(p->p_singlethread);
 			}
 		}
+		PROC_UNLOCK(p);
 		p->p_stats->p_ru.ru_nivcsw++;
 		mi_switch();
 		mtx_unlock_spin(&sched_lock);

==== //depot/projects/smpng/sys/kern/sched_ule.c#7 (text+ko) ====

@@ -23,7 +23,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/kern/sched_ule.c,v 1.29 2003/04/18 05:24:10 jeff Exp $
+ * $FreeBSD: src/sys/kern/sched_ule.c,v 1.30 2003/04/22 19:48:25 jhb Exp $
  */
 
 #include <sys/param.h>
@@ -1138,7 +1138,9 @@
 		pctcpu = (FSCALE * ((FSCALE * rtick)/realstathz)) >> FSHIFT;
 	}
 
+	mtx_lock_spin(&sched_lock);
 	ke->ke_proc->p_swtime = ke->ke_ltick - ke->ke_ftick;
+	mtx_unlock_spin(&sched_lock);
 
 	return (pctcpu);
 }

==== //depot/projects/smpng/sys/kern/sys_process.c#27 (text+ko) ====

@@ -28,7 +28,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/kern/sys_process.c,v 1.106 2003/04/17 22:31:54 jhb Exp $
+ * $FreeBSD: src/sys/kern/sys_process.c,v 1.107 2003/04/22 20:01:56 jhb Exp $
  */
 
 #include <sys/param.h>
@@ -82,12 +82,11 @@
 #define	PROC_ACTION(action) do {					\
 	int error;							\
 									\
-	mtx_lock_spin(&sched_lock);					\
+	PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);			\
 	if ((td->td_proc->p_sflag & PS_INMEM) == 0)			\
 		error = EIO;						\
 	else								\
 		error = (action);					\
-	mtx_unlock_spin(&sched_lock);					\
 	return (error);							\
 } while(0)
 

==== //depot/projects/smpng/sys/sys/proc.h#81 (text+ko) ====

@@ -36,7 +36,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)proc.h	8.15 (Berkeley) 5/19/95
- * $FreeBSD: src/sys/sys/proc.h,v 1.319 2003/04/21 07:02:37 davidxu Exp $
+ * $FreeBSD: src/sys/sys/proc.h,v 1.320 2003/04/22 20:00:25 jhb Exp $
  */
 
 #ifndef _SYS_PROC_H_
@@ -666,8 +666,8 @@
 #define	PS_ALRMPEND	0x00020	/* Pending SIGVTALRM needs to be posted. */
 #define	PS_PROFPEND	0x00040	/* Pending SIGPROF needs to be posted. */
 #define	PS_SWAPINREQ	0x00100	/* Swapin request due to wakeup. */
-#define	PS_SWAPPING	0x00200	/* Process is being swapped. */
-#define	PS_SWAPPINGIN	0x04000	/* Swapin in progress. */
+#define	PS_SWAPPINGOUT	0x00200	/* Process is being swapped out. */
+#define	PS_SWAPPINGIN	0x04000	/* Process is being swapped in. */
 #define	PS_MACPEND	0x08000	/* Ast()-based MAC event pending. */
 
 /* used only in legacy conversion code */
@@ -775,11 +775,9 @@
 } while (0)
 #define	_PHOLD(p) do {							\
 	PROC_LOCK_ASSERT((p), MA_OWNED);				\
-	if ((p)->p_lock++ == 0) {					\
-		mtx_lock_spin(&sched_lock);				\
+	(p)->p_lock++;							\
+	if (((p)->p_sflag & PS_INMEM) == 0)				\
 		faultin((p));						\
-		mtx_unlock_spin(&sched_lock);				\
-	}								\
 } while (0)
 
 #define	PRELE(p) do {							\

==== //depot/projects/smpng/sys/vm/vm_fault.c#25 (text+ko) ====

@@ -66,7 +66,7 @@
  * any improvements or extensions that they make and grant Carnegie the
  * rights to redistribute these changes.
  *
- * $FreeBSD: src/sys/vm/vm_fault.c,v 1.166 2003/04/20 19:25:28 alc Exp $
+ * $FreeBSD: src/sys/vm/vm_fault.c,v 1.167 2003/04/22 20:01:56 jhb Exp $
  */
 
 /*
@@ -917,15 +917,16 @@
 	}
 	vm_page_wakeup(fs.m);
 	vm_page_unlock_queues();
-	mtx_lock_spin(&sched_lock);
-	if (curproc && (curproc->p_sflag & PS_INMEM) && curproc->p_stats) {
+
+	PROC_LOCK(curproc);
+	if ((curproc->p_sflag & PS_INMEM) && curproc->p_stats) {
 		if (hardfault) {
 			curproc->p_stats->p_ru.ru_majflt++;
 		} else {
 			curproc->p_stats->p_ru.ru_minflt++;
 		}
 	}
-	mtx_unlock_spin(&sched_lock);
+	PROC_UNLOCK(curproc);
 
 	/*
 	 * Unlock everything, and return

==== //depot/projects/smpng/sys/vm/vm_glue.c#23 (text+ko) ====

@@ -59,7 +59,7 @@
  * any improvements or extensions that they make and grant Carnegie the
  * rights to redistribute these changes.
  *
- * $FreeBSD: src/sys/vm/vm_glue.c,v 1.165 2003/04/17 15:44:22 trhodes Exp $
+ * $FreeBSD: src/sys/vm/vm_glue.c,v 1.166 2003/04/22 20:00:26 jhb Exp $
  */
 
 #include "opt_vm.h"
@@ -355,14 +355,12 @@
 	sx_slock(&allproc_lock);
 	FOREACH_PROC_IN_SYSTEM(p) {
 		PROC_LOCK(p);
-		mtx_lock_spin(&sched_lock);
 
 		object = p->p_upages_obj;
 		if (object != NULL &&
 		    swap_pager_isswapped(p->p_upages_obj, devidx)) {
 			sx_sunlock(&allproc_lock);
 			faultin(p);
-			mtx_unlock_spin(&sched_lock);
 			PROC_UNLOCK(p);
 			vm_page_lock_queues();
 			TAILQ_FOREACH(m, &object->memq, listq)
@@ -373,7 +371,6 @@
 			goto retry;
 		}
 
-		mtx_unlock_spin(&sched_lock);
 		PROC_UNLOCK(p);
 	}
 	sx_sunlock(&allproc_lock);
@@ -516,51 +513,49 @@
 faultin(p)
 	struct proc *p;
 {
+	struct thread *td;
 
 	GIANT_REQUIRED;
 	PROC_LOCK_ASSERT(p, MA_OWNED);
-	mtx_assert(&sched_lock, MA_OWNED);
 #ifdef NO_SWAPPING
 	if ((p->p_sflag & PS_INMEM) == 0)
 		panic("faultin: proc swapped out with NO_SWAPPING!");
 #else
-	if ((p->p_sflag & PS_INMEM) == 0) {
-		struct thread *td;
-
-		++p->p_lock;
+	/*
+	 * If another process is swapping in this process,
+	 * just wait until it finishes.
+	 */
+	if (p->p_sflag & PS_SWAPPINGIN)
+		msleep(&p->p_sflag, &p->p_mtx, PVM, "faultin", 0);
+	else if ((p->p_sflag & PS_INMEM) == 0) {
 		/*
-		 * If another process is swapping in this process,
-		 * just wait until it finishes.
+		 * Don't let another thread swap process p out while we are
+		 * busy swapping it in.
 		 */
-		if (p->p_sflag & PS_SWAPPINGIN) {
-			mtx_unlock_spin(&sched_lock);
-			msleep(&p->p_sflag, &p->p_mtx, PVM, "faultin", 0);
-			mtx_lock_spin(&sched_lock);
-			--p->p_lock;
-			return;
-		}
-
+		++p->p_lock;
+		mtx_lock_spin(&sched_lock);
 		p->p_sflag |= PS_SWAPPINGIN;
 		mtx_unlock_spin(&sched_lock);
 		PROC_UNLOCK(p);
 
 		vm_proc_swapin(p);
-		FOREACH_THREAD_IN_PROC (p, td) {
+		FOREACH_THREAD_IN_PROC(p, td)
 			pmap_swapin_thread(td);
-			TD_CLR_SWAPPED(td);
-		}
 
 		PROC_LOCK(p);
 		mtx_lock_spin(&sched_lock);
 		p->p_sflag &= ~PS_SWAPPINGIN;
 		p->p_sflag |= PS_INMEM;
-		FOREACH_THREAD_IN_PROC (p, td)
+		FOREACH_THREAD_IN_PROC(p, td) {
+			TD_CLR_SWAPPED(td);
 			if (TD_CAN_RUN(td))
 				setrunnable(td);
+		}
+		mtx_unlock_spin(&sched_lock);
 
 		wakeup(&p->p_sflag);
 
-		/* undo the effect of setting SLOCK above */
+		/* Allow other threads to swap p out now. */
 		--p->p_lock;
 	}
 #endif
@@ -600,7 +595,7 @@
 	sx_slock(&allproc_lock);
 	FOREACH_PROC_IN_SYSTEM(p) {
 		struct ksegrp *kg;
-		if (p->p_sflag & (PS_INMEM | PS_SWAPPING | PS_SWAPPINGIN)) {
+		if (p->p_sflag & (PS_INMEM | PS_SWAPPINGOUT | PS_SWAPPINGIN)) {
 			continue;
 		}
 		mtx_lock_spin(&sched_lock);
@@ -641,20 +636,20 @@
 		goto loop;
 	}
 	PROC_LOCK(p);
-	mtx_lock_spin(&sched_lock);
 
 	/*
 	 * Another process may be bringing or may have already
 	 * brought this process in while we traverse all threads.
 	 * Or, this process may even be being swapped out again.
 	 */
-	if (p->p_sflag & (PS_INMEM|PS_SWAPPING|PS_SWAPPINGIN)) {
-		mtx_unlock_spin(&sched_lock);
+	if (p->p_sflag & (PS_INMEM | PS_SWAPPINGOUT | PS_SWAPPINGIN)) {
 		PROC_UNLOCK(p);
 		goto loop;
 	}
 
+	mtx_lock_spin(&sched_lock);
 	p->p_sflag &= ~PS_SWAPINREQ;
+	mtx_unlock_spin(&sched_lock);
 
 	/*
 	 * We would like to bring someone in. (only if there is space).
@@ -662,6 +657,7 @@
 	 */
 	faultin(p);
 	PROC_UNLOCK(p);
+	mtx_lock_spin(&sched_lock);
 	p->p_swtime = 0;
 	mtx_unlock_spin(&sched_lock);
 	goto loop;
@@ -768,10 +764,10 @@
 		 * skipped because of the if statement above checking 
 		 * for P_SYSTEM
 		 */
+		if ((p->p_sflag & (PS_INMEM|PS_SWAPPINGOUT|PS_SWAPPINGIN)) != PS_INMEM)
+			goto nextproc2;
+
 		mtx_lock_spin(&sched_lock);
-		if ((p->p_sflag & (PS_INMEM|PS_SWAPPING|PS_SWAPPINGIN)) != PS_INMEM)
-			goto nextproc;
-
 		switch (p->p_state) {
 		default:
 			/* Don't swap out processes in any sort
@@ -832,12 +828,8 @@
 				 (minslptime > swap_idle_threshold2))) {
 				swapout(p);
 				didswap++;
-
-				/*
-				 * swapout() unlocks a proc lock. This is
-				 * ugly, but avoids superfluous lock.
-				 */
 				mtx_unlock_spin(&sched_lock);
+				PROC_UNLOCK(p);
 				vm_map_unlock(&vm->vm_map);
 				vmspace_free(vm);
 				sx_sunlock(&allproc_lock);
@@ -879,7 +871,7 @@
 	 * by now.  Assuming that there is only one pageout daemon thread,
 	 * this process should still be in memory.
 	 */
-	KASSERT((p->p_sflag & (PS_INMEM|PS_SWAPPING|PS_SWAPPINGIN)) == PS_INMEM,
+	KASSERT((p->p_sflag & (PS_INMEM|PS_SWAPPINGOUT|PS_SWAPPINGIN)) == PS_INMEM,
 		("swapout: lost a swapout race?"));
 
 #if defined(INVARIANTS)
@@ -900,18 +892,20 @@
 	 */
 	p->p_vmspace->vm_swrss = vmspace_resident_count(p->p_vmspace);
 
+	p->p_sflag &= ~PS_INMEM;
+	p->p_sflag |= PS_SWAPPINGOUT;
 	PROC_UNLOCK(p);
-	p->p_sflag &= ~PS_INMEM;
-	p->p_sflag |= PS_SWAPPING;
+	FOREACH_THREAD_IN_PROC(p, td)
+		TD_SET_SWAPPED(td);
 	mtx_unlock_spin(&sched_lock);
 
 	vm_proc_swapout(p);
-	FOREACH_THREAD_IN_PROC(p, td) {
+	FOREACH_THREAD_IN_PROC(p, td)
 		pmap_swapout_thread(td);
-		TD_SET_SWAPPED(td);
-	}
+
+	PROC_LOCK(p);
 	mtx_lock_spin(&sched_lock);
-	p->p_sflag &= ~PS_SWAPPING;
+	p->p_sflag &= ~PS_SWAPPINGOUT;
 	p->p_swtime = 0;
 }
 #endif /* !NO_SWAPPING */

==== //depot/projects/smpng/sys/vm/vm_pageout.c#27 (text+ko) ====

@@ -65,7 +65,7 @@
  * any improvements or extensions that they make and grant Carnegie the
  * rights to redistribute these changes.
  *
- * $FreeBSD: src/sys/vm/vm_pageout.c,v 1.230 2003/04/20 20:37:14 alc Exp $
+ * $FreeBSD: src/sys/vm/vm_pageout.c,v 1.231 2003/04/22 20:03:08 jhb Exp $
  */
 
 /*
@@ -1543,7 +1543,9 @@
 			 * if this is a system process or if we have already
 			 * looked at this process, skip it.
 			 */
+			PROC_LOCK(p);
 			if (p->p_flag & (P_SYSTEM | P_WEXIT)) {
+				PROC_UNLOCK(p);
 				continue;
 			}
 			/*
@@ -1560,8 +1562,9 @@
 					break;
 				}
 			}
+			mtx_unlock_spin(&sched_lock);
 			if (breakout) {
-				mtx_unlock_spin(&sched_lock);
+				PROC_UNLOCK(p);
 				continue;
 			}
 			/*
@@ -1578,7 +1581,7 @@
 			 */
 			if ((p->p_sflag & PS_INMEM) == 0)
 				limit = 0;	/* XXX */
-			mtx_unlock_spin(&sched_lock);
+			PROC_UNLOCK(p);
 
 			size = vmspace_resident_count(p->p_vmspace);
 			if (limit >= 0 && size >= limit) {



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