commit 50d84c943c3db176796d42c468735d2d6bb87c55
parent 4aeb57b201557db9ea9aada9700db91e23cca0ea
Author: Jesus Galan Lopez (yiyus) <yiyu.jgl@gmail.com>
Date: Mon, 21 Jun 2010 19:25:48 +0200
-m option to set memory size
Diffstat:
4 files changed, 34 insertions(+), 14 deletions(-)
diff --git a/src/9vx/a/devether.c b/src/9vx/a/devether.c
@@ -10,7 +10,7 @@
#include "etherif.h"
-#define MEMSIZE (256<<20) // same as ../mmu.c:29 (TODO: var)
+extern int memsize;
static Ether *etherxx[MaxEther];
@@ -433,7 +433,7 @@ etherprobe(int cardno, int ctlrno)
lg = 14;
/* allocate larger output queues for higher-speed interfaces */
bsz = 1UL << (lg + 17); /* 2ⁱ⁷ = 128K, bsz = 2ⁿ × 128K */
- while (bsz > MEMSIZE && bsz >= 128*1024)
+ while (bsz > memsize && bsz >= 128*1024)
bsz /= 2;
netifinit(ðer->ni, name, Ntypes, bsz);
diff --git a/src/9vx/a/portfns.h b/src/9vx/a/portfns.h
@@ -409,4 +409,4 @@ Proc* _runproc(void);
void uartecho(char*, int);
void vx32sysr1(void);
void vxnewproc(Proc*);
-
+void mmusize(int);
diff --git a/src/9vx/main.c b/src/9vx/main.c
@@ -85,7 +85,7 @@ void
usage(void)
{
// TODO(yy): add debug and other options by ron
- fprint(2, "usage: 9vx [-p file.ini] [-bfgit] [-n [tap] [netdev]] [-a macaddr] [-r root] [-u user]\n");
+ fprint(2, "usage: 9vx [-p file.ini] [-bfgit] [-m memsize] [-n [tap] [netdev]] [-a macaddr] [-r root] [-u user]\n");
exit(1);
}
@@ -97,6 +97,7 @@ nop(void)
int
main(int argc, char **argv)
{
+ int memsize;
int vetap;
char *vedev;
char buf[1024];
@@ -105,11 +106,12 @@ main(int argc, char **argv)
setmach(&mach0);
coherence = nop;
quotefmtinstall();
-
+
+ memsize = 0;
nogui = 0;
nofork = 0;
- usetty = 0;
nve = 0;
+ usetty = 0;
localroot = nil;
ARGBEGIN{
/* debugging options */
@@ -161,6 +163,9 @@ main(int argc, char **argv)
case 'p':
inifile = EARGF(usage());
break;
+ case 'm':
+ memsize = atoi(EARGF(usage()));
+ break;
case 'n':
vetap = 0;
vedev = ARGF();
@@ -212,6 +217,8 @@ main(int argc, char **argv)
if(eve == nil)
panic("strdup eve");
+ mmusize(memsize);
+
mach0init();
mmuinit();
confinit();
@@ -244,6 +251,8 @@ main(int argc, char **argv)
if(bootboot | nofork | nogui | initrc | usetty)
print("-%s%s%s%s%s ", bootboot ? "b" : "", nofork ? "f " : "",
nogui ? "g" : "", initrc ? "i " : "", usetty ? "t " : "");
+ if(memsize != 0)
+ print("-m %i", memsize);
for(int i=0; i<nve; i++){
print("-n %s", ve[i].tap ? "tap ": "");
if(ve[i].dev != nil)
diff --git a/src/9vx/mmu.c b/src/9vx/mmu.c
@@ -25,8 +25,10 @@ int tracemmu;
* so that kernel 0 = user 0, so that pointers can be shared.
* Plan 9 assumes this, and while it's not a ton of work to break that
* assumption, it was easier not to.
+ *
+ * This value may be changed with the -m switch.
*/
-#define MEMSIZE (256<<20) // same as ../a/devether.c:13 (TODO: var)
+int memsize = (256<<20);
static int pagefile;
static char* pagebase;
@@ -108,13 +110,13 @@ mmuinit(void)
if((pagefile = mkstemp(tmp)) < 0)
panic("mkstemp: %r");
- if(ftruncate(pagefile, MEMSIZE) < 0)
+ if(ftruncate(pagefile, memsize) < 0)
panic("ftruncate pagefile: %r");
unlink(tmp); /* "remove on close" */
/* Map pages for direct access at pagebase, wherever that is */
/* MAP_SHARED means write the changes back to the file */
- v = mmap(nil, MEMSIZE, PROT_READ|PROT_WRITE,
+ v = mmap(nil, memsize, PROT_READ|PROT_WRITE,
MAP_SHARED, pagefile, 0);
if(v == MAP_FAILED)
panic("mmap pagefile: %r");
@@ -132,10 +134,10 @@ mmuinit(void)
}
conf.mem[0].base = 0;
- conf.mem[0].npage = MEMSIZE / BY2PG;
+ conf.mem[0].npage = memsize / BY2PG;
palloc.mem[0].base = 0;
- palloc.mem[0].npage = MEMSIZE / BY2PG;
+ palloc.mem[0].npage = memsize / BY2PG;
}
/*
@@ -145,14 +147,14 @@ mmuinit(void)
void*
tmpmap(Page *pg)
{
- assert(pg->pa < MEMSIZE);
+ assert(pg->pa < memsize);
return pagebase + pg->pa;
}
void
tmpunmap(void *v)
{
- assert(pagebase <= (char*)v && (char*)v < pagebase + MEMSIZE);
+ assert(pagebase <= (char*)v && (char*)v < pagebase + memsize);
}
KMap*
@@ -214,7 +216,7 @@ putmmu(ulong va, ulong pa, Page *p)
if(tracemmu || (pa&~(PTEWRITE|PTEVALID)) != p->pa)
iprint("putmmu va %lux pa %lux p->pa %lux\n", va, pa, p->pa);
- assert(p->pa < MEMSIZE && pa < MEMSIZE);
+ assert(p->pa < memsize && pa < memsize);
assert(up);
us = up->pmmu.us;
assert(us);
@@ -387,3 +389,12 @@ printlinuxmaps(void)
sprint(buf, "cat /proc/%d/maps", getpid());
system(buf);
}
+
+void
+mmusize(int size)
+{
+ static int set = 0;
+ if(!set && size){
+ memsize = (size << 20);
+ }
+}