spee up live migration by skipping free pages
cover spee up live migration by skipping free pages
Current QEMU live migration implementation marks all guest's RAM pages as dirtied in the ram bulk stage, all these pages will be processed and it consumes quite a lot of CPU cycles and network bandwidth.
Quoted 1 line
From guest's point of view, it doesn't care about the content in free
page. We can make use of this fact and skip processing the free pages, it can save a lot CPU cycles and reduce the network traffic significantly while speed up the live migration process obviously.
This patch set is the QEMU side implementation.
The virtio-balloon is extended so that QEMU can get the free pages information from the guest.
After getting the free page bitmap, QEMU can use it to filter out guest's free pages. This make the live migration process much more efficient.
In order to skip more free pages, we add an interface to let the user decide whether dropping the cache in guest during live migration.
Performance data
================
Test environment:
CPU: Intel (R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz Host RAM: 64GB Host Linux Kernel: 4.4.0 Host OS: CentOS 7.1 Guest Linux Kernel: 4.5.rc6 Guest OS: CentOS 6.6 Network: Intel X710 with 10 Gigabit connection Guest RAM: 8GB
Case 1: Idle guest just boots:
==================================================
| original | skip free page
--------------------------------------------------
total time(ms) | 1505 | 573
--------------------------------------------------
transferred ram(KB) | 399792 | 379057
==================================================
Case 2: The guest has ever run some memory consuming workload, the workload is terminated before live migration.
==================================================
| original | skip free page
--------------------------------------------------
total time(ms) | 10641 | 597
--------------------------------------------------
transferred ram(KB) | 8350829 | 389900
==================================================
Case 3: The guest has ever built the linux kernel, the building is completed before live migration. The page cache is dropped during live migration in this case.
==================================================
| original | skip free page
--------------------------------------------------
total time(ms) | 2636 | 914
--------------------------------------------------
transferred ram(KB) | 1316747 | 421980
==================================================
Liang Li (5):
bitmap: Add a new bitmap_move function
kvm: Add two new arch specific functions
virtio-balloon: Add a new feature to balloon device
migration: filter out free pages during live migration
migration: Add the interface for cache drop control
balloon.c | 29 +++++++- hmp.c | 8 +++ hw/virtio/virtio-balloon.c | 92 +++++++++++++++++++++++- include/hw/virtio/virtio-balloon.h | 30 +++++++- include/migration/migration.h | 1 + include/qemu/bitmap.h | 13 ++++ include/standard-headers/linux/virtio_balloon.h | 1 + include/sysemu/balloon.h | 12 +++- include/sysemu/kvm.h | 2 + migration/migration.c | 31 +++++++- migration/ram.c | 95 +++++++++++++++++++++++++ qapi-schema.json | 25 ++++++- target-arm/kvm.c | 14 ++++ target-i386/kvm.c | 35 +++++++++ target-mips/kvm.c | 14 ++++ target-ppc/kvm.c | 14 ++++ target-s390x/kvm.c | 14 ++++ 17 files changed, 421 insertions(+), 9 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 1/5 bitmap: Add a new bitmap_move function
Sometimes, it is need to move a portion of bitmap to another place in a large bitmap, if overlap happens, the bitmap_copy can't not work correctly, we need a new function to do this work.
--- include/qemu/bitmap.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
include/qemu/bitmap.h +13 -0
@@ -38,6 +38,7 @@* bitmap_set(dst, pos, nbits) Set specified bit area * bitmap_set_atomic(dst, pos, nbits) Set specified bit area with atomic ops * bitmap_clear(dst, pos, nbits) Clear specified bit area +* bitmap_move(dst, src, nbits) Move *src to *dst * bitmap_test_and_clear_atomic(dst, pos, nbits) Test and clear area * bitmap_find_next_zero_area(buf, len, pos, n, mask) Find bit free area */
@@ -137,6 +138,18 @@ static inline void bitmap_copy(unsigned long *dst, const unsigned long *src, } } +static inline void bitmap_move (unsigned long *dst,const unsigned long *src, +long nbits) +{ +if (small_nbits (nbits)) { +unsigned long tmp = *src; + *dst = tmp; + }else { +long len =BITS_TO_LONGS (nbits) *sizeof (unsigned long ); +memmove (dst, src, len); + } +} +static inline int bitmap_and (unsigned long *dst,const unsigned long *src1,const unsigned long *src2,long nbits) {
Signature · 1 line
1.8.3.1
PATCH 2/5 kvm: Add two new arch specific functions
In reply to Liang LiAdd a new function to get the vm's max pfn and a new function to filter out the holes to get a tight free page bitmap. They are implemented on X86, and all the arches should implement them for live migration optimization.
--- include/sysemu/kvm.h | 2 ++ target-arm/kvm.c | 14 ++++++++++++++ target-i386/kvm.c | 35 +++++++++++++++++++++++++++++++++++ target-mips/kvm.c | 14 ++++++++++++++ target-ppc/kvm.c | 14 ++++++++++++++ target-s390x/kvm.c | 14 ++++++++++++++ 6 files changed, 93 insertions(+)
include/sysemu/kvm.h +2 -0
@@ -228,6 +228,8 @@ int kvm_remove_breakpoint(CPUState *cpu, target_ulong addr, target_ulong len, int type);void kvm_remove_all_breakpoints (CPUState *cpu);int kvm_update_guest_debug (CPUState *cpu,unsigned long reinject_trap); +unsigned long *tighten_guest_free_page_bmap (unsigned long *bmap); +unsigned long get_guest_max_pfn (void );#ifndef _WIN32int kvm_set_signal_mask (CPUState *cpu,const sigset_t *sigset);#endif
target-arm/kvm.c +14 -0
@@ -626,3 +626,17 @@ int kvm_arch_msi_data_to_gsi(uint32_t data) {return (data -32 ) &0xffff ; } + +unsigned long get_guest_max_pfn (void ) +{ +/* To be done */ + +return 0 ; +} + +unsigned long *tighten_guest_free_page_bmap (unsigned long *bmap) +{ +/* To be done */ + +return bmap; +}
target-i386/kvm.c +35 -0
@@ -3334,3 +3334,38 @@ int kvm_arch_msi_data_to_gsi(uint32_t data) {abort (); } + +unsigned long get_guest_max_pfn (void ) +{ +PCMachineState *pcms =PC_MACHINE (current_machine); +ram_addr_t above_4g_mem = pcms->above_4g_mem_size; +unsigned long max_pfn; + +if (above_4g_mem) { + max_pfn = ((1ULL <<32 ) + above_4g_mem) >>TARGET_PAGE_BITS ; + }else { + max_pfn = pcms->below_4g_mem_size >>TARGET_PAGE_BITS ; + } + +return max_pfn; +} + +unsigned long *tighten_guest_free_page_bmap (unsigned long *bmap) +{ +PCMachineState *pcms =PC_MACHINE (current_machine); +ram_addr_t above_4g_mem = pcms->above_4g_mem_size; + +if (above_4g_mem) { +unsigned long *src, *dst, len, pos; +ram_addr_t below_4g_mem = pcms->below_4g_mem_size; + src = bmap + ((1ULL <<32 ) >>TARGET_PAGE_BITS ) /BITS_PER_LONG ; + dst = bmap + (below_4g_mem >>TARGET_PAGE_BITS ) /BITS_PER_LONG ; +bitmap_move (dst, src, above_4g_mem >>TARGET_PAGE_BITS ); + + pos = (above_4g_mem + below_4g_mem) >>TARGET_PAGE_BITS ; + len = ((1ULL <<32 ) - below_4g_mem) >>TARGET_PAGE_BITS ; +bitmap_clear (bmap, pos, len); + } + +return bmap; +}
target-mips/kvm.c +14 -0
@@ -1048,3 +1048,17 @@ int kvm_arch_msi_data_to_gsi(uint32_t data) {abort (); } + +unsigned long get_guest_max_pfn (void ) +{ +/* To be done */ + +return 0 ; +} + +unsigned long *tighten_guest_free_page_bmap (unsigned long *bmap) +{ +/* To be done */ + +return bmap; +}
target-ppc/kvm.c +14 -0
@@ -2579,3 +2579,17 @@ int kvmppc_enable_hwrng(void)return kvmppc_enable_hcall (kvm_state,H_RANDOM ); } + +unsigned long get_guest_max_pfn (void ) +{ +/* To be done */ + +return 0 ; +} + +unsigned long *tighten_guest_free_page_bmap (unsigned long *bmap) +{ +/* To be done */ + +return bmap; +}
target-s390x/kvm.c +14 -0
@@ -2250,3 +2250,17 @@ int kvm_arch_msi_data_to_gsi(uint32_t data) {abort (); } + +unsigned long get_guest_max_pfn (void ) +{ +/* To be done */ + +return 0 ; +} + +unsigned long *tighten_guest_free_page_bmap (unsigned long *bmap) +{ +/* To be done */ + +return bmap; +}
Signature · 1 line
1.8.3.1
PATCH 4/5 migration: filter out free pages during live migration
In reply to Liang LiAfter sending out the request for free pages, live migration process will start without waiting for the free page bitmap is ready. If the free page bitmap is not ready when doing the 1st migration_bitmap_sync() after ram_save_setup(), the free page bitmap will be ignored, this means the free pages will not be filtered out in this case.
The current implementation can not work with post copy, if post copy is enabled, we simply ignore the free pages. Will make it work later.
--- migration/ram.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+)
migration/ram.c +101 -0
@@ -41,6 +41,8 @@#include "trace.h" #include "exec/ram_addr.h" #include "qemu/rcu_queue.h" +#include "sysemu/balloon.h" +#include "sysemu/kvm.h" #ifdef DEBUG_MIGRATION_RAM #define DPRINTF (fmt, ...) \
@@ -226,6 +228,8 @@ static QemuMutex migration_bitmap_mutex;static uint64_t migration_dirty_pages;static uint32_t last_version;static bool ram_bulk_stage; +static bool ignore_freepage_rsp; +static bool drop_page_cache;/* used by the search for pages to send */ struct PageSearchStatus {
@@ -242,6 +246,7 @@ static struct BitmapRcu {struct rcu_head rcu;/* Main migration bitmap */ unsigned long *bmap; +unsigned long *free_page_bmap;/* bitmap of pages that haven't been sent even once * only maintained and used in postcopy at the moment * where it's used to send the dirtymap at the start
@@ -639,6 +644,7 @@ static void migration_bitmap_sync(void)rcu_read_unlock ();qemu_mutex_unlock (&migration_bitmap_mutex); + ignore_freepage_rsp = true;trace_migration_bitmap_sync_end (migration_dirty_pages - num_dirty_pages_init); num_dirty_pages_period += migration_dirty_pages - num_dirty_pages_init;
@@ -1417,6 +1423,9 @@ static void migration_bitmap_free(struct BitmapRcu *bmap) {g_free (bmap->bmap);g_free (bmap->unsentmap); +if (balloon_free_pages_support () && !migrate_postcopy_ram ()) { +g_free (bmap->free_page_bmap); + }g_free (bmap); }
@@ -1487,6 +1496,90 @@ void migration_bitmap_extend(ram_addr_t old, ram_addr_t new) } } +static void filter_out_guest_free_page (unsigned long *free_page_bmap, +long nbits) +{ +long i, page_count =0 , len; +unsigned long *bitmap; + +tighten_guest_free_page_bmap (free_page_bmap); +qemu_mutex_lock (&migration_bitmap_mutex); + bitmap =atomic_rcu_read (&migration_bitmap_rcu)->bmap; +slow_bitmap_complement (bitmap, free_page_bmap, nbits); + + len = (last_ram_offset () >>TARGET_PAGE_BITS ) /BITS_PER_LONG ; +for (i =0 ; i < len; i++) { + page_count +=hweight_long (bitmap[i]); + } + + migration_dirty_pages = page_count; +qemu_mutex_unlock (&migration_bitmap_mutex); +} + +static void ram_request_free_page (unsigned long *bmap,unsigned long max_pfn) +{ +FreePageStatus status; + +/* drop_page_cache should be set by user, the related code will be +* added later, set it to ture temporarily. +*/ + drop_page_cache = true; + + status =balloon_get_free_pages (bmap, max_pfn, drop_page_cache); +switch (status) { +case FREE_PAGE_REQ : + ignore_freepage_rsp = false; +break ; +case FREE_PAGE_ERROR : +error_report ("Errro happend when request free page" ); +break ; +default : +error_report ("unexpected response status: %d" , status); +break ; + } +} + +static void ram_handle_free_page (void ) +{ +unsigned long nbits; +RAMBlock *pc_ram_block; +FreePageStatus status; + + status =balloon_get_free_pages (migration_bitmap_rcu->free_page_bmap, +get_guest_max_pfn (), drop_page_cache); +switch (status) { +case FREE_PAGE_READY : +rcu_read_lock (); + pc_ram_block =QLIST_FIRST_RCU (&ram_list.blocks); + nbits = pc_ram_block->used_length >>TARGET_PAGE_BITS ; +filter_out_guest_free_page (migration_bitmap_rcu->free_page_bmap, nbits); +rcu_read_unlock (); + +qemu_mutex_lock_iothread (); +migration_bitmap_sync (); +qemu_mutex_unlock_iothread (); +/* +* bulk stage assumes in (migration_bitmap_find_and_reset_dirty) that +* every page is dirty, that's no longer ture at this point. +*/ + ram_bulk_stage = false; + last_seen_block =NULL ; + last_sent_block =NULL ; + last_offset =0 ; +break ; +case FREE_PAGE_ERROR : + ignore_freepage_rsp = true; +error_report ("failed to get free page" ); +break ; +case FREE_PAGE_INVALID_PARAM : + ignore_freepage_rsp = true; +error_report ("buffer overflow" ); +break ; +default : +break ; + } +} +/* * 'expected' is the value you expect the bitmap mostly to be full * of; it won't bother printing lines that are all this value.
@@ -1950,6 +2043,11 @@ static int ram_save_setup(QEMUFile *f, void *opaque)qemu_mutex_unlock_ramlist ();qemu_mutex_unlock_iothread (); +if (balloon_free_pages_support () && !migrate_postcopy_ram ()) { +unsigned long max_pfn =get_guest_max_pfn (); + migration_bitmap_rcu->free_page_bmap =bitmap_new (max_pfn); +ram_request_free_page (migration_bitmap_rcu->free_page_bmap, max_pfn); + }qemu_put_be64 (f,ram_bytes_total () |RAM_SAVE_FLAG_MEM_SIZE ); QLIST_FOREACH_RCU(block, &ram_list.blocks, next) {
@@ -1990,6 +2088,9 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)while ((ret =qemu_file_rate_limit (f)) ==0 ) {int pages; +if (!ignore_freepage_rsp) { +ram_handle_free_page (); + } pages =ram_find_and_save_block (f, false, &bytes_transferred);/* no more pages to sent */ if (pages ==0 ) {
Signature · 1 line
1.8.3.1
PATCH 3/5 virtio-balloon: Add a new feature to balloon device
In reply to Liang LiExtend the virtio balloon device to support a new feature, this new feature can help to get guest's free pages information, which can be used for live migration optimzation.
--- balloon.c | 29 +++++++- hw/virtio/virtio-balloon.c | 92 ++++++++++++++++++++++++- include/hw/virtio/virtio-balloon.h | 30 +++++++- include/standard-headers/linux/virtio_balloon.h | 1 + include/sysemu/balloon.h | 12 +++- 5 files changed, 159 insertions(+), 5 deletions(-)
balloon.c +27 -2
@@ -36,6 +36,7 @@static QEMUBalloonEvent *balloon_event_fn;static QEMUBalloonStatus *balloon_stat_fn; +static QEMUBalloonGetFreePage *balloon_get_free_page_fn;static void *balloon_opaque;static bool balloon_inhibited;
@@ -65,9 +66,12 @@ static bool have_balloon(Error **errp) }int qemu_add_balloon_handler (QEMUBalloonEvent *event_func, -QEMUBalloonStatus *stat_func,void *opaque) +QEMUBalloonStatus *stat_func, +QEMUBalloonGetFreePage *get_free_page_func, +void *opaque) { -if (balloon_event_fn || balloon_stat_fn || balloon_opaque) { +if (balloon_event_fn || balloon_stat_fn || balloon_get_free_page_fn + || balloon_opaque) {/* We're already registered one balloon handler. How many can * a guest really have? */
@@ -75,6 +79,7 @@ int qemu_add_balloon_handler(QEMUBalloonEvent *event_func, } balloon_event_fn = event_func; balloon_stat_fn = stat_func; + balloon_get_free_page_fn = get_free_page_func; balloon_opaque = opaque;return 0 ; }
@@ -86,6 +91,7 @@ void qemu_remove_balloon_handler(void *opaque) } balloon_event_fn =NULL ; balloon_stat_fn =NULL ; + balloon_get_free_page_fn =NULL ; balloon_opaque =NULL ; }
@@ -116,3 +122,22 @@ void qmp_balloon(int64_t target, Error **errp)trace_balloon_event (balloon_opaque, target);balloon_event_fn (balloon_opaque, target); } + +bool balloon_free_pages_support (void ) +{ +return balloon_get_free_page_fn ? true : false; +} + +FreePageStatus balloon_get_free_pages (unsigned long *bitmap, +unsigned long len,int drop_cache) +{ +if (!balloon_get_free_page_fn) { +return FREE_PAGE_UNSUPPORT ; + } + +if (!bitmap) { +return FREE_PAGE_INVALID_PARAM ; + } + +return balloon_get_free_page_fn (balloon_opaque, bitmap, len, drop_cache); +}
hw/virtio/virtio-balloon.c +91 -1
136 lines not on this page · raw message
include/hw/virtio/virtio-balloon.h +29 -1
@@ -23,6 +23,27 @@#define VIRTIO_BALLOON (obj) \ OBJECT_CHECK(VirtIOBalloon, (obj), TYPE_VIRTIO_BALLOON) +typedef enum { +REQ_INIT , +REQ_ON_GOING , +REQ_DONE , +REQ_ERROR , +REQ_INVALID_PARAM , +}VirtIoReqStatus ; + +typedef enum { +FREE_PAGE_REQ , +FREE_PAGE_WAITING_FOR_RSP , +FREE_PAGE_READY , +FREE_PAGE_INVALID_PARAM , +FREE_PAGE_UNSUPPORT , +FREE_PAGE_ERROR , +}FreePageStatus ; + +typedef struct GetFreePageReq { +uint64_t param; +}GetFreePageReq ; +typedef struct virtio_balloon_stat VirtIOBalloonStat ; typedef struct virtio_balloon_stat_modern {
@@ -33,16 +54,23 @@ typedef struct virtio_balloon_stat_modern {typedef struct VirtIOBalloon {VirtIODevice parent_obj; -VirtQueue *ivq, *dvq, *svq; +VirtQueue *ivq, *dvq, *svq, *fvq;uint32_t num_pages;uint32_t actual;uint64_t stats[VIRTIO_BALLOON_S_NR ];VirtQueueElement *stats_vq_elem; +VirtQueueElement *free_page_vq_elem;size_t stats_vq_offset;QEMUTimer *stats_timer;int64_t stats_last_update;int64_t stats_poll_interval;uint32_t host_features; +uint64_t *free_page_bmap; +uint64_t bmap_len; +uint64_t free_pages; +uint64_t cache_pages; +GetFreePageReq free_page_req; +VirtIoReqStatus req_status; }VirtIOBalloon ;#endif
include/standard-headers/linux/virtio_balloon.h +1 -0
@@ -34,6 +34,7 @@#define VIRTIO_BALLOON_F_MUST_TELL_HOST 0/* Tell before reclaiming pages */ #define VIRTIO_BALLOON_F_STATS_VQ 1/* Memory Stats virtqueue */ #define VIRTIO_BALLOON_F_DEFLATE_ON_OOM 2/* Deflate balloon on OOM */ +#define VIRTIO_BALLOON_F_GET_FREE_PAGE 3/* Get the free page bitmap */ /* Size of a PFN in the balloon interface. */ #define VIRTIO_BALLOON_PFN_SHIFT 12
include/sysemu/balloon.h +11 -1
@@ -15,14 +15,24 @@#define _QEMU_BALLOON_H#include "qapi-types.h" +#include "hw/virtio/virtio-balloon.h" typedef void (QEMUBalloonEvent )(void *opaque,ram_addr_t target);typedef void (QEMUBalloonStatus )(void *opaque,BalloonInfo *info); +typedef FreePageStatus (QEMUBalloonGetFreePage )(void *opaque, +unsigned long *bitmap, +unsigned long len, +int drop_cache_ctl);int qemu_add_balloon_handler (QEMUBalloonEvent *event_func, -QEMUBalloonStatus *stat_func,void *opaque); +QEMUBalloonStatus *stat_func, +QEMUBalloonGetFreePage *get_free_page_func, +void *opaque);void qemu_remove_balloon_handler (void *opaque);bool qemu_balloon_is_inhibited (void );void qemu_balloon_inhibit (bool state); +bool balloon_free_pages_support (void ); +FreePageStatus balloon_get_free_pages (unsigned long *bitmap, +unsigned long len,int drop_cache_ctl);#endif
Signature · 1 line
1.8.3.1
PATCH 5/5 migration: Add the interface for cache drop control
In reply to Liang LiWhether drop the cache and drop what kind of cache depend on the user, add the related qmp and hmp interface to query and set the cache control value.
--- hmp.c | 8 ++++++++ include/migration/migration.h | 1 + migration/migration.c | 31 ++++++++++++++++++++++++++++++- migration/ram.c | 10 ++-------- qapi-schema.json | 25 ++++++++++++++++++++++--- 5 files changed, 63 insertions(+), 12 deletions(-)
hmp.c +8 -0
@@ -286,6 +286,9 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)monitor_printf (mon," %s: %" PRId64, MigrationParameter_lookup[MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT ], params->x_cpu_throttle_increment); +monitor_printf (mon," %s: %" PRId64, + MigrationParameter_lookup[MIGRATION_PARAMETER_X_DROP_CACHE ], + params->x_drop_cache);monitor_printf (mon,"\n" ); }
@@ -1242,6 +1245,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)bool has_decompress_threads = false;bool has_x_cpu_throttle_initial = false;bool has_x_cpu_throttle_increment = false; +bool has_x_drop_cache = false;int i;for (i =0 ; i <MIGRATION_PARAMETER__MAX ; i++) {
@@ -1262,12 +1266,16 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)case MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT : has_x_cpu_throttle_increment = true;break ; +case MIGRATION_PARAMETER_X_DROP_CACHE : + has_x_drop_cache = true; +break ; }qmp_migrate_set_parameters (has_compress_level, value, has_compress_threads, value, has_decompress_threads, value, has_x_cpu_throttle_initial, value, has_x_cpu_throttle_increment, value, + has_x_drop_cache, value, &err);break ; }
include/migration/migration.h +1 -0
@@ -283,6 +283,7 @@ bool migrate_use_compression(void);int migrate_compress_level (void );int migrate_compress_threads (void );int migrate_decompress_threads (void ); +int migrate_drop_cache (void );bool migrate_use_events (void );/* Sending on the return path - generic and then for each message type */
migration/migration.c +30 -1
@@ -52,6 +52,13 @@/* Define default autoconverge cpu throttle migration parameters */ #define DEFAULT_MIGRATE_X_CPU_THROTTLE_INITIAL 20#define DEFAULT_MIGRATE_X_CPU_THROTTLE_INCREMENT 10 +/* Default cache drop control +* 0: no drop +* 1: drop clean page cache +* 2: drop slab cache +* 3: drop both clean and slab cache +*/ +#define DEFAULT_MIGRATE_X_DROP_CACHE 0/* Migration XBZRLE default cache size */ #define DEFAULT_MIGRATE_CACHE_SIZE (64 * 1024 * 1024)
@@ -91,6 +98,8 @@ MigrationState *migrate_get_current(void) DEFAULT_MIGRATE_X_CPU_THROTTLE_INITIAL, .parameters[MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT ] = DEFAULT_MIGRATE_X_CPU_THROTTLE_INCREMENT, + .parameters[MIGRATION_PARAMETER_X_DROP_CACHE ] = + DEFAULT_MIGRATE_X_DROP_CACHE, };if (!once) {
@@ -525,6 +534,7 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp) s->parameters[MIGRATION_PARAMETER_X_CPU_THROTTLE_INITIAL ]; params->x_cpu_throttle_increment = s->parameters[MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT ]; + params->x_drop_cache = s->parameters[MIGRATION_PARAMETER_X_DROP_CACHE ];return params; }
@@ -721,7 +731,9 @@ void qmp_migrate_set_parameters(bool has_compress_level,bool has_x_cpu_throttle_initial, int64_t x_cpu_throttle_initial, bool has_x_cpu_throttle_increment, - int64_t x_cpu_throttle_increment, Error **errp) + int64_t x_cpu_throttle_increment, + bool has_x_drop_cache, + int64_t x_drop_cache, Error **errp) { MigrationState *s = migrate_get_current();
@@ -756,6 +768,11 @@ void qmp_migrate_set_parameters(bool has_compress_level,"x_cpu_throttle_increment" , "an integer in the range of 1 to 99"); } +if (has_x_drop_cache && (x_drop_cache <0 || x_drop_cache >3 )) { +error_setg (errp,QERR_INVALID_PARAMETER_VALUE , +"x_drop_cache" , +"an integer in the range of 0 to 3" ); + }if (has_compress_level) { s->parameters[MIGRATION_PARAMETER_COMPRESS_LEVEL ] = compress_level;
@@ -776,6 +793,9 @@ void qmp_migrate_set_parameters(bool has_compress_level, s->parameters[MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT ] = x_cpu_throttle_increment; } +if (has_x_drop_cache) { + s->parameters[MIGRATION_PARAMETER_X_DROP_CACHE ] = x_drop_cache; + } }void qmp_migrate_start_postcopy (Error **errp)
@@ -1182,6 +1202,15 @@ int migrate_decompress_threads(void)return s->parameters[MIGRATION_PARAMETER_DECOMPRESS_THREADS ]; } +int migrate_drop_cache (void ) +{ +MigrationState *s; + + s =migrate_get_current (); + +return s->parameters[MIGRATION_PARAMETER_X_DROP_CACHE ]; +} +bool migrate_use_events (void ) {MigrationState *s;
migration/ram.c +2 -8
@@ -229,7 +229,6 @@ static uint64_t migration_dirty_pages;static uint32_t last_version;static bool ram_bulk_stage;static bool ignore_freepage_rsp; -static bool drop_page_cache;/* used by the search for pages to send */ struct PageSearchStatus {
@@ -1520,12 +1519,7 @@ static void ram_request_free_page(unsigned long *bmap, unsigned long max_pfn) {FreePageStatus status; -/* drop_page_cache should be set by user, the related code will be -* added later, set it to ture temporarily. -*/ - drop_page_cache = true; - - status =balloon_get_free_pages (bmap, max_pfn, drop_page_cache); + status =balloon_get_free_pages (bmap, max_pfn,migrate_drop_cache ());switch (status) {case FREE_PAGE_REQ : ignore_freepage_rsp = false;
@@ -1546,7 +1540,7 @@ static void ram_handle_free_page(void)FreePageStatus status; status =balloon_get_free_pages (migration_bitmap_rcu->free_page_bmap, -get_guest_max_pfn (), drop_page_cache); +get_guest_max_pfn (),migrate_drop_cache ());switch (status) {case FREE_PAGE_READY :rcu_read_lock ();
qapi-schema.json +22 -3
@@ -612,11 +612,21 @@ # @x-cpu-throttle-increment: throttle percentage increase each time # auto-converge detects that migration is not making # progress. The default value is 10. (Since 2.5) +# @x-drop-cache: drop guest's page cache during live migration, the value can +# be set to 0, 1, 2, 3. 1 means drop the clean page cache, 2 means +# drop the slab cache, 3 means to drop both clean page cache, 0 means +# do not drop any cache. Drop cache can speed up live migration +# process and reduce the network traffic, the side affect is the +# performance impact to the guest, 1 is the recommended value for +# proper balance between speed and performance. The value only takes +# affect when the virtio-balloon device are enabled and the guest +# has the related driver. The default value is 0. (Since 2.7) # Since: 2.4 ## { 'enum': 'MigrationParameter', 'data': ['compress-level', 'compress-threads', 'decompress-threads', - 'x-cpu-throttle-initial', 'x-cpu-throttle-increment'] } + 'x-cpu-throttle-initial', 'x-cpu-throttle-increment', + 'x-drop-cache'] } # # @migrate-set-parameters
@@ -636,6 +646,10 @@ # @x-cpu-throttle-increment: throttle percentage increase each time # auto-converge detects that migration is not making # progress. The default value is 10. (Since 2.5) +# +# @x-drop-cache: guest cache drop control, determine what kind of guest cache +# to drop during live migration. The default value is 0. (Since 2.7) +# # Since: 2.4 ## { 'command': 'migrate-set-parameters',
@@ -643,7 +657,8 @@ '*compress-threads': 'int', '*decompress-threads': 'int', '*x-cpu-throttle-initial': 'int', - '*x-cpu-throttle-increment': 'int'} } + '*x-cpu-throttle-increment': 'int', + '*x-drop-cache': 'int'} } # # @MigrationParameters
@@ -662,6 +677,9 @@ # auto-converge detects that migration is not making # progress. The default value is 10. (Since 2.5) # +# @x-drop-cache: guest cache drop control, determine what kind of guest cache +# to drop during live migration. The default value is 0. (Since 2.7) +# # Since: 2.4 ## { 'struct': 'MigrationParameters',
@@ -669,7 +687,8 @@ 'compress-threads': 'int', 'decompress-threads': 'int', 'x-cpu-throttle-initial': 'int', - 'x-cpu-throttle-increment': 'int'} } + 'x-cpu-throttle-increment': 'int', + 'x-drop-cache': 'int'} } ## # @query-migrate-parameters #
Signature · 1 line
1.8.3.1
Quoted 14 lines · Liang Li
Current QEMU live migration implementation marks all guest's RAM pages as dirtied in the ram bulk stage, all these pages will be processed and it consumes quite a lot of CPU cycles and network bandwidth.
From guest's point of view, it doesn't care about the content in free
page. We can make use of this fact and skip processing the free pages, it can save a lot CPU cycles and reduce the network traffic significantly while speed up the live migration process obviously.This patch set is the QEMU side implementation.
The virtio-balloon is extended so that QEMU can get the free pages information from the guest.
Quoted 6 lines
After getting the free page bitmap, QEMU can use it to filter out guest's free pages. This make the live migration process much more efficient.
In order to skip more free pages, we add an interface to let the user decide whether dropping the cache in guest during live migration.
Wouldn't that potentially break things like CoLo? Which side is the slow one? We already do condense zero pages into small metadata in the migration stream. Is writing them out the slow part? If so, just don't write them in you're on a clean state.
Alex
Quoted 69 lines
Performance data
================Test environment:
CPU: Intel (R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz Host RAM: 64GB Host Linux Kernel: 4.4.0 Host OS: CentOS 7.1 Guest Linux Kernel: 4.5.rc6 Guest OS: CentOS 6.6 Network: Intel X710 with 10 Gigabit connection Guest RAM: 8GBCase 1: Idle guest just boots:
==================================================
| original | skip free page
--------------------------------------------------
total time(ms) | 1505 | 573
--------------------------------------------------
transferred ram(KB) | 399792 | 379057
==================================================Case 2: The guest has ever run some memory consuming workload, the workload is terminated before live migration.
==================================================
| original | skip free page
--------------------------------------------------
total time(ms) | 10641 | 597
--------------------------------------------------
transferred ram(KB) | 8350829 | 389900
==================================================Case 3: The guest has ever built the linux kernel, the building is completed before live migration. The page cache is dropped during live migration in this case.
==================================================
| original | skip free page
--------------------------------------------------
total time(ms) | 2636 | 914
--------------------------------------------------
transferred ram(KB) | 1316747 | 421980
==================================================Liang Li (5):
bitmap: Add a newbitmap_movefunction
kvm: Add two new arch specific functions
virtio-balloon: Add a new feature to balloon device
migration: filter out free pages during live migration
migration: Add the interface for cache drop controlballoon.c | 29 +++++++- hmp.c | 8 +++ hw/virtio/virtio-balloon.c | 92 +++++++++++++++++++++++- include/hw/virtio/virtio-balloon.h | 30 +++++++- include/migration/migration.h | 1 + include/qemu/bitmap.h | 13 ++++ include/standard-headers/linux/virtio_balloon.h | 1 + include/sysemu/balloon.h | 12 +++- include/sysemu/kvm.h | 2 + migration/migration.c | 31 +++++++- migration/ram.c | 95 +++++++++++++++++++++++++ qapi-schema.json | 25 ++++++- target-arm/kvm.c | 14 ++++ target-i386/kvm.c | 35 +++++++++ target-mips/kvm.c | 14 ++++ target-ppc/kvm.c | 14 ++++ target-s390x/kvm.c | 14 ++++ 17 files changed, 421 insertions(+), 9 deletions(-)
Re: [Qemu-devel] [PATCH QEMU 5/5] migration: Add the interface for cache drop control
In reply to Liang LiQuoted 1 line · Liang Li
Whether drop the cache and drop what kind of cache depend on the
Whether to drop the cache, and what kind of cache drop to perform, depend ...
Quoted 10 lines
user, add the related qmp and hmp interface to query and set the cache control value.
Signed-off-by Liang Li <[email protected]>---
+++
b/qapi-schema.jsonqapi-schema.json +0
-0@@ -612,11 +612,21 @@ # @x-cpu-throttle-increment: throttle percentage increase each time # auto-converge detects that migration is not making
qapi-schema.json line 623
Quoted 10 lines
qapi-schema.json +9
-0# progress. The default value is 10. (Since 2.5) +# @x-drop-cache: drop guest's page cache during live migration, the value can +# be set to 0, 1, 2, 3. 1 means drop the clean page cache, 2 means +# drop the slab cache, 3 means to drop both clean page cache, 0 means +# do not drop any cache. Drop cache can speed up live migration +# process and reduce the network traffic, the side affect is the +# performance impact to the guest, 1 is the recommended value for +# proper balance between speed and performance. The value only takes +# affect when the virtio-balloon device are enabled and the guest +# has the related driver. The default value is 0. (Since 2.7)
Absolutely not this interface. Make this an enum type, not a raw magic-number integer type, where the user requests "x-drop-cache":"clean", "x-drop-cache":"slab", and so on.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
RE: [Qemu-devel] [PATCH QEMU 5/5] migration: Add the interface for cache drop control
Quoted 38 lines
Sent: Tuesday, April 19, 2016 10:52 PM
To: Li, Liang Z; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [Qemu-devel] [PATCH QEMU 5/5] migration: Add the interface for cache drop controlQuoted 1 line · Liang Li
Whether drop the cache and drop what kind of cache depend on the
Whether to drop the cache, and what kind of cache drop to perform, depend ...
qapi-schema.json line 615
Quoted 12 lines
user, add the related qmp and hmp interface to query and set the cache control value.
Signed-off-by Liang Li <[email protected]>---
+++
b/qapi-schema.jsonqapi-schema.json +1
-0@@ -612,11 +612,21 @@ # @x-cpu-throttle-increment: throttle percentage increase each time # auto-converge detects that migration is not making # progress. The default value is 10. (Since 2.5) +# @x-drop-cache: drop guest's page cache during live migration, the valuecan
Review line 617
Quoted 2 lines
(quoted diff) +2
-0+# be set to 0, 1, 2, 3. 1 means drop the clean page cache, 2 means +# drop the slab cache, 3 means to drop both clean page cache, 0means
qapi-schema.json
Quoted 4 lines
qapi-schema.json +4
-0+# do not drop any cache. Drop cache can speed up live migration +# process and reduce the network traffic, the side affect is the +# performance impact to the guest, 1 is the recommended value for +# proper balance between speed and performance. The value onlytakes
Quoted 7 lines
qapi-schema.json line 623
Quoted 2 lines
qapi-schema.json +2
-0+# affect when the virtio-balloon device are enabled and the guest +# has the related driver. The default value is 0. (Since 2.7)Absolutely not this interface. Make this an enum type, not a raw magic- number integer type, where the user requests "x-drop-cache":"clean", "x- drop-cache":"slab", and so on.
The enum type looks better, thanks!
Liang
Quoted 3 lines
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Re: [PATCH QEMU 3/5] virtio-balloon: Add a new feature to balloon device
In reply to Liang Lihw/virtio/virtio-balloon.c static void virtio_balloon_stat(void *opaque, BalloonInfo *info) · line 448
Quoted 10 lines · Liang Li
hw/virtio/virtio-balloon.c +10
-0+if (s->req_status ==REQ_INIT ) { + s->free_page_bmap = bitmap; +if (elem ==NULL || !elem->in_num) { + elem =virtqueue_pop (s->fvq,sizeof (VirtQueueElement)); +if (!elem) { +return FREE_PAGE_ERROR ; + } + s->free_page_vq_elem = elem; + } + s->free_page_req.param = drop_cache_ctl;
Dropping cache should probably be a separate request - seems independently useful.
Signature · 1 line
MST