[libvirt] [PATCH v2] qemu: process: Improve update of maximum baloon state at startup

In commit 641a145d73fdc3dd9350fd57b3d3247abf101c05 I've added code that resets the ballon memory value to full size prior to resuming the vCPUs since the size certainly was not reduced at that point. Since qemuProcess start is used also in code paths with already booted up guests (migration, save/restore) the assumption is not entirely true since the guest might already been running before. This patch adds a function that queries the monitor rather than using the full size since a balloon event would not be reissued in case we are recovering a saved migration state. Additionally the new function is used also when reconnecting to a VM after libvirtd restart since we might have missed a few ballon events while libvirtd was not running. --- src/qemu/qemu_process.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index ba84182..13b1696 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2065,6 +2065,38 @@ qemuProcessReconnectRefreshChannelVirtioState(virQEMUDriverPtr driver, static int +qemuProcessRefreshBallonState(virQEMUDriverPtr driver, + virDomainObjPtr vm, + int asyncJob) +{ + unsigned long long balloon; + int rc; + + /* if no balloning is available, the current size equals to the current + * full memory size */ + if (!vm->def->memballoon || + vm->def->memballoon->model == VIR_DOMAIN_MEMBALLOON_MODEL_NONE) { + vm->def->mem.cur_balloon = virDomainDefGetMemoryActual(vm->def); + return 0; + } + + if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0) + return -1; + + rc = qemuMonitorGetBalloonInfo(qemuDomainGetMonitor(vm), &balloon); + if (qemuDomainObjExitMonitor(driver, vm) < 0) + rc = -1; + + if (rc < 0) + return -1; + + vm->def->mem.cur_balloon = balloon; + + return 0; +} + + +static int qemuProcessWaitForMonitor(virQEMUDriverPtr driver, virDomainObjPtr vm, int asyncJob, @@ -3779,6 +3811,9 @@ qemuProcessReconnect(void *opaque) if (qemuProcessReconnectRefreshChannelVirtioState(driver, obj) < 0) goto error; + if (qemuProcessRefreshBallonState(driver, obj, QEMU_ASYNC_JOB_NONE) < 0) + goto error; + if (qemuProcessRecoverJob(driver, obj, conn, &oldjob) < 0) goto error; @@ -4922,7 +4957,8 @@ int qemuProcessStart(virConnectPtr conn, /* Since CPUs were not started yet, the ballon could not return the memory * to the host and thus cur_balloon needs to be updated so that GetXMLdesc * and friends return the correct size in case they can't grab the job */ - vm->def->mem.cur_balloon = virDomainDefGetMemoryActual(vm->def); + if (qemuProcessRefreshBallonState(driver, vm, asyncJob) < 0) + goto cleanup; VIR_DEBUG("Detecting actual memory size for video device"); if (qemuProcessUpdateVideoRamSize(driver, vm, asyncJob) < 0) -- 2.4.1

On Wed, Jul 01, 2015 at 10:13:27 +0200, Peter Krempa wrote:
In commit 641a145d73fdc3dd9350fd57b3d3247abf101c05 I've added code that resets the ballon memory value to full size prior to resuming the vCPUs since the size certainly was not reduced at that point.
Since qemuProcess start is used also in code paths with already booted up guests (migration, save/restore) the assumption is not entirely true since the guest might already been running before.
This patch adds a function that queries the monitor rather than using the full size since a balloon event would not be reissued in case we are recovering a saved migration state.
Additionally the new function is used also when reconnecting to a VM after libvirtd restart since we might have missed a few ballon events while libvirtd was not running. --- src/qemu/qemu_process.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-)
Ping?

s/baloon/balloon/ in the subject On Wed, Jul 01, 2015 at 10:13:27AM +0200, Peter Krempa wrote:
In commit 641a145d73fdc3dd9350fd57b3d3247abf101c05 I've added code that resets the ballon memory value to full size prior to resuming the vCPUs
s/ballon/balloon/
since the size certainly was not reduced at that point.
Since qemuProcess start is used also in code paths with already booted
qemuProcessStart
up guests (migration, save/restore) the assumption is not entirely true since the guest might already been running before.
This patch adds a function that queries the monitor rather than using the full size since a balloon event would not be reissued in case we are
This one is fine.
recovering a saved migration state.
Additionally the new function is used also when reconnecting to a VM after libvirtd restart since we might have missed a few ballon events
s/ballon/balloon/
while libvirtd was not running. --- src/qemu/qemu_process.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-)
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index ba84182..13b1696 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2065,6 +2065,38 @@ qemuProcessReconnectRefreshChannelVirtioState(virQEMUDriverPtr driver,
static int +qemuProcessRefreshBallonState(virQEMUDriverPtr driver,
s/Ballon/Balloon/
+ virDomainObjPtr vm, + int asyncJob) +{ + unsigned long long balloon; + int rc; + + /* if no balloning is available, the current size equals to the current
s/ballon/balloon/ ACK with the subject and the function name fixed. Jan

On Tue, Jul 14, 2015 at 13:50:24 +0200, Ján Tomko wrote:
s/baloon/balloon/ in the subject
On Wed, Jul 01, 2015 at 10:13:27AM +0200, Peter Krempa wrote:
In commit 641a145d73fdc3dd9350fd57b3d3247abf101c05 I've added code that resets the ballon memory value to full size prior to resuming the vCPUs
s/ballon/balloon/
since the size certainly was not reduced at that point.
Since qemuProcess start is used also in code paths with already booted
qemuProcessStart
up guests (migration, save/restore) the assumption is not entirely true since the guest might already been running before.
This patch adds a function that queries the monitor rather than using the full size since a balloon event would not be reissued in case we are
This one is fine.
recovering a saved migration state.
Additionally the new function is used also when reconnecting to a VM after libvirtd restart since we might have missed a few ballon events
s/ballon/balloon/
while libvirtd was not running. --- src/qemu/qemu_process.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-)
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index ba84182..13b1696 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2065,6 +2065,38 @@ qemuProcessReconnectRefreshChannelVirtioState(virQEMUDriverPtr driver,
static int +qemuProcessRefreshBallonState(virQEMUDriverPtr driver,
s/Ballon/Balloon/
+ virDomainObjPtr vm, + int asyncJob) +{ + unsigned long long balloon; + int rc; + + /* if no balloning is available, the current size equals to the current
s/ballon/balloon/
ACK with the subject and the function name fixed.
I've fixed all of them and pushed this patch. Thanks. Peter

title: s/baloon/balloon On 07/01/2015 04:13 AM, Peter Krempa wrote:
In commit 641a145d73fdc3dd9350fd57b3d3247abf101c05 I've added code that resets the ballon memory value to full size prior to resuming the vCPUs
s/ballon/balloon ACK with all the incorrect spellings fixed (including one introduced in the referenced commit). John
since the size certainly was not reduced at that point.
Since qemuProcess start is used also in code paths with already booted up guests (migration, save/restore) the assumption is not entirely true since the guest might already been running before.
This patch adds a function that queries the monitor rather than using the full size since a balloon event would not be reissued in case we are recovering a saved migration state.
Additionally the new function is used also when reconnecting to a VM after libvirtd restart since we might have missed a few ballon events
^^
while libvirtd was not running. --- src/qemu/qemu_process.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-)
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index ba84182..13b1696 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2065,6 +2065,38 @@ qemuProcessReconnectRefreshChannelVirtioState(virQEMUDriverPtr driver,
static int +qemuProcessRefreshBallonState(virQEMUDriverPtr driver,
^^
+ virDomainObjPtr vm, + int asyncJob) +{ + unsigned long long balloon; + int rc; + + /* if no balloning is available, the current size equals to the current
^^
+ * full memory size */ + if (!vm->def->memballoon || + vm->def->memballoon->model == VIR_DOMAIN_MEMBALLOON_MODEL_NONE) { + vm->def->mem.cur_balloon = virDomainDefGetMemoryActual(vm->def); + return 0; + } + + if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0) + return -1; + + rc = qemuMonitorGetBalloonInfo(qemuDomainGetMonitor(vm), &balloon); + if (qemuDomainObjExitMonitor(driver, vm) < 0) + rc = -1; + + if (rc < 0) + return -1; + + vm->def->mem.cur_balloon = balloon; + + return 0; +} + + +static int qemuProcessWaitForMonitor(virQEMUDriverPtr driver, virDomainObjPtr vm, int asyncJob, @@ -3779,6 +3811,9 @@ qemuProcessReconnect(void *opaque) if (qemuProcessReconnectRefreshChannelVirtioState(driver, obj) < 0) goto error;
+ if (qemuProcessRefreshBallonState(driver, obj, QEMU_ASYNC_JOB_NONE) < 0)
^^
+ goto error; + if (qemuProcessRecoverJob(driver, obj, conn, &oldjob) < 0) goto error;
@@ -4922,7 +4957,8 @@ int qemuProcessStart(virConnectPtr conn, /* Since CPUs were not started yet, the ballon could not return the memory
^^
* to the host and thus cur_balloon needs to be updated so that GetXMLdesc * and friends return the correct size in case they can't grab the job */ - vm->def->mem.cur_balloon = virDomainDefGetMemoryActual(vm->def); + if (qemuProcessRefreshBallonState(driver, vm, asyncJob) < 0)
^^
+ goto cleanup;
VIR_DEBUG("Detecting actual memory size for video device"); if (qemuProcessUpdateVideoRamSize(driver, vm, asyncJob) < 0)
participants (3)
-
John Ferlan
-
Ján Tomko
-
Peter Krempa