]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: Introduce memory allocation threads
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 21 Mar 2022 15:49:25 +0000 (16:49 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 24 Mar 2022 14:45:41 +0000 (15:45 +0100)
Since its v5.0.0 release QEMU is capable of specifying number of
threads used to allocate memory. It defaults to 1, which may be
too low for humongous guests with gigantic pages.

In general, on QEMU cmd line level it is possible to use
different number of threads per each memory-backend-* object, in
practical terms it's not useful. Therefore, use <memoryBacking/>
to set guest wide value and let all memory devices 'inherit' it,
silently. IOW, don't introduce per device knob because that would
only complicate things for a little or no benefit.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
docs/formatdomain.rst
src/conf/domain_conf.c
src/conf/domain_conf.h
src/conf/schemas/domaincommon.rng
tests/qemuxml2argvdata/memfd-memory-numa.xml

index d188de4858e78fe876ec6f72b27766bf8bc7bc8e..e4925320047fe6a7b6ebf0c2b572f74cfffda659 100644 (file)
@@ -1004,7 +1004,7 @@ Memory Backing
        <locked/>
        <source type="file|anonymous|memfd"/>
        <access mode="shared|private"/>
-       <allocation mode="immediate|ondemand"/>
+       <allocation mode="immediate|ondemand" threads='8'/>
        <discard/>
      </memoryBacking>
      ...
@@ -1053,8 +1053,10 @@ influence how virtual memory pages are backed by host pages.
    Using the ``mode`` attribute, specify if the memory is to be "shared" or
    "private". This can be overridden per numa node by ``memAccess``.
 ``allocation``
-   Using the ``mode`` attribute, specify when to allocate the memory by
-   supplying either "immediate" or "ondemand".
+   Using the optional ``mode`` attribute, specify when to allocate the memory by
+   supplying either "immediate" or "ondemand". :since:`Since 8.2.0` it is
+   possible to set the number of threads that hypervisor uses to allocate
+   memory via ``threads`` attribute.
 ``discard``
    When set and supported by hypervisor the memory content is discarded just
    before guest shuts down (or when DIMM module is unplugged). Please note that
index 153954a0b0f183a9325b18b1575164b67638e766..731139f80fcbc135670d806606e53cdba2914447 100644 (file)
@@ -18915,6 +18915,13 @@ virDomainDefParseMemory(virDomainDef *def,
         VIR_FREE(tmp);
     }
 
+    if (virXPathUInt("string(./memoryBacking/allocation/@threads)",
+                     ctxt, &def->mem.allocation_threads) == -2) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("Failed to parse memory allocation threads"));
+        return -1;
+    }
+
     if (virXPathNode("./memoryBacking/hugepages", ctxt)) {
         /* hugepages will be used */
         if ((n = virXPathNodeSet("./memoryBacking/hugepages/page", ctxt, &nodes)) < 0) {
@@ -27465,6 +27472,7 @@ virDomainMemorybackingFormat(virBuffer *buf,
                              const virDomainMemtune *mem)
 {
     g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
+    g_auto(virBuffer) allocAttrBuf = VIR_BUFFER_INITIALIZER;
 
     if (mem->nhugepages)
         virDomainHugepagesFormat(&childBuf, mem->hugepages, mem->nhugepages);
@@ -27479,8 +27487,13 @@ virDomainMemorybackingFormat(virBuffer *buf,
         virBufferAsprintf(&childBuf, "<access mode='%s'/>\n",
                           virDomainMemoryAccessTypeToString(mem->access));
     if (mem->allocation)
-        virBufferAsprintf(&childBuf, "<allocation mode='%s'/>\n",
+        virBufferAsprintf(&allocAttrBuf, " mode='%s'",
                           virDomainMemoryAllocationTypeToString(mem->allocation));
+    if (mem->allocation_threads > 0)
+        virBufferAsprintf(&allocAttrBuf, " threads='%u'", mem->allocation_threads);
+
+    virXMLFormatElement(&childBuf, "allocation", &allocAttrBuf, NULL);
+
     if (mem->discard)
         virBufferAddLit(&childBuf, "<discard/>\n");
 
index b69abfa270b7c781716f5d29f50aebe932ce5127..49c964e6e1c0f5e62cde8e1d5222fb4663fb8137 100644 (file)
@@ -2702,6 +2702,7 @@ struct _virDomainMemtune {
     int source; /* enum virDomainMemorySource */
     int access; /* enum virDomainMemoryAccess */
     int allocation; /* enum virDomainMemoryAllocation */
+    unsigned int allocation_threads;
 
     virTristateBool discard;
 };
index 9c1b64a6447b7c024565196a18e91054a27ffd8c..34bccee2f52d61cd5b8d8a7f863166041ce8356e 100644 (file)
             </optional>
             <optional>
               <element name="allocation">
-                <attribute name="mode">
-                  <choice>
-                    <value>immediate</value>
-                    <value>ondemand</value>
-                  </choice>
-                </attribute>
+                <optional>
+                  <attribute name="mode">
+                    <choice>
+                      <value>immediate</value>
+                      <value>ondemand</value>
+                    </choice>
+                  </attribute>
+                </optional>
+                <optional>
+                  <attribute name="threads">
+                    <ref name="unsignedInt"/>
+                  </attribute>
+                </optional>
               </element>
             </optional>
             <optional>
index 1ebcee8939f9bce61c1aefb7799f20a29ddc3ebc..1ac87e3aef4c84d8a2038365dae5ec64ac18dabb 100644 (file)
@@ -10,7 +10,7 @@
     </hugepages>
     <source type='memfd'/>
     <access mode='shared'/>
-    <allocation mode='immediate'/>
+    <allocation mode='immediate' threads='8'/>
   </memoryBacking>
   <vcpu placement='static'>8</vcpu>
   <numatune>