Skip to contentSkip to conversation

libxc: checkpoint compression

PATCH Superseded [email protected] 4 participants 9 messages Nov 14, 2011 – Dec 1, 2011 Arm/actions semi architecture

lore
Share & tools
lore
#0 lore raw

PATCH v7 1/1 libxc: checkpoint compression

This patch series adds checkpoint compression functionality, while running under Remus.

Changes since last version:
1. renamed page_aligned_alloc to xc_memalign and declare it as a global function in xenctrl.h, instead of declaring it in xc_private.h

Shriram

#1 lore raw

PATCH v7 1/1 tools/libxc: introduce xc_memalign in xc_{minios, linux, solaris, netbsd}.c

# HG changeset patch
# User Shriram Rajagopalan <[email protected]>
# Date 1321309573 28800
# Node ID 7e992e479411201fb9a0356f6f27966de7d48967
# Parent 54a5e994a241a506900ee0e197bb42e5f1d8e759 tools/libxc: introduce xc_memalign in xc_{minios,linux,solaris,netbsd}.c

Move (page aligned) buffer allocations in {os}_privcmd_alloc_hypercall_buffer into a global function xc_memalign. This API is also used by Remus compression code to allocate compression caches that need to be page aligned.

tools/libxc/xc_linux.c +12 -0
diff -r 54a5e994a241 -r 7e992e479411 tools/libxc/xc_linux.c
@@ -55,6 +55,18 @@
     errno = saved_errno;
 }
 
+void *xc_memalign(xc_interface *xch, size_t alignment, size_t size)
+{
+    int ret;
+    void *ptr;
+
+    ret = posix_memalign(&ptr, alignment, size);
+    if (ret != 0 || !ptr)
+        return NULL;
+
+    return ptr;
+}
+
 /*
  * Local variables:
  * mode: C
tools/libxc/xc_linux_osdep.c +2 -3
diff -r 54a5e994a241 -r 7e992e479411 tools/libxc/xc_linux_osdep.c
@@ -91,10 +91,9 @@
 {
     size_t size = npages * XC_PAGE_SIZE;
     void *p;
-    int ret;
 
-    ret = posix_memalign(&p, XC_PAGE_SIZE, size);
-    if (ret != 0 || !p)
+    p = xc_memalign(xch, XC_PAGE_SIZE, size);
+    if (!p)
         return NULL;
 
     if ( mlock(p, size) < 0 )
tools/libxc/xc_minios.c +6 -1
diff -r 54a5e994a241 -r 7e992e479411 tools/libxc/xc_minios.c
@@ -73,7 +73,7 @@
 
 static void *minios_privcmd_alloc_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, int npages)
 {
-    return memalign(PAGE_SIZE, npages * PAGE_SIZE);
+    return xc_memalign(xch, PAGE_SIZE, npages * PAGE_SIZE);
 }
 
 static void minios_privcmd_free_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, void *ptr, int npages)
@@ -437,6 +437,11 @@
         fsync(fd);
 }
 
+void *xc_memalign(xc_interface *xch, size_t alignment, size_t size)
+{
+    return memalign(alignment, size);
+}
+
 static xc_osdep_handle minios_gnttab_open(xc_gnttab *xcg)
 {
     int fd = alloc_fd(FTYPE_GNTMAP);
tools/libxc/xc_netbsd.c +7 -1
diff -r 54a5e994a241 -r 7e992e479411 tools/libxc/xc_netbsd.c
@@ -71,8 +71,9 @@
 static void *netbsd_privcmd_alloc_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, int npages)
 {
     size_t size = npages * XC_PAGE_SIZE;
-    void *p = valloc(size);
+    void *p;
 
+    p = xc_memalign(xch, XC_PAGE_SIZE, size);
     if (!p)
         return NULL;
 
@@ -378,6 +379,11 @@
     errno = saved_errno;
 }
 
+void *xc_memalign(xc_interface *xch, size_t alignment, size_t size)
+{
+    return valloc(size);
+}
+
 static struct xc_osdep_ops *netbsd_osdep_init(xc_interface *xch, enum xc_osdep_type type)
 {
     switch ( type )
tools/libxc/xc_solaris.c +6 -1
diff -r 54a5e994a241 -r 7e992e479411 tools/libxc/xc_solaris.c
@@ -70,7 +70,7 @@
 
 static void *solaris_privcmd_alloc_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, int npages)
 {
-    return memalign(XC_PAGE_SIZE, npages * XC_PAGE_SIZE);
+    return xc_memalign(xch, XC_PAGE_SIZE, npages * XC_PAGE_SIZE);
 }
 
 static void solaris_privcmd_free_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, void *ptr, int npages)
@@ -314,6 +314,11 @@
     // TODO: Implement for Solaris!
 }
 
+void *xc_memalign(xc_interface *xch, size_t alignment, size_t size)
+{
+    return memalign(alignment, size);
+}
+
 static struct xc_osdep_ops *solaris_osdep_init(xc_interface *xch, enum xc_osdep_type type)
 {
     switch ( type )
tools/libxc/xenctrl.h +2 -0
diff -r 54a5e994a241 -r 7e992e479411 tools/libxc/xenctrl.h
@@ -1129,6 +1129,8 @@
                       uint64_t *time,
                       xc_hypercall_buffer_t *data);
 
+void *xc_memalign(xc_interface *xch, size_t alignment, size_t size);
+
 /**
  * Memory maps a range within one domain to a local address range.  Mappings
  * should be unmapped with munmap and should follow the same rules as mmap
#3 lore raw

PATCH v7 1/1 tools/libxc: Remus Checkpoint Compression

In reply to [email protected]

# HG changeset patch
# User Shriram Rajagopalan <[email protected]> # Date 1321309629 28800
# Node ID 71d482d5f9aeba050454aa0130c4280090ea8e28 # Parent 7e992e479411201fb9a0356f6f27966de7d48967 tools/libxc: Remus Checkpoint Compression

Instead of sending dirty pages of guest memory as-is, use a simple compression algorithm that sends a RLE-encoded XOR of the page against its last sent copy. A small LRU cache is used to hold recently dirtied pages. Pagetable pages are sent as-is, as they are canonicalized at sender side and uncanonicalized at receiver.

tools/libxc/Makefile +1 -1
diff -r 7e992e479411 -r 71d482d5f9ae tools/libxc/Makefile
@@ -42,7 +42,7 @@
 GUEST_SRCS-y :=
 GUEST_SRCS-y += xg_private.c xc_suspend.c
 GUEST_SRCS-$(CONFIG_MIGRATE) += xc_domain_restore.c xc_domain_save.c
-GUEST_SRCS-$(CONFIG_MIGRATE) += xc_offline_page.c
+GUEST_SRCS-$(CONFIG_MIGRATE) += xc_offline_page.c xc_compression.c
 GUEST_SRCS-$(CONFIG_HVM) += xc_hvm_build.c
 
 vpath %.c ../../xen/common/libelf
tools/libxc/xc_compression.c new file +552 -0

552 lines not on this page · raw message

tools/libxc/xc_domain_restore.c +72 -1

133 lines not on this page · raw message

tools/libxc/xc_domain_save.c +210 -8

302 lines not on this page · raw message

tools/libxc/xenctrl.h +60 -0

64 lines not on this page · raw message

tools/libxc/xenguest.h +1 -0
diff -r 7e992e479411 -r 71d482d5f9ae tools/libxc/xenguest.h
@@ -27,6 +27,7 @@
 #define XCFLAGS_DEBUG     2
 #define XCFLAGS_HVM       4
 #define XCFLAGS_STDVGA    8
+#define XCFLAGS_CHECKPOINT_COMPRESS    16
 #define X86_64_B_SIZE   64 
 #define X86_32_B_SIZE   32
 
tools/libxc/xg_save_restore.h +119 -1

138 lines not on this page · raw message

#4 lore raw

PATCH v7 1/1 remus: command line switch to enable/disable checkpoint compression

In reply to [email protected]

# HG changeset patch
# User Shriram Rajagopalan <[email protected]>
# Date 1321309631 28800
# Node ID 50316e043a2144831c1fa7cf2d96de8df4796f68
# Parent 71d482d5f9aeba050454aa0130c4280090ea8e28
remus: command line switch to enable/disable checkpoint compression

Add a command line switch to remus script that allows the user to enable or disable checkpoint compression in the libxc code.

tools/python/xen/lowlevel/checkpoint/checkpoint.c +4 -3
diff -r 71d482d5f9ae -r 50316e043a21 tools/python/xen/lowlevel/checkpoint/checkpoint.c
@@ -104,13 +104,14 @@
   PyObject* postcopy_cb = NULL;
   PyObject* checkpoint_cb = NULL;
   unsigned int interval = 0;
+  unsigned int flags = 0;
 
   int fd;
   struct save_callbacks callbacks;
   int rc;
 
-  if (!PyArg_ParseTuple(args, "O|OOOI", &iofile, &suspend_cb, &postcopy_cb,
-                       &checkpoint_cb, &interval))
+  if (!PyArg_ParseTuple(args, "O|OOOII", &iofile, &suspend_cb, &postcopy_cb,
+			&checkpoint_cb, &interval, &flags))
     return NULL;
 
   self->interval = interval;
@@ -160,7 +161,7 @@
   callbacks.data = self;
 
   self->threadstate = PyEval_SaveThread();
-  rc = checkpoint_start(&self->cps, fd, &callbacks);
+  rc = checkpoint_start(&self->cps, fd, &callbacks, flags);
   PyEval_RestoreThread(self->threadstate);
 
   if (rc < 0) {
tools/python/xen/lowlevel/checkpoint/checkpoint.h +3 -1
diff -r 71d482d5f9ae -r 50316e043a21 tools/python/xen/lowlevel/checkpoint/checkpoint.h
@@ -40,13 +40,15 @@
     timer_t timer;
 } checkpoint_state;
 
+#define CHECKPOINT_FLAGS_COMPRESSION 1
 char* checkpoint_error(checkpoint_state* s);
 
 void checkpoint_init(checkpoint_state* s);
 int checkpoint_open(checkpoint_state* s, unsigned int domid);
 void checkpoint_close(checkpoint_state* s);
 int checkpoint_start(checkpoint_state* s, int fd,
-                    struct save_callbacks* callbacks);
+		     struct save_callbacks* callbacks,
+		     unsigned int remus_flags);
 int checkpoint_suspend(checkpoint_state* s);
 int checkpoint_resume(checkpoint_state* s);
 int checkpoint_postflush(checkpoint_state* s);
tools/python/xen/lowlevel/checkpoint/libcheckpoint.c +4 -1
diff -r 71d482d5f9ae -r 50316e043a21 tools/python/xen/lowlevel/checkpoint/libcheckpoint.c
@@ -170,7 +170,8 @@
 }
 
 int checkpoint_start(checkpoint_state* s, int fd,
-                    struct save_callbacks* callbacks)
+		     struct save_callbacks* callbacks,
+		     unsigned int remus_flags)
 {
     int hvm, rc;
     int flags = XCFLAGS_LIVE;
@@ -188,6 +189,8 @@
        if (switch_qemu_logdirty(s, 1))
            return -1;
     }
+    if (remus_flags & CHECKPOINT_FLAGS_COMPRESSION)
+      flags |= XCFLAGS_CHECKPOINT_COMPRESS;
 
     callbacks->switch_qemu_logdirty = noop_switch_logdirty;
 
tools/python/xen/remus/save.py +5 -2
diff -r 71d482d5f9ae -r 50316e043a21 tools/python/xen/remus/save.py
@@ -133,7 +133,7 @@
 
 class Saver(object):
     def __init__(self, domid, fd, suspendcb=None, resumecb=None,
-                 checkpointcb=None, interval=0):
+                 checkpointcb=None, interval=0, flags=0):
         """Create a Saver object for taking guest checkpoints.
         domid:        name, number or UUID of a running domain
         fd:           a stream to which checkpoint data will be written.
@@ -141,12 +141,14 @@
         resumecb:     callback invoked before guest resumes
         checkpointcb: callback invoked when a checkpoint is complete. Return
                       True to take another checkpoint, or False to stop.
+        flags:        Remus flags to be passed to xc_domain_save
         """
         self.fd = fd
         self.suspendcb = suspendcb
         self.resumecb = resumecb
         self.checkpointcb = checkpointcb
         self.interval = interval
+        self.flags = flags
 
         self.vm = vm.VM(domid)
 
@@ -164,7 +166,8 @@
             try:
                 self.checkpointer.open(self.vm.domid)
                 self.checkpointer.start(self.fd, self.suspendcb, self.resumecb,
-                                        self.checkpointcb, self.interval)
+                                        self.checkpointcb, self.interval,
+                                        self.flags)
             except xen.lowlevel.checkpoint.error, e:
                 raise CheckpointError(e)
         finally:
tools/remus/remus +9 -1
diff -r 71d482d5f9ae -r 50316e043a21 tools/remus/remus
@@ -16,6 +16,9 @@
 class CfgException(Exception): pass
 
 class Cfg(object):
+
+    REMUS_FLAGS_COMPRESSION = 1
+
     def __init__(self):
         # must be set
         self.domid = 0
@@ -25,6 +28,7 @@
         self.port = XendOptions.instance().get_xend_relocation_port()
         self.interval = 200
         self.netbuffer = True
+        self.flags = self.REMUS_FLAGS_COMPRESSION
         self.timer = False
 
         parser = optparse.OptionParser()
@@ -38,6 +42,8 @@
                           help='replicate to /dev/null (no disk checkpoints, only memory & net buffering)')
         parser.add_option('', '--no-net', dest='nonet', action='store_true',
                           help='run without net buffering (benchmark option)')
+        parser.add_option('', '--no-compression', dest='nocompress', action='store_true',
+                          help='run without checkpoint compression')
         parser.add_option('', '--timer', dest='timer', action='store_true',
                           help='force pause at checkpoint interval (experimental)')
         self.parser = parser
@@ -56,6 +62,8 @@
             self.nullremus = True
         if opts.nonet:
             self.netbuffer = False
+        if opts.nocompress:
+            self.flags &= ~self.REMUS_FLAGS_COMPRESSION
         if opts.timer:
             self.timer = True
 
@@ -190,7 +198,7 @@
     rc = 0
 
     checkpointer = save.Saver(cfg.domid, fd, postsuspend, preresume, commit,
-                              interval)
+                              interval, cfg.flags)
 
     try:
         checkpointer.start()
Acked-by on v7 1/1
#2 lore raw

Re: [PATCH 1 of 3 V7] tools/libxc: introduce xc_memalign in xc_{minios, linux, solaris, netbsd}.c

In reply to [email protected]
Quoted 7 lines · On Mon, 2011-11-14 at 22:51 +0000, [email protected] wrote:

# HG changeset patch
# User Shriram Rajagopalan <[email protected]>
# Date 1321309573 28800
# Node ID 7e992e479411201fb9a0356f6f27966de7d48967
# Parent 54a5e994a241a506900ee0e197bb42e5f1d8e759 tools/libxc: introduce xc_memalign in xc_{minios,linux,solaris,netbsd}.c

Quoted 5 lines

Move (page aligned) buffer allocations in {os}_privcmd_alloc_hypercall_buffer into a global function xc_memalign. This API is also used by Remus compression code to allocate compression caches that need to be page aligned.

Quoted 125 lines

diff -r 54a5e994a241 -r 7e992e479411 tools/libxc/xc_linux.c

tools/libxc/xc_linux.c +12 -0
@@ -55,6 +55,18 @@
     errno = saved_errno;
 }
 
+void *xc_memalign(xc_interface *xch, size_t alignment, size_t size)
+{
+    int ret;
+    void *ptr;
+
+    ret = posix_memalign(&ptr, alignment, size);
+    if (ret != 0 || !ptr)
+        return NULL;
+
+    return ptr;
+}
+
 /*
  * Local variables:
  * mode: C

diff -r 54a5e994a241 -r 7e992e479411 tools/libxc/xc_linux_osdep.c

tools/libxc/xc_linux_osdep.c +2 -3
@@ -91,10 +91,9 @@
 {
     size_t size = npages * XC_PAGE_SIZE;
     void *p;
-    int ret;
 
-    ret = posix_memalign(&p, XC_PAGE_SIZE, size);
-    if (ret != 0 || !p)
+    p = xc_memalign(xch, XC_PAGE_SIZE, size);
+    if (!p)
         return NULL;
 
     if ( mlock(p, size) < 0 )

diff -r 54a5e994a241 -r 7e992e479411 tools/libxc/xc_minios.c

tools/libxc/xc_minios.c +6 -1
@@ -73,7 +73,7 @@
 
 static void *minios_privcmd_alloc_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, int npages)
 {
-    return memalign(PAGE_SIZE, npages * PAGE_SIZE);
+    return xc_memalign(xch, PAGE_SIZE, npages * PAGE_SIZE);
 }
 
 static void minios_privcmd_free_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, void *ptr, int npages)
@@ -437,6 +437,11 @@
         fsync(fd);
 }
 
+void *xc_memalign(xc_interface *xch, size_t alignment, size_t size)
+{
+    return memalign(alignment, size);
+}
+
 static xc_osdep_handle minios_gnttab_open(xc_gnttab *xcg)
 {
     int fd = alloc_fd(FTYPE_GNTMAP);

diff -r 54a5e994a241 -r 7e992e479411 tools/libxc/xc_netbsd.c

tools/libxc/xc_netbsd.c +7 -1
@@ -71,8 +71,9 @@
 static void *netbsd_privcmd_alloc_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, int npages)
 {
     size_t size = npages * XC_PAGE_SIZE;
-    void *p = valloc(size);
+    void *p;
 
+    p = xc_memalign(xch, XC_PAGE_SIZE, size);
     if (!p)
         return NULL;
 
@@ -378,6 +379,11 @@
     errno = saved_errno;
 }
 
+void *xc_memalign(xc_interface *xch, size_t alignment, size_t size)
+{
+    return valloc(size);
+}
+
 static struct xc_osdep_ops *netbsd_osdep_init(xc_interface *xch, enum xc_osdep_type type)
 {
     switch ( type )

diff -r 54a5e994a241 -r 7e992e479411 tools/libxc/xc_solaris.c

tools/libxc/xc_solaris.c +6 -1
@@ -70,7 +70,7 @@
 
 static void *solaris_privcmd_alloc_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, int npages)
 {
-    return memalign(XC_PAGE_SIZE, npages * XC_PAGE_SIZE);
+    return xc_memalign(xch, XC_PAGE_SIZE, npages * XC_PAGE_SIZE);
 }
 
 static void solaris_privcmd_free_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, void *ptr, int npages)
@@ -314,6 +314,11 @@
     // TODO: Implement for Solaris!
 }
 
+void *xc_memalign(xc_interface *xch, size_t alignment, size_t size)
+{
+    return memalign(alignment, size);
+}
+
 static struct xc_osdep_ops *solaris_osdep_init(xc_interface *xch, enum xc_osdep_type type)
 {
     switch ( type )

diff -r 54a5e994a241 -r 7e992e479411 tools/libxc/xenctrl.h

tools/libxc/xenctrl.h +2 -0
@@ -1129,6 +1129,8 @@
                       uint64_t *time,
                       xc_hypercall_buffer_t *data);
 
+void *xc_memalign(xc_interface *xch, size_t alignment, size_t size);
+
 /**
  * Memory maps a range within one domain to a local address range.  Mappings
  * should be unmapped with munmap and should follow the same rules as mmap
#5 lore raw
In reply to [email protected]

Ian,
Do you have any other comments for this patch set?

thanks
shriram

Quoted 7 lines · On Mon, Nov 14, 2011 at 2:51 PM, <[email protected]> wrote:

This patch series adds checkpoint compression functionality, while running under Remus.

Changes since last version:
1. renamed page_aligned_alloc to xc_memalign and declare it as a global function in xenctrl.h, instead of declaring it in xc_private.h

Quoted 7 lines

Shriram

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#6 lore raw

ping!

Quoted 25 lines · Shriram Rajagopalan

Ian,
Do you have any other comments for this patch set?

thanks
shriram

Quoted 14 lines · On Mon, Nov 14, 2011 at 2:51 PM, <[email protected]> wrote:

This patch series adds checkpoint compression functionality, while running under Remus.

Changes since last version:
1. renamed page_aligned_alloc to xc_memalign and declare it as a global function in xenctrl.h, instead of declaring it in xc_private.h

Shriram

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#8 lore raw
In reply to [email protected]

[email protected] writes ("[Xen-devel] [PATCH 0 of 3 V7] libxc: checkpoint compression"):

Quoted 6 lines

This patch series adds checkpoint compression functionality, while running under Remus.

Changes since last version:
1. renamed page_aligned_alloc to xc_memalign and declare it as a global function in xenctrl.h, instead of declaring it in xc_private.h

Thanks.

I have applied all three of these.

I fixed up a conflict in tools/libxc/xg_save_restore.h. In particular note that the new save file ids you allocated had to be changed to -12 and -13 since -11 had already been taken.

Ian.