[libvirt] [PATCHv5 0/4] Add support for memory backing with file source

Hi, we would like to introduce 3 new elements source,access and allocation in memoryBacking element. For now it was made for numa topology. <memoryBacking> <source type="file|anonymous"/> <access mode="shared|private"/> <allocation mode="immediate|ondemand"/> </memoryBacking> If allocation is immediate then -mem-prealloc should be added to the qemu commanline. If source is file then -object memory-backend-file,id=mem,size=1024M,mem-path=*lib dir path* -numa node,memdev=mem Will be added to the qemu commandline If access is shared then the "share=on" parameter will be added to the memory-backend-file e.g. -object memory-backend-file,id=mem,size=1024M,mem-path=/var/lib/libvirt/qemu,share=on The access mode can be overriden by specifying token memAccess in numa cell. The mem-path can be defined by new config parameter memory_backing_dir. PS: the sometime failing test qemuhotplug was failing also before this patch :) Jaroslav Safka (4): qemu,conf: Rename virNumaMemAccess to virDomainMemoryAccess qemu_conf: Add param memory_backing_dir conf: Add new xml elements for file memorybacking support qemu: Add args generation for file memory backing docs/formatdomain.html.in | 9 ++ docs/schemas/domaincommon.rng | 30 +++++ src/conf/domain_conf.c | 133 ++++++++++++++++----- src/conf/domain_conf.h | 22 ++++ src/conf/numa_conf.c | 15 +-- src/conf/numa_conf.h | 14 +-- src/qemu/libvirtd_qemu.aug | 3 + src/qemu/qemu.conf | 4 + src/qemu/qemu_command.c | 55 ++++++--- src/qemu/qemu_conf.c | 9 ++ src/qemu/qemu_conf.h | 2 + src/qemu/qemu_process.c | 2 +- src/qemu/test_libvirtd_qemu.aug.in | 1 + .../qemuxml2argv-fd-memory-no-numa-topology.args | 21 ++++ .../qemuxml2argv-fd-memory-no-numa-topology.xml | 27 +++++ .../qemuxml2argv-fd-memory-numa-topology.args | 24 ++++ .../qemuxml2argv-fd-memory-numa-topology.xml | 30 +++++ .../qemuxml2argv-fd-memory-numa-topology2.args | 27 +++++ .../qemuxml2argv-fd-memory-numa-topology2.xml | 31 +++++ .../qemuxml2argv-fd-memory-numa-topology3.args | 30 +++++ .../qemuxml2argv-fd-memory-numa-topology3.xml | 32 +++++ .../qemuxml2argv-memorybacking-set.xml | 24 ++++ .../qemuxml2argv-memorybacking-unset.xml | 24 ++++ tests/qemuxml2argvtest.c | 13 ++ .../qemuxml2xmlout-memorybacking-set.xml | 32 +++++ .../qemuxml2xmlout-memorybacking-unset.xml | 32 +++++ tests/qemuxml2xmltest.c | 3 + 27 files changed, 584 insertions(+), 65 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-no-numa-topology.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-no-numa-topology.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology2.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology2.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology3.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology3.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-memorybacking-set.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-memorybacking-unset.xml create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-memorybacking-set.xml create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-memorybacking-unset.xml -- 2.7.4 -------------------------------------------------------------- Intel Research and Development Ireland Limited Registered in Ireland Registered Office: Collinstown Industrial Park, Leixlip, County Kildare Registered Number: 308263 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.

Rename to avoid duplicate code. Because virDomainMemoryAccess will be used in memorybacking for setting default behaviour. NOTE: The enum cannot be moved to qemu/domain_conf because of headers dependency --- src/conf/numa_conf.c | 15 ++++++++------- src/conf/numa_conf.h | 14 +++++++------- src/qemu/qemu_command.c | 10 +++++----- src/qemu/qemu_process.c | 2 +- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c index 9818d95..bfd3703 100644 --- a/src/conf/numa_conf.c +++ b/src/conf/numa_conf.c @@ -43,10 +43,11 @@ VIR_ENUM_IMPL(virDomainNumatunePlacement, "static", "auto"); -VIR_ENUM_IMPL(virNumaMemAccess, VIR_NUMA_MEM_ACCESS_LAST, +VIR_ENUM_IMPL(virDomainMemoryAccess, VIR_DOMAIN_MEMORY_ACCESS_LAST, "default", "shared", - "private"); + "private") + typedef struct _virDomainNumaNode virDomainNumaNode; typedef virDomainNumaNode *virDomainNumaNodePtr; @@ -64,7 +65,7 @@ struct _virDomainNuma { virBitmapPtr cpumask; /* bitmap of vCPUs corresponding to the node */ virBitmapPtr nodeset; /* host memory nodes where this guest node resides */ virDomainNumatuneMemMode mode; /* memory mode selection */ - virNumaMemAccess memAccess; /* shared memory access configuration */ + virDomainMemoryAccess memAccess; /* shared memory access configuration */ } *mem_nodes; /* guest node configuration */ size_t nmem_nodes; @@ -777,7 +778,7 @@ virDomainNumaDefCPUParseXML(virDomainNumaPtr def, goto cleanup; if ((tmp = virXMLPropString(nodes[i], "memAccess"))) { - if ((rc = virNumaMemAccessTypeFromString(tmp)) <= 0) { + if ((rc = virDomainMemoryAccessTypeFromString(tmp)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Invalid 'memAccess' attribute value '%s'"), tmp); @@ -803,7 +804,7 @@ int virDomainNumaDefCPUFormat(virBufferPtr buf, virDomainNumaPtr def) { - virNumaMemAccess memAccess; + virDomainMemoryAccess memAccess; char *cpustr; size_t ncells = virDomainNumaGetNodeCount(def); size_t i; @@ -827,7 +828,7 @@ virDomainNumaDefCPUFormat(virBufferPtr buf, virBufferAddLit(buf, " unit='KiB'"); if (memAccess) virBufferAsprintf(buf, " memAccess='%s'", - virNumaMemAccessTypeToString(memAccess)); + virDomainMemoryAccessTypeToString(memAccess)); virBufferAddLit(buf, "/>\n"); VIR_FREE(cpustr); } @@ -936,7 +937,7 @@ virDomainNumaGetNodeCpumask(virDomainNumaPtr numa, } -virNumaMemAccess +virDomainMemoryAccess virDomainNumaGetNodeMemoryAccessMode(virDomainNumaPtr numa, size_t node) { diff --git a/src/conf/numa_conf.h b/src/conf/numa_conf.h index 90deacb..05529ba 100644 --- a/src/conf/numa_conf.h +++ b/src/conf/numa_conf.h @@ -46,14 +46,14 @@ VIR_ENUM_DECL(virDomainNumatunePlacement) VIR_ENUM_DECL(virDomainNumatuneMemMode) typedef enum { - VIR_NUMA_MEM_ACCESS_DEFAULT, - VIR_NUMA_MEM_ACCESS_SHARED, - VIR_NUMA_MEM_ACCESS_PRIVATE, + VIR_DOMAIN_MEMORY_ACCESS_DEFAULT = 0, /* No memory access defined */ + VIR_DOMAIN_MEMORY_ACCESS_SHARED, /* Memory access is set as shared */ + VIR_DOMAIN_MEMORY_ACCESS_PRIVATE, /* Memory access is set as private */ - VIR_NUMA_MEM_ACCESS_LAST -} virNumaMemAccess; + VIR_DOMAIN_MEMORY_ACCESS_LAST, +} virDomainMemoryAccess; +VIR_ENUM_DECL(virDomainMemoryAccess) -VIR_ENUM_DECL(virNumaMemAccess) virDomainNumaPtr virDomainNumaNew(void); void virDomainNumaFree(virDomainNumaPtr numa); @@ -90,7 +90,7 @@ size_t virDomainNumaGetNodeCount(virDomainNumaPtr numa) virBitmapPtr virDomainNumaGetNodeCpumask(virDomainNumaPtr numa, size_t node) ATTRIBUTE_NONNULL(1); -virNumaMemAccess virDomainNumaGetNodeMemoryAccessMode(virDomainNumaPtr numa, +virDomainMemoryAccess virDomainNumaGetNodeMemoryAccessMode(virDomainNumaPtr numa, size_t node) ATTRIBUTE_NONNULL(1); unsigned long long virDomainNumaGetNodeMemorySize(virDomainNumaPtr numa, diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 1396661..601f11b 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3232,7 +3232,7 @@ qemuBuildMemoryBackendStr(unsigned long long size, virDomainHugePagePtr hugepage = NULL; virDomainNumatuneMemMode mode; const long system_page_size = virGetSystemPageSizeKB(); - virNumaMemAccess memAccess = VIR_NUMA_MEM_ACCESS_DEFAULT; + virDomainMemoryAccess memAccess = VIR_DOMAIN_MEMORY_ACCESS_DEFAULT; size_t i; char *mem_path = NULL; virBitmapPtr nodemask = NULL; @@ -3327,18 +3327,18 @@ qemuBuildMemoryBackendStr(unsigned long long size, goto cleanup; switch (memAccess) { - case VIR_NUMA_MEM_ACCESS_SHARED: + case VIR_DOMAIN_MEMORY_ACCESS_SHARED: if (virJSONValueObjectAdd(props, "b:share", true, NULL) < 0) goto cleanup; break; - case VIR_NUMA_MEM_ACCESS_PRIVATE: + case VIR_DOMAIN_MEMORY_ACCESS_PRIVATE: if (virJSONValueObjectAdd(props, "b:share", false, NULL) < 0) goto cleanup; break; - case VIR_NUMA_MEM_ACCESS_DEFAULT: - case VIR_NUMA_MEM_ACCESS_LAST: + case VIR_DOMAIN_MEMORY_ACCESS_DEFAULT: + case VIR_DOMAIN_MEMORY_ACCESS_LAST: break; } } else { diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 184440d..92fa69b 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4498,7 +4498,7 @@ qemuProcessStartWarnShmem(virDomainObjPtr vm) if (!shmem && vm->def->mem.nhugepages) { for (i = 0; i < virDomainNumaGetNodeCount(vm->def->numa); i++) { if (virDomainNumaGetNodeMemoryAccessMode(vm->def->numa, i) == - VIR_NUMA_MEM_ACCESS_SHARED) { + VIR_DOMAIN_MEMORY_ACCESS_SHARED) { shmem = true; break; } -- 2.7.4 -------------------------------------------------------------- Intel Research and Development Ireland Limited Registered in Ireland Registered Office: Collinstown Industrial Park, Leixlip, County Kildare Registered Number: 308263 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.

Add new parameter memory_backing_dir where files will be stored when memoryBacking source is selected as file. Value is stored inside char* memoryBackingDir --- src/qemu/libvirtd_qemu.aug | 3 +++ src/qemu/qemu.conf | 4 ++++ src/qemu/qemu_conf.c | 9 +++++++++ src/qemu/qemu_conf.h | 2 ++ src/qemu/test_libvirtd_qemu.aug.in | 1 + 5 files changed, 19 insertions(+) diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug index de723b2..82bae9e 100644 --- a/src/qemu/libvirtd_qemu.aug +++ b/src/qemu/libvirtd_qemu.aug @@ -109,6 +109,8 @@ module Libvirtd_qemu = let gluster_debug_level_entry = int_entry "gluster_debug_level" + let memory_entry = str_entry "memory_backing_dir" + (* Each entry in the config is one of the following ... *) let entry = default_tls_entry | vnc_entry @@ -125,6 +127,7 @@ module Libvirtd_qemu = | log_entry | nvram_entry | gluster_debug_level_entry + | memory_entry let comment = [ label "#comment" . del /#[ \t]*/ "# " . store /([^ \t\n][^\n]*)?/ . del /\n/ "\n" ] let empty = [ label "#empty" . eol ] diff --git a/src/qemu/qemu.conf b/src/qemu/qemu.conf index a8cd369..97d769d 100644 --- a/src/qemu/qemu.conf +++ b/src/qemu/qemu.conf @@ -673,3 +673,7 @@ # devices entries throughout the domain lifetime. This namespace is turned on # by default. #namespaces = [ "mount" ] + +# This directory is used for memoryBacking source if configured as file. +# NOTE: big files will be stored here +#memory_backing_dir = "/var/lib/libvirt/qemu/ram" diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 6613d59..0223a95 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -186,6 +186,8 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged) goto error; if (virAsprintf(&cfg->nvramDir, "%s/nvram", cfg->libDir) < 0) goto error; + if (virAsprintf(&cfg->memoryBackingDir, "%s/ram", cfg->libDir) < 0) + goto error; } else { char *rundir; char *cachedir; @@ -231,6 +233,8 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged) if (virAsprintf(&cfg->nvramDir, "%s/qemu/nvram", cfg->configBaseDir) < 0) goto error; + if (virAsprintf(&cfg->memoryBackingDir, "%s/qemu/ram", cfg->configBaseDir) < 0) + goto error; } if (virAsprintf(&cfg->configDir, "%s/qemu", cfg->configBaseDir) < 0) @@ -408,6 +412,8 @@ static void virQEMUDriverConfigDispose(void *obj) VIR_FREE(cfg->lockManagerName); virFirmwareFreeList(cfg->firmwares, cfg->nfirmwares); + + VIR_FREE(cfg->memoryBackingDir); } @@ -835,6 +841,9 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg, } } + if (virConfGetValueString(conf, "memory_backing_dir", &cfg->memoryBackingDir) < 0) + goto cleanup; + ret = 0; cleanup: diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 92a7a50..91904ed 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -195,6 +195,8 @@ struct _virQEMUDriverConfig { virFirmwarePtr *firmwares; size_t nfirmwares; unsigned int glusterDebugLevel; + + char *memoryBackingDir; }; /* Main driver state */ diff --git a/src/qemu/test_libvirtd_qemu.aug.in b/src/qemu/test_libvirtd_qemu.aug.in index a749f09..bd25235 100644 --- a/src/qemu/test_libvirtd_qemu.aug.in +++ b/src/qemu/test_libvirtd_qemu.aug.in @@ -94,3 +94,4 @@ module Test_libvirtd_qemu = { "namespaces" { "1" = "mount" } } +{ "memory_backing_dir" = "/var/lib/libvirt/qemu/ram" } -- 2.7.4 -------------------------------------------------------------- Intel Research and Development Ireland Limited Registered in Ireland Registered Office: Collinstown Industrial Park, Leixlip, County Kildare Registered Number: 308263 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.

This part introduces new xml elements for file based memorybacking support and their parsing. (It allows vhost-user to be used without hugepages.) New xml elements: <memoryBacking> <source type="file|anonymous"/> <access mode="shared|private"/> <allocation mode="immediate|ondemand"/> </memoryBacking> --- docs/formatdomain.html.in | 9 ++ docs/schemas/domaincommon.rng | 30 +++++ src/conf/domain_conf.c | 133 ++++++++++++++++----- src/conf/domain_conf.h | 22 ++++ .../qemuxml2argv-memorybacking-set.xml | 24 ++++ .../qemuxml2argv-memorybacking-unset.xml | 24 ++++ .../qemuxml2xmlout-memorybacking-set.xml | 32 +++++ .../qemuxml2xmlout-memorybacking-unset.xml | 32 +++++ tests/qemuxml2xmltest.c | 3 + 9 files changed, 276 insertions(+), 33 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-memorybacking-set.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-memorybacking-unset.xml create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-memorybacking-set.xml create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-memorybacking-unset.xml diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 77d8e71..0a115f5 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -903,6 +903,9 @@ </hugepages> <nosharepages/> <locked/> + <source type="file|anonymous"/> + <access mode="shared|private"/> + <allocation mode="immediate|ondemand"/> </memoryBacking> ... </domain> @@ -942,6 +945,12 @@ most of the host's memory). Doing so may be dangerous to both the domain and the host itself since the host's kernel may run out of memory. <span class="since">Since 1.0.6</span></dd> + <dt><code>source</code></dt> + <dd>In this attribute you can switch to file memorybacking or keep default anonymous.</dd> + <dt><code>access</code></dt> + <dd>Specify if memory is shared or private. This can be overridden per numa node by <code>memAccess</code></dd> + <dt><code>allocation</code></dt> + <dd>Specify when allocate the memory</dd> </dl> diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index cc6e0d0..d715bff 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -565,6 +565,36 @@ <empty/> </element> </optional> + <optional> + <element name="source"> + <attribute name="type"> + <choice> + <value>file</value> + <value>anonymous</value> + </choice> + </attribute> + </element> + </optional> + <optional> + <element name="access"> + <attribute name="mode"> + <choice> + <value>shared</value> + <value>private</value> + </choice> + </attribute> + </element> + </optional> + <optional> + <element name="allocation"> + <attribute name="mode"> + <choice> + <value>immediate</value> + <value>ondemand</value> + </choice> + </attribute> + </element> + </optional> </interleave> </element> </optional> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 877a0bf..e47b87f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -837,6 +837,16 @@ VIR_ENUM_IMPL(virDomainDiskMirrorState, VIR_DOMAIN_DISK_MIRROR_STATE_LAST, "abort", "pivot") +VIR_ENUM_IMPL(virDomainMemorySource, VIR_DOMAIN_MEMORY_SOURCE_LAST, + "none", + "file", + "anonymous") + +VIR_ENUM_IMPL(virDomainMemoryAllocation, VIR_DOMAIN_MEMORY_ALLOCATION_LAST, + "none", + "immediate", + "ondemand") + VIR_ENUM_IMPL(virDomainLoader, VIR_DOMAIN_LOADER_TYPE_LAST, "rom", @@ -16594,48 +16604,93 @@ virDomainDefParseXML(xmlDocPtr xml, } VIR_FREE(tmp); - if ((n = virXPathNodeSet("./memoryBacking/hugepages/page", ctxt, &nodes)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot extract hugepages nodes")); - goto error; + tmp = virXPathString("string(./memoryBacking/source/@type)", ctxt); + if (tmp) { + if ((def->mem.source = virDomainMemorySourceTypeFromString(tmp)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown memoryBacking/source/type '%s'"), tmp); + goto error; + } + VIR_FREE(tmp); } - if (n) { - if (VIR_ALLOC_N(def->mem.hugepages, n) < 0) + tmp = virXPathString("string(./memoryBacking/access/@mode)", ctxt); + if (tmp) { + if ((def->mem.access = virDomainMemoryAccessTypeFromString(tmp)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown memoryBacking/access/mode '%s'"), tmp); goto error; + } + VIR_FREE(tmp); + } - for (i = 0; i < n; i++) { - if (virDomainHugepagesParseXML(nodes[i], ctxt, - &def->mem.hugepages[i]) < 0) + tmp = virXPathString("string(./memoryBacking/allocation/@mode)", ctxt); + if (tmp) { + if ((def->mem.allocation = virDomainMemoryAllocationTypeFromString(tmp)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown memoryBacking/allocation/mode '%s'"), tmp); + goto error; + } + VIR_FREE(tmp); + } + + if (virXPathNode("./memoryBacking/hugepages", ctxt)) { + /* hugepages will be used */ + + if (def->mem.allocation == VIR_DOMAIN_MEMORY_ALLOCATION_ONDEMAND) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("hugepages are not allowed with memory allocation ondemand")); + goto error; + } + + if (def->mem.source == VIR_DOMAIN_MEMORY_SOURCE_ANONYMOUS) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("hugepages are not allowed with anonymous memory source")); + goto error; + } + + if ((n = virXPathNodeSet("./memoryBacking/hugepages/page", ctxt, &nodes)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("cannot extract hugepages nodes")); + goto error; + } + + if (n) { + if (VIR_ALLOC_N(def->mem.hugepages, n) < 0) goto error; - def->mem.nhugepages++; - for (j = 0; j < i; j++) { - if (def->mem.hugepages[i].nodemask && - def->mem.hugepages[j].nodemask && - virBitmapOverlaps(def->mem.hugepages[i].nodemask, - def->mem.hugepages[j].nodemask)) { - virReportError(VIR_ERR_XML_DETAIL, - _("nodeset attribute of hugepages " - "of sizes %llu and %llu intersect"), - def->mem.hugepages[i].size, - def->mem.hugepages[j].size); - goto error; - } else if (!def->mem.hugepages[i].nodemask && - !def->mem.hugepages[j].nodemask) { - virReportError(VIR_ERR_XML_DETAIL, - _("two master hugepages detected: " - "%llu and %llu"), - def->mem.hugepages[i].size, - def->mem.hugepages[j].size); + for (i = 0; i < n; i++) { + if (virDomainHugepagesParseXML(nodes[i], ctxt, + &def->mem.hugepages[i]) < 0) goto error; + def->mem.nhugepages++; + + for (j = 0; j < i; j++) { + if (def->mem.hugepages[i].nodemask && + def->mem.hugepages[j].nodemask && + virBitmapOverlaps(def->mem.hugepages[i].nodemask, + def->mem.hugepages[j].nodemask)) { + virReportError(VIR_ERR_XML_DETAIL, + _("nodeset attribute of hugepages " + "of sizes %llu and %llu intersect"), + def->mem.hugepages[i].size, + def->mem.hugepages[j].size); + goto error; + } else if (!def->mem.hugepages[i].nodemask && + !def->mem.hugepages[j].nodemask) { + virReportError(VIR_ERR_XML_DETAIL, + _("two master hugepages detected: " + "%llu and %llu"), + def->mem.hugepages[i].size, + def->mem.hugepages[j].size); + goto error; + } } } - } - VIR_FREE(nodes); - } else { - if ((node = virXPathNode("./memoryBacking/hugepages", ctxt))) { + VIR_FREE(nodes); + } else { + /* no hugepage pages */ if (VIR_ALLOC(def->mem.hugepages) < 0) goto error; @@ -23728,7 +23783,9 @@ virDomainDefFormatInternal(virDomainDefPtr def, virBufferAddLit(buf, "</memtune>\n"); } - if (def->mem.nhugepages || def->mem.nosharepages || def->mem.locked) { + if (def->mem.nhugepages || def->mem.nosharepages || def->mem.locked + || def->mem.source || def->mem.access || def->mem.allocation) + { virBufferAddLit(buf, "<memoryBacking>\n"); virBufferAdjustIndent(buf, 2); if (def->mem.nhugepages) @@ -23737,6 +23794,16 @@ virDomainDefFormatInternal(virDomainDefPtr def, virBufferAddLit(buf, "<nosharepages/>\n"); if (def->mem.locked) virBufferAddLit(buf, "<locked/>\n"); + if (def->mem.source) + virBufferAsprintf(buf, "<source type='%s'/>\n", + virDomainMemorySourceTypeToString(def->mem.source)); + if (def->mem.access) + virBufferAsprintf(buf, "<access mode='%s'/>\n", + virDomainMemoryAccessTypeToString(def->mem.access)); + if (def->mem.allocation) + virBufferAsprintf(buf, "<allocation mode='%s'/>\n", + virDomainMemoryAllocationTypeToString(def->mem.allocation)); + virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "</memoryBacking>\n"); } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 4d830c5..2615630 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -586,6 +586,22 @@ typedef enum { VIR_DOMAIN_DISK_MIRROR_STATE_LAST } virDomainDiskMirrorState; +typedef enum { + VIR_DOMAIN_MEMORY_SOURCE_NONE = 0, /* No memory source defined */ + VIR_DOMAIN_MEMORY_SOURCE_FILE, /* Memory source is set as file */ + VIR_DOMAIN_MEMORY_SOURCE_ANONYMOUS, /* Memory source is set as anonymous */ + + VIR_DOMAIN_MEMORY_SOURCE_LAST, +} virDomainMemorySource; + +typedef enum { + VIR_DOMAIN_MEMORY_ALLOCATION_NONE = 0, /* No memory allocation defined */ + VIR_DOMAIN_MEMORY_ALLOCATION_IMMEDIATE, /* Memory allocation is set as immediate */ + VIR_DOMAIN_MEMORY_ALLOCATION_ONDEMAND, /* Memory allocation is set as ondemand */ + + VIR_DOMAIN_MEMORY_ALLOCATION_LAST, +} virDomainMemoryAllocation; + /* Stores the virtual disk configuration */ struct _virDomainDiskDef { @@ -2130,6 +2146,10 @@ struct _virDomainMemtune { unsigned long long soft_limit; /* in kibibytes, limit at off_t bytes */ unsigned long long min_guarantee; /* in kibibytes, limit at off_t bytes */ unsigned long long swap_hard_limit; /* in kibibytes, limit at off_t bytes */ + + int source; /* enum virDomainMemorySource */ + int access; /* enum virDomainMemoryAccess */ + int allocation; /* enum virDomainMemoryAllocation */ }; typedef struct _virDomainPowerManagement virDomainPowerManagement; @@ -3115,6 +3135,8 @@ VIR_ENUM_DECL(virDomainTPMModel) VIR_ENUM_DECL(virDomainTPMBackend) VIR_ENUM_DECL(virDomainMemoryModel) VIR_ENUM_DECL(virDomainMemoryBackingModel) +VIR_ENUM_DECL(virDomainMemorySource) +VIR_ENUM_DECL(virDomainMemoryAllocation) VIR_ENUM_DECL(virDomainIOMMUModel) VIR_ENUM_DECL(virDomainShmemModel) /* from libvirt.h */ diff --git a/tests/qemuxml2argvdata/qemuxml2argv-memorybacking-set.xml b/tests/qemuxml2argvdata/qemuxml2argv-memorybacking-set.xml new file mode 100644 index 0000000..e23bc36 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-memorybacking-set.xml @@ -0,0 +1,24 @@ +<domain type='qemu'> + <name>SomeDummyGuest</name> + <uuid>ef1bdff4-27f3-4e85-a807-5fb4d58463cc</uuid> + <memory unit='KiB'>1048576</memory> + <currentMemory unit='KiB'>1048576</currentMemory> + <memoryBacking> + <source type='file'/> + <access mode='shared'/> + <allocation mode='immediate'/> + </memoryBacking> + <vcpu placement='static'>2</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu</emulator> + <memballoon model='virtio'/> + </devices> +</domain> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-memorybacking-unset.xml b/tests/qemuxml2argvdata/qemuxml2argv-memorybacking-unset.xml new file mode 100644 index 0000000..6f50765 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-memorybacking-unset.xml @@ -0,0 +1,24 @@ +<domain type='qemu'> + <name>SomeDummyGuest</name> + <uuid>ef1bdff4-27f3-4e85-a807-5fb4d58463cc</uuid> + <memory unit='KiB'>1048576</memory> + <currentMemory unit='KiB'>1048576</currentMemory> + <memoryBacking> + <source type="anonymous"/> + <access mode="private"/> + <allocation mode="ondemand"/> + </memoryBacking> + <vcpu placement='static'>2</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu</emulator> + <memballoon model='virtio'/> + </devices> +</domain> diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-memorybacking-set.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-memorybacking-set.xml new file mode 100644 index 0000000..fb07472 --- /dev/null +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-memorybacking-set.xml @@ -0,0 +1,32 @@ +<domain type='qemu'> + <name>SomeDummyGuest</name> + <uuid>ef1bdff4-27f3-4e85-a807-5fb4d58463cc</uuid> + <memory unit='KiB'>1048576</memory> + <currentMemory unit='KiB'>1048576</currentMemory> + <memoryBacking> + <source type='file'/> + <access mode='shared'/> + <allocation mode='immediate'/> + </memoryBacking> + <vcpu placement='static'>2</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu</emulator> + <controller type='usb' index='0'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> + </controller> + <controller type='pci' index='0' model='pci-root'/> + <input type='mouse' bus='ps2'/> + <input type='keyboard' bus='ps2'/> + <memballoon model='virtio'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> + </memballoon> + </devices> +</domain> diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-memorybacking-unset.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-memorybacking-unset.xml new file mode 100644 index 0000000..ac2a278 --- /dev/null +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-memorybacking-unset.xml @@ -0,0 +1,32 @@ +<domain type='qemu'> + <name>SomeDummyGuest</name> + <uuid>ef1bdff4-27f3-4e85-a807-5fb4d58463cc</uuid> + <memory unit='KiB'>1048576</memory> + <currentMemory unit='KiB'>1048576</currentMemory> + <memoryBacking> + <source type='anonymous'/> + <access mode='private'/> + <allocation mode='ondemand'/> + </memoryBacking> + <vcpu placement='static'>2</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu</emulator> + <controller type='usb' index='0'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> + </controller> + <controller type='pci' index='0' model='pci-root'/> + <input type='mouse' bus='ps2'/> + <input type='keyboard' bus='ps2'/> + <memballoon model='virtio'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> + </memballoon> + </devices> +</domain> diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 4f3b09a..0702f58 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -1042,6 +1042,9 @@ mymain(void) DO_TEST("virtio-input", NONE); DO_TEST("virtio-input-passthrough", NONE); + DO_TEST("memorybacking-set", NONE); + DO_TEST("memorybacking-unset", NONE); + virObjectUnref(cfg); DO_TEST("acpi-table", NONE); -- 2.7.4 -------------------------------------------------------------- Intel Research and Development Ireland Limited Registered in Ireland Registered Office: Collinstown Industrial Park, Leixlip, County Kildare Registered Number: 308263 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.

This patch add support for file memory backing on numa topology. The specified access mode in memoryBacking can be overriden by specifying token memAccess in numa cell. --- src/qemu/qemu_command.c | 45 ++++++++++++++++------ .../qemuxml2argv-fd-memory-no-numa-topology.args | 21 ++++++++++ .../qemuxml2argv-fd-memory-no-numa-topology.xml | 27 +++++++++++++ .../qemuxml2argv-fd-memory-numa-topology.args | 24 ++++++++++++ .../qemuxml2argv-fd-memory-numa-topology.xml | 30 +++++++++++++++ .../qemuxml2argv-fd-memory-numa-topology2.args | 27 +++++++++++++ .../qemuxml2argv-fd-memory-numa-topology2.xml | 31 +++++++++++++++ .../qemuxml2argv-fd-memory-numa-topology3.args | 30 +++++++++++++++ .../qemuxml2argv-fd-memory-numa-topology3.xml | 32 +++++++++++++++ tests/qemuxml2argvtest.c | 13 +++++++ 10 files changed, 268 insertions(+), 12 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-no-numa-topology.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-no-numa-topology.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology2.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology2.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology3.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology3.xml diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 601f11b..5fa735e 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3314,17 +3314,26 @@ qemuBuildMemoryBackendStr(unsigned long long size, if (!(props = virJSONValueNewObject())) return -1; - if (pagesize) { - if (qemuGetDomainHupageMemPath(def, cfg, pagesize, &mem_path) < 0) - goto cleanup; - + if (pagesize || def->mem.source == VIR_DOMAIN_MEMORY_SOURCE_FILE) { *backendType = "memory-backend-file"; - if (virJSONValueObjectAdd(props, - "b:prealloc", true, - "s:mem-path", mem_path, - NULL) < 0) - goto cleanup; + if (def->mem.source == VIR_DOMAIN_MEMORY_SOURCE_FILE) { + /* we can have both pagesize and mem source, then check mem source first */ + force = true; + if (virJSONValueObjectAdd(props, + "s:mem-path", cfg->memoryBackingDir, + NULL) < 0) + goto cleanup; + } else { + if (qemuGetDomainHupageMemPath(def, cfg, pagesize, &mem_path) < 0) + goto cleanup; + + if (virJSONValueObjectAdd(props, + "b:prealloc", true, + "s:mem-path", mem_path, + NULL) < 0) + goto cleanup; + } switch (memAccess) { case VIR_DOMAIN_MEMORY_ACCESS_SHARED: @@ -3338,6 +3347,12 @@ qemuBuildMemoryBackendStr(unsigned long long size, break; case VIR_DOMAIN_MEMORY_ACCESS_DEFAULT: + if (def->mem.access == VIR_DOMAIN_MEMORY_ACCESS_SHARED) { + if (virJSONValueObjectAdd(props, "b:share", true, NULL) < 0) + goto cleanup; + } + break; + case VIR_DOMAIN_MEMORY_ACCESS_LAST: break; } @@ -7302,7 +7317,10 @@ qemuBuildMemPathStr(virQEMUDriverConfigPtr cfg, if (qemuGetDomainHupageMemPath(def, cfg, def->mem.hugepages[0].size, &mem_path) < 0) return -1; - virCommandAddArgList(cmd, "-mem-prealloc", "-mem-path", mem_path, NULL); + if (def->mem.allocation != VIR_DOMAIN_MEMORY_ALLOCATION_IMMEDIATE) + virCommandAddArgList(cmd, "-mem-prealloc", NULL); + + virCommandAddArgList(cmd, "-mem-path", mem_path, NULL); VIR_FREE(mem_path); return 0; @@ -7332,9 +7350,12 @@ qemuBuildMemCommandLine(virCommandPtr cmd, virDomainDefGetMemoryInitial(def) / 1024); } + if (def->mem.allocation == VIR_DOMAIN_MEMORY_ALLOCATION_IMMEDIATE) + virCommandAddArgList(cmd, "-mem-prealloc", NULL); + /* - * Add '-mem-path' (and '-mem-prealloc') parameter here only if - * there is no numa node specified. + * Add '-mem-path' (and '-mem-prealloc') parameter here if + * the hugepages and no numa node is specified. */ if (!virDomainNumaGetNodeCount(def->numa) && qemuBuildMemPathStr(cfg, def, qemuCaps, cmd) < 0) diff --git a/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-no-numa-topology.args b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-no-numa-topology.args new file mode 100644 index 0000000..951a7cb --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-no-numa-topology.args @@ -0,0 +1,21 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/home/test \ +USER=test \ +LOGNAME=test \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu-system-x86_64 \ +-name instance-00000092 \ +-S \ +-M pc-i440fx-wily \ +-m 14336 \ +-mem-prealloc \ +-smp 8,sockets=8,cores=1,threads=1 \ +-uuid 126f2720-6f8e-45ab-a886-ec9277079a67 \ +-nographic \ +-nodefaults \ +-monitor unix:/tmp/lib/domain--1-instance-00000092/monitor.sock,server,nowait \ +-no-acpi \ +-boot c \ +-usb \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-no-numa-topology.xml b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-no-numa-topology.xml new file mode 100644 index 0000000..243b65d --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-no-numa-topology.xml @@ -0,0 +1,27 @@ +<domain type='kvm' id='56'> + <name>instance-00000092</name> + <uuid>126f2720-6f8e-45ab-a886-ec9277079a67</uuid> + <memory unit='KiB'>14680064</memory> + <currentMemory unit='KiB'>14680064</currentMemory> + <memoryBacking> + <source type='file'/> + <access mode='shared'/> + <allocation mode='immediate'/> + </memoryBacking> + <vcpu placement='static'>8</vcpu> + <os> + <type arch='x86_64' machine='pc-i440fx-wily'>hvm</type> + <boot dev='hd'/> + </os> + <cpu> + <topology sockets='8' cores='1' threads='1'/> + </cpu> + <clock offset='utc' /> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu-system-x86_64</emulator> + <memballoon model='virtio'/> + </devices> +</domain> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology.args b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology.args new file mode 100644 index 0000000..bef8136 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology.args @@ -0,0 +1,24 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/home/test \ +USER=test \ +LOGNAME=test \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu-system-x86_64 \ +-name instance-00000092 \ +-S \ +-M pc-i440fx-wily \ +-m 14336 \ +-mem-prealloc \ +-smp 8,sockets=1,cores=8,threads=1 \ +-object memory-backend-file,id=ram-node0,mem-path=/var/lib/libvirt/qemu/ram,\ +share=yes,size=15032385536 \ +-numa node,nodeid=0,cpus=0-7,memdev=ram-node0 \ +-uuid 126f2720-6f8e-45ab-a886-ec9277079a67 \ +-nographic \ +-nodefaults \ +-monitor unix:/tmp/lib/domain--1-instance-00000092/monitor.sock,server,nowait \ +-no-acpi \ +-boot c \ +-usb \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology.xml b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology.xml new file mode 100644 index 0000000..ca5402d --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology.xml @@ -0,0 +1,30 @@ +<domain type='kvm'> + <name>instance-00000092</name> + <uuid>126f2720-6f8e-45ab-a886-ec9277079a67</uuid> + <memory unit='KiB'>14680064</memory> + <currentMemory unit='KiB'>14680064</currentMemory> + <memoryBacking> + <source type='file'/> + <access mode='shared'/> + <allocation mode='immediate'/> + </memoryBacking> + <vcpu placement='static'>8</vcpu> + <os> + <type arch='x86_64' machine='pc-i440fx-wily'>hvm</type> + <boot dev='hd'/> + </os> + <cpu> + <topology sockets='1' cores='8' threads='1'/> + <numa> + <cell id='0' cpus='0-7' memory='14680064' unit='KiB'/> + </numa> + </cpu> + <clock offset='utc' /> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu-system-x86_64</emulator> + <memballoon model='virtio'/> + </devices> +</domain> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology2.args b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology2.args new file mode 100644 index 0000000..4420b9a --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology2.args @@ -0,0 +1,27 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/home/test \ +USER=test \ +LOGNAME=test \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu-system-x86_64 \ +-name instance-00000092 \ +-S \ +-M pc-i440fx-wily \ +-m 28672 \ +-mem-prealloc \ +-smp 20,sockets=1,cores=8,threads=1 \ +-object memory-backend-file,id=ram-node0,mem-path=/var/lib/libvirt/qemu/ram,\ +size=15032385536 \ +-numa node,nodeid=0,cpus=0-7,memdev=ram-node0 \ +-object memory-backend-file,id=ram-node1,mem-path=/var/lib/libvirt/qemu/ram,\ +share=yes,size=15032385536 \ +-numa node,nodeid=1,cpus=8-15,memdev=ram-node1 \ +-uuid 126f2720-6f8e-45ab-a886-ec9277079a67 \ +-nographic \ +-nodefaults \ +-monitor unix:/tmp/lib/domain--1-instance-00000092/monitor.sock,server,nowait \ +-no-acpi \ +-boot c \ +-usb \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology2.xml b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology2.xml new file mode 100644 index 0000000..49beff1 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology2.xml @@ -0,0 +1,31 @@ + <domain type='kvm' id='56'> + <name>instance-00000092</name> + <uuid>126f2720-6f8e-45ab-a886-ec9277079a67</uuid> + <memory unit='KiB'>14680064</memory> + <currentMemory unit='KiB'>14680064</currentMemory> + <memoryBacking> + <source type='file'/> + <access mode='private'/> + <allocation mode='immediate'/> + </memoryBacking> + <vcpu placement='static'>20</vcpu> + <os> + <type arch='x86_64' machine='pc-i440fx-wily'>hvm</type> + <boot dev='hd'/> + </os> + <cpu> + <topology sockets='1' cores='8' threads='1'/> + <numa> + <cell id='0' cpus='0-7' memory='14680064' unit='KiB'/> + <cell id='1' cpus='8-15' memory='14680064' unit='KiB' memAccess='shared'/> + </numa> + </cpu> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu-system-x86_64</emulator> + <memballoon model='virtio'/> + </devices> + </domain> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology3.args b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology3.args new file mode 100644 index 0000000..4d98aa0 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology3.args @@ -0,0 +1,30 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/home/test \ +USER=test \ +LOGNAME=test \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu-system-x86_64 \ +-name instance-00000092 \ +-S \ +-M pc-i440fx-wily \ +-m 43008 \ +-mem-prealloc \ +-smp 32,sockets=1,cores=24,threads=1 \ +-object memory-backend-file,id=ram-node0,mem-path=/var/lib/libvirt/qemu/ram,\ +share=yes,size=15032385536 \ +-numa node,nodeid=0,cpus=0-1,memdev=ram-node0 \ +-object memory-backend-file,id=ram-node1,mem-path=/var/lib/libvirt/qemu/ram,\ +share=yes,size=15032385536 \ +-numa node,nodeid=1,cpus=2-3,memdev=ram-node1 \ +-object memory-backend-file,id=ram-node2,mem-path=/var/lib/libvirt/qemu/ram,\ +share=no,size=15032385536 \ +-numa node,nodeid=2,cpus=4-5,memdev=ram-node2 \ +-uuid 126f2720-6f8e-45ab-a886-ec9277079a67 \ +-nographic \ +-nodefaults \ +-monitor unix:/tmp/lib/domain--1-instance-00000092/monitor.sock,server,nowait \ +-no-acpi \ +-boot c \ +-usb \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology3.xml b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology3.xml new file mode 100644 index 0000000..7933507 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology3.xml @@ -0,0 +1,32 @@ + <domain type='kvm' id='56'> + <name>instance-00000092</name> + <uuid>126f2720-6f8e-45ab-a886-ec9277079a67</uuid> + <memory unit='KiB'>14680064</memory> + <currentMemory unit='KiB'>14680064</currentMemory> + <memoryBacking> + <source type='file'/> + <access mode='shared'/> + <allocation mode='immediate'/> + </memoryBacking> + <vcpu placement='static'>32</vcpu> + <os> + <type arch='x86_64' machine='pc-i440fx-wily'>hvm</type> + <boot dev='hd'/> + </os> + <cpu> + <topology sockets='1' cores='24' threads='1'/> + <numa> + <cell id='0' cpus='0-1' memory='14680064' unit='KiB'/> + <cell id='1' cpus='2-3' memory='14680064' unit='KiB' memAccess='shared'/> + <cell id='2' cpus='4-5' memory='14680064' unit='KiB' memAccess='private'/> + </numa> + </cpu> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu-system-x86_64</emulator> + <memballoon model='virtio'/> + </devices> + </domain> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index d0b0cec..c244ad5 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -594,6 +594,9 @@ mymain(void) driver.config->spiceTLS = 1; if (VIR_STRDUP_QUIET(driver.config->spicePassword, "123456") < 0) return EXIT_FAILURE; + VIR_FREE(driver.config->memoryBackingDir); + if (VIR_STRDUP_QUIET(driver.config->memoryBackingDir, "/var/lib/libvirt/qemu/ram") < 0) + return EXIT_FAILURE; # define DO_TEST_FULL(name, migrateFrom, migrateFd, flags, \ parseFlags, gic, ...) \ @@ -2465,6 +2468,16 @@ mymain(void) DO_TEST("cpu-hotplug-startup", QEMU_CAPS_QUERY_HOTPLUGGABLE_CPUS); + DO_TEST("fd-memory-numa-topology", QEMU_CAPS_MEM_PATH, QEMU_CAPS_OBJECT_MEMORY_FILE, + QEMU_CAPS_KVM); + DO_TEST("fd-memory-numa-topology2", QEMU_CAPS_MEM_PATH, QEMU_CAPS_OBJECT_MEMORY_FILE, + QEMU_CAPS_KVM); + DO_TEST("fd-memory-numa-topology3", QEMU_CAPS_MEM_PATH, QEMU_CAPS_OBJECT_MEMORY_FILE, + QEMU_CAPS_KVM); + + DO_TEST("fd-memory-no-numa-topology", QEMU_CAPS_MEM_PATH, QEMU_CAPS_OBJECT_MEMORY_FILE, + QEMU_CAPS_KVM); + qemuTestDriverFree(&driver); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; -- 2.7.4 -------------------------------------------------------------- Intel Research and Development Ireland Limited Registered in Ireland Registered Office: Collinstown Industrial Park, Leixlip, County Kildare Registered Number: 308263 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.

On 02/02/2017 02:27 PM, Jaroslav Safka wrote:
Hi, we would like to introduce 3 new elements source,access and allocation in memoryBacking element. For now it was made for numa topology.
<memoryBacking> <source type="file|anonymous"/> <access mode="shared|private"/> <allocation mode="immediate|ondemand"/> </memoryBacking>
If allocation is immediate then -mem-prealloc should be added to the qemu commanline. If source is file then -object memory-backend-file,id=mem,size=1024M,mem-path=*lib dir path* -numa node,memdev=mem Will be added to the qemu commandline
If access is shared then the "share=on" parameter will be added to the memory-backend-file e.g. -object memory-backend-file,id=mem,size=1024M,mem-path=/var/lib/libvirt/qemu,share=on
The access mode can be overriden by specifying token memAccess in numa cell. The mem-path can be defined by new config parameter memory_backing_dir.
PS: the sometime failing test qemuhotplug was failing also before this patch :)
Jaroslav Safka (4): qemu,conf: Rename virNumaMemAccess to virDomainMemoryAccess qemu_conf: Add param memory_backing_dir conf: Add new xml elements for file memorybacking support qemu: Add args generation for file memory backing
docs/formatdomain.html.in | 9 ++ docs/schemas/domaincommon.rng | 30 +++++ src/conf/domain_conf.c | 133 ++++++++++++++++----- src/conf/domain_conf.h | 22 ++++ src/conf/numa_conf.c | 15 +-- src/conf/numa_conf.h | 14 +-- src/qemu/libvirtd_qemu.aug | 3 + src/qemu/qemu.conf | 4 + src/qemu/qemu_command.c | 55 ++++++--- src/qemu/qemu_conf.c | 9 ++ src/qemu/qemu_conf.h | 2 + src/qemu/qemu_process.c | 2 +- src/qemu/test_libvirtd_qemu.aug.in | 1 + .../qemuxml2argv-fd-memory-no-numa-topology.args | 21 ++++ .../qemuxml2argv-fd-memory-no-numa-topology.xml | 27 +++++ .../qemuxml2argv-fd-memory-numa-topology.args | 24 ++++ .../qemuxml2argv-fd-memory-numa-topology.xml | 30 +++++ .../qemuxml2argv-fd-memory-numa-topology2.args | 27 +++++ .../qemuxml2argv-fd-memory-numa-topology2.xml | 31 +++++ .../qemuxml2argv-fd-memory-numa-topology3.args | 30 +++++ .../qemuxml2argv-fd-memory-numa-topology3.xml | 32 +++++ .../qemuxml2argv-memorybacking-set.xml | 24 ++++ .../qemuxml2argv-memorybacking-unset.xml | 24 ++++ tests/qemuxml2argvtest.c | 13 ++ .../qemuxml2xmlout-memorybacking-set.xml | 32 +++++ .../qemuxml2xmlout-memorybacking-unset.xml | 32 +++++ tests/qemuxml2xmltest.c | 3 + 27 files changed, 584 insertions(+), 65 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-no-numa-topology.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-no-numa-topology.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology2.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology2.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology3.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology3.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-memorybacking-set.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-memorybacking-unset.xml create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-memorybacking-set.xml create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-memorybacking-unset.xml
Looking good. ACK to all of them. However, please send a patch (as a reply to this cover letter) that updates docs/news.xml. Only after that it is possible to push these. Michal

Thanks :) Will be this diff ok? diff --git a/docs/news.xml b/docs/news.xml index f408293..d01ce08 100644 --- a/docs/news.xml +++ b/docs/news.xml @@ -23,6 +23,16 @@ built-in replication and disaster recovery. </description> </change> + <change> + <summary> + qemu: Add support for memory backing with file source + </summary> + <description> + Add support in numa topology for file source inside memory backing (hugepages are not needed) + Three new elements "source","access" and "allocation" were added to "memoryBacking" element. + Also new configuration parameter "memory_backing_dir" was added. + </description> + </change> </section> <section title="Improvements"> <change>
-----Original Message----- From: Michal Privoznik [mailto:mprivozn@redhat.com] Sent: Thursday, February 09, 2017 9:58 AM To: Safka, JaroslavX <jaroslavx.safka@intel.com>; libvir-list@redhat.com Cc: Mooney, Sean K <sean.k.mooney@intel.com>; Ptacek, MichalX <michalx.ptacek@intel.com> Subject: Re: [libvirt] [PATCHv5 0/4] Add support for memory backing with file source
On 02/02/2017 02:27 PM, Jaroslav Safka wrote:
Hi, we would like to introduce 3 new elements source,access and allocation in memoryBacking element. For now it was made for numa topology.
<memoryBacking> <source type="file|anonymous"/> <access mode="shared|private"/> <allocation mode="immediate|ondemand"/> </memoryBacking>
If allocation is immediate then -mem-prealloc should be added to the qemu commanline. If source is file then -object memory-backend-file,id=mem,size=1024M,mem-path=*lib dir path* -numa node,memdev=mem Will be added to the qemu commandline
If access is shared then the "share=on" parameter will be added to the memory-backend-file e.g. -object memory-backend-file,id=mem,size=1024M,mem-path=/var/lib/libvirt/qemu,s hare=on
The access mode can be overriden by specifying token memAccess in numa cell. The mem-path can be defined by new config parameter memory_backing_dir.
PS: the sometime failing test qemuhotplug was failing also before this patch :)
Jaroslav Safka (4): qemu,conf: Rename virNumaMemAccess to virDomainMemoryAccess qemu_conf: Add param memory_backing_dir conf: Add new xml elements for file memorybacking support qemu: Add args generation for file memory backing
docs/formatdomain.html.in | 9 ++ docs/schemas/domaincommon.rng | 30 +++++ src/conf/domain_conf.c | 133 ++++++++++++++++----- src/conf/domain_conf.h | 22 ++++ src/conf/numa_conf.c | 15 +-- src/conf/numa_conf.h | 14 +-- src/qemu/libvirtd_qemu.aug | 3 + src/qemu/qemu.conf | 4 + src/qemu/qemu_command.c | 55 ++++++--- src/qemu/qemu_conf.c | 9 ++ src/qemu/qemu_conf.h | 2 + src/qemu/qemu_process.c | 2 +- src/qemu/test_libvirtd_qemu.aug.in | 1 + .../qemuxml2argv-fd-memory-no-numa-topology.args | 21 ++++ .../qemuxml2argv-fd-memory-no-numa-topology.xml | 27 +++++ .../qemuxml2argv-fd-memory-numa-topology.args | 24 ++++ .../qemuxml2argv-fd-memory-numa-topology.xml | 30 +++++ .../qemuxml2argv-fd-memory-numa-topology2.args | 27 +++++ .../qemuxml2argv-fd-memory-numa-topology2.xml | 31 +++++ .../qemuxml2argv-fd-memory-numa-topology3.args | 30 +++++ .../qemuxml2argv-fd-memory-numa-topology3.xml | 32 +++++ .../qemuxml2argv-memorybacking-set.xml | 24 ++++ .../qemuxml2argv-memorybacking-unset.xml | 24 ++++ tests/qemuxml2argvtest.c | 13 ++ .../qemuxml2xmlout-memorybacking-set.xml | 32 +++++ .../qemuxml2xmlout-memorybacking-unset.xml | 32 +++++ tests/qemuxml2xmltest.c | 3 + 27 files changed, 584 insertions(+), 65 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-no-numa-topology.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-no-numa-topology.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology2.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology2.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology3.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology3.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-memorybacking-set.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-memorybacking-unset.xml create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-memorybacking-set.xml create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-memorybacking-unset.xml
Looking good. ACK to all of them. However, please send a patch (as a reply to this cover letter) that updates docs/news.xml. Only after that it is possible to push these.
Michal
Intel Research and Development Ireland Limited Registered in Ireland Registered Office: Collinstown Industrial Park, Leixlip, County Kildare Registered Number: 308263 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.

On 02/09/2017 10:34 AM, Safka, JaroslavX wrote:
Thanks :) Will be this diff ok?
diff --git a/docs/news.xml b/docs/news.xml index f408293..d01ce08 100644 --- a/docs/news.xml +++ b/docs/news.xml @@ -23,6 +23,16 @@ built-in replication and disaster recovery. </description> </change> + <change> + <summary> + qemu: Add support for memory backing with file source + </summary> + <description> + Add support in numa topology for file source inside memory backing (hugepages are not needed) + Three new elements "source","access" and "allocation" were added to "memoryBacking" element. + Also new configuration parameter "memory_backing_dir" was added. + </description> + </change> </section>
I've tweaked it a little bit, ACKed and pushed. Congratulations on your first libvirt contribution! Michal
participants (3)
-
Jaroslav Safka
-
Michal Privoznik
-
Safka, JaroslavX