plan 9 kernel history: overview | file list | diff list

1992/0805/port/swap.c (diff list | history)

1992/0804/sys/src/9/port/swap.c:21,271992/0805/sys/src/9/port/swap.c:21,27 (short | long | prev | next)
1991/0705    
Image 	swapimage; 
static 	int swopen; 
Page	*iolist[Maxpages]; 
1992/0804    
int	ioptr, npage; 
1992/0805    
int	ioptr; 
1991/0705    
 
void 
swapinit(void) 
1992/0804/sys/src/9/port/swap.c:87,931992/0805/sys/src/9/port/swap.c:87,93
1991/0705    
{ 
	Proc *p, *ep; 
	Segment *s; 
1992/0304    
	int i, type; 
1992/0805    
	int i; 
1991/0705    
 
1992/0303    
	if(waserror())  
		panic("pager: os error\n"); 
1992/0804/sys/src/9/port/swap.c:99,1071992/0805/sys/src/9/port/swap.c:99,105
1992/0303    
loop: 
	u->p->psstate = "Idle"; 
	sleep(&swapalloc.r, needpages, 0); 
	u->p->psstate = "Pageout"; 
1992/0301    
 
1992/0804    
	npage = 0; 
1992/0303    
	for(;;) { 
		p++; 
1992/0628    
		if(p >= ep) 
1992/0804/sys/src/9/port/swap.c:116,1371992/0805/sys/src/9/port/swap.c:114,141
1992/0303    
					goto loop; 
1992/0628    
 
1992/0303    
				if(s = p->seg[i]) { 
1992/0304    
					type = s->type&SG_TYPE; 
					switch(type) { 
1992/0805    
					switch(s->type&SG_TYPE) { 
1992/0304    
					default: 
						break; 
					case SG_TEXT: 
1992/0805    
						pageout(p, s); 
						break; 
1992/0304    
					case SG_DATA: 
					case SG_BSS: 
					case SG_STACK: 
					case SG_SHARED: 
1992/0805    
						u->p->psstate = "Pageout"; 
1992/0304    
						pageout(p, s); 
						executeio(); 
1992/0805    
						if(ioptr != 0) { 
							u->p->psstate = "I/O"; 
							executeio(); 
						} 
1992/0304    
					} 
1992/0303    
				} 
1991/0705    
			} 
1992/0805    
			continue; 
1991/0705    
		} 
1992/0303    
		else  
1992/0805    
 
1992/0303    
		if(palloc.freecount < swapalloc.highwater) { 
1992/0725    
			if(!cpuserver) 
				freebroken();	/* can use the memory */ 
1992/0804/sys/src/9/port/swap.c:142,1491992/0805/sys/src/9/port/swap.c:146,151
1992/0303    
			wakeup(&palloc.r); 
		} 
1991/0705    
	} 
1992/0804    
	if(npage == 0) 
		print("swap: pass took no pages\n"); 
1992/0303    
	goto loop; 
1991/0705    
} 
 
1992/0804/sys/src/9/port/swap.c:150,1581992/0805/sys/src/9/port/swap.c:152,160
1991/0705    
void			 
pageout(Proc *p, Segment *s) 
{ 
1992/0302    
	Pte **sm, **endsm, *l; 
1992/0805    
	int type, i; 
	Pte *l; 
1992/0302    
	Page **pg, *entry; 
1992/0304    
	int type; 
1991/0705    
 
	if(!canqlock(&s->lk))	/* We cannot afford to wait, we will surely deadlock */ 
		return; 
1992/0804/sys/src/9/port/swap.c:177,1851992/0805/sys/src/9/port/swap.c:179,186
1991/0705    
 
	/* Pass through the pte tables looking for memory pages to swap out */ 
	type = s->type&SG_TYPE; 
	endsm = &s->map[SEGMAPSIZE]; 
1992/0302    
	for(sm = s->map; sm < endsm; sm++) { 
		l = *sm; 
1992/0805    
	for(i = 0; i < SEGMAPSIZE; i++) { 
		l = s->map[i]; 
1992/0302    
		if(l == 0) 
			continue; 
		for(pg = l->first; pg < l->last; pg++) { 
1992/0804/sys/src/9/port/swap.c:187,1971992/0805/sys/src/9/port/swap.c:188,200
1992/0302    
			if(pagedout(entry)) 
				continue; 
1992/0303    
 
			if(entry->modref & PG_REF) 
1992/0805    
			if(entry->modref & PG_REF) { 
1992/0302    
				entry->modref &= ~PG_REF; 
			else  
1992/0711    
				pagepte(type, pg); 
1992/0805    
				continue; 
			} 
1991/0705    
 
1992/0805    
			pagepte(type, pg); 
 
1992/0302    
			if(ioptr >= Maxpages) 
				goto out; 
		} 
1992/0804/sys/src/9/port/swap.c:206,2131992/0805/sys/src/9/port/swap.c:209,216
1991/0705    
int 
canflush(Proc *p, Segment *s) 
{ 
	Proc *ep; 
	int i; 
1992/0805    
	Proc *ep; 
1991/0705    
 
	lock(s); 
	if(s->ref == 1) {		/* Easy if we are the only user */ 
1992/0804/sys/src/9/port/swap.c:232,2381992/0805/sys/src/9/port/swap.c:235,240
1992/0302    
		} 
		p++; 
	} 
                 
1991/0705    
	return 1;						 
} 
 
1992/0804/sys/src/9/port/swap.c:272,2781992/0805/sys/src/9/port/swap.c:274,279
1991/0705    
		/* Add me to IO transaction list */ 
		iolist[ioptr++] = outp; 
	} 
1992/0804    
	npage++; 
1991/0705    
} 
 
void 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)