sys/vm/vm_glue.c
/*
 * Swapout is driven by the pageout daemon.  Very simple, we find eligible
 * procs and unwire their u-areas.  We try to always "swap" at least one
 * process in case we need the room for a swapin.
 * If any procs have been sleeping/stopped for at least maxslp seconds,
 * they are swapped.  Else, we swap the longest-sleeping or stopped process,
 * if any, otherwise the longest-resident process.
 */
Swapout is driven by the pageout daemon.  Very simple, we find eligible
procs and unwire their u-areas.  We try to always "swap" at least one
process in case we need the room for a swapin.
If any procs have been sleeping/stopped for at least maxslp seconds,
they are swapped.  Else, we swap the longest-sleeping or stopped process,
if any, otherwise the longest-resident process.
Swapout is driven by the pageout daemon . Very simple we find eligible procs and unwire their u - areas . We try to always " swap " at least one process in case we need the room for a swapin . If any procs have been sleeping / stopped for at least maxslp seconds they are swapped . Else we swap the longest - sleeping or stopped process if any otherwise the longest - resident process .
void
swapout_threads()
{
	register struct proc *p;
	struct proc *outp, *outp2;
	int outpri, outpri2;
	int didswap = 0;
	extern int maxslp;
#ifdef DEBUG
	if (!enableswap)
		return;
#endif
	outp = outp2 = NULL;
	outpri = outpri2 = 0;
	for (p = allproc.lh_first; p != 0; p = p->p_list.le_next) {
		if (!swappable(p))
			continue;
		switch (p->p_stat) {
		case SRUN:
			if (p->p_swtime > outpri2) {
				outp2 = p;
				outpri2 = p->p_swtime;
			}
			continue;
		case SSLEEP:
		case SSTOP:
			if (p->p_slptime >= maxslp) {
				swapout(p);
				didswap++;
			} else if (p->p_slptime > outpri) {
				outp = p;
				outpri = p->p_slptime;
			}
			continue;
		}
	}
	if (didswap == 0 &&
	    cnt.v_free_count <= atop(round_page(ctob(UPAGES)))) {
		if ((p = outp) == 0)
			p = outp2;
#ifdef DEBUG
		if (swapdebug & SDB_SWAPOUT)
			printf("swapout_threads: no duds, try procp %x\n", p);
#endif
		if (p)
			swapout(p);
	}
}
void swapout_threads ( ) { register struct proc * p ; struct proc * outp , * outp2 ; int outpri , outpri2 ; int didswap = 0 ; extern int maxslp ; #ifdef DEBUG if ( ! enableswap ) return ; #endif outp = outp2 = NULL ; outpri = outpri2 = 0 ; for ( p = allproc . lh_first ; p != 0 ; p = p -> p_list . le_next ) { if ( ! swappable ( p ) ) continue ; switch ( p -> p_stat ) { case SRUN : if ( p -> p_swtime > outpri2 ) { outp2 = p ; outpri2 = p -> p_swtime ; } continue ; case SSLEEP : case SSTOP : if ( p -> p_slptime >= maxslp ) { swapout ( p ) ; didswap ++ ; } else if ( p -> p_slptime > outpri ) { outp = p ; outpri = p -> p_slptime ; } continue ; } } if ( didswap == 0 && cnt . v_free_count <= atop ( round_page ( ctob ( UPAGES ) ) ) ) { if ( ( p = outp ) == 0 ) p = outp2 ; #ifdef DEBUG if ( swapdebug & SDB_SWAPOUT ) printf ( " \n " , p ) ; #endif if ( p ) swapout ( p ) ; } }
Swapout is driven by the pageout daemon.
Swapout is driven by the pageout daemon .
/*
	 * If we didn't get rid of any real duds, toss out the next most
	 * likely sleeping/stopped or running candidate.  We only do this
	 * if we are real low on memory since we don't gain much by doing
	 * it (UPAGES pages).
	 */