Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/rump/librump/rumpkern Do a minidehumanizenumber for RUMP...



details:   https://anonhg.NetBSD.org/src/rev/045b34f379ba
branches:  trunk
changeset: 760583:045b34f379ba
user:      pooka <pooka%NetBSD.org@localhost>
date:      Sat Jan 08 09:40:05 2011 +0000

description:
Do a minidehumanizenumber for RUMP_MEMLIMIT.  Now you can set it
to e.g. 16m instead of having to type out 16777216.

diffstat:

 sys/rump/librump/rumpkern/vm.c |  37 +++++++++++++++++++++++++++++++++----
 1 files changed, 33 insertions(+), 4 deletions(-)

diffs (60 lines):

diff -r 2fd7fb2fa7eb -r 045b34f379ba sys/rump/librump/rumpkern/vm.c
--- a/sys/rump/librump/rumpkern/vm.c    Sat Jan 08 09:36:26 2011 +0000
+++ b/sys/rump/librump/rumpkern/vm.c    Sat Jan 08 09:40:05 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vm.c,v 1.104 2010/12/01 20:29:57 pooka Exp $   */
+/*     $NetBSD: vm.c,v 1.105 2011/01/08 09:40:05 pooka Exp $   */
 
 /*
  * Copyright (c) 2007-2010 Antti Kantee.  All Rights Reserved.
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vm.c,v 1.104 2010/12/01 20:29:57 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm.c,v 1.105 2011/01/08 09:40:05 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -256,10 +256,39 @@
        int error;
 
        if (rumpuser_getenv("RUMP_MEMLIMIT", buf, sizeof(buf), &error) == 0) {
-               rump_physmemlimit = strtoll(buf, NULL, 10);
+               unsigned long tmp;
+               char *ep;
+               int mult;
+
+               tmp = strtoll(buf, &ep, 10);
+               if (strlen(ep) > 1)
+                       panic("uvm_init: invalid RUMP_MEMLIMIT: %s", buf);
+
+               /* mini-dehumanize-number */
+               mult = 1;
+               switch (*ep) {
+               case 'k':
+                       mult = 1024;
+                       break;
+               case 'm':
+                       mult = 1024*1024;
+                       break;
+               case 'g':
+                       mult = 1024*1024*1024;
+                       break;
+               case 0:
+                       break;
+               default:
+                       panic("uvm_init: invalid RUMP_MEMLIMIT: %s", buf);
+               }
+               rump_physmemlimit = tmp * mult;
+
+               if (rump_physmemlimit / mult != tmp)
+                       panic("uvm_init: RUMP_MEMLIMIT overflow: %s", buf);
                /* it's not like we'd get far with, say, 1 byte, but ... */
                if (rump_physmemlimit == 0)
-                       panic("uvm_init: no memory available");
+                       panic("uvm_init: no memory");
+
 #define HUMANIZE_BYTES 9
                CTASSERT(sizeof(buf) >= HUMANIZE_BYTES);
                format_bytes(buf, HUMANIZE_BYTES, rump_physmemlimit);



Home | Main Index | Thread Index | Old Index