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 Make it possible to define an uppe...



details:   https://anonhg.NetBSD.org/src/rev/76d330102249
branches:  trunk
changeset: 755669:76d330102249
user:      pooka <pooka%NetBSD.org@localhost>
date:      Mon Jun 14 21:04:56 2010 +0000

description:
Make it possible to define an upper limit for memory consumed by
the rump kernel by specifying RUMP_MEMLIMIT.  In case allocation
over that limit is attempted, essentially pool reclaim and uvm_wait()
is done.  The default is to allow to allocate as much as the host
will give.

XXX: uvm_km_alloc and malloc(9) do not currently conform.  the
former is easy, the latter requires kern_malloc.c (rump malloc is
currently directly relegated to host malloc).

diffstat:

 sys/rump/librump/rumpkern/locks_up.c     |   8 ++--
 sys/rump/librump/rumpkern/memalloc.c     |   6 +-
 sys/rump/librump/rumpkern/rump_private.h |   3 +-
 sys/rump/librump/rumpkern/vm.c           |  53 +++++++++++++++++++++++++++++--
 4 files changed, 58 insertions(+), 12 deletions(-)

diffs (181 lines):

diff -r b3dc1ad2c435 -r 76d330102249 sys/rump/librump/rumpkern/locks_up.c
--- a/sys/rump/librump/rumpkern/locks_up.c      Mon Jun 14 19:05:24 2010 +0000
+++ b/sys/rump/librump/rumpkern/locks_up.c      Mon Jun 14 21:04:56 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locks_up.c,v 1.3 2010/06/03 10:56:20 pooka Exp $       */
+/*     $NetBSD: locks_up.c,v 1.4 2010/06/14 21:04:56 pooka Exp $       */
 
 /*
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: locks_up.c,v 1.3 2010/06/03 10:56:20 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locks_up.c,v 1.4 2010/06/14 21:04:56 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -88,7 +88,7 @@
        KASSERT(upm->upm_owner == NULL);
        KASSERT(upm->upm_wanted == 0);
        rumpuser_cv_destroy(upm->upm_rucv);
-       rumpuser_free(upm);
+       rump_hyperfree(upm, sizeof(*upm));
 }
 
 void
@@ -192,7 +192,7 @@
 
        rumpuser_cv_destroy(uprw->uprw_rucv_reader);
        rumpuser_cv_destroy(uprw->uprw_rucv_writer);
-       rumpuser_free(uprw);
+       rump_hyperfree(uprw, sizeof(*uprw));
 }
 
 /* take rwlock.  prefer writers over readers (see rw_tryenter and rw_exit) */
diff -r b3dc1ad2c435 -r 76d330102249 sys/rump/librump/rumpkern/memalloc.c
--- a/sys/rump/librump/rumpkern/memalloc.c      Mon Jun 14 19:05:24 2010 +0000
+++ b/sys/rump/librump/rumpkern/memalloc.c      Mon Jun 14 21:04:56 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: memalloc.c,v 1.8 2010/06/03 19:36:21 pooka Exp $       */
+/*     $NetBSD: memalloc.c,v 1.9 2010/06/14 21:04:56 pooka Exp $       */
 
 /*
  * Copyright (c) 2009 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: memalloc.c,v 1.8 2010/06/03 19:36:21 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: memalloc.c,v 1.9 2010/06/14 21:04:56 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/kmem.h>
@@ -73,7 +73,7 @@
 {
        void *rv;
 
-       rv = rump_hypermalloc(size, 0, (flags & M_WAITOK) != 0, "malloc");
+       rv = rumpuser_malloc(size, 0);
        if (rv && flags & M_ZERO)
                memset(rv, 0, size);
 
diff -r b3dc1ad2c435 -r 76d330102249 sys/rump/librump/rumpkern/rump_private.h
--- a/sys/rump/librump/rumpkern/rump_private.h  Mon Jun 14 19:05:24 2010 +0000
+++ b/sys/rump/librump/rumpkern/rump_private.h  Mon Jun 14 21:04:56 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rump_private.h,v 1.53 2010/06/13 16:49:01 pooka Exp $  */
+/*     $NetBSD: rump_private.h,v 1.54 2010/06/14 21:04:56 pooka Exp $  */
 
 /*
  * Copyright (c) 2007 Antti Kantee.  All Rights Reserved.
@@ -139,5 +139,6 @@
 void   rump_softint_run(struct cpu_info *);
 
 void   *rump_hypermalloc(size_t, int, bool, const char *);
+void   rump_hyperfree(void *, size_t);
 
 #endif /* _SYS_RUMP_PRIVATE_H_ */
diff -r b3dc1ad2c435 -r 76d330102249 sys/rump/librump/rumpkern/vm.c
--- a/sys/rump/librump/rumpkern/vm.c    Mon Jun 14 19:05:24 2010 +0000
+++ b/sys/rump/librump/rumpkern/vm.c    Mon Jun 14 21:04:56 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vm.c,v 1.83 2010/06/10 21:40:42 pooka Exp $    */
+/*     $NetBSD: vm.c,v 1.84 2010/06/14 21:04:56 pooka Exp $    */
 
 /*
  * Copyright (c) 2007-2010 Antti Kantee.  All Rights Reserved.
@@ -43,7 +43,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vm.c,v 1.83 2010/06/10 21:40:42 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm.c,v 1.84 2010/06/14 21:04:56 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -91,6 +91,10 @@
 static kmutex_t pdaemonmtx;
 static kcondvar_t pdaemoncv, oomwait;
 
+#define RUMPMEM_UNLIMITED ((unsigned long)-1)
+static unsigned long physmemlimit = RUMPMEM_UNLIMITED;
+static unsigned long curphysmem;
+
 /*
  * vm pages 
  */
@@ -235,8 +239,24 @@
 void
 uvm_init(void)
 {
+       char buf[64];
+       int error;
 
-       uvmexp.free = 1024*1024; /* XXX */
+       if (rumpuser_getenv("RUMP_MEMLIMIT", buf, sizeof(buf), &error) == 0) {
+               physmemlimit = strtoll(buf, NULL, 10);
+               /* it's not like we'd get far with, say, 1 byte, but ... */
+               if (physmemlimit == 0)
+                       panic("uvm_init: no memory available");
+#define HUMANIZE_BYTES 9
+               CTASSERT(sizeof(buf) >= HUMANIZE_BYTES);
+               format_bytes(buf, HUMANIZE_BYTES, physmemlimit);
+#undef HUMANIZE_BYTES
+       } else {
+               strlcpy(buf, "unlimited (host limit)", sizeof(buf));
+       }
+       aprint_verbose("total memory = %s\n", buf);
+
+       uvmexp.free = 1024*1024; /* XXX: arbitrary & not updated */
 
        mutex_init(&pagermtx, MUTEX_DEFAULT, 0);
        mutex_init(&uvm_pageqlock, MUTEX_DEFAULT, 0);
@@ -622,7 +642,7 @@
 uvm_km_free_poolpage(struct vm_map *map, vaddr_t addr)
 {
 
-       rumpuser_free((void *)addr);
+       rump_hyperfree((void *)addr, PAGE_SIZE);
 }
 
 vaddr_t
@@ -854,8 +874,23 @@
 void *
 rump_hypermalloc(size_t howmuch, int alignment, bool waitok, const char *wmsg)
 {
+       unsigned long newmem;
        void *rv;
 
+       /* first we must be within the limit */
+ limitagain:
+       if (physmemlimit != RUMPMEM_UNLIMITED) {
+               newmem = atomic_add_long_nv(&curphysmem, howmuch);
+               if (newmem > physmemlimit) {
+                       newmem = atomic_add_long_nv(&curphysmem, -howmuch);
+                       if (!waitok)
+                               return NULL;
+                       uvm_wait(wmsg);
+                       goto limitagain;
+               }
+       }
+
+       /* second, we must get something from the backend */
  again:
        rv = rumpuser_malloc(howmuch, alignment);
        if (__predict_false(rv == NULL && waitok)) {
@@ -865,3 +900,13 @@
 
        return rv;
 }
+
+void
+rump_hyperfree(void *what, size_t size)
+{
+
+       if (physmemlimit != RUMPMEM_UNLIMITED) {
+               atomic_add_long(&curphysmem, -size);
+       }
+       rumpuser_free(what);
+}



Home | Main Index | Thread Index | Old Index