Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/port/swap.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


## diffname port/swap.c 1991/0705
## diff -e /dev/null /n/bootesdump/1991/0705/sys/src/9/port/swap.c
0a
#include	"u.h"
#include	"lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"
#include	"ureg.h"
#include	"errno.h"

/* Predeclaration */
void	pageout(Proc *p, Segment*);
int	pagepte(int, Segment*, Page**);
void	openswap(void);
int	needpages(void*);
void	pager(void*);
void	executeio(void);
int	canflush(Proc *p, Segment*);

enum
{
	Maxpages = 500,		/* Max number of pageouts per process pass */
};

Image 	swapimage;
static 	int swopen;
Page	*iolist[Maxpages];
int	ioptr;

void
swapinit(void)
{
	swapalloc.swmap = ialloc(conf.nswap, 0);
	swapalloc.top = &swapalloc.swmap[conf.nswap];
	swapalloc.alloc = swapalloc.swmap;

	swapalloc.free = conf.nswap;
}

ulong
newswap(void)
{
	char *look;
	int n;

	lock(&swapalloc);
	if(swapalloc.free == 0)
		panic("out of swap space");

	n = swapalloc.top - swapalloc.alloc;
	look = swapalloc.alloc;
	while(n && *look) {
		n--;
		look++;
	}
	if(n == 0) {
		look = swapalloc.swmap;
		while(*look)
			look++;
	}
	if(look == swapalloc.top)
		swapalloc.alloc = swapalloc.swmap;
	else
		swapalloc.alloc = look+1;

	*look = 1;
	unlock(&swapalloc);
	return (look-swapalloc.swmap) * BY2PG; 
}

void
putswap(Page *p)
{
	lock(&swapalloc);
	if(--swapalloc.swmap[((ulong)p)/BY2PG] == 0)
		swapalloc.free++;
	unlock(&swapalloc);
}

void
dupswap(Page *p)
{
	lock(&swapalloc);
	swapalloc.swmap[((ulong)p)/BY2PG]++;
	unlock(&swapalloc);
}

void
kickpager(void)
{
	static int started;

	if(started)
		wakeup(&swapalloc.r);
	else {
		kproc("pager", pager, 0);
		started = 1;
	}
}

void
pager(void *junk)
{
	Proc *p, *ep;
	Segment *s;
	int i;

	p = proctab(0);
	ep = &p[conf.nproc];
	for(;;) {
		if(waserror()) 
			panic("pager: os error\n");

		for(p = proctab(0); p < ep; p++) {
			if(p->state == Dead || p->kp)
				continue;

			sleep(&swapalloc.r, needpages, 0);

			if(swapimage.c) {
				for(i = 0; i < NSEG; i++)
					if(s = p->seg[i]) {
						pageout(p, s);
						executeio();
					}
			}
			else {
				/* Emulate the old system if no swap channel */
				print("no physical memory\n");
				pprint("no physical memory\n");
				tsleep(&swapalloc.r, return0, 0, 1000);
				wakeup(&palloc.r);
			}
		}

		poperror();
	}
}

void			
pageout(Proc *p, Segment *s)
{
	Pte **sm, **endsm;
	Page **pg, **epg;
	int type;

	if(!canqlock(&s->lk))	/* We cannot afford to wait, we will surely deadlock */
		return;

	if(!canflush(p, s) || s->steal) {
		qunlock(&s->lk);
		putseg(s);
		return;
	}

	if(waserror()) {
		qunlock(&s->lk);
		putseg(s);
		return;
	}

	/* 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;
				}
		}

	poperror();
	qunlock(&s->lk);
	putseg(s);

	wakeup(&palloc.r);
}

int
canflush(Proc *p, Segment *s)
{
	Proc *ep;
	int i;

	lock(s);
	if(s->ref == 1) {		/* Easy if we are the only user */
		s->ref++;
		unlock(s);
		return canpage(p);
	}
	s->ref++;
	unlock(s);

	/* Now we must do hardwork to ensure all processes which have tlb
	 * entries for this segment are flushed
	 */
	p = proctab(0);
	ep = &p[conf.nproc];
	for(; p < ep; p++)
		if(p->state != Dead)
			for(i = 0; i < NSEG; i++)
				if(p->seg[i] == s)
					if(!canpage(p))
						return 0;
	return 1;						
}

int
pagepte(int type, Segment *s, Page **pg)
{
	ulong daddr;
	char *kaddr;
	int n;
	Chan *c;
	Page *outp;
	KMap *k;

	outp = *pg;

	switch(type) {
	case SG_TEXT:					/* Revert to demand load */
		putpage(outp);
		*pg = 0;
		break;
	case SG_DATA:
		/* Unmodified data may be reverted to a demand load record if it
		 * is not the last page in the DSEG
		 */
/*							BUG: needs to check the last page
		if((outp->modref&PG_MOD) == 0) {
			putpage(outp);
			*pg = 0;
			break;
		}
*/
							/* NO break */	
	case SG_BSS:
	case SG_STACK:
	case SG_SHARED:
		lockpage(outp);
		outp->ref++;
		uncachepage(outp);
		unlockpage(outp);

		daddr = newswap();
		outp->daddr = daddr;

		/* Enter swap page into cache before segment is unlocked so that
		 * a fault will cause a cache recovery rather than a pagein on a
		 * partially written block.
		 */
		cachepage(outp, &swapimage);
		*pg = (Page*)(daddr|PG_ONSWAP);

		/* Add me to IO transaction list */
		iolist[ioptr++] = outp;
	}

	return 1;
}

void
executeio(void)
{
	Page *out;
	int i, n;
	Chan *c;
	char *kaddr;
	KMap *k;

	c = swapimage.c;

	for(i = 0; i < ioptr; i++) {
		out = iolist[i];
		if(out->ref > 2) {
			lockpage(out);
			if(out->ref > 2) {		/* Page was reclaimed, abort io */
				out->ref -= 2;
				unlockpage(out);
				continue;
			}
			unlockpage(out);
		}
		k = kmap(out);
		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");

		n = (*devtab[c->type].write)(c, kaddr, BY2PG, out->daddr);
		if(n != BY2PG)
			nexterror();

		qunlock(&c->wrl);
		kunmap(k);
		poperror();

		/* Free up the page after I/O */
		lockpage(out);
		out->ref--;
		unlockpage(out);
		putpage(out);
	}

	ioptr = 0;
}

int
needpages(void *p)
{
	return palloc.freecount < HIGHWATER+MAXHEADROOM;
}

void
setswapchan(Chan *c)
{
	if(swapimage.c) {
		if(swapalloc.free != conf.nswap)
			errors("swap channel busy");
		close(swapimage.c);
	}
	incref(c);
	swapimage.c = c;
}

.
## diffname port/swap.c 1991/0706
## diff -e /n/bootesdump/1991/0705/sys/src/9/port/swap.c /n/bootesdump/1991/0706/sys/src/9/port/swap.c
199c
	 * entries for this segment will be flushed if we suceed in pageing it out
.
20c
	Maxpages = 500,		/* Max number of pageouts per segment pass */
.
12d
## diffname port/swap.c 1991/0720
## diff -e /n/bootesdump/1991/0706/sys/src/9/port/swap.c /n/bootesdump/1991/0720/sys/src/9/port/swap.c
127d
## diffname port/swap.c 1991/0726
## diff -e /n/bootesdump/1991/0720/sys/src/9/port/swap.c /n/bootesdump/1991/0726/sys/src/9/port/swap.c
116a
			if(p->state == Dead || p->kp)
				continue;
.
## diffname port/swap.c 1991/0727
## diff -e /n/bootesdump/1991/0726/sys/src/9/port/swap.c /n/bootesdump/1991/0727/sys/src/9/port/swap.c
126c
			else 
			if(palloc.freecount < HIGHWATER) {
.
## diffname port/swap.c 1991/0926
## diff -e /n/bootesdump/1991/0727/sys/src/9/port/swap.c /n/bootesdump/1991/0926/sys/src/9/port/swap.c
115a
			u->p->psstate = "Pageout";
.
114a
			u->p->psstate = "Idle";
.
## diffname port/swap.c 1991/0928
## diff -e /n/bootesdump/1991/0926/sys/src/9/port/swap.c /n/bootesdump/1991/0928/sys/src/9/port/swap.c
63a
	swapalloc.free--;
.
## diffname port/swap.c 1991/1115
## diff -e /n/bootesdump/1991/0928/sys/src/9/port/swap.c /n/bootesdump/1991/1115/sys/src/9/port/swap.c
322a
	USED(p);
.
105a
	USED(junk);
.
## diffname port/swap.c 1992/0111
## diff -e /n/bootesdump/1991/1115/sys/src/9/port/swap.c /n/bootesdump/1992/0111/sys/src/9/port/swap.c
7c
#include	"../port/error.h"
.
## diffname port/swap.c 1992/0114
## diff -e /n/bootesdump/1992/0111/sys/src/9/port/swap.c /n/bootesdump/1992/0114/sys/src/9/port/swap.c
333c
			error(Einuse);
.
## diffname port/swap.c 1992/0120
## diff -e /n/bootesdump/1992/0114/sys/src/9/port/swap.c /n/bootesdump/1992/0120/sys/src/9/port/swap.c
6d
## diffname port/swap.c 1992/0130
## diff -e /n/bootesdump/1992/0120/sys/src/9/port/swap.c /n/bootesdump/1992/0130/sys/src/9/port/swap.c
130a
				/* Rob made me do it ! */
				if(conf.cntrlp == 0)
					freebroken();

.
## diffname port/swap.c 1992/0301
## diff -e /n/bootesdump/1992/0130/sys/src/9/port/swap.c /n/bootesdump/1992/0301/sys/src/9/port/swap.c
295a
#endif
.
289c
			if(out->ref > 2) {	
.
286a
#ifdef asdf
.
238,248d
116,121d
111a
		u->p->psstate = "Idle";
		sleep(&swapalloc.r, needpages, 0);
		u->p->psstate = "Pageout";

.
18c
	Maxpages = 300,		/* Max number of pageouts per segment pass */
.
## diffname port/swap.c 1992/0302
## diff -e /n/bootesdump/1992/0301/sys/src/9/port/swap.c /n/bootesdump/1992/0302/sys/src/9/port/swap.c
289,291d
255a
		scavenge++;
.
234a

.
233a
		scavenge++;
.
229c
print("outp: %lux\n", *pg);
.
214a
		}
		p++;
	}

.
209,210c
	while(p < ep) {
		if(p->state != Dead) {
.
185d
181a
			if(ioptr >= Maxpages)
				goto out;
		}
	}
out:
	
	print("%s: %d: type %s %d pages\n", p->text, p->pid, sname[type], scavenge);
.
169,180c
	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);
.
165a
	scavenge = 0;

.
149a
extern char *sname[];
.
147,148c
	Pte **sm, **endsm, *l;
	Page **pg, *entry;
.
24a
int	scavenge;
.
18c
	Maxpages = 100,		/* Max number of pageouts per segment pass */
.
## diffname port/swap.c 1992/0303
## diff -e /n/bootesdump/1992/0302/sys/src/9/port/swap.c /n/bootesdump/1992/0303/sys/src/9/port/swap.c
333c
	return palloc.freecount < swapalloc.headroom;
.
293,303c

.
245d
242d
238,240d
193,194c
	DBG("%s: %d: %5s s %d nr %d fr %d\n", 
	p->text, p->pid, sname[type], scavenge, nr, palloc.freecount);

.
184d
181,182c

			if(entry->modref & PG_REF)
.
177a
			nr++;
.
168a
	nr = 0;
.
161a
	if(!canflush(p, s)) {
		qunlock(&s->lk);
		putseg(s);
		return;
	}

.
156c
	if(s->steal) {
.
152a

.
150c
	int type, nr;
.
142a
	goto loop;
.
141c
			/* Emulate the old system if no swap channel */
			print("no physical memory\n");
			tsleep(&swapalloc.r, return0, 0, 1000);
			wakeup(&palloc.r);
		}
.
139a
		else 
		if(palloc.freecount < swapalloc.highwater) {
			/* Rob made me do it ! */
			if(conf.cntrlp == 0)
				freebroken();
.
134,137c
		if(swapimage.c) {
			for(i = 0; i < NSEG; i++) {
				if(!needpages(junk))
					goto loop;
				if(s = p->seg[i]) {
					pageout(p, s);
					executeio();
				}
.
121,132c
		if(p->state == Dead || p->kp)
			continue;
.
117,119c
	for(;;) {
		p++;
		if(p > ep)
			p = proctab(0);
.
113,115c
loop:
	u->p->psstate = "Idle";
	sleep(&swapalloc.r, needpages, 0);
	u->p->psstate = "Pageout";
.
109,111d
105a
	if(waserror()) 
		panic("pager: os error\n");

.
20a
#define DBG	if(1)print

.
18c
	Maxpages = 500,		/* Max number of pageouts per segment pass */
.
## diffname port/swap.c 1992/0304
## diff -e /n/bootesdump/1992/0303/sys/src/9/port/swap.c /n/bootesdump/1992/0304/sys/src/9/port/swap.c
327d
288,289d
286d
262d
251c
void
.
209,211d
194d
183,185d
171c
	if(!canflush(p, s)) {	/* Able to invalidate all tlbs with references */
.
165c
	if(s->steal) {		/* Protected by /dev/proc */
.
161d
158,159c
	int type;
.
133,134c
					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();
					}
.
106c
	int i, type;
.
27d
21,22d
10c
void	pagepte(int, Segment*, Page**);
.
## diffname port/swap.c 1992/0307
## diff -e /n/bootesdump/1992/0304/sys/src/9/port/swap.c /n/bootesdump/1992/0307/sys/src/9/port/swap.c
265a
	case SG_SHDATA:
.
## diffname port/swap.c 1992/0321
## diff -e /n/bootesdump/1992/0307/sys/src/9/port/swap.c /n/bootesdump/1992/0321/sys/src/9/port/swap.c
2c
#include	"../port/lib.h"
.
## diffname port/swap.c 1992/0619
## diff -e /n/bootesdump/1992/0321/sys/src/9/port/swap.c /n/bootesdump/1992/0619/sys/src/9/port/swap.c
29c
	swapalloc.swmap = xalloc(conf.nswap);
.
## diffname port/swap.c 1992/0625
## diff -e /n/bootesdump/1992/0619/sys/src/9/port/swap.c /n/bootesdump/1992/0625/sys/src/9/port/swap.c
319c
		unlock(out);
.
317c
		lock(out);
.
270c
		unlock(outp);
.
267c
		lock(outp);
.
## diffname port/swap.c 1992/0628
## diff -e /n/bootesdump/1992/0625/sys/src/9/port/swap.c /n/bootesdump/1992/0628/sys/src/9/port/swap.c
278a
		outp->daddr = daddr;
.
272,274d
266a
		daddr = newswap();

.
128a

.
119c
		if(p >= ep)
.
46,60c
	look = memchr(swapalloc.swmap, 0, conf.nswap);
	if(look == 0)
		panic("inconsistant swap");
.
40d
## diffname port/swap.c 1992/0629
## diff -e /n/bootesdump/1992/0628/sys/src/9/port/swap.c /n/bootesdump/1992/0629/sys/src/9/port/swap.c
256c
		cachedel(&swapimage, daddr);
.
## diffname port/swap.c 1992/0711
## diff -e /n/bootesdump/1992/0629/sys/src/9/port/swap.c /n/bootesdump/1992/0711/sys/src/9/port/swap.c
238c
pagepte(int type, Page **pg)
.
191c
				pagepte(type, pg);
.
10c
void	pagepte(int, Page**);
.
## diffname port/swap.c 1992/0725
## diff -e /n/bootesdump/1992/0711/sys/src/9/port/swap.c /n/bootesdump/1992/0725/sys/src/9/port/swap.c
135,137c
			if(!cpuserver)
				freebroken();	/* can use the memory */
.
## diffname port/swap.c 1992/0804
## diff -e /n/bootesdump/1992/0725/sys/src/9/port/swap.c /n/bootesdump/1992/0804/sys/src/9/port/swap.c
271a
	npage++;
.
143a
	if(npage == 0)
		print("swap: pass took no pages\n");
.
103a
	npage = 0;
.
24c
int	ioptr, npage;
.
## diffname port/swap.c 1992/0805
## diff -e /n/bootesdump/1992/0804/sys/src/9/port/swap.c /n/bootesdump/1992/0805/sys/src/9/port/swap.c
275d
235d
210a
	Proc *ep;
.
209d
194a
			pagepte(type, pg);

.
192,193c
				continue;
			}
.
190c
			if(entry->modref & PG_REF) {
.
180,182c
	for(i = 0; i < SEGMAPSIZE; i++) {
		l = s->map[i];
.
155d
153c
	int type, i;
	Pte *l;
.
145,146d
134c

.
132a
			continue;
.
129c
						if(ioptr != 0) {
							u->p->psstate = "I/O";
							executeio();
						}
.
127a
						u->p->psstate = "Pageout";
.
123a
						pageout(p, s);
						break;
.
119,120c
					switch(s->type&SG_TYPE) {
.
104d
102d
90c
	int i;
.
24c
int	ioptr;
.
## diffname port/swap.c 1992/0825
## diff -e /n/bootesdump/1992/0805/sys/src/9/port/swap.c /n/bootesdump/1992/0825/sys/src/9/port/swap.c
335d
304d
295d
## diffname port/swap.c 1992/0905
## diff -e /n/bootesdump/1992/0825/sys/src/9/port/swap.c /n/bootesdump/1992/0905/sys/src/9/port/swap.c
18c
	Maxpages = 500,	/* Max number of pageouts per segment pass */
.
## diffname port/swap.c 1992/0910
## diff -e /n/bootesdump/1992/0905/sys/src/9/port/swap.c /n/bootesdump/1992/0910/sys/src/9/port/swap.c
164d
21,24c
	Image 	swapimage;
static 	int	swopen;
static	Page	*iolist[Maxpages];
static	int	ioptr;
.
13,14d
11d
8c
int	canflush(Proc *p, Segment*);
void	executeio(void);
int	needpages(void*);
.
## diffname port/swap.c 1992/0912
## diff -e /n/bootesdump/1992/0910/sys/src/9/port/swap.c /n/bootesdump/1992/0912/sys/src/9/port/swap.c
59a
	if(idx < swapalloc.last)
		swapalloc.last = idx;
.
58c
	idx = &swapalloc.swmap[((ulong)p)/BY2PG];
	if(--(*idx) == 0)
.
56a
	uchar *idx;

.
48a
	swapalloc.last = look;
.
46,47c
		panic("inconsistent swap");
	
.
44c
	look = memchr(swapalloc.last, 0, swapalloc.top-swapalloc.last);
.
38c
	uchar *look;
.
31c
	swapalloc.last = swapalloc.swmap;
.
## diffname port/swap.c 1992/0913
## diff -e /n/bootesdump/1992/0912/sys/src/9/port/swap.c /n/bootesdump/1992/0913/sys/src/9/port/swap.c
296d
64,65c
		if(idx < swapalloc.last)
			swapalloc.last = idx;
	}
.
62c
	if(--(*idx) == 0) {
.
## diffname port/swap.c 1992/1209
## diff -e /n/bootesdump/1992/0913/sys/src/9/port/swap.c /n/bootesdump/1992/1209/sys/src/9/port/swap.c
17c
	Maxpages = SEGMAXSIZE/BY2PG,	/* Max # of pageouts per segment pass */
.
## diffname port/swap.c 1993/0103
## diff -e /n/bootesdump/1992/1209/sys/src/9/port/swap.c /n/bootesdump/1993/0103/sys/src/9/port/swap.c
32a
	iolist = xalloc(Maxpages*sizeof(Page*));
	if(swapalloc.swmap == 0 || iolist == 0)
		panic("swapinit: not enough memory");
.
22c
static	Page	**iolist;
.
## diffname port/swap.c 1993/0501
## diff -e /n/bootesdump/1993/0103/sys/src/9/port/swap.c /n/fornaxdump/1993/0501/sys/src/brazil/port/swap.c
139c
							up->psstate = "I/O";
.
136c
						up->psstate = "Pageout";
.
109c
	up->psstate = "Idle";
.
## diffname port/swap.c 1993/0910
## diff -e /n/fornaxdump/1993/0501/sys/src/brazil/port/swap.c /n/fornaxdump/1993/0910/sys/src/brazil/port/swap.c
326c
	for(i = 0; i < NCOLOR; i++)
		if(palloc.freecol[i] < swapalloc.headroom/NCOLOR)
			return 1;
	return 0;
.
324a
	int i;

.
214d
155c
			for(i = 0; i < NCOLOR; i++)
				wakeup(&palloc.r[i]);
.
147,148c
		else {
.
145d
112c
	while(needpages(junk)) {
.
## diffname port/swap.c 1993/1008
## diff -e /n/fornaxdump/1993/0910/sys/src/brazil/port/swap.c /n/fornaxdump/1993/1008/sys/src/brazil/port/swap.c
116a
		/* don't swap out programs from devroot.c */
		if(devchar[p->seg[SG_TEXT]->image->c->type] == '/')
			continue;

.
## diffname port/swap.c 1993/1011
## diff -e /n/fornaxdump/1993/1008/sys/src/brazil/port/swap.c /n/fornaxdump/1993/1011/sys/src/brazil/port/swap.c
118c
		img = p->seg[SG_TEXT]->image;
		if(img && devchar[img->c->type] == '/')
.
99a
	Image *img;
	Segment *s;
	Proc *p, *ep;
.
97,98d
## diffname port/swap.c 1993/1105
## diff -e /n/fornaxdump/1993/1011/sys/src/brazil/port/swap.c /n/fornaxdump/1993/1105/sys/src/brazil/port/swap.c
121,123d
117a
		if(p->state == Dead || p->kp)
			continue;

.
## diffname port/swap.c 1993/1120
## diff -e /n/fornaxdump/1993/1105/sys/src/brazil/port/swap.c /n/fornaxdump/1993/1120/sys/src/brazil/port/swap.c
332,335c
	return palloc.freecount < swapalloc.headroom;
.
329,330d
158,160c
			tsleep(&swapalloc.r, return0, 0, 5000);
			wakeup(&palloc.r);
.
121c
		/* don't swap out programs from devroot.c - they
		 * supply important system services
		 */
.
## diffname port/swap.c 1993/1123
## diff -e /n/fornaxdump/1993/1120/sys/src/brazil/port/swap.c /n/fornaxdump/1993/1123/sys/src/brazil/port/swap.c
156a
			else
				killbig();
.
## diffname port/swap.c 1994/0509
## diff -e /n/fornaxdump/1993/1123/sys/src/brazil/port/swap.c /n/fornaxdump/1994/0509/sys/src/brazil/port/swap.c
264c
	case SG_TEXT:				/* Revert to demand load */
.
## diffname port/swap.c 1994/0817
## diff -e /n/fornaxdump/1994/0509/sys/src/brazil/port/swap.c /n/fornaxdump/1994/0817/sys/src/brazil/port/swap.c
35a

	swapimage.notext = 1;
.
## diffname port/swap.c 1994/0914
## diff -e /n/fornaxdump/1994/0817/sys/src/brazil/port/swap.c /n/fornaxdump/1994/0914/sys/src/brazil/port/swap.c
126c
		img = p->seg[TSEG]->image;
.
## diffname port/swap.c 1995/0319
## diff -e /n/fornaxdump/1994/0914/sys/src/brazil/port/swap.c /n/fornaxdump/1995/0319/sys/src/brazil/port/swap.c
164c
			tsleep(&swapalloc.pause, return0, 0, 5000);
.
123,129d
100d
## diffname port/swap.c 1995/0804
## diff -e /n/fornaxdump/1995/0319/sys/src/brazil/port/swap.c /n/fornaxdump/1995/0804/sys/src/brazil/port/swap.c
326d
324c
needpages(void*)
.
106d
## diffname port/swap.c 1995/0815
## diff -e /n/fornaxdump/1995/0804/sys/src/brazil/port/swap.c /n/fornaxdump/1995/0815/sys/src/brazil/port/swap.c
322c
static int
.
287c
static void
.
249c
static void
.
233c
	 * entries for this segment will be flushed if we succeed in paging it out
.
217c
static int
.
162c
static void			
.
96c
static void
.
8,13c
static int	canflush(Proc*, Segment*);
static void	executeio(void);
static int	needpages(void*);
static void	pageout(Proc*, Segment*);
static void	pagepte(int, Page**);
static void	pager(void*);
.
## diffname port/swap.c 1997/0327
## diff -e /n/fornaxdump/1995/0815/sys/src/brazil/port/swap.c /n/emeliedump/1997/0327/sys/src/brazil/port/swap.c
334c
		cclose(swapimage.c);
.
306c
		n = devtab[c->type]->write(c, kaddr, BY2PG, out->daddr);
.
## diffname port/swap.c 1997/0516
## diff -e /n/emeliedump/1997/0327/sys/src/brazil/port/swap.c /n/emeliedump/1997/0516/sys/src/brazil/port/swap.c
136a
					case SG_MAP:
.
## diffname port/swap.c 1998/0403
## diff -e /n/emeliedump/1997/0516/sys/src/brazil/port/swap.c /n/emeliedump/1998/0403/sys/src/brazil/port/swap.c
337d
334a
		}
.
333c
		if(swapalloc.free != conf.nswap){
			cclose(c);
.
## diffname port/swap.c 1998/0512
## diff -e /n/emeliedump/1998/0403/sys/src/brazil/port/swap.c /n/emeliedump/1998/0512/sys/src/brazil/port/swap.c
247c
	return 1;
.
163c
static void
.
103c
	if(waserror())
.
57c
	return (look-swapalloc.swmap) * BY2PG;
.
52c

.
## diffname port/swap.c 1998/0916
## diff -e /n/emeliedump/1998/0512/sys/src/brazil/port/swap.c /n/emeliedump/1998/0916/sys/src/brazil/port/swap.c
208c
			if(ioptr >= conf.nswppo)
.
192c
	size = s->mapsize;
	for(i = 0; i < size; i++) {
.
166c
	int type, i, size;
.
33c
	iolist = xalloc(conf.nswppo*sizeof(Page*));
.
15,19d
## diffname port/swap.c 1998/1020
## diff -e /n/emeliedump/1998/0916/sys/src/brazil/port/swap.c /n/emeliedump/1998/1020/sys/src/brazil/port/swap.c
280a
		break;
.
263a
	case SG_MAP:
.
138a
						break;
.
131a
					case SG_SHDATA:
.
## diffname port/swap.c 1999/0108
## diff -e /n/emeliedump/1998/1020/sys/src/brazil/port/swap.c /n/emeliedump/1999/0108/sys/src/brazil/port/swap.c
280a
		unlock(outp);
.
272d
266a
		/* if it's already on disk, we're done */
#ifdef asdf
		lock(outp);
		if(outp->daddr != 0 && outp->image == &swapimage){
			dupswap((Page*)outp->daddr);
			*pg = (Page*)(outp->daddr|PG_ONSWAP);
			unlock(outp);
			putpage(outp);
			return;
		}
		unlock(outp);
#endif asdf

.
143a
			qunlock(&p->seglock);
.
119a
				}
.
118c
				if(!needpages(junk)){
					qunlock(&p->seglock);
.
116a
			p++;
			if(p >= ep)
				p = proctab(0);
	
			if(p->state == Dead || p->kp)
				continue;

			qlock(&p->seglock);
.
113,115d
109,111d
77a
int
swapcount(ulong daddr)
{
	return swapalloc.swmap[daddr/BY2PG];
}

.
73a
	if(swapalloc.swmap[((ulong)p)/BY2PG]==255)
		panic("dupswap");
.
62a
		if(swapalloc.swmap[((ulong)p)/BY2PG]==255)
			panic("putswap");
.
## diffname port/swap.c 1999/0109
## diff -e /n/emeliedump/1999/0108/sys/src/brazil/port/swap.c /n/emeliedump/1999/0109/sys/src/brazil/port/swap.c
310c
		/* Add page to IO transaction list */
.
304a
		outp->ref++;

		/*
		 *  enter it into the cache so that a fault happening
		 *  during the write will grab the page from the cache
		 */
.
301,303c
		/*
		 *  incr the reference count to make sure it sticks around while
		 *  being written
.
298c

		/* forget anything that it used to cache */
.
296a

.
294a
		/*
		 *  get a new swap address and clear any pages
		 *  referring to it from the cache
		 */
.
285c
		if(outp->image == &swapimage){
.
282c
		/* if it's already on disk, no need to do io again */
.
78d
76c
	if(++swapalloc.swmap[((ulong)p)/BY2PG] == 0)
.
68a
	if(*idx >= 254)
		panic("putswap %lux == %ud", p, *idx);
.
63,64d
## diffname port/swap.c 1999/0110
## diff -e /n/emeliedump/1999/0109/sys/src/brazil/port/swap.c /n/emeliedump/1999/0110/sys/src/brazil/port/swap.c
356a
		up->psstate = "I/Oput";
.
353a
		up->psstate = "I/Odec";
.
345a
		up->psstate = "I/Owr";
.
339a
		up->psstate = "I/Okm";
.
338a
		if(ioptr > conf.nswppo)
			panic("executeio: ioptr %d > %d\n", ioptr, conf.nswppo);
.
326a
void
pagersummary(void)
{
	print("%lud/%lud memory %lud/%lud swap %d iolist\n",
		palloc.user-palloc.freecount,
		palloc.user, conf.nswap-swapalloc.free, conf.nswap,
		ioptr);
}

.
314a
		 *  rather than one partially written to the disk
.
281,293d
127c
			if(!canqlock(&p->seglock))
				continue;		/* process changing its segments */

.
## diffname port/swap.c 1999/0112
## diff -e /n/emeliedump/1999/0110/sys/src/brazil/port/swap.c /n/emeliedump/1999/0112/sys/src/brazil/port/swap.c
361d
357d
348d
341d
## diffname port/swap.c 1999/0115
## diff -e /n/emeliedump/1999/0112/sys/src/brazil/port/swap.c /n/emeliedump/1999/0115/sys/src/brazil/port/swap.c
378a

	/*
	 *  if this isn't a file, set the swap space
	 *  to be at most the size of the partition
	 */
	if(devtab[c->type]->dc != L'M'){
		devtab[c->type]->stat(c, dirbuf);
		convM2D(dirbuf, &d);
		if(d.length < conf.nswap*BY2PG){
			conf.nswap = d.length/BY2PG;
			swapalloc.top = &swapalloc.swmap[conf.nswap];
			swapalloc.free = conf.nswap;
		}
	}

.
371a
	char dirbuf[DIRLEN];
	Dir d;

.
## diffname port/swap.c 1999/0120
## diff -e /n/emeliedump/1999/0115/sys/src/brazil/port/swap.c /n/emeliedump/1999/0120/sys/src/brazil/port/swap.c
397a
}

int
swapfull(void)
{
	return swapalloc.free < conf.nswap/10;
.
287a
		if(daddr == ~0)
			break;
.
43a
	if(swapalloc.free == 0){
		unlock(&swapalloc);
		return ~0;
	}

.
41,42d
## diffname port/swap.c 2001/0424
## diff -e /n/emeliedump/1999/0120/sys/src/brazil/port/swap.c /n/emeliedump/2001/0424/sys/src/9/port/swap.c
285d
151d
## diffname port/swap.c 2001/0425
## diff -e /n/emeliedump/2001/0424/sys/src/9/port/swap.c /n/emeliedump/2001/0425/sys/src/9/port/swap.c
283d
150d
## diffname port/swap.c 2001/0527
## diff -e /n/emeliedump/2001/0425/sys/src/9/port/swap.c /n/emeliedump/2001/0527/sys/src/9/port/swap.c
389,390c
		n = devtab[c->type]->stat(c, dirbuf, sizeof dirbuf);
		if(n <= 0){
			cclose(c);
			error("stat failed in setswapchan");
		}
		convM2D(dirbuf, n, &d, nil);
.
374a
	int n;
.
373c
	uchar dirbuf[sizeof(Dir)+100];
.
## diffname port/swap.c 2002/0502
## diff -e /n/emeliedump/2001/0527/sys/src/9/port/swap.c /n/emeliedump/2002/0502/sys/src/9/port/swap.c
127c
			if(p->state == Dead || p->noswap)
.
## diffname port/swap.c 2003/0407
## diff -e /n/emeliedump/2002/0502/sys/src/9/port/swap.c /n/emeliedump/2003/0407/sys/src/9/port/swap.c
170c
			tsleep(&up->sleep, return0, 0, 5000);
.

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].