[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCHv2 1/2] qemu: reflect any memory rounding back to xml

On 03/31/2012 02:47 PM, Osier Yang wrote:
On 03/30/2012 11:56 PM, Eric Blake wrote:
If we round up a user's memory request, we should update the XML
to reflect the actual value in use by the VM, rather than giving
an artificially small value back to the user.

* src/qemu/qemu_command.c (qemuBuildNumaArgStr)
(qemuBuildCommandLine): Reflect rounding back to XML.
src/qemu/qemu_command.c | 11 +++++++----
1 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 3d2bb6b..8f6471b 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3916,8 +3916,9 @@ qemuBuildNumaArgStr(const virDomainDefPtr def,
virCommandPtr cmd)
virBufferAsprintf(&buf, "node,nodeid=%d", def->cpu->cells[i].cellid);
virBufferAddLit(&buf, ",cpus=");
- virBufferAsprintf(&buf, "mem=%d",
- VIR_DIV_UP(def->cpu->cells[i].mem, 1024));
+ def->cpu->cells[i].mem = VIR_DIV_UP(def->cpu->cells[i].mem,
+ 1024) * 1024;
+ virBufferAsprintf(&buf, "mem=%d", def->cpu->cells[i].mem / 1024);

if (virBufferError(&buf))
goto error;
@@ -4061,10 +4062,12 @@ qemuBuildCommandLine(virConnectPtr conn,

/* Set '-m MB' based on maxmem, because the lower 'memory' limit
* is set post-startup using the balloon driver. If balloon driver
- * is not supported, then they're out of luck anyway
+ * is not supported, then they're out of luck anyway. Update the
+ * XML to reflect our rounding.
virCommandAddArg(cmd, "-m");
- virCommandAddArgFormat(cmd, "%llu", VIR_DIV_UP(def->mem.max_balloon,
+ def->mem.max_balloon = VIR_DIV_UP(def->mem.max_balloon, 1024) * 1024;
+ virCommandAddArgFormat(cmd, "%llu", def->mem.max_balloon / 1024);
if (def->mem.hugepage_backed) {
if (!driver->hugetlbfs_mount) {

It makes sense to reflect the real memory used in qemu command
line back to domain conf, but IMHO we need the documentations to
declare that the these memory stuffs mighted be rounded up,
otherwise I guess bugs will come by confused users.

However, the value will be rounded up to the nearest kibibyte by libvirt, and may be further rounded to the granularity supported by the hypervisor. Some hypervisors also enforce a minimum, such as 4000KiB. unit since 0.9.11

Forgot about it, we already have documentation for it, :=)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]