sys/vm/vm_glue.c
/*
 * Brutally simple:
 *	1. Attempt to swapin every swaped-out, runnable process in
 *	   order of priority.
 *	2. If not enough memory, wake the pageout daemon and let it
 *	   clear some space.
 */
Brutally simple:
1. Attempt to swapin every swaped-out, runnable process in
order of priority.
2. If not enough memory, wake the pageout daemon and let it
clear some space.
Brutally simple : 1 . Attempt to swapin every swaped - out runnable process in order of priority . 2 . If not enough memory wake the pageout daemon and let it clear some space .
void
scheduler()
{
	register struct proc *p;
	register int pri;
	struct proc *pp;
	int ppri;
	vm_offset_t addr;
	vm_size_t size;
loop:
#ifdef DEBUG
	while (!enableswap)
		tsleep((caddr_t)&proc0, PVM, "noswap", 0);
#endif
	pp = NULL;
	ppri = INT_MIN;
	for (p = allproc.lh_first; p != 0; p = p->p_list.le_next) {
		if (p->p_stat == SRUN && (p->p_flag & P_INMEM) == 0) {
			pri = p->p_swtime + p->p_slptime - p->p_nice * 8;
			if (pri > ppri) {
				pp = p;
				ppri = pri;
			}
		}
	}
#ifdef DEBUG
	if (swapdebug & SDB_FOLLOW)
		printf("scheduler: running, procp %x pri %d\n", pp, ppri);
#endif
	if ((p = pp) == NULL) {
		tsleep((caddr_t)&proc0, PVM, "scheduler", 0);
		goto loop;
	}
	size = round_page(ctob(UPAGES));
	addr = (vm_offset_t) p->p_addr;
	if (cnt.v_free_count > atop(size)) {
#ifdef DEBUG
		if (swapdebug & SDB_SWAPIN)
			printf("swapin: pid %d(%s)@%x, pri %d free %d\n",
			       p->p_pid, p->p_comm, p->p_addr,
			       ppri, cnt.v_free_count);
#endif
		vm_map_pageable(kernel_map, addr, addr+size, FALSE);
		cpu_swapin(p);
		(void) splstatclock();
		if (p->p_stat == SRUN)
			setrunqueue(p);
		p->p_flag |= P_INMEM;
		(void) spl0();
		p->p_swtime = 0;
		goto loop;
	}
#ifdef DEBUG
	if (swapdebug & SDB_FOLLOW)
		printf("scheduler: no room for pid %d(%s), free %d\n",
		       p->p_pid, p->p_comm, cnt.v_free_count);
#endif
	(void) splhigh();
	VM_WAIT;
	(void) spl0();
#ifdef DEBUG
	if (swapdebug & SDB_FOLLOW)
		printf("scheduler: room again, free %d\n", cnt.v_free_count);
#endif
	goto loop;
}
void scheduler ( ) { register struct proc * p ; register int pri ; struct proc * pp ; int ppri ; vm_offset_t addr ; vm_size_t size ; loop : #ifdef DEBUG while ( ! enableswap ) tsleep ( ( caddr_t ) & proc0 , PVM , " " , 0 ) ; #endif pp = NULL ; ppri = INT_MIN ; for ( p = allproc . lh_first ; p != 0 ; p = p -> p_list . le_next ) { if ( p -> p_stat == SRUN && ( p -> p_flag & P_INMEM ) == 0 ) { pri = p -> p_swtime + p -> p_slptime - p -> p_nice * 8 ; if ( pri > ppri ) { pp = p ; ppri = pri ; } } } #ifdef DEBUG if ( swapdebug & SDB_FOLLOW ) printf ( " \n " , pp , ppri ) ; #endif if ( ( p = pp ) == NULL ) { tsleep ( ( caddr_t ) & proc0 , PVM , " " , 0 ) ; goto loop ; } size = round_page ( ctob ( UPAGES ) ) ; addr = ( vm_offset_t ) p -> p_addr ; if ( cnt . v_free_count > atop ( size ) ) { #ifdef DEBUG if ( swapdebug & SDB_SWAPIN ) printf ( " \n " , p -> p_pid , p -> p_comm , p -> p_addr , ppri , cnt . v_free_count ) ; #endif vm_map_pageable ( kernel_map , addr , addr + size , FALSE ) ; cpu_swapin ( p ) ; ( void ) splstatclock ( ) ; if ( p -> p_stat == SRUN ) setrunqueue ( p ) ; p -> p_flag |= P_INMEM ; ( void ) spl0 ( ) ; p -> p_swtime = 0 ; goto loop ; } #ifdef DEBUG if ( swapdebug & SDB_FOLLOW ) printf ( " \n " , p -> p_pid , p -> p_comm , cnt . v_free_count ) ; #endif ( void ) splhigh ( ) ; VM_WAIT ; ( void ) spl0 ( ) ; #ifdef DEBUG if ( swapdebug & SDB_FOLLOW ) printf ( " \n " , cnt . v_free_count ) ; #endif goto loop ; }
Brutally simple:
      1.
Brutally simple : 1 .
/* XXX should also penalize based on vm_swrss */ /*
	 * Nothing to do, back to sleep
	 */ /*
	 * We would like to bring someone in.
	 * This part is really bogus cuz we could deadlock on memory
	 * despite our feeble check.
	 * XXX should require at least vm_swrss / 2
	 */ /*
		 * Some architectures need to be notified when the
		 * user area has moved to new physical page(s) (e.g.
		 * see pmax/pmax/vm_machdep.c).
		 */ /*
	 * Not enough memory, jab the pageout daemon and wait til the
	 * coast is clear.
	 */