WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] Adds 'memory_sharing' option to domain co

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] Adds 'memory_sharing' option to domain config scripts. It passes domain id to
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 16 Dec 2009 22:41:31 -0800
Delivery-date: Wed, 16 Dec 2009 22:44:16 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1261031277 0
# Node ID 054042ba73b68711be62eb0a46f6af40858a37b2
# Parent  7d28228db41de5020b4bf7ee621ec79a6f2b86bc
Adds 'memory_sharing' option to domain config scripts. It passes domain id to
the tapdisk2 process if sharing is enabled (tapdisk2 is not normally aware what
domain it is working for).

Signed-off-by: Grzegorz Milos <Grzegorz.Milos@xxxxxxxxxx>
---
 tools/blktap2/drivers/tapdisk2.c                 |    7 +++++-
 tools/examples/xmexample.hvm                     |    4 +++
 tools/memshr/interface.c                         |   16 +++++++++++++++
 tools/memshr/memshr.h                            |    1 
 tools/python/xen/lowlevel/xc/xc.c                |   24 +++++++++++++++++++++++
 tools/python/xen/xend/XendConfig.py              |   14 ++++++++++++-
 tools/python/xen/xend/image.py                   |    3 ++
 tools/python/xen/xend/server/BlktapController.py |    5 +++-
 tools/python/xen/xm/create.py                    |    7 +++++-
 9 files changed, 77 insertions(+), 4 deletions(-)

diff -r 7d28228db41d -r 054042ba73b6 tools/blktap2/drivers/tapdisk2.c
--- a/tools/blktap2/drivers/tapdisk2.c  Thu Dec 17 06:27:56 2009 +0000
+++ b/tools/blktap2/drivers/tapdisk2.c  Thu Dec 17 06:27:57 2009 +0000
@@ -34,6 +34,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/ioctl.h>
+#include <memshr.h>
 
 #include "tapdisk.h"
 #include "blktap2.h"
@@ -411,13 +412,17 @@ main(int argc, char *argv[])
 
        params = NULL;
 
-       while ((c = getopt(argc, argv, "n:h")) != -1) {
+       while ((c = getopt(argc, argv, "n:s:h")) != -1) {
                switch (c) {
                case 'n':
                        params = optarg;
                        break;
                case 'h':
                        usage(argv[0], 0);
+            break;
+        case 's':
+            memshr_set_domid(atoi(optarg));
+            break;
                default:
                        usage(argv[0], EINVAL);
                }
diff -r 7d28228db41d -r 054042ba73b6 tools/examples/xmexample.hvm
--- a/tools/examples/xmexample.hvm      Thu Dec 17 06:27:56 2009 +0000
+++ b/tools/examples/xmexample.hvm      Thu Dec 17 06:27:57 2009 +0000
@@ -24,6 +24,10 @@ memory = 128
 # If not explicictly set, xend will pick an appropriate value.  
 # Should be at least 2KB per MB of domain memory, plus a few MB per vcpu.
 # shadow_memory = 8
+
+# Whether to transparently share this domain's memory with other domains.
+# default = 0
+# memory_sharing = 0
 
 # A name for your domain. All domains must have different names.
 name = "ExampleHVMDomain"
diff -r 7d28228db41d -r 054042ba73b6 tools/memshr/interface.c
--- a/tools/memshr/interface.c  Thu Dec 17 06:27:56 2009 +0000
+++ b/tools/memshr/interface.c  Thu Dec 17 06:27:57 2009 +0000
@@ -21,6 +21,12 @@
 #include "memshr-priv.h"
 #include "shm.h"
 
+typedef struct {
+    int     enabled;
+    domid_t domid;
+} memshr_vbd_info_t;
+
+memshr_vbd_info_t vbd_info = {0, DOMID_INVALID};
 
 typedef struct {
     struct shared_memshr_info *shared_info;
@@ -31,6 +37,11 @@ private_memshr_info_t memshr;
 private_memshr_info_t memshr;
 
 #define SHARED_INFO  (memshr.shared_info)
+
+void memshr_set_domid(int domid)
+{
+    vbd_info.domid = domid;
+}
 
 void memshr_daemon_initialize(void)
 {
@@ -88,5 +99,10 @@ void memshr_vbd_initialize(void)
         DPRINTF("Failed to open blockshr_hash.\n");
         return;
     }
+
+    if(vbd_info.domid == DOMID_INVALID)
+        return;
+
+    vbd_info.enabled = 1;
 }
 
diff -r 7d28228db41d -r 054042ba73b6 tools/memshr/memshr.h
--- a/tools/memshr/memshr.h     Thu Dec 17 06:27:56 2009 +0000
+++ b/tools/memshr/memshr.h     Thu Dec 17 06:27:57 2009 +0000
@@ -23,6 +23,7 @@
 
 typedef uint64_t xen_mfn_t;
 
+extern void memshr_set_domid(int domid);
 extern void memshr_daemon_initialize(void);
 extern void memshr_vbd_initialize(void);
 
diff -r 7d28228db41d -r 054042ba73b6 tools/python/xen/lowlevel/xc/xc.c
--- a/tools/python/xen/lowlevel/xc/xc.c Thu Dec 17 06:27:56 2009 +0000
+++ b/tools/python/xen/lowlevel/xc/xc.c Thu Dec 17 06:27:57 2009 +0000
@@ -1658,6 +1658,22 @@ static PyObject *pyxc_tmem_shared_auth(X
     return zero;
 }
 
+static PyObject *pyxc_dom_set_memshr(XcObject *self, PyObject *args)
+{
+    uint32_t dom;
+    int enable;
+
+    if (!PyArg_ParseTuple(args, "ii", &dom, &enable))
+        return NULL;
+
+    if (xc_memshr_control(self->xc_handle, dom, enable) != 0)
+        return pyxc_error_to_exception();
+    
+    Py_INCREF(zero);
+    return zero;
+}
+
+
 static PyMethodDef pyxc_methods[] = {
     { "handle",
       (PyCFunction)pyxc_handle,
@@ -2161,6 +2177,14 @@ static PyMethodDef pyxc_methods[] = {
       " uuid_str [str]: uuid.\n"
       " auth [int]: 0|1 .\n"
       "Returns: [int] 0 on success; exception on error.\n" },
+
+    { "dom_set_memshr", 
+      (PyCFunction)pyxc_dom_set_memshr,
+      METH_VARARGS, "\n"
+      "Enable/disable memory sharing for the domain.\n"
+      " dom     [int]:        Domain identifier.\n"
+      " enable  [int,0|1]:    Disable or enable?\n"
+      "Returns: [int] 0 on success; -1 on error.\n" },
 
     { NULL, NULL, 0, NULL }
 };
diff -r 7d28228db41d -r 054042ba73b6 tools/python/xen/xend/XendConfig.py
--- a/tools/python/xen/xend/XendConfig.py       Thu Dec 17 06:27:56 2009 +0000
+++ b/tools/python/xen/xend/XendConfig.py       Thu Dec 17 06:27:57 2009 +0000
@@ -230,6 +230,7 @@ XENAPI_CFG_TYPES = {
     'suppress_spurious_page_faults': bool0,
     's3_integrity' : int,
     'superpages' : int,
+    'memory_sharing': int,
 }
 
 # List of legacy configuration keys that have no equivalent in the
@@ -328,7 +329,7 @@ class XendConfig(dict):
         
         dict.__init__(self)
         self.update(self._defaults())
-
+        
         if filename:
             try:
                 sxp_obj = sxp.parse(open(filename,'r'))
@@ -390,6 +391,7 @@ class XendConfig(dict):
             'shadow_memory': 0,
             'memory_static_max': 0,
             'memory_dynamic_max': 0,
+            'memory_sharing': 0,
             'devices': {},
             'on_xend_start': 'ignore',
             'on_xend_stop': 'ignore',
@@ -441,6 +443,12 @@ class XendConfig(dict):
         if not self["memory_static_max"] > 0:
             raise XendConfigError("memory_static_max must be greater " \
                                   "than zero")
+        if self["memory_sharing"] and not self.is_hvm():
+            raise XendConfigError("memory_sharing can only be enabled " \
+                                  "for HVM domains")
+        if self["memory_sharing"] and not self.is_hap():
+            raise XendConfigError("memory_sharing can only be enabled " \
+                                  "for HAP enabled boxes")
 
     def _actions_sanity_check(self):
         for event in ['shutdown', 'reboot', 'crash']:
@@ -2150,6 +2158,10 @@ class XendConfig(dict):
         val = sxp.child_value(image_sxp, 'superpages')
         if val is not None:
             self['superpages'] = val
+        
+        val = sxp.child_value(image_sxp, 'memory_sharing')
+        if val is not None:
+            self['memory_sharing'] = val
 
         for key in XENAPI_PLATFORM_CFG_TYPES.keys():
             val = sxp.child_value(image_sxp, key, None)
diff -r 7d28228db41d -r 054042ba73b6 tools/python/xen/xend/image.py
--- a/tools/python/xen/xend/image.py    Thu Dec 17 06:27:56 2009 +0000
+++ b/tools/python/xen/xend/image.py    Thu Dec 17 06:27:57 2009 +0000
@@ -84,6 +84,7 @@ class ImageHandler:
 
     ostype = None
     superpages = 0
+    memory_sharing = 0
 
     def __init__(self, vm, vmConfig):
         self.vm = vm
@@ -820,6 +821,8 @@ class HVMImageHandler(ImageHandler):
         self.apic = int(vmConfig['platform'].get('apic', 0))
         self.acpi = int(vmConfig['platform'].get('acpi', 0))
         self.guest_os_type = vmConfig['platform'].get('guest_os_type')
+        self.memory_sharing = int(vmConfig['memory_sharing'])
+        xc.dom_set_memshr(self.vm.getDomid(), self.memory_sharing)
 
 
     # Return a list of cmd line args to the device models based on the
diff -r 7d28228db41d -r 054042ba73b6 
tools/python/xen/xend/server/BlktapController.py
--- a/tools/python/xen/xend/server/BlktapController.py  Thu Dec 17 06:27:56 
2009 +0000
+++ b/tools/python/xen/xend/server/BlktapController.py  Thu Dec 17 06:27:57 
2009 +0000
@@ -198,7 +198,10 @@ class Blktap2Controller(BlktapController
                     self.deviceClass = 'tap2'
                     return devid
 
-        cmd = [ TAPDISK_BINARY, '-n', '%s:%s' % (params, file) ]
+        if self.vm.image.memory_sharing:
+            cmd = [ TAPDISK_BINARY, '-n', '%s:%s' % (params, file), '-s', '%d' 
% self.vm.getDomid() ]
+        else:
+            cmd = [ TAPDISK_BINARY, '-n', '%s:%s' % (params, file) ]
         (rc,stdout,stderr) = doexec(cmd)
 
         if rc != 0:
diff -r 7d28228db41d -r 054042ba73b6 tools/python/xen/xm/create.py
--- a/tools/python/xen/xm/create.py     Thu Dec 17 06:27:56 2009 +0000
+++ b/tools/python/xen/xm/create.py     Thu Dec 17 06:27:57 2009 +0000
@@ -195,6 +195,10 @@ gopts.var('shadow_memory', val='MEMORY',
 gopts.var('shadow_memory', val='MEMORY',
           fn=set_int, default=0,
           use="Domain shadow memory in MB.")
+
+gopts.var('memory_sharing', val='no|yes',
+          fn=set_bool, default=0,
+          use="Should memory be shared?")
 
 gopts.var('cpu', val='CPU',
           fn=set_int, default=None,
@@ -1058,7 +1062,8 @@ def configure_hvm(config_image, vals):
              'usb', 'usbdevice',
              'vcpus', 'vnc', 'vncconsole', 'vncdisplay', 'vnclisten',
              'vncunused', 'viridian', 'vpt_align',
-             'xauthority', 'xen_extended_power_mgmt', 'xen_platform_pci' ]
+             'xauthority', 'xen_extended_power_mgmt', 'xen_platform_pci',
+             'memory_sharing' ]
 
     for a in args:
         if a in vals.__dict__ and vals.__dict__[a] is not None:

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] Adds 'memory_sharing' option to domain config scripts. It passes domain id to, Xen patchbot-unstable <=