1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-15 10:17:20 +00:00

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.
This commit is contained in:
Doug Rabson 2001-09-10 07:03:59 +00:00
parent e061a6ca19
commit 9a905b8b26
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=83279
2 changed files with 57 additions and 0 deletions

View File

@ -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).
*/

View File

@ -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