sys/vm/vm_swap.c
/*
 * Set up swap devices.
 * Initialize linked list of free swap
 * headers. These do not actually point
 * to buffers, but rather to pages that
 * are being swapped in and out.
 */
Set up swap devices.
Initialize linked list of free swap
headers. These do not actually point
to buffers, but rather to pages that
are being swapped in and out.
Set up swap devices . Initialize linked list of free swap headers . These do not actually point to buffers but rather to pages that are being swapped in and out .
void
swapinit()
{
	register int i;
	register struct buf *sp = swbuf;
	register struct proc *p = &proc0;	
	struct swdevt *swp;
	int error;
#ifdef SEQSWAP
	nswdev = niswdev = 0;
	nswap = niswap = 0;
	for (swp = swdevt; swp->sw_dev != NODEV || swp->sw_vp != NULL; swp++) {
		if (swp->sw_flags & SW_SEQUENTIAL)
			break;
		niswdev++;
		if (swp->sw_nblks > niswap)
			niswap = swp->sw_nblks;
	}
	niswap = roundup(niswap, dmmax);
	niswap *= niswdev;
	if (swdevt[0].sw_vp == NULL &&
	    bdevvp(swdevt[0].sw_dev, &swdevt[0].sw_vp))
		panic("swapvp");
	for ( ; swp->sw_dev != NODEV; swp++) {
		if ((swp->sw_flags & SW_SEQUENTIAL) == 0)
			panic("binit: mis-ordered swap devices");
		nswdev++;
		if (swp->sw_nblks > 0) {
			if (swp->sw_nblks % dmmax)
				swp->sw_nblks -= (swp->sw_nblks % dmmax);
			nswap += swp->sw_nblks;
		}
	}
	nswdev += niswdev;
	if (nswdev == 0)
		panic("swapinit");
	nswap += niswap;
#else
	nswdev = 0;
	nswap = 0;
	for (swp = swdevt; swp->sw_dev != NODEV || swp->sw_vp != NULL; swp++) {
		nswdev++;
		if (swp->sw_nblks > nswap)
			nswap = swp->sw_nblks;
	}
	if (nswdev == 0)
		panic("swapinit");
	if (nswdev > 1)
		nswap = ((nswap + dmmax - 1) / dmmax) * dmmax;
	nswap *= nswdev;
	if (swdevt[0].sw_vp == NULL &&
	    bdevvp(swdevt[0].sw_dev, &swdevt[0].sw_vp))
		panic("swapvp");
#endif
	if (nswap == 0)
		printf("WARNING: no swap space found\n");
	else if (error = swfree(p, 0)) {
		printf("swfree errno %d\n", error);	
		panic("swapinit swfree 0");
	}
	bswlist.b_actf = sp;
	for (i = 0; i < nswbuf - 1; i++, sp++) {
		sp->b_actf = sp + 1;
		sp->b_rcred = sp->b_wcred = p->p_ucred;
		sp->b_vnbufs.le_next = NOLIST;
	}
	sp->b_rcred = sp->b_wcred = p->p_ucred;
	sp->b_vnbufs.le_next = NOLIST;
	sp->b_actf = NULL;
}
void swapinit ( ) { register int i ; register struct buf * sp = swbuf ; register struct proc * p = & proc0 ; struct swdevt * swp ; int error ; #ifdef SEQSWAP nswdev = niswdev = 0 ; nswap = niswap = 0 ; for ( swp = swdevt ; swp -> sw_dev != NODEV || swp -> sw_vp != NULL ; swp ++ ) { if ( swp -> sw_flags & SW_SEQUENTIAL ) break ; niswdev ++ ; if ( swp -> sw_nblks > niswap ) niswap = swp -> sw_nblks ; } niswap = roundup ( niswap , dmmax ) ; niswap *= niswdev ; if ( swdevt [ 0 ] . sw_vp == NULL && bdevvp ( swdevt [ 0 ] . sw_dev , & swdevt [ 0 ] . sw_vp ) ) panic ( " " ) ; for ( ; swp -> sw_dev != NODEV ; swp ++ ) { if ( ( swp -> sw_flags & SW_SEQUENTIAL ) == 0 ) panic ( " " ) ; nswdev ++ ; if ( swp -> sw_nblks > 0 ) { if ( swp -> sw_nblks % dmmax ) swp -> sw_nblks -= ( swp -> sw_nblks % dmmax ) ; nswap += swp -> sw_nblks ; } } nswdev += niswdev ; if ( nswdev == 0 ) panic ( " " ) ; nswap += niswap ; #else nswdev = 0 ; nswap = 0 ; for ( swp = swdevt ; swp -> sw_dev != NODEV || swp -> sw_vp != NULL ; swp ++ ) { nswdev ++ ; if ( swp -> sw_nblks > nswap ) nswap = swp -> sw_nblks ; } if ( nswdev == 0 ) panic ( " " ) ; if ( nswdev > 1 ) nswap = ( ( nswap + dmmax - 1 ) / dmmax ) * dmmax ; nswap *= nswdev ; if ( swdevt [ 0 ] . sw_vp == NULL && bdevvp ( swdevt [ 0 ] . sw_dev , & swdevt [ 0 ] . sw_vp ) ) panic ( " " ) ; #endif if ( nswap == 0 ) printf ( " \n " ) ; else if ( error = swfree ( p , 0 ) ) { printf ( " \n " , error ) ; panic ( " " ) ; } bswlist . b_actf = sp ; for ( i = 0 ; i < nswbuf - 1 ; i ++ , sp ++ ) { sp -> b_actf = sp + 1 ; sp -> b_rcred = sp -> b_wcred = p -> p_ucred ; sp -> b_vnbufs . le_next = NOLIST ; } sp -> b_rcred = sp -> b_wcred = p -> p_ucred ; sp -> b_vnbufs . le_next = NOLIST ; sp -> b_actf = NULL ; }
Set up swap devices.
Set up swap devices .
/* XXX */ /*
	 * Count swap devices, and adjust total swap space available.
	 * Some of the space will not be countable until later (dynamically
	 * configurable devices) and some of the counted space will not be
	 * available until a swapon() system call is issued, both usually
	 * happen when the system goes multi-user.
	 *
	 * If using NFS for swap, swdevt[0] will already be bdevvp'd.	XXX
	 */ /*
	 * All interleaved devices must come first
	 */ /*
	 * The remainder must be sequential
	 */ /* XXX */ /*
	 * Now set up swap buffer headers.
	 */