qemu: add support for shared memory mapping

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Martin Kletzander 2014-09-08 11:36:09 +02:00
parent def6b35989
commit c7abf2c856
3 changed files with 50 additions and 0 deletions

View File

@ -6553,6 +6553,7 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg,
for (i = 0; i < def->cpu->ncells; i++) {
int cellmem = VIR_DIV_UP(def->cpu->cells[i].mem, 1024);
def->cpu->cells[i].mem = cellmem * 1024;
virTristateSwitch memAccess = def->cpu->cells[i].memAccess;
VIR_FREE(cpumask);
VIR_FREE(nodemask);
@ -6631,7 +6632,28 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg,
virBufferAsprintf(&buf,
"memory-backend-file,prealloc=yes,mem-path=%s",
mem_path);
switch (memAccess) {
case VIR_MEM_ACCESS_SHARED:
virBufferAddLit(&buf, ",share=on");
break;
case VIR_MEM_ACCESS_PRIVATE:
virBufferAddLit(&buf, ",share=off");
break;
case VIR_MEM_ACCESS_DEFAULT:
case VIR_MEM_ACCESS_LAST:
break;
}
} else {
if (memAccess) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Shared memory mapping is supported "
"only with hugepages"));
goto cleanup;
}
virBufferAddLit(&buf, "memory-backend-ram");
}
@ -6662,6 +6684,13 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg,
virCommandAddArg(cmd, "-object");
virCommandAddArgBuffer(cmd, &buf);
} else {
if (memAccess) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Shared memory mapping is not supported "
"with this QEMU"));
goto cleanup;
}
}
virCommandAddArg(cmd, "-numa");

View File

@ -0,0 +1,16 @@
LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
/usr/bin/qemu -S -M pc -m 4096 -smp 4 \
-object memory-backend-file,prealloc=yes,mem-path=/dev/hugepages1G/libvirt/qemu,\
size=1024M,id=ram-node0,host-nodes=0-3,policy=bind \
-numa node,nodeid=0,cpus=0,memdev=ram-node0 \
-object memory-backend-file,prealloc=yes,mem-path=/dev/hugepages2M/libvirt/qemu,\
share=on,size=1024M,id=ram-node1,host-nodes=0-3,policy=bind \
-numa node,nodeid=1,cpus=1,memdev=ram-node1 \
-object memory-backend-file,prealloc=yes,mem-path=/dev/hugepages1G/libvirt/qemu,\
share=off,size=1024M,id=ram-node2,host-nodes=0-3,policy=bind \
-numa node,nodeid=2,cpus=2,memdev=ram-node2 \
-object memory-backend-file,prealloc=yes,mem-path=/dev/hugepages1G/libvirt/qemu,\
size=1024M,id=ram-node3,host-nodes=3,policy=bind \
-numa node,nodeid=3,cpus=3,memdev=ram-node3 \
-nographic -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -usb \
-hda /dev/HostVG/QEMUGuest1 -net none -serial none -parallel none

View File

@ -684,6 +684,8 @@ mymain(void)
QEMU_CAPS_OBJECT_MEMORY_FILE);
DO_TEST("hugepages-pages3", QEMU_CAPS_MEM_PATH, QEMU_CAPS_OBJECT_MEMORY_RAM,
QEMU_CAPS_OBJECT_MEMORY_FILE);
DO_TEST("hugepages-shared", QEMU_CAPS_MEM_PATH, QEMU_CAPS_OBJECT_MEMORY_RAM,
QEMU_CAPS_OBJECT_MEMORY_FILE);
DO_TEST("nosharepages", QEMU_CAPS_MACHINE_OPT, QEMU_CAPS_MEM_MERGE);
DO_TEST("disk-cdrom", NONE);
DO_TEST("disk-cdrom-network-http", QEMU_CAPS_KVM, QEMU_CAPS_DEVICE,
@ -1208,6 +1210,9 @@ mymain(void)
DO_TEST_PARSE_ERROR("cpu-numa3", NONE);
DO_TEST_FAILURE("cpu-numa-disjoint", NONE);
DO_TEST("cpu-numa-disjoint", QEMU_CAPS_NUMA);
DO_TEST_FAILURE("cpu-numa-memshared", QEMU_CAPS_SMP_TOPOLOGY,
QEMU_CAPS_OBJECT_MEMORY_RAM);
DO_TEST_FAILURE("cpu-numa-memshared", QEMU_CAPS_SMP_TOPOLOGY);
DO_TEST("cpu-host-model", NONE);
skipLegacyCPUs = true;
DO_TEST("cpu-host-model-fallback", NONE);