From d787313ea16928b8dbd063f78706e198eddca4ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Czern=C3=BD?= Date: Tue, 1 Mar 2022 10:49:55 +0100 Subject: [PATCH] F #5753: Better live mem resize for KVM (#1820) (cherry picked from commit c6965c3cfe28cccb3773fe2eda9d86fa4d87e8ef) --- share/doc/xsd/vm.xsd | 1 - src/fireedge/src/client/constants/vm.js | 1 - src/vm/VirtualMachine.cc | 8 +----- src/vmm/LibVirtDriverKVM.cc | 38 +++++++------------------ src/vmm_mad/exec/vmm_exec_kvm.conf | 3 -- src/vmm_mad/remotes/kvm/resize | 27 +----------------- 6 files changed, 13 insertions(+), 65 deletions(-) diff --git a/share/doc/xsd/vm.xsd b/share/doc/xsd/vm.xsd index b14d397f31..170694d3a7 100644 --- a/share/doc/xsd/vm.xsd +++ b/share/doc/xsd/vm.xsd @@ -121,7 +121,6 @@ - diff --git a/src/fireedge/src/client/constants/vm.js b/src/fireedge/src/client/constants/vm.js index 81d3471b3f..01de7e87d3 100644 --- a/src/fireedge/src/client/constants/vm.js +++ b/src/fireedge/src/client/constants/vm.js @@ -179,7 +179,6 @@ import { ScheduleAction } from 'client/constants/scheduler' * @property {string} [TEMPLATE.MEMORY] - * @property {string} [TEMPLATE.MEMORY_COST] - * @property {string} [TEMPLATE.MEMORY_MAX] - - * @property {string} [TEMPLATE.MEMORY_SLOTS] - * @property {Nic|Nic[]} [TEMPLATE.NIC] - * @property {NicAlias|NicAlias[]} [TEMPLATE.NIC_ALIAS] - * @property {any} [TEMPLATE.NIC_DEFAULT] - diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 2fa9d9a24e..0274e77fc8 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -832,19 +832,13 @@ int VirtualMachine::insert(SqlDB * db, string& error_str) user_obj_template->erase("MEMORY"); obj_template->add("MEMORY", memory); - // Check optional MEMORY_MAX and MEMORY_SLOTS attribute + // Check optional MEMORY_MAX attribute if ( user_obj_template->get("MEMORY_MAX", ivalue) && ivalue > 0 ) { user_obj_template->erase("MEMORY_MAX"); obj_template->add("MEMORY_MAX", ivalue); } - if ( user_obj_template->get("MEMORY_SLOTS", ivalue) && ivalue > 0 ) - { - user_obj_template->erase("MEMORY_SLOTS"); - obj_template->add("MEMORY_SLOTS", ivalue); - } - if ( user_obj_template->get("CPU", fvalue) == false || fvalue <= 0 ) { goto error_cpu; diff --git a/src/vmm/LibVirtDriverKVM.cc b/src/vmm/LibVirtDriverKVM.cc index 1e8b9d427f..31395b6a15 100644 --- a/src/vmm/LibVirtDriverKVM.cc +++ b/src/vmm/LibVirtDriverKVM.cc @@ -718,7 +718,16 @@ int LibVirtDriver::deployment_description_kvm( // Memory must be expressed in Kb if (vm->get_template_attribute("MEMORY",memory)) { - file << "\t" << memory * 1024 << "" << endl; + bool has_memory_max = vm->get_template_attribute("MEMORY_MAX", memory_max); + has_memory_max = has_memory_max && memory < memory_max; + + if (!has_memory_max) + { + memory_max = memory; + } + + file << "\t" << memory_max * 1024 << "" << endl; + file << "\t" << memory * 1024 << "" << endl; } else { @@ -726,18 +735,6 @@ int LibVirtDriver::deployment_description_kvm( return -1; } - bool has_memory_max = vm->get_template_attribute("MEMORY_MAX", memory_max); - has_memory_max = has_memory_max && memory < memory_max; - - if (!topology && has_memory_max) - { - int slots = 0; - get_attribute(vm, host, cluster, "MEMORY_SLOTS", slots); - - file << "\t" << memory_max * 1024 << "" << endl; - } - // ------------------------------------------------------------------------ // OS and boot options // ------------------------------------------------------------------------ @@ -851,7 +848,7 @@ int LibVirtDriver::deployment_description_kvm( cpu_mode = "custom"; } - if ( !cpu_model.empty() || topology != 0 || has_memory_max ) + if ( !cpu_model.empty() || topology != 0 ) { file << "\t\n"; } - if (nodes.empty() && has_memory_max) - { - int cpus = to_i(vcpu) - 1; - if (cpus < 0) - { - cpus = 0; - } - - file << "\t\t\n\t\t\t\n\t\t" << endl; - } - vtopol(file, topology, nodes, numa_tune, mbacking); file << "\t\n"; diff --git a/src/vmm_mad/exec/vmm_exec_kvm.conf b/src/vmm_mad/exec/vmm_exec_kvm.conf index 91c3ed0b20..7453434546 100644 --- a/src/vmm_mad/exec/vmm_exec_kvm.conf +++ b/src/vmm_mad/exec/vmm_exec_kvm.conf @@ -20,7 +20,6 @@ # - emulator # - os [kernel,initrd,boot,root,kernel_cmd,arch,machine,sd_disk_bus] # - vcpu -# - memory_slots: number of memory slots for hotplug memory # - graphics [type, listen, passwd, keymap, random_passwd] # - features [acpi, pae, apic, hyperv, localtime, guest_agent, virtio_scsi_queues, iothreads] # - cpu_model [model] @@ -34,8 +33,6 @@ #VCPU = 1 -MEMORY_SLOTS = 16 - OS = [ ARCH = "x86_64" ] diff --git a/src/vmm_mad/remotes/kvm/resize b/src/vmm_mad/remotes/kvm/resize index d664014f04..da65dec69b 100755 --- a/src/vmm_mad/remotes/kvm/resize +++ b/src/vmm_mad/remotes/kvm/resize @@ -53,33 +53,8 @@ if [ ! -z "$MEM" -a "$MEM" -ne "$MEM_OLD" ]; then sudo -n sysctl vm.drop_caches=3 vm.compact_memory=1 >/dev/null fi - # Extract node id from virsh dumpxml - XML_INFO=$(virsh --connect ${LIBVIRT_URI} dumpxml ${DOMAIN}) - IFS= read -r -d '' NODE_ID < <(echo "$XML_INFO" | $XPATH --subtree /domain/cpu/numa/cell/@id) - - MEM_DIFF=$(expr $MEM - $MEM_OLD) - - case $MEM_DIFF in - -*) - ACTION="detach-device" - MEM_DIFF=${MEM_DIFF#-} - ;; - *) - ACTION="attach-device" - ;; - esac - - # Create tmp file with memory device specification - TMPFILE=$(mktemp /tmp/resize.XXXXXX) - echo -e "\n\t\n\ - $MEM_DIFF\n\ - $NODE_ID\n\t\n" >$TMPFILE - # Add memory to VM - exec_and_log "virsh --connect ${LIBVIRT_URI} ${ACTION} ${DOMAIN} ${TMPFILE} --live" - - # Cleanup - rm $TMPFILE + exec_and_log "virsh --connect ${LIBVIRT_URI} setmem ${DOMAIN} $((${MEM}*1024))" # Compact memory if [ "x$CLEANUP_MEMORY_ON_STOP" = "xyes" ]; then