From: Martin Lucina Date: Fri, 21 Nov 2014 18:00:07 +0000 (+0100) Subject: Size RUMP_MEMLIMIT dynamically based on domU memory X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=f147e0a8af105699043e81c56416cfae6031301e;p=rumpuser-xen.git Size RUMP_MEMLIMIT dynamically based on domU memory RUMP_MEMLIMIT was previously hardcoded to 8MB. We size it dynamically based on domU memory allocation, with the rump kernel getting 50%. Signed-off-by: Martin Lucina --- diff --git a/include/mini-os/mm.h b/include/mini-os/mm.h index 56b2eb2..148ea3c 100644 --- a/include/mini-os/mm.h +++ b/include/mini-os/mm.h @@ -76,5 +76,6 @@ unsigned long alloc_contig_pages(int order, unsigned int addr_bits); int free_physical_pages(xen_pfn_t *mfns, int n); void fini_mm(void); +uint64_t minios_get_memsize(void); #endif /* _MINIOS_MM_H_ */ diff --git a/rumphyper_base.c b/rumphyper_base.c index 0f8e05d..ce204aa 100644 --- a/rumphyper_base.c +++ b/rumphyper_base.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -89,34 +90,58 @@ rumpuser_dprintf(const char *fmt, ...) minios_free_pages(buf, 0); } -static struct { - const char *name; - const char *value; -} envtab[] = { - { RUMPUSER_PARAM_NCPU, "1" }, - { RUMPUSER_PARAM_HOSTNAME, "rump4xen" }, - { "RUMP_VERBOSE", "1" }, - { "RUMP_MEMLIMIT", "8m" }, - { NULL, NULL }, -}; - int -rumpuser_getparam(const char *name, void *buf, size_t blen) +rumpuser_getparam(const char *name, void *buf, size_t buflen) { - int i; + int rv = 0; + + if (buflen <= 1) + return EINVAL; + + if (strcmp(name, RUMPUSER_PARAM_NCPU) == 0 + || strcmp(name, "RUMP_VERBOSE") == 0) { + strncpy(buf, "1", buflen-1); + + } else if (strcmp(name, RUMPUSER_PARAM_HOSTNAME) == 0) { + strncpy(buf, "rump-xen", buflen-1); + + /* for memlimit, we have to implement int -> string ... */ + } else if (strcmp(name, "RUMP_MEMLIMIT") == 0) { + uint64_t memsize; + char tmp[64]; + char *res = buf; + unsigned i, j; + + /* use up to 50% memory for rump kernel */ + memsize = minios_get_memsize() / 2; + if (memsize < (8 * 1024 * 1024)) { + minios_printk("rumphyper: warning: low on physical " + "memory (%llu bytes), " + "suggest increasing domU allocation\n", + memsize); + memsize = 8 * 1024 * 1024; + } - for (i = 0; envtab[i].name; i++) { - if (strcmp(name, envtab[i].name) == 0) { - if (blen < strlen(envtab[i].value)+1) { + for (i = 0; memsize > 0; i++) { + if (i >= sizeof(tmp)-1) return E2BIG; - } else { - strcpy(buf, envtab[i].value); - return 0; + tmp[i] = (memsize % 10) + '0'; + memsize = memsize / 10; + } + if (i >= buflen) { + rv = 1; + } else { + res[i] = '\0'; + for (j = i; i > 0; i--) { + res[j-i] = tmp[i-1]; } } + + } else { + rv = ENOENT; } - return ENOENT; + return rv; } /* Use same values both for absolute and relative clock. */ diff --git a/xen/mm.c b/xen/mm.c index 58c7118..14b3419 100644 --- a/xen/mm.c +++ b/xen/mm.c @@ -376,8 +376,11 @@ int free_physical_pages(xen_pfn_t *mfns, int n) } #endif - - +static uint64_t memsize = 0; +uint64_t minios_get_memsize(void) +{ + return memsize; +} void init_mm(void) { @@ -395,6 +398,7 @@ void init_mm(void) (u_long)to_virt(PFN_PHYS(max_pfn)), PFN_PHYS(max_pfn)); init_page_allocator(PFN_PHYS(start_pfn), PFN_PHYS(max_pfn)); minios_printk("MM: done\n"); + memsize = PFN_PHYS(max_pfn) - PFN_PHYS(start_pfn); arch_init_p2m(max_pfn);