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

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

1992/0301/sys/src/9/port/swap.c:15,211992/0302/sys/src/9/port/swap.c:15,21 (short | long | prev | next)
1991/0705    
 
enum 
{ 
1992/0301    
	Maxpages = 300,		/* Max number of pageouts per segment pass */ 
1992/0302    
	Maxpages = 100,		/* Max number of pageouts per segment pass */ 
1991/0705    
}; 
 
Image 	swapimage; 
1992/0301/sys/src/9/port/swap.c:22,271992/0302/sys/src/9/port/swap.c:22,28
1991/0705    
static 	int swopen; 
Page	*iolist[Maxpages]; 
int	ioptr; 
1992/0302    
int	scavenge; 
1991/0705    
 
void 
swapinit(void) 
1992/0301/sys/src/9/port/swap.c:144,1521992/0302/sys/src/9/port/swap.c:145,154
1991/0705    
void			 
pageout(Proc *p, Segment *s) 
{ 
	Pte **sm, **endsm; 
	Page **pg, **epg; 
1992/0302    
	Pte **sm, **endsm, *l; 
	Page **pg, *entry; 
1991/0705    
	int type; 
1992/0302    
extern char *sname[]; 
1991/0705    
 
	if(!canqlock(&s->lk))	/* We cannot afford to wait, we will surely deadlock */ 
		return; 
1992/0301/sys/src/9/port/swap.c:163,1881992/0302/sys/src/9/port/swap.c:165,200
1991/0705    
		return; 
	} 
 
1992/0302    
	scavenge = 0; 
 
1991/0705    
	/* Pass through the pte tables looking for memory pages to swap out */ 
	type = s->type&SG_TYPE; 
	endsm = &s->map[SEGMAPSIZE]; 
	for(sm = s->map; sm < endsm && ioptr < Maxpages; sm++) 
		if(*sm) { 
			pg = (*sm)->pages; 
			for(epg = &pg[PTEPERTAB]; pg < epg && ioptr < Maxpages; pg++) 
				if(!pagedout(*pg)) { 
					if((*pg)->modref & PG_REF) 
						(*pg)->modref &= ~PG_REF; 
					else  
					if(pagepte(type, s, pg) == 0) 
						break; 
				} 
		} 
1992/0302    
	for(sm = s->map; sm < endsm; sm++) { 
		l = *sm; 
		if(l == 0) 
			continue; 
		for(pg = l->first; pg < l->last; pg++) { 
			entry = *pg; 
			if(pagedout(entry)) 
				continue; 
			if(entry->modref & PG_REF) { 
				print("MODREF\n"); 
				entry->modref &= ~PG_REF; 
			} 
			else  
				pagepte(type, s, pg); 
1991/0705    
 
1992/0302    
			if(ioptr >= Maxpages) 
				goto out; 
		} 
	} 
out: 
	 
	print("%s: %d: type %s %d pages\n", p->text, p->pid, sname[type], scavenge); 
1991/0705    
	poperror(); 
	qunlock(&s->lk); 
	putseg(s); 
                 
	wakeup(&palloc.r); 
} 
 
1992/0301/sys/src/9/port/swap.c:206,2171992/0302/sys/src/9/port/swap.c:218,233
1991/0705    
	 */ 
	p = proctab(0); 
	ep = &p[conf.nproc]; 
	for(; p < ep; p++) 
		if(p->state != Dead) 
1992/0302    
	while(p < ep) { 
		if(p->state != Dead) { 
1991/0705    
			for(i = 0; i < NSEG; i++) 
				if(p->seg[i] == s) 
					if(!canpage(p)) 
						return 0; 
1992/0302    
		} 
		p++; 
	} 
 
1991/0705    
	return 1;						 
} 
 
1992/0301/sys/src/9/port/swap.c:226,2371992/0302/sys/src/9/port/swap.c:242,255
1991/0705    
	KMap *k; 
 
	outp = *pg; 
                 
1992/0302    
print("outp: %lux\n", *pg); 
1991/0705    
	switch(type) { 
	case SG_TEXT:					/* Revert to demand load */ 
		putpage(outp); 
		*pg = 0; 
1992/0302    
		scavenge++; 
1991/0705    
		break; 
1992/0302    
 
1991/0705    
	case SG_DATA: 
	case SG_BSS: 
	case SG_STACK: 
1992/0301/sys/src/9/port/swap.c:253,2581992/0302/sys/src/9/port/swap.c:271,277
1991/0705    
 
		/* Add me to IO transaction list */ 
		iolist[ioptr++] = outp; 
1992/0302    
		scavenge++; 
1991/0705    
	} 
 
	return 1; 
1992/0301/sys/src/9/port/swap.c:286,2941992/0302/sys/src/9/port/swap.c:305,310
1991/0705    
		kaddr = (char*)VA(k); 
		qlock(&c->wrl); 
 
		/* BUG: what to do ? Nobody to tell, nowhere to go: open to suggestions  
		 *	the problem is I do not know whose page this is. 
		 */ 
		if(waserror()) 
			panic("executeio: page out I/O error"); 
 


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