Hi,

This patch introduces 2 new hypervisor options, migration_bandwidth and
migration_downtime and uses them to implement KVM migration bandwidth
and downtime control.

migration_bandwidth controls KVM's maximal bandwidth during migration,
in MiB/s. Default value is 32 MiB/s, same as KVM's internal default. 
This option is a global hypervisor option.

migration_downtime sets the amount of time (in ms) a KVM instance is
allowed to freeze while copying memory pages. This is useful when
migrating busy guests, as KVM's internal default of 30ms is sometimes
too low for the page-copying algorithm to converge in a reasonable time
window. This is a per-instance option, with a default of 30m, same as
KVM's internal default.

Signed-off-by: Apollon Oikonomopoulos <[email protected]>
---
 lib/constants.py         |    7 +++++++
 lib/hypervisor/hv_kvm.py |   10 ++++++++++
 2 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/lib/constants.py b/lib/constants.py
index e13d82c..1370281 100644
--- a/lib/constants.py
+++ b/lib/constants.py
@@ -434,6 +434,8 @@ HV_USB_MOUSE = "usb_mouse"
 HV_DEVICE_MODEL = "device_model"
 HV_INIT_SCRIPT = "init_script"
 HV_MIGRATION_PORT = "migration_port"
+HV_MIGRATION_BANDWIDTH = "migration_bandwidth"
+HV_MIGRATION_DOWNTIME = "migration_downtime"
 HV_USE_LOCALTIME = "use_localtime"
 HV_DISK_CACHE = "disk_cache"
 HV_SECURITY_MODEL = "security_model"
@@ -465,6 +467,8 @@ HVS_PARAMETER_TYPES = {
   HV_DEVICE_MODEL: VTYPE_STRING,
   HV_INIT_SCRIPT: VTYPE_STRING,
   HV_MIGRATION_PORT: VTYPE_INT,
+  HV_MIGRATION_BANDWIDTH: VTYPE_INT,
+  HV_MIGRATION_DOWNTIME: VTYPE_INT,
   HV_USE_LOCALTIME: VTYPE_BOOL,
   HV_DISK_CACHE: VTYPE_STRING,
   HV_SECURITY_MODEL: VTYPE_STRING,
@@ -732,6 +736,8 @@ HVC_DEFAULTS = {
     HV_DISK_TYPE: HT_DISK_PARAVIRTUAL,
     HV_USB_MOUSE: '',
     HV_MIGRATION_PORT: 8102,
+    HV_MIGRATION_BANDWIDTH: 32,
+    HV_MIGRATION_DOWNTIME: 30,
     HV_USE_LOCALTIME: False,
     HV_DISK_CACHE: HT_CACHE_DEFAULT,
     HV_SECURITY_MODEL: HT_SM_NONE,
@@ -748,6 +754,7 @@ HVC_DEFAULTS = {
 
 HVC_GLOBALS = frozenset([
   HV_MIGRATION_PORT,
+  HV_MIGRATION_BANDWIDTH,
   ])
 
 BEC_DEFAULTS = {
diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py
index af04dca..51fa10f 100644
--- a/lib/hypervisor/hv_kvm.py
+++ b/lib/hypervisor/hv_kvm.py
@@ -78,6 +78,8 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     constants.HV_USB_MOUSE:
       hv_base.ParamInSet(False, constants.HT_KVM_VALID_MOUSE_TYPES),
     constants.HV_MIGRATION_PORT: hv_base.NET_PORT_CHECK,
+    constants.HV_MIGRATION_BANDWIDTH: hv_base.NO_CHECK,
+    constants.HV_MIGRATION_DOWNTIME: hv_base.NO_CHECK,
     constants.HV_USE_LOCALTIME: hv_base.NO_CHECK,
     constants.HV_DISK_CACHE:
       hv_base.ParamInSet(True, constants.HT_VALID_CACHE_TYPES),
@@ -811,6 +813,14 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     if not live:
       self._CallMonitorCommand(instance_name, 'stop')
 
+    migrate_command = ('migrate_set_speed %dm' %
+        instance.hvparams[constants.HV_MIGRATION_BANDWIDTH])
+    self._CallMonitorCommand(instance_name, migrate_command)
+
+    migrate_command = ('migrate_set_downtime %dms' %
+        instance.hvparams[constants.HV_MIGRATION_DOWNTIME])
+    self._CallMonitorCommand(instance_name, migrate_command)
+
     migrate_command = 'migrate -d tcp:%s:%s' % (target, port)
     self._CallMonitorCommand(instance_name, migrate_command)
 
-- 
1.5.6.5

Reply via email to