summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordfr <dfr@FreeBSD.org>2001-09-10 07:03:59 +0000
committerdfr <dfr@FreeBSD.org>2001-09-10 07:03:59 +0000
commite755df50cdab297b9941b9905f4a24a65249636c (patch)
tree0eda994f18ff567f154e8487527d9bc599905725
parent4ee6142f0a8ecb5ebf2ef76f93cbaf094eb5753d (diff)
downloadFreeBSD-src-e755df50cdab297b9941b9905f4a24a65249636c.zip
FreeBSD-src-e755df50cdab297b9941b9905f4a24a65249636c.tar.gz
Implement support for MAXMEM option and hw.physmem environment variable
which can be used to artificially reduce the memory size of a machine for debugging (or other) purposes.
-rw-r--r--sys/alpha/alpha/machdep.c55
-rw-r--r--sys/conf/options.alpha2
2 files changed, 57 insertions, 0 deletions
diff --git a/sys/alpha/alpha/machdep.c b/sys/alpha/alpha/machdep.c
index 3b62476..04aa677 100644
--- a/sys/alpha/alpha/machdep.c
+++ b/sys/alpha/alpha/machdep.c
@@ -92,6 +92,7 @@
#include "opt_ddb.h"
#include "opt_simos.h"
#include "opt_msgbuf.h"
+#include "opt_maxmem.h"
#include <sys/param.h>
#include <sys/systm.h>
@@ -805,6 +806,60 @@ alpha_init(pfn, ptb, bim, bip, biv)
Maxmem = physmem;
+#ifdef MAXMEM
+ /*
+ * MAXMEM define is in kilobytes.
+ */
+ Maxmem = alpha_btop(MAXMEM * 1024);
+#endif
+
+ /*
+ * hw.physmem is a size in bytes; we also allow k, m, and g suffixes
+ * for the appropriate modifiers. This overrides MAXMEM.
+ */
+ if ((p = getenv("hw.physmem")) != NULL) {
+ u_int64_t AllowMem, sanity;
+ char *ep;
+
+ sanity = AllowMem = strtouq(p, &ep, 0);
+ if ((ep != p) && (*ep != 0)) {
+ switch(*ep) {
+ case 'g':
+ case 'G':
+ AllowMem <<= 10;
+ case 'm':
+ case 'M':
+ AllowMem <<= 10;
+ case 'k':
+ case 'K':
+ AllowMem <<= 10;
+ break;
+ default:
+ AllowMem = sanity = 0;
+ }
+ if (AllowMem < sanity)
+ AllowMem = 0;
+ }
+ if (AllowMem == 0)
+ printf("Ignoring invalid memory size of '%s'\n", p);
+ else
+ Maxmem = alpha_btop(AllowMem);
+ }
+
+ while (physmem > Maxmem) {
+ int i = phys_avail_cnt - 2;
+ size_t sz = alpha_btop(phys_avail[i+1] - phys_avail[i]);
+ size_t nsz;
+ if (physmem - sz > Maxmem) {
+ phys_avail[i] = 0;
+ phys_avail_cnt -= 2;
+ } else {
+ nsz = sz - (physmem - Maxmem);
+ phys_avail[i+1] = phys_avail[i] + alpha_ptob(nsz);
+ physmem -= (sz - nsz);
+ }
+ }
+
/*
* Initialize error message buffer (at end of core).
*/
diff --git a/sys/conf/options.alpha b/sys/conf/options.alpha
index 5422f00..e44a198 100644
--- a/sys/conf/options.alpha
+++ b/sys/conf/options.alpha
@@ -18,6 +18,8 @@ DEC_3000_500 opt_cpu.h
DEC_1000A opt_cpu.h
API_UP1000 opt_cpu.h
+MAXMEM
+
PPC_PROBE_CHIPSET opt_ppc.h
PPC_DEBUG opt_ppc.h
OpenPOWER on IntegriCloud