cwfs: add fsmempercent enviroment variable to control iobuffer allocation

This commit is contained in:
cinap_lenrek 2012-05-18 02:01:04 +02:00
parent a24626c51f
commit 3b2b18328b
2 changed files with 37 additions and 24 deletions

View file

@ -303,6 +303,15 @@ number and byte order; if either is wrong, it will issue a warning.
If the label cannot be read, If the label cannot be read,
.I cwfs .I cwfs
will attempt to write a new label. will attempt to write a new label.
.PP
The original file server reserved the rest of the machines RAM for
io buffers. Where
.I cwfs
running under the Plan 9 kernel reserves a settable percentage
of the remaining user pages. The percentage is read from the
enviroment variable
.B fsmempercent
which when not set is assumed to be 25% (default).
.SH EXAMPLES .SH EXAMPLES
Place the root of the Place the root of the
.B dump .B dump

View file

@ -4,34 +4,40 @@
static ulong static ulong
memsize(void) memsize(void)
{ {
int nf, pgsize = 0; ulong pgsize, userpgs, userused;
ulong userpgs = 0, userused = 0; char *s, *f[2];
char *ln, *sl; int n, mpcnt;
char *fields[2];
Biobuf *bp; Biobuf *bp;
bp = Bopen("#c/swap", OREAD); mpcnt = 25;
if (bp != nil) { pgsize = userpgs = userused = 0;
while ((ln = Brdline(bp, '\n')) != nil) { if(bp = Bopen("#c/swap", OREAD)) {
ln[Blinelen(bp)-1] = '\0'; while(s = Brdline(bp, '\n')) {
nf = tokenize(ln, fields, nelem(fields)); if((n = Blinelen(bp)) < 1)
if (nf != 2)
continue; continue;
if (strcmp(fields[1], "pagesize") == 0) s[n-1] = '\0';
pgsize = atoi(fields[0]); if(tokenize(s, f, nelem(f)) != 2)
else if (strcmp(fields[1], "user") == 0) { continue;
sl = strchr(fields[0], '/'); if(strcmp(f[1], "pagesize") == 0)
if (sl == nil) pgsize = strtoul(f[0], 0, 0);
continue; else if(strcmp(f[1], "user") == 0) {
userpgs = atol(sl+1); userused = strtoul(f[0], &s, 0);
userused = atol(fields[0]); if(*s == '/')
userpgs = strtoul(s+1, 0, 0);
} }
} }
Bterm(bp); Bterm(bp);
if (pgsize > 0 && userused < userpgs)
return (userpgs - userused)*pgsize;
} }
return 64*MB; if(pgsize && userused < userpgs){
if(s = getenv("fsmempercent")){
mpcnt = atoi(s);
free(s);
}
if(mpcnt < 1)
mpcnt = 1;
return ((userpgs-userused)*mpcnt/100)*pgsize;
}
return 16*MB;
} }
@ -65,7 +71,6 @@ enum { HWIDTH = 8 }; /* buffers per hash */
void void
iobufinit(void) iobufinit(void)
{ {
long m;
int i; int i;
char *xiop; char *xiop;
Iobuf *p, *q; Iobuf *p, *q;
@ -74,8 +79,7 @@ iobufinit(void)
wlock(&mainlock); /* init */ wlock(&mainlock); /* init */
wunlock(&mainlock); wunlock(&mainlock);
m = memsize() / 4; niob = memsize() / (sizeof(Iobuf) + RBUFSIZE + sizeof(Hiob)/HWIDTH);
niob = m / (sizeof(Iobuf) + RBUFSIZE + sizeof(Hiob)/HWIDTH);
nhiob = niob / HWIDTH; nhiob = niob / HWIDTH;
while(!prime(nhiob)) while(!prime(nhiob))
nhiob++; nhiob++;