shithub: plan9front

Download patch

ref: e7715ce2c669fd4ac95dec7851c71136aeb0053f
parent: a22697039dfb531634f084e28517e60c766fa9dd
author: Noam Preil <noam@pixelhero.dev>
date: Sun Jun 20 23:52:09 EDT 2021

venti: fix detection of available RAM (fixes -m)

--- a/sys/src/cmd/venti/srv/venti.c	Sun Jun 20 23:49:42 2021
+++ b/sys/src/cmd/venti/srv/venti.c	Sun Jun 20 23:52:09 2021
@@ -35,7 +35,7 @@
 	Biobuf *bp;
 
 	size = 64*1024*1024;
-	bp = Bopen("#c/swap", OREAD);
+	bp = Bopen("/dev/swap", OREAD);
 	if (bp != nil) {
 		while ((ln = Brdline(bp, '\n')) != nil) {
 			ln[Blinelen(bp)-1] = '\0';
@@ -57,8 +57,17 @@
 			size = (userpgs - userused) * pgsize;
 	}
 	/* cap it to keep the size within 32 bits */
-	if (size >= 3840UL * 1024 * 1024)
+	if (size >= 3840UL * 1024 * 1024){
 		size = 3840UL * 1024 * 1024;
+		fprint(2, "%s: Reduced free memory detected to 3840MiB because we don't support 64-bit addresses yet.\n", argv0);
+	}
+	/* FIXME: we use signed 32-bit integers in some places for some fucking reason. 
+	   Limiting accordingly for now.
+	*/
+	if (size >= 2047UL * 1024 * 1024){
+		size = 2047UL * 1024 * 1024;
+		fprint(2, "%s: Reduced free memory detected to 2047MiB because we have bugz.\n", argv0);
+	}
 	return size;
 }
 
@@ -97,9 +106,9 @@
 		fprint(2, "%s: bloom filter bigger than mem pcnt; "
 			"resorting to minimum values (9MB total)\n", argv0);
 	else {
-		if (avail >= 3840UL * 1024 * 1024){
-			avail = 3840UL * 1024 * 1024;	/* sanity */
-			fprint(2, "%s: restricting memory usage to 3840MiB\n", argv0);
+		if (avail >= 2047UL * 1024 * 1024){
+			avail = 2047UL * 1024 * 1024;	/* sanity */
+			fprint(2, "%s: restricting memory usage to 2047MiB\n", argv0);
 		}
 		avail /= 2;
 		all.icmem = avail;