Skip to contentSkip to conversation

libxc: checkpoint compression

PATCH Superseded [email protected] 2 participants 7 messages Nov 8, 2011 – Nov 10, 2011 Arm/actions semi architecture

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v6 1/1 libxc: checkpoint compression

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

Changes since last version:
1. Introduced a generic api page_aligned_alloc() for allocating page aligned buffers. Also provided platform specific implementations using memalign/valloc/posix_memalign in xc_{minios, linux, netbsd, solaris}.c
2. use the above generic api for allocating cache/page buffers in xc_compression.c. Also modified xc_{minios,linux,netbsd,solaris}.c : {os}_privcmd_alloc_hypercall_buffer to use page_aligned_alloc instead of allocating memory via memalign calls.

Shriram

#1 lore raw

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

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

Move (page aligned) buffer allocations in {os}_privcmd_alloc_hypercall_buffer into a global function page_aligned_alloc. 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 58a24a7d4b87 tools/libxc/xc_linux.c
@@ -55,6 +55,18 @@
     errno = saved_errno;
 }
 
+void *page_aligned_alloc(xc_interface *xch, size_t size)
+{
+    int ret;
+    void *ptr;
+
+    ret = posix_memalign(&ptr, XC_PAGE_SIZE, size);
+    if (ret != 0 || !ptr)
+        return NULL;
+
+    return ptr;
+}
+
 /*
  * Local variables:
  * mode: C
tools/libxc/xc_linux_osdep.c +10 -3
diff -r 54a5e994a241 -r 58a24a7d4b87 tools/libxc/xc_linux_osdep.c
@@ -36,9 +36,17 @@
 #include <xen/sys/gntdev.h>
 #include <xen/sys/gntalloc.h>
 
+#include "xc_private.h"
 #include "xenctrl.h"
 #include "xenctrlosdep.h"
 
+/* We need xc_private.h for page_aligned_alloc().
+ * xc_private.h already defines ERROR and PERROR.
+ * So we undef it and redefine it here.
+ */
+#undef ERROR
+#undef PERROR
+
 #define ERROR(_m, _a...)  xc_osdep_log(xch,XTL_ERROR,XC_INTERNAL_ERROR,_m , ## _a )
 #define PERROR(_m, _a...) xc_osdep_log(xch,XTL_ERROR,XC_INTERNAL_ERROR,_m \
                   " (%d = %s)", ## _a , errno, xc_strerror(xch, errno))
@@ -91,10 +99,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 = page_aligned_alloc(xch, size);
+    if (!p)
         return NULL;
 
     if ( mlock(p, size) < 0 )
tools/libxc/xc_minios.c +6 -1
diff -r 54a5e994a241 -r 58a24a7d4b87 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 page_aligned_alloc(xch, 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 *page_aligned_alloc(xc_interface *xch, size_t size)
+{
+    return memalign(PAGE_SIZE, 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 58a24a7d4b87 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 = page_aligned_alloc(xch, size);
     if (!p)
         return NULL;
 
@@ -378,6 +379,11 @@
     errno = saved_errno;
 }
 
+void *page_aligned_alloc(xc_interface *xch, 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_private.h +3 -0
diff -r 54a5e994a241 -r 58a24a7d4b87 tools/libxc/xc_private.h
@@ -302,6 +302,9 @@
 /* Optionally flush file to disk and discard page cache */
 void discard_file_cache(xc_interface *xch, int fd, int flush);
 
+/* Encapsulates memalign style calls for different OSes. */
+void *page_aligned_alloc(xc_interface *xch, size_t size);
+
 #define MAX_MMU_UPDATES 1024
 struct xc_mmu {
     mmu_update_t updates[MAX_MMU_UPDATES];
tools/libxc/xc_solaris.c +6 -1
diff -r 54a5e994a241 -r 58a24a7d4b87 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 page_aligned_alloc(xch, 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 *page_aligned_alloc(xc_interface *xch, size_t size)
+{
+    return memalign(XC_PAGE_SIZE, size);
+}
+
 static struct xc_osdep_ops *solaris_osdep_init(xc_interface *xch, enum xc_osdep_type type)
 {
     switch ( type )
#2 lore raw

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

tools/libxc/xc_linux_osdep.c line 39

Quoted 8 lines · On Tue, 2011-11-08 at 22:39 +0000, [email protected] wrote:

diff -r 54a5e994a241 -r 58a24a7d4b87 tools/libxc/xc_linux_osdep.c

tools/libxc/xc_linux_osdep.c +1 -0
@@ -36,9 +36,17 @@
 #include <xen/sys/gntdev.h>
 #include <xen/sys/gntalloc.h>
 
+#include "xc_private.h"

I'd like to avoid including xc_private from this file. Although it's in tree it is a plugin and avoiding internal APIs serves to help ensure that external plugins can actually be written using the public APIs.

I think you can make this function public, as long as you name it xc_blah.

Ian.

#3 lore raw

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

Quoted 14 lines · Ian Campbell

tools/libxc/xc_linux_osdep.c Tue Nov 08 14:26:02 2011 -0800 line 39

Quoted 8 lines · On Tue, 2011-11-08 at 22:39 +0000, [email protected] wrote:

diff -r 54a5e994a241 -r 58a24a7d4b87 tools/libxc/xc_linux_osdep.c

tools/libxc/xc_linux_osdep.c Tue Nov 08 14:26:02 2011 -0800 renamed from tools/libxc/xc_linux_osdep.c Wed Nov 02 17:09:09 2011 +0000 +1 -0
@@ -36,9 +36,17 @@
 #include <xen/sys/gntdev.h>
 #include <xen/sys/gntalloc.h>
 
+#include "xc_private.h"

I'd like to avoid including xc_private from this file. Although it's in tree it is a plugin and avoiding internal APIs serves to help ensure that external plugins can actually be written using the public APIs.

Quoted 5 lines

I think you can make this function public, as long as you name it xc_blah.

Ian.

The reason I declared the function in xc_private.h was to maintain consistency, like discard_file_cache(). But I see your point.

Just to make sure I get it right this time.
Are you suggesting that I declare a
public function xc_page_aligned_alloc in a header like xenctrl.h and have respective platform specific implementations in xc_{minios,linux,netbsd}.c ? That way I won't have to include xc_private.h in linux_osdep.c (it already includes xenctrl.h).

And are you okay with other modifications in these files (like abstracting out memaligns from privcmd_hypercall_alloc() )..?

Shriram

Quoted 1 line
#4 lore raw

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

Quoted 22 lines · Shriram Rajagopalan
Quoted 14 lines · Ian Campbell

tools/libxc/xc_linux_osdep.c Tue Nov 08 14:26:02 2011 -0800 line 39

Quoted 8 lines · On Tue, 2011-11-08 at 22:39 +0000, [email protected] wrote:

diff -r 54a5e994a241 -r 58a24a7d4b87 tools/libxc/xc_linux_osdep.c

tools/libxc/xc_linux_osdep.c Tue Nov 08 14:26:02 2011 -0800 renamed from tools/libxc/xc_linux_osdep.c Wed Nov 02 17:09:09 2011 +0000 +1 -0
@@ -36,9 +36,17 @@
 #include <xen/sys/gntdev.h>
 #include <xen/sys/gntalloc.h>
 
+#include "xc_private.h"

I'd like to avoid including xc_private from this file. Although it's in tree it is a plugin and avoiding internal APIs serves to help ensure that external plugins can actually be written using the public APIs.

Quoted 5 lines

I think you can make this function public, as long as you name it xc_blah.

Ian.

Quoted 7 lines

The reason I declared the function in xc_private.h was to maintain consistency, like discard_file_cache(). But I see your point.

Just to make sure I get it right this time.
Are you suggesting that I declare a
public function xc_page_aligned_alloc in a header like xenctrl.h and have respective platform specific implementations in xc_{minios,linux,netbsd}.c ? That way I won't have to include xc_private.h in linux_osdep.c (it already includes xenctrl.h).

That sounds about right. You could just export a xc_memalign rather than xc_page_aligned_alloc, your name is a bit of a mouthful and xc_memalign is a bit more general I guess?

I'd expect a function called xc_page_aligned_alloc to take a number of pages rather than bytes. Either way is fine though.

Quoted 1 line

And are you okay with other modifications in these files (like abstracting out memaligns from privcmd_hypercall_alloc() )..?

Looks fine.

Ian.

Quoted 4 lines

Shriram

Quoted 1 line
#5 lore raw

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

In reply to [email protected]

# HG changeset patch
# User Shriram Rajagopalan <[email protected]> # Date 1320791182 28800
# Node ID 326b1e6172f1f2557087a2b1b69978021fa9ac1f # Parent 58a24a7d4b87540692363b081dd72f62a6d380dd 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 58a24a7d4b87 -r 326b1e6172f1 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 58a24a7d4b87 -r 326b1e6172f1 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

#6 lore raw

PATCH v6 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 1320791205 28800
# Node ID 9a33be85736845a984dca151ff9abfcb99e8e1d2
# Parent 326b1e6172f1f2557087a2b1b69978021fa9ac1f
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 326b1e6172f1 -r 9a33be857368 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 326b1e6172f1 -r 9a33be857368 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 326b1e6172f1 -r 9a33be857368 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 326b1e6172f1 -r 9a33be857368 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 326b1e6172f1 -r 9a33be857368 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()