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

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

1992/0303/sys/src/9/port/swap.c:7,131992/0304/sys/src/9/port/swap.c:7,13 (short | long | prev | next)
1991/0705    
 
/* Predeclaration */ 
void	pageout(Proc *p, Segment*); 
int	pagepte(int, Segment*, Page**); 
1992/0304    
void	pagepte(int, Segment*, Page**); 
1991/0705    
int	needpages(void*); 
void	pager(void*); 
void	executeio(void); 
1992/0303/sys/src/9/port/swap.c:18,301992/0304/sys/src/9/port/swap.c:18,27
1992/0303    
	Maxpages = 500,		/* Max number of pageouts per segment pass */ 
1991/0705    
}; 
 
1992/0303    
#define DBG	if(1)print 
                 
1991/0705    
Image 	swapimage; 
static 	int swopen; 
Page	*iolist[Maxpages]; 
int	ioptr; 
1992/0302    
int	scavenge; 
1991/0705    
 
void 
swapinit(void) 
1992/0303/sys/src/9/port/swap.c:103,1091992/0304/sys/src/9/port/swap.c:100,106
1991/0705    
{ 
	Proc *p, *ep; 
	Segment *s; 
	int i; 
1992/0304    
	int i, type; 
1991/0705    
 
1992/0303    
	if(waserror())  
		panic("pager: os error\n"); 
1992/0303/sys/src/9/port/swap.c:130,1371992/0304/sys/src/9/port/swap.c:127,144
1992/0303    
				if(!needpages(junk)) 
					goto loop; 
				if(s = p->seg[i]) { 
					pageout(p, s); 
					executeio(); 
1992/0304    
					type = s->type&SG_TYPE; 
					switch(type) { 
					default: 
						break; 
					case SG_TEXT: 
					case SG_DATA: 
					case SG_BSS: 
					case SG_STACK: 
					case SG_SHARED: 
						pageout(p, s); 
						executeio(); 
					} 
1992/0303    
				} 
1991/0705    
			} 
		} 
1992/0303/sys/src/9/port/swap.c:155,1741992/0304/sys/src/9/port/swap.c:162,179
1991/0705    
{ 
1992/0302    
	Pte **sm, **endsm, *l; 
	Page **pg, *entry; 
1992/0303    
	int type, nr; 
1992/0302    
extern char *sname[]; 
1992/0304    
	int type; 
1991/0705    
 
1992/0303    
                 
1991/0705    
	if(!canqlock(&s->lk))	/* We cannot afford to wait, we will surely deadlock */ 
		return; 
 
1992/0303    
	if(s->steal) { 
1992/0304    
	if(s->steal) {		/* Protected by /dev/proc */ 
1991/0705    
		qunlock(&s->lk); 
		putseg(s); 
		return; 
	} 
 
1992/0303    
	if(!canflush(p, s)) { 
1992/0304    
	if(!canflush(p, s)) {	/* Able to invalidate all tlbs with references */ 
1992/0303    
		qunlock(&s->lk); 
		putseg(s); 
		return; 
1992/0303/sys/src/9/port/swap.c:180,1881992/0304/sys/src/9/port/swap.c:185,190
1991/0705    
		return; 
	} 
 
1992/0302    
	scavenge = 0; 
1992/0303    
	nr = 0; 
1992/0302    
                 
1991/0705    
	/* Pass through the pte tables looking for memory pages to swap out */ 
	type = s->type&SG_TYPE; 
	endsm = &s->map[SEGMAPSIZE]; 
1992/0303/sys/src/9/port/swap.c:191,1971992/0304/sys/src/9/port/swap.c:193,198
1992/0302    
		if(l == 0) 
			continue; 
		for(pg = l->first; pg < l->last; pg++) { 
1992/0303    
			nr++; 
1992/0302    
			entry = *pg; 
			if(pagedout(entry)) 
				continue; 
1992/0303/sys/src/9/port/swap.c:206,2141992/0304/sys/src/9/port/swap.c:207,212
1992/0302    
		} 
	} 
out: 
1992/0303    
	DBG("%s: %d: %5s s %d nr %d fr %d\n",  
	p->text, p->pid, sname[type], scavenge, nr, palloc.freecount); 
                 
1991/0705    
	poperror(); 
	qunlock(&s->lk); 
	putseg(s); 
1992/0303/sys/src/9/port/swap.c:248,2541992/0304/sys/src/9/port/swap.c:246,252
1991/0705    
	return 1;						 
} 
 
int 
1992/0304    
void 
1991/0705    
pagepte(int type, Segment *s, Page **pg) 
{ 
	ulong daddr; 
1992/0303/sys/src/9/port/swap.c:259,2651992/0304/sys/src/9/port/swap.c:257,262
1991/0705    
	case SG_TEXT:					/* Revert to demand load */ 
		putpage(outp); 
		*pg = 0; 
1992/0302    
		scavenge++; 
1991/0705    
		break; 
1992/0302    
 
1991/0705    
	case SG_DATA: 
1992/0303/sys/src/9/port/swap.c:283,2921992/0304/sys/src/9/port/swap.c:280,286
1991/0705    
 
		/* Add me to IO transaction list */ 
		iolist[ioptr++] = outp; 
1992/0302    
		scavenge++; 
1991/0705    
	} 
                 
	return 1; 
} 
 
void 
1992/0303/sys/src/9/port/swap.c:324,3301992/0304/sys/src/9/port/swap.c:318,323
1991/0705    
		unlockpage(out); 
		putpage(out); 
	} 
                 
	ioptr = 0; 
} 
 


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