Source-Changes-HG archive

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

[src/trunk]: src/sys/arch The Xen balloon driver enables growing and shrinking



details:   https://anonhg.NetBSD.org/src/rev/6b22fe00645d
branches:  trunk
changeset: 756090:6b22fe00645d
user:      cherry <cherry%NetBSD.org@localhost>
date:      Tue Jul 06 15:00:09 2010 +0000

description:
The Xen balloon driver enables growing and shrinking
PV domains on the fly, by collaborating with UVM and the hypervisor

diffstat:

 sys/arch/amd64/conf/XEN3_DOM0      |    4 +-
 sys/arch/amd64/conf/XEN3_DOMU      |    3 +-
 sys/arch/i386/conf/XEN3_DOM0       |    3 +-
 sys/arch/i386/conf/XEN3_DOMU       |    3 +-
 sys/arch/xen/conf/files.xen        |    5 +-
 sys/arch/xen/include/balloon.h     |   37 +
 sys/arch/xen/xen/balloon.c         |  877 +++++++++++++++++++++++++++++++++++++
 sys/arch/xen/xenbus/xenbus_probe.c |   12 +-
 8 files changed, 936 insertions(+), 8 deletions(-)

diffs (truncated from 1057 to 300 lines):

diff -r 2db96ff07977 -r 6b22fe00645d sys/arch/amd64/conf/XEN3_DOM0
--- a/sys/arch/amd64/conf/XEN3_DOM0     Tue Jul 06 14:59:22 2010 +0000
+++ b/sys/arch/amd64/conf/XEN3_DOM0     Tue Jul 06 15:00:09 2010 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: XEN3_DOM0,v 1.55 2010/06/26 13:08:37 bouyer Exp $
+# $NetBSD: XEN3_DOM0,v 1.56 2010/07/06 15:00:09 cherry Exp $
 
 include        "arch/amd64/conf/std.xen"
 
@@ -12,6 +12,8 @@
 
 #
 options        DOM0OPS
+#options         XEN_BALLOON     # Xen memory ballooning - Experimental
+
 # boot messages with MPBIOS, acpi and ioapic can be quite large
 options        MSGBUFSIZE=24576
 
diff -r 2db96ff07977 -r 6b22fe00645d sys/arch/amd64/conf/XEN3_DOMU
--- a/sys/arch/amd64/conf/XEN3_DOMU     Tue Jul 06 14:59:22 2010 +0000
+++ b/sys/arch/amd64/conf/XEN3_DOMU     Tue Jul 06 15:00:09 2010 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: XEN3_DOMU,v 1.23 2010/05/08 22:16:25 mrg Exp $
+# $NetBSD: XEN3_DOMU,v 1.24 2010/07/06 15:00:09 cherry Exp $
 
 include        "arch/amd64/conf/std.xen"
 
@@ -13,6 +13,7 @@
 #
 options        MAXPHYS=32768   #xbd doesn't handle 64k transfers
 #options       DOM0OPS
+#options         XEN_BALLOON   # Xen memory ballooning - Experimental
 
 #options       VM86            # virtual 8086 emulation
 #options       USER_LDT        # user-settable LDT; used by WINE
diff -r 2db96ff07977 -r 6b22fe00645d sys/arch/i386/conf/XEN3_DOM0
--- a/sys/arch/i386/conf/XEN3_DOM0      Tue Jul 06 14:59:22 2010 +0000
+++ b/sys/arch/i386/conf/XEN3_DOM0      Tue Jul 06 15:00:09 2010 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: XEN3_DOM0,v 1.35 2010/06/26 13:08:37 bouyer Exp $
+#      $NetBSD: XEN3_DOM0,v 1.36 2010/07/06 15:00:09 cherry Exp $
 #
 #      XEN3_0: Xen 3.0 domain0 kernel
 
@@ -23,6 +23,7 @@
 # making MCLBYTES = PAGE_SIZE avoids a copy when a mbuf cluster is sent
 # to a domU, at the expense of a higher memory usage by the network stack.
 #options       MCLSHIFT=12
+#options         XEN_BALLOON     # Xen memory ballooning - Experimental
 
 makeoptions    CPUFLAGS="-march=i686"
 
diff -r 2db96ff07977 -r 6b22fe00645d sys/arch/i386/conf/XEN3_DOMU
--- a/sys/arch/i386/conf/XEN3_DOMU      Tue Jul 06 14:59:22 2010 +0000
+++ b/sys/arch/i386/conf/XEN3_DOMU      Tue Jul 06 15:00:09 2010 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: XEN3_DOMU,v 1.24 2010/05/08 22:16:28 mrg Exp $
+# $NetBSD: XEN3_DOMU,v 1.25 2010/07/06 15:00:09 cherry Exp $
 
 include        "arch/xen/conf/std.xen"
 
@@ -13,6 +13,7 @@
 #
 options        XEN
 #options       DOM0OPS
+#options         XEN_BALLOON     # Xen memory ballooning - Experimental
 
 makeoptions    CPUFLAGS="-march=i686"
 
diff -r 2db96ff07977 -r 6b22fe00645d sys/arch/xen/conf/files.xen
--- a/sys/arch/xen/conf/files.xen       Tue Jul 06 14:59:22 2010 +0000
+++ b/sys/arch/xen/conf/files.xen       Tue Jul 06 15:00:09 2010 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.xen,v 1.107 2010/05/10 18:46:58 dyoung Exp $
+#      $NetBSD: files.xen,v 1.108 2010/07/06 15:00:09 cherry Exp $
 #      NetBSD: files.x86,v 1.10 2003/10/08 17:30:00 bouyer Exp 
 #      NetBSD: files.i386,v 1.254 2004/03/25 23:32:10 jmc Exp 
 
@@ -396,7 +396,7 @@
 include        "dev/pcmcia/files.pcmcia"
 
 # Domain-0 operations
-defflag        opt_xen.h                       DOM0OPS XEN_COMPAT_030001
+defflag        opt_xen.h                       DOM0OPS XEN_COMPAT_030001 XEN_BALLOON
 file   arch/xen/xen/privcmd.c          dom0ops
 file   arch/xen/x86/xen_shm_machdep.c  dom0ops
 file   arch/x86/pci/pci_machdep.c      hypervisor & pci & dom0ops
@@ -406,6 +406,7 @@
 file   arch/xen/xen/xennetback_xenbus.c xvif
 file   arch/xen/xen/xennet_checksum.c  xvif | xennet
 file   arch/xen/xen/xbdback_xenbus.c xbdback
+file    arch/xen/xen/balloon.c          hypervisor
 
 ifdef i386
 include "arch/i386/conf/majors.i386"
diff -r 2db96ff07977 -r 6b22fe00645d sys/arch/xen/include/balloon.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/xen/include/balloon.h    Tue Jul 06 15:00:09 2010 +0000
@@ -0,0 +1,37 @@
+/* $NetBSD: balloon.h,v 1.1 2010/07/06 15:00:09 cherry Exp $ */
+
+/*-
+ * Copyright (c) 2010 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Cherry G. Mathew <cherry%zyx.in@localhost> 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _XEN_BALLOON_H
+#define _XEN_BALLOON_H
+
+void balloon_xenbus_setup(void);
+
+#endif /* _XEN_BALLOON_H */
diff -r 2db96ff07977 -r 6b22fe00645d sys/arch/xen/xen/balloon.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/xen/xen/balloon.c        Tue Jul 06 15:00:09 2010 +0000
@@ -0,0 +1,877 @@
+/* $NetBSD: balloon.c,v 1.1 2010/07/06 15:00:09 cherry Exp $ */
+
+/*-
+ * Copyright (c) 2010 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Cherry G. Mathew <cherry%zyx.in@localhost> and
+ * Jean-Yves Migeon <jym%NetBSD.org@localhost> 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * The Xen balloon driver enables growing and shrinking PV
+ * domains on the fly, by allocating and freeing memory directly.
+ */
+
+#define BALLOONDEBUG 1
+
+/*
+ * sysctl TODOs:
+ * xen.balloon
+ * xen.balloon.current: DONE
+ * xen.balloon.target: DONE
+ * xen.balloon.low-balloon: In Progress
+ * xen.balloon.high-balloon: In Progress
+ * xen.balloon.limit: XXX
+ *
+ * sysctl labels = { 'current'      : 'Current allocation',
+ *           'target'       : 'Requested target',
+ *           'low-balloon'  : 'Low-mem balloon',
+ *           'high-balloon' : 'High-mem balloon',
+ *           'limit'        : 'Xen hard limit' }
+ *
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: balloon.c,v 1.1 2010/07/06 15:00:09 cherry Exp $");
+
+#include <sys/inttypes.h>
+#include <sys/param.h>
+
+#include <sys/condvar.h>
+#include <sys/kernel.h>
+#include <sys/kmem.h>
+#include <sys/kthread.h>
+#include <sys/mutex.h>
+#include <sys/queue.h>
+#include <sys/sysctl.h>
+
+#include <xen/xen.h>
+#include <xen/xenbus.h>
+#include <xen/balloon.h>
+
+#include <uvm/uvm.h>
+#include <uvm/uvm_extern.h>
+#include <xen/xenpmap.h>
+
+#define BALLOONINTERVALMS 100 /* milliseconds */
+
+#define BALLOON_DELTA 1024 /* The maximum increments allowed in a
+                           * single call of balloon_inflate() or
+                           * balloon_deflate
+                           */
+#define BALLOON_RETRIES 4  /* Number of time every (in|de)flate of
+                           * BALLOON_DELTA or less, occurs
+                           */
+
+/* XXX: fix limits */
+#define BALLOON_BALLAST 256 /* In pages */
+#define XEN_RESERVATION_MIN (uvmexp.freemin + BALLOON_BALLAST) /* In pages */
+#define XEN_RESERVATION_MAX nkmempages /* In pages */
+
+/* Forward declaration */
+static void xenbus_balloon_watcher(struct xenbus_watch *, const char **,
+                                  unsigned int);
+
+struct balloon_page_entry {
+       struct vm_page *pg;
+       SLIST_ENTRY(balloon_page_entry) entry;
+};
+
+static struct balloon_conf {
+       kmutex_t flaglock; /* Protects condvar (below) */
+       kcondvar_t cv_memchanged; /* Notifier flag for target (below) */
+
+       kmutex_t tgtlock; /* Spin lock, protects .target, below */
+       size_t target; /* Target VM reservation size, in pages. */
+
+       /* The following are not protected by above locks */
+       SLIST_HEAD(, balloon_page_entry) balloon_page_entries;
+       size_t balloon_num_page_entries;
+
+       /* Balloon limits */
+       size_t xen_res_min;
+       size_t xen_res_max;
+} balloon_conf;
+
+static struct xenbus_watch xenbus_balloon_watch = {
+       .node = __UNCONST("memory/target"),
+       .xbw_callback = xenbus_balloon_watcher,
+};
+
+static uint64_t sysctl_current;
+static uint64_t sysctl_target;
+
+/* List of MFNs for inflating/deflating balloon */
+static xen_pfn_t *mfn_lista;
+
+/* Returns zero, on error */
+static size_t
+xenmem_get_maxreservation(void)
+{
+#if 0   /* XXX: Fix this call */
+       int s, ret;
+
+       s = splvm();
+       ret = HYPERVISOR_memory_op(XENMEM_maximum_reservation, 
+           & (domid_t) { DOMID_SELF });
+
+       splx(s);
+
+       if (ret < 0) {
+               panic("Could not obtain hypervisor max reservation for VM\n");
+               return 0;
+       }
+
+       return ret;
+#else
+       return nkmempages;
+#endif
+}
+
+/* Returns zero, on error */
+static size_t
+xenmem_get_currentreservation(void)
+{
+       int s, ret;
+
+       s = splvm();



Home | Main Index | Thread Index | Old Index