cwfs: add fsmempercent enviroment variable to control iobuffer allocation
parent
a24626c51f
commit
3b2b18328b
|
@ -303,6 +303,15 @@ number and byte order; if either is wrong, it will issue a warning.
|
|||
If the label cannot be read,
|
||||
.I cwfs
|
||||
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
|
||||
Place the root of the
|
||||
.B dump
|
||||
|
|
|
@ -4,34 +4,40 @@
|
|||
static ulong
|
||||
memsize(void)
|
||||
{
|
||||
int nf, pgsize = 0;
|
||||
ulong userpgs = 0, userused = 0;
|
||||
char *ln, *sl;
|
||||
char *fields[2];
|
||||
ulong pgsize, userpgs, userused;
|
||||
char *s, *f[2];
|
||||
int n, mpcnt;
|
||||
Biobuf *bp;
|
||||
|
||||
bp = Bopen("#c/swap", OREAD);
|
||||
if (bp != nil) {
|
||||
while ((ln = Brdline(bp, '\n')) != nil) {
|
||||
ln[Blinelen(bp)-1] = '\0';
|
||||
nf = tokenize(ln, fields, nelem(fields));
|
||||
if (nf != 2)
|
||||
mpcnt = 25;
|
||||
pgsize = userpgs = userused = 0;
|
||||
if(bp = Bopen("#c/swap", OREAD)) {
|
||||
while(s = Brdline(bp, '\n')) {
|
||||
if((n = Blinelen(bp)) < 1)
|
||||
continue;
|
||||
if (strcmp(fields[1], "pagesize") == 0)
|
||||
pgsize = atoi(fields[0]);
|
||||
else if (strcmp(fields[1], "user") == 0) {
|
||||
sl = strchr(fields[0], '/');
|
||||
if (sl == nil)
|
||||
continue;
|
||||
userpgs = atol(sl+1);
|
||||
userused = atol(fields[0]);
|
||||
s[n-1] = '\0';
|
||||
if(tokenize(s, f, nelem(f)) != 2)
|
||||
continue;
|
||||
if(strcmp(f[1], "pagesize") == 0)
|
||||
pgsize = strtoul(f[0], 0, 0);
|
||||
else if(strcmp(f[1], "user") == 0) {
|
||||
userused = strtoul(f[0], &s, 0);
|
||||
if(*s == '/')
|
||||
userpgs = strtoul(s+1, 0, 0);
|
||||
}
|
||||
}
|
||||
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
|
||||
iobufinit(void)
|
||||
{
|
||||
long m;
|
||||
int i;
|
||||
char *xiop;
|
||||
Iobuf *p, *q;
|
||||
|
@ -74,8 +79,7 @@ iobufinit(void)
|
|||
wlock(&mainlock); /* init */
|
||||
wunlock(&mainlock);
|
||||
|
||||
m = memsize() / 4;
|
||||
niob = m / (sizeof(Iobuf) + RBUFSIZE + sizeof(Hiob)/HWIDTH);
|
||||
niob = memsize() / (sizeof(Iobuf) + RBUFSIZE + sizeof(Hiob)/HWIDTH);
|
||||
nhiob = niob / HWIDTH;
|
||||
while(!prime(nhiob))
|
||||
nhiob++;
|
||||
|
|
Loading…
Reference in New Issue