COarse-grain LOck-stepping Virtual Machines for Non-stop Service
cover COarse-grain LOck-stepping Virtual Machines for Non-stop Service
Virtual machine (VM) replication is a well known technique for providing application-agnostic software-implemented hardware fault tolerance - "non-stop service". Currently, remus provides this function, but it buffers all output packets, and the latency is unacceptable.
In xen summit 2012, We introduce a new VM replication solution: colo (COarse-grain LOck-stepping virtual machine). The presentation is in the following URL:
http://www.slideshare.net/xen_com_mgr/colo-coarsegrain-lockstepping-virtual-machines-for-nonstop-service
Here is the summary of the solution:
Quoted 1 line
From the client's point of view, as long as the client observes identical
responses from the primary and secondary VMs, according to the service semantics, then the secondary VM(SVM) is a valid replica of the primary VM(PVM), and can successfully take over when a hardware failure of the PVM is detected.
This patchset is RFC, and implements the frame of colo:
1. Both PVM and SVM are running
2. Forward the input packets from client to secondary machine(slaver)
3. Forward the output packets from SVM to primary machine(master)
4. Compare the output packets from PVM and SVM on the master side. If the output packets are different, do a checkpoint
Changelog:
Patch 1: optimize the dirty pages transfer speed.
Patch 2-3: allow SVM running after checkpoint
Patch 4-5: modification for colo on the master side(wait a new checkpoint,
communicate with slaver when doing checkoint)
Patch 6-7: implement colo's user interface
Wen Congyang (7):
xc_domain_save: cache pages mapping
xc_domain_restore: introduce restore_callbacks for colo
colo: implement restore_callbacks
xc_domain_save: flush cache before calling callbacks->postcopy()
xc_domain_save: implement save_callbacks for colo
XendCheckpoint: implement colo
remus: implement colo mode
tools/libxc/Makefile | 4 +- tools/libxc/ia64/xc_ia64_linux_restore.c | 3 +- tools/libxc/xc_domain_restore.c | 256 +++++--- tools/libxc/xc_domain_restore_colo.c | 740 ++++++++++++++++++++++ tools/libxc/xc_domain_save.c | 162 +++-- tools/libxc/xc_save_restore_colo.h | 44 ++ tools/libxc/xenguest.h | 57 +- tools/libxl/libxl_dom.c | 2 +- tools/python/xen/lowlevel/checkpoint/checkpoint.c | 289 ++++++++- tools/python/xen/lowlevel/checkpoint/checkpoint.h | 2 + tools/python/xen/remus/image.py | 7 +- tools/python/xen/remus/save.py | 6 +- tools/python/xen/xend/XendCheckpoint.py | 138 ++-- tools/remus/remus | 8 +- tools/xcutils/xc_restore.c | 3 +- xen/include/public/xen.h | 1 + 16 files changed, 1503 insertions(+), 219 deletions(-) create mode 100644 tools/libxc/xc_domain_restore_colo.c create mode 100644 tools/libxc/xc_save_restore_colo.h
Signature · 1 line
1.8.0
RFC PATCH 1/7 xc_domain_save: cache pages mapping
We map the dirty pages, and copy them to secondary machine, and then unmap it. xc_map_foreign_bulk() is too slow, so we can't use full bandwidth to transfer dirty pages. In out test, the transfer speed is less than 300Mb/s. For virtual machine (VM) replication, the transfer speed is very important, so we should cache pages mapping to map the same page only one time. In our test, the transfer speed is about 2Gb/s with this patch.
--- tools/libxc/xc_domain_save.c | 113 +++++++++++++++++++++++++------------------ 1 file changed, 66 insertions(+), 47 deletions(-)
tools/libxc/xc_domain_save.c +66 -47
@@ -896,6 +896,50 @@ static int save_tsc_info(xc_interface *xch, uint32_t dom, int io_fd)return 0 ; } +/* big cache to avoid future map */ +static char **pages_base; + +static int colo_ro_map_and_cache (xc_interface *xch,uint32_t dom, +unsigned long *pfn_batch,xen_pfn_t *pfn_type, +int *pfn_err,int batch) +{ +static xen_pfn_t cache_pfn_type[MAX_BATCH_SIZE ]; +static int cache_pfn_err[MAX_BATCH_SIZE ]; +int i, cache_batch =0 ; +char *map; + +for (i =0 ; i < batch; i++) + { +if (!pages_base[pfn_batch[i]]) + cache_pfn_type[cache_batch++] = pfn_type[i]; + } + +if (cache_batch) + { + map =xc_map_foreign_bulk (xch, dom,PROT_READ , cache_pfn_type, cache_pfn_err, cache_batch); +if (!map) +return -1 ; + } + + cache_batch =0 ; +for (i =0 ; i < batch; i++) + { +if (pages_base[pfn_batch[i]]) + { + pfn_err[i] =0 ; + } +else + { +if (!cache_pfn_err[cache_batch]) + pages_base[pfn_batch[i]] = map +PAGE_SIZE * cache_batch; + pfn_err[i] = cache_pfn_err[cache_batch]; + cache_batch++; + } + } + +return 0 ; +} +int xc_domain_save (xc_interface *xch,int io_fd,uint32_t dom,uint32_t max_iters,uint32_t max_factor,uint32_t flags,struct save_callbacks * callbacks,int hvm)
@@ -927,9 +971,6 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter/* Live mapping of shared info structure */ shared_info_any_t *live_shinfo =NULL ; -/* base of the region in which domain memory is mapped */ -unsigned char *region_base =NULL ; -/* A copy of the CPU eXtended States of the guest. */ DECLARE_HYPERCALL_BUFFER (void, buffer);
@@ -1111,6 +1152,14 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_itermemset (pfn_type,0 ,ROUNDUP (MAX_BATCH_SIZE *sizeof (*pfn_type),PAGE_SHIFT )); + pages_base =calloc (dinfo->p2m_size,sizeof (*pages_base)); +if (!pages_base) + { +ERROR ("failed to alloc memory to cache page mapping" ); + errno =ENOMEM ; + goto out; + } +/* Setup the mfn_to_pfn table mapping */ if ( !(ctx->live_m2p =xc_map_m2p (xch, ctx->max_mfn,PROT_READ , &ctx->m2p_mfn0)) ) {
@@ -1308,9 +1357,8 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iterif ( batch ==0 ) goto skip;/* vanishingly unlikely... */ - region_base =xc_map_foreign_bulk ( - xch, dom,PROT_READ , pfn_type, pfn_err, batch); -if ( region_base ==NULL ) +if (colo_ro_map_and_cache (xch, dom, pfn_batch, pfn_type, pfn_err, + batch) <0 ) {PERROR ("map batch failed" ); goto out;
@@ -1356,7 +1404,7 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iterDPRINTF ("%d pfn=%08lx sum=%08lx\n" , iter, pfn_type[j], -csum_page (region_base + (PAGE_SIZE *j))); +csum_page (pages_base[pfn_batch[j]])); else DPRINTF("%d pfn= %08lx mfn= %08lx [mfn]= %08lx" " sum= %08lx\n",
@@ -1364,13 +1412,12 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter pfn_type[j], gmfn,mfn_to_pfn (gmfn), - csum_page(region_base + (PAGE_SIZE*j))); + csum_page(pages_base[pfn_batch[j]])); } }if ( !run ) { -munmap (region_base, batch*PAGE_SIZE );continue ;/* bail on this batch: no valid pages */ }
@@ -1393,33 +1440,14 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter pfn_type[j] = ((unsigned long *)pfn_type)[j];/* entering this loop, pfn_type is now in pfns (Not mfns) */ - run =0 ;for ( j =0 ; j < batch; j++ ) {unsigned long pfn, pagetype; -void *spage = (char *)region_base + (PAGE_SIZE *j); +void *spage = pages_base[pfn_batch[j]]; pfn = pfn_type[j] & ~XEN_DOMCTL_PFINFO_LTAB_MASK ; pagetype = pfn_type[j] &XEN_DOMCTL_PFINFO_LTAB_MASK ; -if ( pagetype !=0 ) - { -/* If the page is not a normal data page, write out any -run of pages we may have previously acumulated */ -if ( run ) - { -if (ratewrite (io_fd, live, - (char *)region_base+(PAGE_SIZE *(j-run)), -PAGE_SIZE *run) !=PAGE_SIZE *run ) - { -PERROR ("Error when writing to state file (4a)" -" (errno %d)" , errno); - goto out; - } - run =0 ; - } - } -/* skip pages that aren't present */ if ( pagetype ==XEN_DOMCTL_PFINFO_XTAB )continue ;
@@ -1449,28 +1477,19 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter }else { -/* We have a normal page: accumulate it for writing. */ - run++; +/* stop accumulate write temporarily. we will add it +* back via writev() when needed. +*/ +if (ratewrite (io_fd, live, spage,PAGE_SIZE ) !=PAGE_SIZE ) + { +PERROR ("Error when writing to state file (4c)" +" (errno %d)" , errno); + goto out; + } } }/* end of the write out for this batch */ -if ( run ) - { -/* write out the last accumulated run of pages */ -if (ratewrite (io_fd, live, - (char *)region_base+(PAGE_SIZE *(j-run)), -PAGE_SIZE *run) !=PAGE_SIZE *run ) - { -PERROR ("Error when writing to state file (4c)" -" (errno %d)" , errno); - goto out; - } - } - sent_this_iter += batch; - -munmap (region_base, batch*PAGE_SIZE ); - }/* end of this while loop for this iteration */ skip:
Signature · 1 line
1.8.0
RFC PATCH 2/7 xc_domain_restore: introduce restore_callbacks for colo
In reply to Wen CongyangIn colo mode, SVM also runs. So we should update xc_restore to support it. The first step is: add some callbacks for colo.
We add the following callbacks:
1. init(): init the private data used for colo
2. free(): free the resource we allocate and store in the private data
3. get_page(): SVM runs, so we can't update the memory in apply_batch(). This callback will return a page buffer, and apply_batch() will copy the page to this buffer. The content of this buffer should be the current content of this page, so we can use it to do verify.
4. flush_memory(): update the SVM memory and pagetable.
5. update_p2m(): update the SVM p2m page.
6. finish_restore(): wait a new checkpoint.
We also add a new structure restore_data to avoid pass too many arguments to these callbacks. This structure stores the variables used in xc_domain_store(), and these variables will be used in the callback.
--- tools/libxc/ia64/xc_ia64_linux_restore.c | 3 +- tools/libxc/xc_domain_restore.c | 256 +++++++++++++++++++++---------- tools/libxc/xenguest.h | 54 ++++++- tools/libxl/libxl_dom.c | 2 +- tools/xcutils/xc_restore.c | 3 +- 5 files changed, 230 insertions(+), 88 deletions(-)
tools/libxc/ia64/xc_ia64_linux_restore.c +2 -1
@@ -550,7 +550,8 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom, unsigned int store_evtchn, unsigned long *store_mfn, unsigned int console_evtchn, unsigned long *console_mfn, - unsigned int hvm, unsigned int pae, int superpages) + unsigned int hvm, unsigned int pae, int superpages, + struct restore_callbacks *callbacks) {DECLARE_DOMCTL ;int rc =1 ;
tools/libxc/xc_domain_restore.c +172 -84
384 lines not on this page · raw message
tools/libxc/xenguest.h +53 -1
66 lines not on this page · raw message
tools/libxl/libxl_dom.c +1 -1
@@ -305,7 +305,7 @@ int libxl__domain_restore_common(libxl_ctx *ctx, uint32_t domid, rc =xc_domain_restore (ctx->xch, fd, domid, state->store_port, &state->store_mfn, state->console_port, &state->console_mfn, - info->hvm, info->u.hvm.pae,0 ); + info->hvm, info->u.hvm.pae,0 ,NULL );if ( rc ) {LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"restoring domain" );return ERROR_FAIL ;
tools/xcutils/xc_restore.c +2 -1
@@ -46,7 +46,8 @@ main(int argc, char **argv) superpages =0 ; ret =xc_domain_restore (xch, io_fd, domid, store_evtchn, &store_mfn, - console_evtchn, &console_mfn, hvm, pae, superpages); + console_evtchn, &console_mfn, hvm, pae, superpages, +NULL );if ( ret ==0 ) {
Signature · 1 line
1.8.0
RFC PATCH 3/7 colo: implement restore_callbacks
In reply to Wen CongyangThis patch implements restore callbacks for colo:
1. init(): allocate some memory
2. free(): free the memory allocated in init()
3. get_page(): We have cache the whole memory, so just return the buffer. This page is also marked as dirty.
4. flush_memory():
We update the memory as the following:
a. pin non-dirty L1 pagetables
b. unpin pagetables execpt non-dirty L1
c. update the memory
d. pin page tables
e. unpin non-dirty L1 pagetables
5. update_p2m(): Just update the dirty pages which store p2m.
6. finish_store():
We run xc_restore in XendCheckpoint.py. We communicate with XendCheckpoint.py like this:
a. write "finish\n" to stdout when we are ready to resume the vm. b. XendCheckpoint.py writes "resume\n" when the vm is resumed c. write "resume\n" to stdout when postresume is done
d. XendCheckpoint.py writes "suspend\n" when a new checkpoint begins e. write "suspend\n" to stdout when the vm is suspended f. XendCheckpoint.py writes "start\n" when primary begins to transfer
dirty pages.
--- tools/libxc/Makefile | 4 +- tools/libxc/xc_domain_restore_colo.c | 740 +++++++++++++++++++++++++++++++++++ tools/libxc/xc_domain_save.c | 34 +- tools/libxc/xc_save_restore_colo.h | 44 +++ xen/include/public/xen.h | 1 + 5 files changed, 788 insertions(+), 35 deletions(-) create mode 100644 tools/libxc/xc_domain_restore_colo.c create mode 100644 tools/libxc/xc_save_restore_colo.h
tools/libxc/Makefile +2 -2
@@ -42,12 +42,12 @@ CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c 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_domain_restore.c xc_domain_save.c xc_domain_restore_colo.c GUEST_SRCS-$(CONFIG_MIGRATE) += xc_offline_page.c GUEST_SRCS-$(CONFIG_HVM) += xc_hvm_build.c vpath %.c ../../xen/common/libelf -CFLAGS += -I../../xen/common/libelf +CFLAGS += -I../../xen/common/libelf -I../xenstore GUEST_SRCS-y += libelf-tools.c libelf-loader.c GUEST_SRCS-y += libelf-dominfo.c libelf-relocate.c
tools/libxc/xc_domain_restore_colo.c new file +740 -0
740 lines not on this page · raw message
tools/libxc/xc_domain_save.c +1 -33
@@ -28,8 +28,7 @@#include "xc_private.h" #include "xc_dom.h" -#include "xg_private.h" -#include "xg_save_restore.h" +#include "xc_save_restore_colo.h" #include <xen/hvm/params.h> #include "xc_e820.h"
@@ -82,37 +81,6 @@ struct outbuf { ((mfn_to_pfn(_mfn) < (dinfo->p2m_size)) && \ (pfn_to_mfn(mfn_to_pfn(_mfn)) == (_mfn)))) -/* -** During (live) save/migrate, we maintain a number of bitmaps to track -** which pages we have to send, to fixup, and to skip. -*/ - -#define BITS_PER_LONG (sizeof(unsigned long) * 8) -#define BITS_TO_LONGS (bits) (((bits)+BITS_PER_LONG-1)/BITS_PER_LONG) -#define BITMAP_SIZE (BITS_TO_LONGS(dinfo->p2m_size) * sizeof(unsigned long)) - -#define BITMAP_ENTRY (_nr,_bmap) \ - ((volatile unsigned long *)(_bmap))[(_nr)/BITS_PER_LONG] - -#define BITMAP_SHIFT (_nr) ((_nr) % BITS_PER_LONG) - -#define ORDER_LONG (sizeof(unsigned long) == 4 ? 5 : 6) - -static inline int test_bit (int nr,volatile void * addr) -{ -return (BITMAP_ENTRY (nr, addr) >>BITMAP_SHIFT (nr)) &1 ; -} - -static inline void clear_bit (int nr,volatile void * addr) -{ -BITMAP_ENTRY (nr, addr) &= ~(1UL <<BITMAP_SHIFT (nr)); -} - -static inline void set_bit (int nr,volatile void * addr) -{ -BITMAP_ENTRY (nr, addr) |= (1UL <<BITMAP_SHIFT (nr)); -} -/* Returns the hamming weight (i.e. the number of bits set) in a N-bit word */ static inline unsigned int hweight32 (unsigned int w) {
tools/libxc/xc_save_restore_colo.h new file +44 -0
44 lines not on this page · raw message
xen/include/public/xen.h +1 -0
@@ -93,6 +93,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_pfn_t);#define __HYPERVISOR_domctl 36#define __HYPERVISOR_kexec_op 37#define __HYPERVISOR_tmem_op 38 +#define __HYPERVISOR_reset_memory_op 40/* Architecture-specific hypercall definitions. */ #define __HYPERVISOR_arch_0 48
Signature · 1 line
1.8.0
Re: [RFC PATCH 3/7] colo: implement restore_callbacks
Hi,
tools/libxc/xc_domain_restore_colo.c line 735
Quoted 4 lines · Wen Congyang
tools/libxc/xc_domain_restore_colo.c new file +4
-0+/* reset memory */ + hypercall.op = __HYPERVISOR_reset_memory_op; + hypercall.arg[0 ] = (unsigned long )dom; +do_xen_hypercall (xch, &hypercall);
You've added a new hypercall here but I don't see any implementation (or documentation). Are there some xen-side patches missing?
Cheers,
Tim.
Quoted 16 lines
xen/include/public/xen.h +1
-0@@ -93,6 +93,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_pfn_t);#define __HYPERVISOR_domctl 36#define __HYPERVISOR_kexec_op 37#define __HYPERVISOR_tmem_op 38 +#define __HYPERVISOR_reset_memory_op 40/* Architecture-specific hypercall definitions. */ #define __HYPERVISOR_arch_0 48Signature · 7 lines
1.8.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
RFC PATCH 4/7 xc_domain_save: flush cache before calling callbacks->postcopy()
In reply to Wen Congyangcallbacks->postcopy() may use the fd to transfer something to the other end, so we should flush cache before calling callbacks->postcopy()
--- tools/libxc/xc_domain_save.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/libxc/xc_domain_save.c +3 -3
@@ -1886,9 +1886,6 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter out: completed =1 ; -if ( !rc && callbacks->postcopy ) - callbacks->postcopy (callbacks->data); -/* Flush last write and discard cache for file. */ if (outbuf_flush (xch, &ob, io_fd) <0 ) {PERROR ("Error when flushing output buffer" );
@@ -1897,6 +1894,9 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iterdiscard_file_cache (xch, io_fd,1 /* flush */ ); +if ( !rc && callbacks->postcopy ) + callbacks->postcopy (callbacks->data); +/* checkpoint_cb can spend arbitrarily long in between rounds */ if (!rc && callbacks->checkpoint && callbacks->checkpoint (callbacks->data) >0 )
Signature · 1 line
1.8.0
RFC PATCH 5/7 xc_domain_save: implement save_callbacks for colo
In reply to Wen CongyangAdd a new save callbacks:
1. post_sendstate(): SVM will run only when XC_SAVE_ID_LAST_CHECKPOINT is sent to slaver. But we only sent XC_SAVE_ID_LAST_CHECKPOINT when we do live migration now. Add this callback, and we can send it in this callback.
Update some callbacks for colo:
1. suspend(): In colo mode, both PVM and SVM are running. So we should suspend both PVM and SVM.
Communicate with slaver like this:
a. write "continue" to notify slaver to suspend SVM
b. suspend PVM and SVM
c. slaver writes "suspend" to tell master that SVM is suspended
2. postcopy(): In colo mode, both PVM and SVM are running, and we have suspended both PVM and SVM. So we should resume PVM and SVM Communicate with slaver like this:
a. write "resume" to notify slaver to resume SVM
b. resume PVM and SVM
c. slaver writes "resume" to tell master that SVM is resumed
3. checkpoint(): In colo mode, we do a new checkpoint only when output packet from PVM and SVM is different. We will block in this callback and return when a output packet is different.
--- tools/libxc/xc_domain_save.c | 9 + tools/libxc/xenguest.h | 3 + tools/python/xen/lowlevel/checkpoint/checkpoint.c | 289 +++++++++++++++++++++- tools/python/xen/lowlevel/checkpoint/checkpoint.h | 2 + 4 files changed, 299 insertions(+), 4 deletions(-)
tools/libxc/xc_domain_save.c +9 -0
@@ -1645,6 +1645,15 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter } } +if ( callbacks->post_sendstate ) + { +if ( callbacks->post_sendstate (callbacks->data) <0 ) + { +PERROR ("Error: post_sendstate()\n" ); + goto out; + } + } +/* Zero terminate */ i =0 ;if (wrexact (io_fd, &i,sizeof (int )) )
tools/libxc/xenguest.h +3 -0
@@ -43,6 +43,9 @@ struct save_callbacks {/* Enable qemu-dm logging dirty pages to xen */ int (*switch_qemu_logdirty)(int domid,unsigned enable,void *data);/* HVM only */ +/* called before Zero terminate is sent */ +int (*post_sendstate)(void *data); +/* to be provided as the last argument to each callback function */ void * data; };
tools/python/xen/lowlevel/checkpoint/checkpoint.c +285 -4
387 lines not on this page · raw message
tools/python/xen/lowlevel/checkpoint/checkpoint.h +2 -0
@@ -40,6 +40,8 @@ typedef struct {timer_t timer; } checkpoint_state; +#define CHECKPOINT_FLAGS_COLO 2 +char *checkpoint_error (checkpoint_state * s);void checkpoint_init (checkpoint_state * s);
Signature · 1 line
1.8.0
RFC PATCH 6/7 XendCheckpoint: implement colo
In reply to Wen CongyangIn colo mode, XendCheckpoit.py will communicate with both master and xc_restore. This patch implements this communication. In colo mode, the signature is "GuestColoRestore".
--- tools/python/xen/xend/XendCheckpoint.py | 138 +++++++++++++++++++++++--------- 1 file changed, 101 insertions(+), 37 deletions(-)
tools/python/xen/xend/XendCheckpoint.py +101 -37
@@ -25,6 +25,7 @@ from xen.xend.XendConstants import * from xen.xend import XendNode SIGNATURE = "LinuxGuestRecord" +COLO_SIGNATURE = "GuestColoRestore" QEMU_SIGNATURE = "QemuDeviceModelRecord" dm_batch = 512 XC_SAVE = "xc_save"
@@ -203,10 +204,15 @@ def restore(xd, fd, dominfo = None, paused = False, relocating = False): signature = read_exact(fd, len(SIGNATURE), "not a valid guest state file: signature read") - if signature != SIGNATURE: + if signature != SIGNATURE and signature != COLO_SIGNATURE: raise XendError("not a valid guest state file: found '%s'" % signature) + if signature == COLO_SIGNATURE: + colo = True + else + colo = False + l = read_exact(fd, sizeof_int, "not a valid guest state file: config size read") vmconfig_size = unpack("!i", l)[0]
@@ -305,6 +311,7 @@ def restore(xd, fd, dominfo = None, paused = False, relocating = False): log.debug("[xc_restore]: %s", string.join(cmd)) handler = RestoreInputHandler() + restore_handler = RestoreHandler(fd, colo, dominfo, inputHandler) forkHelper(cmd, fd, handler.handler, True)
@@ -321,35 +328,9 @@ def restore(xd, fd, dominfo = None, paused = False, relocating = False): raise XendError('Could not read store MFN') if not is_hvm and handler.console_mfn is None: - raise XendError('Could not read console MFN') - - restore_image.setCpuid() - - # xc_restore will wait for source to close connection - - dominfo.completeRestore(handler.store_mfn, handler.console_mfn) - - # - # We shouldn't hold the domains_lock over a waitForDevices - # As this function sometime gets called holding this lock, - # we must release it and re-acquire it appropriately - # - from xen.xend import XendDomain + raise XendError('Could not read console MFN') - lock = True; - try: - XendDomain.instance().domains_lock.release() - except: - lock = False; - - try: - dominfo.waitForDevices() # Wait for backends to set up - finally: - if lock: - XendDomain.instance().domains_lock.acquire() - - if not paused: - dominfo.unpause() + restorehandler.resume(True, paused, None) return dominfo except Exception, exn:
@@ -358,23 +339,106 @@ def restore(xd, fd, dominfo = None, paused = False, relocating = False): raise exn +class RestoreHandler: + def __init__(self, fd, colo, dominfo, inputHandler): + self.fd = fd + self.colo = colo + self.firsttime = True + self.inputHandler = inputHandler + self.dominfo = dominfo + + def resume(self, finish, paused, child): + fd = self.fd + dominfo = self.dominfo + handler = self.inputHandler + restore_image.setCpuid() + dominfo.completeRestore(handler.store_mfn, handler.console_mfn) + + if self.colo and not finish: + # notify master that checkpoint finishes + write_exact(fd, "finish", "failed to write finish done") + buf = read_exact(fd, 6, "failed to read resume flag") + if buf != "resume": + return False + + from xen.xend import XendDomain + + if self.firsttime: + lock = True; + try: + XendDomain.instance().domains_lock.release() + except: + lock = False; + + try: + dominfo.waitForDevices() # Wait for backends to set up + finally: + if lock: + XendDomain.instance().domains_lock.acquire() + if not paused: + dominfo.unpause() + else: + # colo + xc.domain_resume(dominfo.domid, 0) + ResumeDomain(dominfo.domid) + + if self.colo and not finish: + child.tochild.write("resume\n") + child.tochild.flush() + buf = child.fromchild.readline() + if buf != "resume\n": + return False + if self.firsttime: + util.runcmd("/etc/xen/scripts/HA_fw_runtime.sh slaver") + # notify master side VM resumed + write_exact(fd, "resume", "failed to write resume done"); + + # wait new checkpoint + buf = read_exact(fd, 8, "failed to read continue flag") + if buf != "continue": + return False + + child.tochild.write("suspend\n") + buf = child.fromchild.readline() + if buf != "suspend\n": + return False + + # notify master side suspend done. + write_exact(fd, "suspend", "failed to write suspend done") + buf = read_exact(fd, 5, "failed to read start flag") + if buf != "start": + return False + + child.tochild.write("start\n") + child.tochild.flush() + + self.firsttime = False + class RestoreInputHandler: - def __init__(self): + def __init__(self, colo): self.store_mfn = None self.console_mfn = None - def handler(self, line, _): + def handler(self, line, child, restorehandler): + if line == "finish\n": + # colo + return restorehandler.resume(False, False, child) + m = re.match(r"^(store-mfn) (\d+)$", line) if m: self.store_mfn = int(m.group(2)) - else: - m = re.match(r"^(console-mfn) (\d+)$", line) - if m: - self.console_mfn = int(m.group(2)) + return True + + m = re.match(r"^(console-mfn) (\d+)$", line) + if m: + self.console_mfn = int(m.group(2)) + return True + + return False -def forkHelper(cmd, fd, inputHandler, closeToChild): +def forkHelper(cmd, fd, inputHandler, closeToChild, restorehandler): child = xPopen3(cmd, True, -1, [fd]) if closeToChild:
@@ -392,7 +456,7 @@ def forkHelper(cmd, fd, inputHandler, closeToChild): else: line = line.rstrip() log.debug('%s', line) - inputHandler(line, child.tochild) + inputHandler(line, child, restorehandler) except IOError, exn: raise XendError('Error reading from child process for %s: %s' %
Signature · 1 line
1.8.0
RFC PATCH 7/7 remus: implement colo mode
In reply to Wen CongyangAdd a new option --colo to the command remus. We will ignore the
options: --time, -i, --no-net when --colo is specified. In colo mode, we will write new signature "GuestColoRestore". If the xen-tool in secondary machine does not support colo, it will reject this signature, and the command remus will fail.
--- tools/python/xen/remus/image.py | 7 +++++-- tools/python/xen/remus/save.py | 6 ++++-- tools/remus/remus | 8 +++++++- 3 files changed, 16 insertions(+), 5 deletions(-)
tools/python/xen/remus/image.py +5 -2
@@ -189,9 +189,12 @@ def parseheader(header): "parses a header sexpression" return vm.parsedominfo(vm.strtosxpr(header)) -def makeheader(dominfo): +def makeheader(dominfo, colo): "create an image header from a VM dominfo sxpr" - items = [SIGNATURE] + if colo: + items = [COLO_SIGNATURE] + else: + items = [SIGNATURE] sxpr = vm.sxprtostr(dominfo) items.append(struct.pack('!i', len(sxpr))) items.append(sxpr)
tools/python/xen/remus/save.py +4 -2
@@ -127,7 +127,7 @@ class Keepalive(object): class Saver(object): def __init__(self, domid, fd, suspendcb=None, resumecb=None, - checkpointcb=None, interval=0): + checkpointcb=None, interval=0, colo): """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.
@@ -135,12 +135,14 @@ class Saver(object): resumecb: callback invoked before guest resumes checkpointcb: callback invoked when a checkpoint is complete. Return True to take another checkpoint, or False to stop. + colo: use colo mode """ self.fd = fd self.suspendcb = suspendcb self.resumecb = resumecb self.checkpointcb = checkpointcb self.interval = interval + self.colo = colo self.vm = vm.VM(domid)
@@ -149,7 +151,7 @@ class Saver(object): def start(self): vm.getshadowmem(self.vm) - hdr = image.makeheader(self.vm.dominfo) + hdr = image.makeheader(self.vm.dominfo, self.colo) self.fd.write(hdr) self.fd.flush()
tools/remus/remus +7 -1
@@ -37,6 +37,8 @@ class Cfg(object): help='run without net buffering (benchmark option)') parser.add_option('', '--timer', dest='timer', action='store_true', help='force pause at checkpoint interval (experimental)') + parser.add_option('', '--colo', dest='colo', action='store_true', + help='use colo checkpointing (experimental)') self.parser = parser def usage(self):
@@ -53,6 +55,10 @@ class Cfg(object): self.netbuffer = False if opts.timer: self.timer = True + if opts.colo: + self.interval = 0 + self.netbuffer = False + self.timer = True if not args: raise CfgException('Missing domain')
@@ -181,7 +187,7 @@ def run(cfg): rc = 0 checkpointer = save.Saver(cfg.domid, fd, postsuspend, preresume, commit, - interval) + interval, cfg.colo) try: checkpointer.start()
Signature · 1 line
1.8.0
Quoted 4 lines · Wen Congyang
Virtual machine (VM) replication is a well known technique for providing application-agnostic software-implemented hardware fault tolerance - "non-stop service". Currently, remus provides this function, but it buffers all output packets, and the latency is unacceptable.
Just FYI, as we're in a feature freeze this can't be accepted until the 4.3 release sometime in June; and since in the mean time we'll be trying to get other features sorted and bugs fixed, you may not get much review time until then.
-George
FYI, it would be nice to cc the maintainer when you submit such a major functionality change,
especially for the xend code base that has so far been the only stable workable remus solution.
Quoted 12 lines · George Dunlap
Quoted 3 lines · Wen Congyang
Virtual machine (VM) replication is a well known technique for providing application-agnostic software-implemented hardware fault tolerance - "non-stop service". Currently, remus provides this function, but it
buffers
Quoted 1 line
all output packets, and the latency is unacceptable.
Just FYI, as we're in a feature freeze this can't be accepted until the 4.3 release sometime in June; and since in the mean time we'll be trying to get other features sorted and bugs fixed, you may not get much review time until then.
Quoted 7 lines
-George
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 2 lines · Shriram Rajagopalan
the xend code base that has so far been the only stable workable remus solution.
What is the status of xl remus at the minute? Is it being actively worked on?
Ian
Quoted 18 lines · Wen Congyang
Virtual machine (VM) replication is a well known technique for providing application-agnostic software-implemented hardware fault tolerance - "non-stop service". Currently, remus provides this function, but it buffers all output packets, and the latency is unacceptable.
In xen summit 2012, We introduce a new VM replication solution: colo (COarse-grain LOck-stepping virtual machine). The presentation is in the following URL:
Here is the summary of the solution:
From the client's point of view, as long as the client observes identical responses from the primary and secondary VMs, according to the service semantics, then the secondary VM(SVM) is a valid replica of the primary VM(PVM), and can successfully take over when a hardware failure of the PVM is detected.
Quoted 8 lines
This patchset is RFC, and implements the frame of colo:
1. Both PVM and SVM are running
2. Forward the input packets from client to secondary machine(slaver)
3. Forward the output packets from SVM to primary machine(master)
4. Compare the output packets from PVM and SVM on the master side. If the output packets are different, do a checkpoint
I skimmed through the presentation. Interesting approach. It would be nice to have the performance report
that is mentioned in the slides, available, so that we can understand the exact setups for the benchmarks.
A few quick thoughts after looking at the presentation:
0. I am not completely sold on the type of applications you have used to
benchmark the system. They seem
stateless and dont have much of memory churn (dirty pages/epoch). It would be nice to benchmark your system against something more
realistic, like the DVDStore benchmark
or percona-tools' TPCC benchmark with MySQL. [The clients have to be
outside the system, mind you].
And finally, something like Specweb2005, where there are about 1000
dirty pages per 25ms epoch.
I care more about how many concurrent connections was handled by the
server and how frequently did you
have to synchronize between the machines.
1. The checkpoints are going to be very costly. If you are doing coarse
grained locking and assuming
that checkpoint are triggered every second, you would probably lose
all benefits of checkpoint compression.
Also your working set would have grown considerably large. You will
inevitably end up taking the
slow path, where you suspend the VM, "synchronously" send a ton of
pages over the network
(on the order of 10-100s of megabytes), and then resume the VM.
Replicating this checkpoint is going to take
a long time and will screw performance.
The usual fast path has a small buffer (16/32 MB) to copy out the
dirty pages to the buffer, and asynchronously
transmit it to the backup.
2. Whats the story for the DISK? The slides show that the VMs share a SAN disk.
And if both primary and secondary are operational, whose packets are
you going
to discard, in a programmatic manner ?
While you have a FTP server benchmark, it doesnt demonstrate output
consistency.
I would suggest you run something like DVDStore (from Dell) or some
simple mysql TPCC
and see if the clients raise a hue and cry about data corruption. ;)
3. What happens if one is running faster than the other ?
Lets say the application does a bunch of read/write (dependent)
to/from the SAN.
each write depends on the output of the previous read. And the writes
are non-deterministic
(i.e. differ between primary and secondary). Wont this system end up
in perpetual synchronization,
since the outputs from primary and backup would be different, causing
a checkpoint again and again ?
And I would like to see atleast some *informal* guarantees of data consistency - might sound academic but
when you are talking about putting critical customer applications like a MySQL database, a SAP server or an
e-commerce web app, "consistency" matters! It helps to convince people that this system is not some half baked
experiment but something that is well thought of.
Once again, please CC me on the patches. Several files you have touched belong to remus code
and the MAINTAINERS file has the maintainer info.
Nit: in one of your slides, you mentioned (75 ms/checkpoint, of which 2/3rds was spend in suspend/resume).
That isnt an artifact of Remus, FYI. I have run remus at 20ms checkpoint interval, where VMs were suspended,
checkpointed and resumed in under 2ms.
With the addition of a ton of functionality -- both at the toolstack and in the guest kernel -- the suspend resume times have
gone up considerably. If you want to reduce that overhead, try a SuSe based kernel that has suspend-event channel support.
You may not need any of those lazy netifs/netups etc.
Even with that, the new power management framework in the 3.* kernels seem to have made suspend/resume pretty slow.
thanks
shriram
Changelog:
Quoted 37 lines
Patch 1: optimize the dirty pages transfer speed. Patch 2-3: allow SVM running after checkpoint
Patch 4-5: modification for colo on the master side(wait a new
checkpoint,
communicate with slaver when doing checkoint)
Patch 6-7: implement colo's user interfaceWen Congyang (7):
xc_domain_save: cache pages mapping
xc_domain_restore: introducerestore_callbacksfor colo
colo: implementrestore_callbacks
xc_domain_save: flush cache before callingcallbacks->postcopy()
xc_domain_save: implementsave_callbacksfor colo
XendCheckpoint: implement colo
remus: implement colo modetools/libxc/Makefile | 4 +- tools/libxc/ia64/xc_ia64_linux_restore.c | 3 +- tools/libxc/xc_domain_restore.c | 256 +++++--- tools/libxc/xc_domain_restore_colo.c | 740 ++++++++++++++++++++++ tools/libxc/xc_domain_save.c | 162 +++-- tools/libxc/xc_save_restore_colo.h | 44 ++ tools/libxc/xenguest.h | 57 +- tools/libxl/libxl_dom.c | 2 +- tools/python/xen/lowlevel/checkpoint/checkpoint.c | 289 ++++++++- tools/python/xen/lowlevel/checkpoint/checkpoint.h | 2 + tools/python/xen/remus/image.py | 7 +- tools/python/xen/remus/save.py | 6 +- tools/python/xen/xend/XendCheckpoint.py | 138 ++-- tools/remus/remus | 8 +- tools/xcutils/xc_restore.c | 3 +- xen/include/public/xen.h | 1 + 16 files changed, 1503 insertions(+), 219 deletions(-) create mode 100644 tools/libxc/xc_domain_restore_colo.c create mode 100644 tools/libxc/xc_save_restore_colo.h
Quoted 9 lines
--
1.8.0_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel