postcopy (& 1 test) patch for 2.7
v5 cover postcopy (& 1 test) patch for 2.7
From: "Dr. David Alan Gilbert" <[email protected]>
Hi,
This is a small set of postcopy changes, the largest of which
is an x86 test for postcopy.
Andrea's libqtest change came about from running my test under very heavy load.
The test includes a self contained migration workload that rapidly changes RAM in a predictable fashion allowing us to end up in postcopy mode and also to be able to check the contents of RAM.
Note this sometimes fails on Linux kernels 4.5 (and current 4.6) which have a KVM+THP bug. Use this fix:
https://lists.gnu.org/archive/html/qemu-devel/2016-04/msg04028.html
v5:
Swing sys/ #include's into the ifdef __linux__ on the postcopy test
v4:
Add a patch to fail migrate-set-capability when turning on postcopy if we don't have the kernel support.
v3:
Change all the test asserts to be g_assert macros (Marcel's suggestion)
v2:
Split 'Add stats...' into two (Eric's comment)
Test:
Survive qmp events landing when we're expecting a response from the command (qmp/libqtest doesn't help in that)
Fix a race where we'd start postcopy early
Dave
Andrea Arcangeli (1):
tests: fix libqtest socket timeouts
Dr. David Alan Gilbert (5):
Postcopy: Avoid 0 length discards
Migration: Split out ram part of qmp_query_migrate
Postcopy: Add stats on page requests
test: Postcopy
Postcopy: Check for support when setting the capability
hmp.c | 4 + include/migration/migration.h | 2 + migration/migration.c | 73 +++---- migration/ram.c | 5 +- qapi-schema.json | 6 +- tests/Makefile.include | 2 + tests/libqtest.c | 2 +- tests/postcopy-test.c | 455 ++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 511 insertions(+), 38 deletions(-) create mode 100644 tests/postcopy-test.c
Signature · 1 line
2.7.4
PATCH v5 1/6 Postcopy: Avoid 0 length discards
From: "Dr. David Alan Gilbert" <[email protected]>
The discard code in migration/ram.c would send request for zero length discards in the case where no discards were needed. It doesn't appear to have had any bad effect.
--- migration/ram.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
migration/ram.c +3 -1
@@ -1557,7 +1557,9 @@ static int postcopy_send_discard_bm_ram(MigrationState *ms, }else { discard_length = zero - one; } -postcopy_discard_send_range (ms, pds, one, discard_length); +if (discard_length) { +postcopy_discard_send_range (ms, pds, one, discard_length); + } current = one + discard_length; }else { current = one;
Signature · 1 line
2.7.4
PATCH v5 3/6 Postcopy: Add stats on page requests
In reply to Dr. David Alan Gilbert (git)From: "Dr. David Alan Gilbert" <[email protected]>
On the source, add a count of page requests received from the destination.
--- hmp.c | 4 ++++ include/migration/migration.h | 2 ++ migration/migration.c | 2 ++ migration/ram.c | 1 + qapi-schema.json | 6 +++++- 5 files changed, 14 insertions(+), 1 deletion(-)
hmp.c +4 -0
@@ -217,6 +217,10 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict)monitor_printf (mon,"dirty pages rate: %" PRIu64" pages\n" , info->ram->dirty_pages_rate); } +if (info->ram->postcopy_requests) { +monitor_printf (mon,"postcopy request count: %" PRIu64"\n" , + info->ram->postcopy_requests); + } }if (info->has_disk) {
include/migration/migration.h +2 -0
@@ -160,6 +160,8 @@ struct MigrationStateint64_t xbzrle_cache_size;int64_t setup_time;int64_t dirty_sync_count; +/* Count of requests incoming from destination */ +int64_t postcopy_requests;/* Flag set once the migration has been asked to enter postcopy */ bool start_postcopy;
migration/migration.c +2 -0
@@ -614,6 +614,7 @@ static void populate_ram_info(MigrationInfo *info, MigrationState *s) info->ram->normal_bytes =norm_mig_bytes_transferred (); info->ram->mbps = s->mbps; info->ram->dirty_sync_count = s->dirty_sync_count; + info->ram->postcopy_requests = s->postcopy_requests;if (s->state !=MIGRATION_STATUS_COMPLETED ) { info->ram->remaining =ram_bytes_remaining ();
@@ -991,6 +992,7 @@ MigrationState *migrate_init(const MigrationParams *params) s->dirty_sync_count =0 ; s->start_postcopy = false; s->postcopy_after_devices = false; + s->postcopy_requests =0 ; s->migration_thread_running = false; s->last_req_rb =NULL ;error_free (s->error);
migration/ram.c +1 -0
@@ -1169,6 +1169,7 @@ int ram_save_queue_pages(MigrationState *ms, const char *rbname, {RAMBlock *ramblock; + ms->postcopy_requests++;rcu_read_lock ();if (!rbname) {/* Reuse last RAMBlock */
qapi-schema.json +5 -1
@@ -382,13 +382,17 @@ # # @dirty-sync-count: number of times that dirty ram was synchronized (since 2.1) # +# @postcopy-requests: The number of page requests received from the destination +# (since 2.7) +# # Since: 0.14.0 ## { 'struct': 'MigrationStats', 'data': {'transferred': 'int', 'remaining': 'int', 'total': 'int' , 'duplicate': 'int', 'skipped': 'int', 'normal': 'int', 'normal-bytes': 'int', 'dirty-pages-rate' : 'int', - 'mbps' : 'number', 'dirty-sync-count' : 'int' } } + 'mbps' : 'number', 'dirty-sync-count' : 'int', + 'postcopy-requests' : 'int' } } ## # @XBZRLECacheStats
Signature · 1 line
2.7.4
PATCH v5 2/6 Migration: Split out ram part of qmp_query_migrate
In reply to Dr. David Alan Gilbert (git)From: "Dr. David Alan Gilbert" <[email protected]>
The RAM section of qmp_query_migrate is reasonably complex and repeated 3 times. Split it out into a helper.
--- migration/migration.c | 57 ++++++++++++++++++++------------------------------- 1 file changed, 22 insertions(+), 35 deletions(-)
migration/migration.c +22 -35
@@ -602,6 +602,25 @@ static void get_xbzrle_cache_stats(MigrationInfo *info) } } +static void populate_ram_info (MigrationInfo *info,MigrationState *s) +{ + info->has_ram = true; + info->ram =g_malloc0 (sizeof (*info->ram)); + info->ram->transferred =ram_bytes_transferred (); + info->ram->total =ram_bytes_total (); + info->ram->duplicate =dup_mig_pages_transferred (); + info->ram->skipped =skipped_mig_pages_transferred (); + info->ram->normal =norm_mig_pages_transferred (); + info->ram->normal_bytes =norm_mig_bytes_transferred (); + info->ram->mbps = s->mbps; + info->ram->dirty_sync_count = s->dirty_sync_count; + +if (s->state !=MIGRATION_STATUS_COMPLETED ) { + info->ram->remaining =ram_bytes_remaining (); + info->ram->dirty_pages_rate = s->dirty_pages_rate; + } +} +MigrationInfo *qmp_query_migrate (Error **errp) {MigrationInfo *info =g_malloc0 (sizeof (*info));
@@ -626,18 +645,7 @@ MigrationInfo *qmp_query_migrate(Error **errp) info->has_setup_time = true; info->setup_time = s->setup_time; - info->has_ram = true; - info->ram =g_malloc0 (sizeof (*info->ram)); - info->ram->transferred =ram_bytes_transferred (); - info->ram->remaining =ram_bytes_remaining (); - info->ram->total =ram_bytes_total (); - info->ram->duplicate =dup_mig_pages_transferred (); - info->ram->skipped =skipped_mig_pages_transferred (); - info->ram->normal =norm_mig_pages_transferred (); - info->ram->normal_bytes =norm_mig_bytes_transferred (); - info->ram->dirty_pages_rate = s->dirty_pages_rate; - info->ram->mbps = s->mbps; - info->ram->dirty_sync_count = s->dirty_sync_count; +populate_ram_info (info, s);if (blk_mig_active ()) { info->has_disk = true;
@@ -665,18 +673,7 @@ MigrationInfo *qmp_query_migrate(Error **errp) info->has_setup_time = true; info->setup_time = s->setup_time; - info->has_ram = true; - info->ram =g_malloc0 (sizeof (*info->ram)); - info->ram->transferred =ram_bytes_transferred (); - info->ram->remaining =ram_bytes_remaining (); - info->ram->total =ram_bytes_total (); - info->ram->duplicate =dup_mig_pages_transferred (); - info->ram->skipped =skipped_mig_pages_transferred (); - info->ram->normal =norm_mig_pages_transferred (); - info->ram->normal_bytes =norm_mig_bytes_transferred (); - info->ram->dirty_pages_rate = s->dirty_pages_rate; - info->ram->mbps = s->mbps; - info->ram->dirty_sync_count = s->dirty_sync_count; +populate_ram_info (info, s);if (blk_mig_active ()) { info->has_disk = true;
@@ -699,17 +696,7 @@ MigrationInfo *qmp_query_migrate(Error **errp) info->has_setup_time = true; info->setup_time = s->setup_time; - info->has_ram = true; - info->ram =g_malloc0 (sizeof (*info->ram)); - info->ram->transferred =ram_bytes_transferred (); - info->ram->remaining =0 ; - info->ram->total =ram_bytes_total (); - info->ram->duplicate =dup_mig_pages_transferred (); - info->ram->skipped =skipped_mig_pages_transferred (); - info->ram->normal =norm_mig_pages_transferred (); - info->ram->normal_bytes =norm_mig_bytes_transferred (); - info->ram->mbps = s->mbps; - info->ram->dirty_sync_count = s->dirty_sync_count; +populate_ram_info (info, s);break ;case MIGRATION_STATUS_FAILED : info->has_status = true;
Signature · 1 line
2.7.4
PATCH v5 5/6 tests: fix libqtest socket timeouts
In reply to Dr. David Alan Gilbert (git)From: Andrea Arcangeli <[email protected]>
I kept getting timeouts and unix socket accept failures under high load, the patch fixes it.
--- tests/libqtest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/libqtest.c +1 -1
@@ -26,7 +26,7 @@#include "qapi/qmp/qjson.h" #define MAX_IRQ 256 -#define SOCKET_TIMEOUT 5 +#define SOCKET_TIMEOUT 50QTestState *global_qtest;
Signature · 1 line
2.7.4
PATCH v5 6/6 Postcopy: Check for support when setting the capability
In reply to Dr. David Alan Gilbert (git)From: "Dr. David Alan Gilbert" <[email protected]>
Knowing whether the destination host supports migration with postcopy can be tricky.
The destination doesn't need the capability set, however if we set it then use the opportunity to do the test and tell the user/management layer early.
--- migration/migration.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
migration/migration.c +14 -0
@@ -720,6 +720,7 @@ void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params, {MigrationState *s =migrate_get_current ();MigrationCapabilityStatusList *cap; +bool old_postcopy_cap =migrate_postcopy_ram ();if (migration_is_setup_or_active (s->state)) {error_setg (errp,QERR_MIGRATION_ACTIVE );
@@ -742,6 +743,19 @@ void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params, s->enabled_capabilities[MIGRATION_CAPABILITY_POSTCOPY_RAM ] = false; } +/* This check is reasonably expensive, so only when it's being +* set the first time, also it's only the destination that needs +* special support. +*/ +if (!old_postcopy_cap &&runstate_check (RUN_STATE_INMIGRATE ) && + !postcopy_ram_supported_by_host ()) { +/* postcopy_ram_supported_by_host will have emitted a more +* detailed message +*/ +error_report ("Postcopy is not supported" ); + s->enabled_capabilities[MIGRATION_CAPABILITY_POSTCOPY_RAM ] = + false; + } } }
Signature · 1 line
2.7.4
PATCH v5 4/6 test: Postcopy
In reply to Dr. David Alan Gilbert (git)From: "Dr. David Alan Gilbert" <[email protected]>
This is a postcopy test (x86 only) that actually runs the guest and checks the memory contents.
The test runs from an x86 boot block with the hex embedded in the test; the source for this is:
...........
.code16
.org 0x7c00
.file "fill.s"
.text
.globl start
.type start, @function
start: # at 0x7c00 ?
cli
lgdt gdtdesc
mov $1,%eax
mov %eax,%cr0 # Protected mode enable
data32 ljmp $8,$0x7c20.org 0x7c20
.code32
# A20 enable - not sure I actually need this
inb $0x92,%al
or $2,%al
outb %al, $0x92
# set up DS for the whole of RAM (needed on KVM)
mov $16,%eax
mov %eax,%ds
mov $65,%ax
mov $0x3f8,%dx
outb %al,%dx
# bl keeps a counter so we limit the output speed
mov $0, %blmainloop:
# Start from 1MB
mov $(1024*1024),%eax
innerloop:
incb (%eax)
add $4096,%eax
cmp $(100*1024*1024),%eax
jl innerloop
inc %bl
jnz mainloop
mov $66,%ax
mov $0x3f8,%dx
outb %al,%dx
jmp mainloop
# GDT magic from old (GPLv2) Grub startup.S
.p2align 2 /* force 4-byte alignment */
gdt:
.word 0, 0
.byte 0, 0, 0, 0
/* -- code segment --
* base = 0x00000000, limit = 0xFFFFF (4 KiB Granularity), present
* type = 32bit code execute/read, DPL = 0
*/
.word 0xFFFF, 0
.byte 0, 0x9A, 0xCF, 0
/* -- data segment --
* base = 0x00000000, limit 0xFFFFF (4 KiB Granularity), present
* type = 32 bit data read/write, DPL = 0
*/
.word 0xFFFF, 0
.byte 0, 0x92, 0xCF, 0gdtdesc:
.word 0x27 /* limit */
.long gdt /* addr *//* I'm a bootable disk */
.org 0x7dfe
.byte 0x55
.byte 0xAA...........
and that can be assembled by the following magic:
as --32 -march=i486 fill.s -o fill.o objcopy -O binary fill.o fill.boot
dd if=fill.boot of=bootsect bs=256 count=2 skip=124 xxd -i bootsect
--- tests/Makefile.include | 2 + tests/postcopy-test.c | 455 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 457 insertions(+) create mode 100644 tests/postcopy-test.c
tests/Makefile.include +2 -0
@@ -228,6 +228,7 @@ endif check-qtest-i386-y += tests/test-netfilter$(EXESUF) check-qtest-i386-y += tests/test-filter-mirror$(EXESUF) check-qtest-i386-y += tests/test-filter-redirector$(EXESUF) +check-qtest-i386-y += tests/postcopy-test$(EXESUF) check-qtest-x86_64-y = $(check-qtest-i386-y) gcov-files-i386-y += i386-softmmu/hw/timer/mc146818rtc.c gcov-files-x86_64-y = $(subst i386-softmmu/,x86_64-softmmu/,$(gcov-files-i386-y))
@@ -587,6 +588,7 @@ tests/usb-hcd-uhci-test$(EXESUF): tests/usb-hcd-uhci-test.o $(libqos-usb-obj-y) tests/usb-hcd-ehci-test$(EXESUF): tests/usb-hcd-ehci-test.o $(libqos-usb-obj-y) tests/usb-hcd-xhci-test$(EXESUF): tests/usb-hcd-xhci-test.o $(libqos-usb-obj-y) tests/pc-cpu-test$(EXESUF): tests/pc-cpu-test.o +tests/postcopy-test$(EXESUF): tests/postcopy-test.o tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o qemu-char.o qemu-timer.o $(qtest-obj-y) $(test-io-obj-y) tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_helper.o tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o $(test-util-obj-y)
tests/postcopy-test.c new file +455 -0
455 lines not on this page · raw message
Signature · 1 line
2.7.4