This is already being done for pSeries guests, so let's extend
the treatment for x86. The difference here is that the existing
x86 alignment in the QEMU driver might be restricted only to
QEMU, meaning that we can't put it in virDomainMemoryDefPostParse()
without infering that all hypervisors would handle it the same
way.
Instead, let's create a qemuDomainMemoryDefPostParse() that will
be called in qemuDomainDeviceDefPostParse() to do that. After this
change, def->nmems will always be aligned after parsing time.
qemuDomainAlignMemorySizes() doesn't need to align each memory
module before calculating 'hotplugmem'.
We'll also generated aligned values in the resulting XML as well.
Some xml2xml tests were changed to reflect this new behavior.
Signed-off-by: Daniel Henrique Barboza <danielhb413(a)gmail.com>
---
src/qemu/qemu_domain.c | 45 +++++++++++--------
tests/qemuxml2argvdata/hugepages-nvdimm.xml | 2 +-
.../memory-hotplug-nvdimm-access.xml | 2 +-
.../memory-hotplug-nvdimm-align.xml | 2 +-
.../memory-hotplug-nvdimm-label.xml | 2 +-
.../memory-hotplug-nvdimm-pmem.xml | 2 +-
.../memory-hotplug-nvdimm-readonly.xml | 2 +-
.../memory-hotplug-nvdimm.xml | 2 +-
tests/qemuxml2argvdata/pages-dimm-discard.xml | 2 +-
.../memory-hotplug-dimm.xml | 4 +-
10 files changed, 36 insertions(+), 29 deletions(-)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index e40c122311..c06c33f8d0 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -5343,6 +5343,23 @@ qemuDomainTPMDefPostParse(virDomainTPMDefPtr tpm,
}
+static int
+qemuDomainMemoryDefPostParse(virDomainMemoryDefPtr mem,
+ virArch arch)
+{
+ /* For x86, dimm memory modules require 2MiB alignment rather than
+ * the 1MiB we are using elsewhere. */
+ unsigned int x86MemoryModuleSizeAlignment = 2048;
+
+ /* ppc64 memory module alignment is done in
+ * virDomainMemoryDefPostParse(). */
+ if (!ARCH_IS_PPC64(arch))
+ mem->size = VIR_ROUND_UP(mem->size, x86MemoryModuleSizeAlignment);
+
+ return 0;
+}
+
+
static int
qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
const virDomainDef *def,
@@ -5400,6 +5417,10 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
ret = qemuDomainTPMDefPostParse(dev->data.tpm, def->os.arch);
break;
+ case VIR_DOMAIN_DEVICE_MEMORY:
+ ret = qemuDomainMemoryDefPostParse(dev->data.memory, def->os.arch);
+ break;
+
case VIR_DOMAIN_DEVICE_LEASE:
case VIR_DOMAIN_DEVICE_FS:
case VIR_DOMAIN_DEVICE_INPUT:
@@ -5412,7 +5433,6 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
case VIR_DOMAIN_DEVICE_MEMBALLOON:
case VIR_DOMAIN_DEVICE_NVRAM:
case VIR_DOMAIN_DEVICE_RNG:
- case VIR_DOMAIN_DEVICE_MEMORY:
case VIR_DOMAIN_DEVICE_IOMMU:
case VIR_DOMAIN_DEVICE_AUDIO:
ret = 0;
@@ -8042,15 +8062,6 @@ qemuDomainGetMemorySizeAlignment(const virDomainDef *def)
}
-static unsigned long long
-qemuDomainGetMemoryModuleSizeAlignment(void)
-{
- /* For x86, dimm memory modules require 2MiB alignment rather than
- * the 1MiB we are using elsewhere. */
- return 2048;
-}
-
-
int
qemuDomainAlignMemorySizes(virDomainDefPtr def)
{
@@ -8077,16 +8088,12 @@ qemuDomainAlignMemorySizes(virDomainDefPtr def)
virDomainNumaSetNodeMemorySize(def->numa, i, mem);
}
- /* Align memory module sizes. This needs to occur before 'initialmem'
- * calculation because virDomainDefGetMemoryInitial() uses the size
- * of the modules in the math. */
+ /* Calculate hotplugmem. The memory modules are already aligned at this
+ * point:
+ *
+ * - ppc64 mem modules are being aligned by virDomainMemoryDefPostParse();
+ * - x86 mem modules are being aligned by qemuDomainMemoryDefPostParse(). */
for (i = 0; i < def->nmems; i++) {
- /* ppc64 memory modules are aligned by virDomainMemoryDefPostParse(). */
- if (!ARCH_IS_PPC64(def->os.arch)) {
- align = qemuDomainGetMemoryModuleSizeAlignment();
- def->mems[i]->size = VIR_ROUND_UP(def->mems[i]->size, align);
- }
-
hotplugmem += def->mems[i]->size;
if (def->mems[i]->size > maxmemkb) {
diff --git a/tests/qemuxml2argvdata/hugepages-nvdimm.xml
b/tests/qemuxml2argvdata/hugepages-nvdimm.xml
index 144d02b56e..d356ad12a8 100644
--- a/tests/qemuxml2argvdata/hugepages-nvdimm.xml
+++ b/tests/qemuxml2argvdata/hugepages-nvdimm.xml
@@ -39,7 +39,7 @@
<path>/tmp/nvdimm</path>
</source>
<target>
- <size unit='KiB'>523264</size>
+ <size unit='KiB'>524288</size>
<node>0</node>
</target>
<address type='dimm' slot='0'/>
diff --git a/tests/qemuxml2argvdata/memory-hotplug-nvdimm-access.xml
b/tests/qemuxml2argvdata/memory-hotplug-nvdimm-access.xml
index a1cc1264eb..4ac5589076 100644
--- a/tests/qemuxml2argvdata/memory-hotplug-nvdimm-access.xml
+++ b/tests/qemuxml2argvdata/memory-hotplug-nvdimm-access.xml
@@ -48,7 +48,7 @@
<path>/tmp/nvdimm</path>
</source>
<target>
- <size unit='KiB'>523264</size>
+ <size unit='KiB'>524288</size>
<node>0</node>
</target>
<address type='dimm' slot='0'/>
diff --git a/tests/qemuxml2argvdata/memory-hotplug-nvdimm-align.xml
b/tests/qemuxml2argvdata/memory-hotplug-nvdimm-align.xml
index 018a693aaf..2436b1a1af 100644
--- a/tests/qemuxml2argvdata/memory-hotplug-nvdimm-align.xml
+++ b/tests/qemuxml2argvdata/memory-hotplug-nvdimm-align.xml
@@ -49,7 +49,7 @@
<alignsize unit='KiB'>2048</alignsize>
</source>
<target>
- <size unit='KiB'>523264</size>
+ <size unit='KiB'>524288</size>
<node>0</node>
</target>
<address type='dimm' slot='0'/>
diff --git a/tests/qemuxml2argvdata/memory-hotplug-nvdimm-label.xml
b/tests/qemuxml2argvdata/memory-hotplug-nvdimm-label.xml
index c9d54a6088..6e8902a25e 100644
--- a/tests/qemuxml2argvdata/memory-hotplug-nvdimm-label.xml
+++ b/tests/qemuxml2argvdata/memory-hotplug-nvdimm-label.xml
@@ -48,7 +48,7 @@
<path>/tmp/nvdimm</path>
</source>
<target>
- <size unit='KiB'>523264</size>
+ <size unit='KiB'>524288</size>
<node>0</node>
<label>
<size unit='KiB'>128</size>
diff --git a/tests/qemuxml2argvdata/memory-hotplug-nvdimm-pmem.xml
b/tests/qemuxml2argvdata/memory-hotplug-nvdimm-pmem.xml
index 391d70f20e..a1a49f68ad 100644
--- a/tests/qemuxml2argvdata/memory-hotplug-nvdimm-pmem.xml
+++ b/tests/qemuxml2argvdata/memory-hotplug-nvdimm-pmem.xml
@@ -49,7 +49,7 @@
<pmem/>
</source>
<target>
- <size unit='KiB'>523264</size>
+ <size unit='KiB'>524288</size>
<node>0</node>
</target>
<address type='dimm' slot='0'/>
diff --git a/tests/qemuxml2argvdata/memory-hotplug-nvdimm-readonly.xml
b/tests/qemuxml2argvdata/memory-hotplug-nvdimm-readonly.xml
index 09b2c5c833..32000acb6d 100644
--- a/tests/qemuxml2argvdata/memory-hotplug-nvdimm-readonly.xml
+++ b/tests/qemuxml2argvdata/memory-hotplug-nvdimm-readonly.xml
@@ -48,7 +48,7 @@
<path>/tmp/nvdimm</path>
</source>
<target>
- <size unit='KiB'>523264</size>
+ <size unit='KiB'>524288</size>
<node>0</node>
<readonly/>
</target>
diff --git a/tests/qemuxml2argvdata/memory-hotplug-nvdimm.xml
b/tests/qemuxml2argvdata/memory-hotplug-nvdimm.xml
index a32474da06..815fca3412 100644
--- a/tests/qemuxml2argvdata/memory-hotplug-nvdimm.xml
+++ b/tests/qemuxml2argvdata/memory-hotplug-nvdimm.xml
@@ -48,7 +48,7 @@
<path>/tmp/nvdimm</path>
</source>
<target>
- <size unit='KiB'>523264</size>
+ <size unit='KiB'>524288</size>
<node>0</node>
</target>
<address type='dimm' slot='0'/>
diff --git a/tests/qemuxml2argvdata/pages-dimm-discard.xml
b/tests/qemuxml2argvdata/pages-dimm-discard.xml
index 3d233687e1..a0ba528823 100644
--- a/tests/qemuxml2argvdata/pages-dimm-discard.xml
+++ b/tests/qemuxml2argvdata/pages-dimm-discard.xml
@@ -40,7 +40,7 @@
</memory>
<memory model='dimm' access='private' discard='yes'>
<target>
- <size unit='KiB'>524287</size>
+ <size unit='KiB'>524288</size>
<node>0</node>
</target>
<address type='dimm' slot='1'/>
diff --git a/tests/qemuxml2xmloutdata/memory-hotplug-dimm.xml
b/tests/qemuxml2xmloutdata/memory-hotplug-dimm.xml
index 326b5c954c..985a4fc094 100644
--- a/tests/qemuxml2xmloutdata/memory-hotplug-dimm.xml
+++ b/tests/qemuxml2xmloutdata/memory-hotplug-dimm.xml
@@ -45,7 +45,7 @@
</memballoon>
<memory model='dimm'>
<target>
- <size unit='KiB'>523264</size>
+ <size unit='KiB'>524288</size>
<node>0</node>
</target>
<address type='dimm' slot='0'/>
@@ -56,7 +56,7 @@
<pagesize unit='KiB'>2048</pagesize>
</source>
<target>
- <size unit='KiB'>524287</size>
+ <size unit='KiB'>524288</size>
<node>0</node>
</target>
<address type='dimm' slot='1'/>
--
2.26.2