shithub: riscv

Download patch

ref: 3b2b18328b6d6e9fb8005c28d8abce59c4bc44e0
parent: a24626c51f894e0976d2eadbcb93cc337a50fafc
author: cinap_lenrek <[email protected]>
date: Thu May 17 22:01:04 EDT 2012

cwfs: add fsmempercent enviroment variable to control iobuffer allocation

--- a/sys/man/4/cwfs
+++ b/sys/man/4/cwfs
@@ -303,6 +303,15 @@
 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
--- a/sys/src/cmd/cwfs/malloc.c
+++ b/sys/src/cmd/cwfs/malloc.c
@@ -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 @@
 void
 iobufinit(void)
 {
-	long m;
 	int i;
 	char *xiop;
 	Iobuf *p, *q;
@@ -74,8 +79,7 @@
 	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++;