]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemuBuildMemoryBackendProps: Get pagesize early
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 29 Mar 2019 15:21:28 +0000 (16:21 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 3 Apr 2019 14:37:19 +0000 (16:37 +0200)
https://bugzilla.redhat.com/show_bug.cgi?id=1693066

Up until memfd introduction (in 24b74d187ca) we did not need to
know @pagesize because qemuGetDomainHupageMemPath() could deal
with it being zero (value of zero means use the default hugetlbfs
mount). But since for memfd we are not passing a path to
hugetlbfs mount rather the page size value we need to know its
value upfront.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_command.c
tests/qemuxml2argvdata/memfd-memory-default-hugepage.x86_64-latest.args [new file with mode: 0644]
tests/qemuxml2argvdata/memfd-memory-default-hugepage.xml [new file with mode: 0644]
tests/qemuxml2argvtest.c
tests/qemuxml2xmloutdata/memfd-memory-default-hugepage.xml [new symlink]
tests/qemuxml2xmltest.c

index 98d67dab2cd9bae430ec7372770f62f7d7c9eef9..029780fe86bb9ebdfe4d011431e1ed7d8db9a900 100644 (file)
@@ -3408,6 +3408,27 @@ qemuBuildMemoryBackendPropsShare(virJSONValuePtr props,
 }
 
 
+static int
+qemuqemuBuildMemoryBackendPropsGetPagesize(virQEMUDriverConfigPtr cfg,
+                                           unsigned long long *pagesize)
+{
+    virHugeTLBFSPtr p;
+
+    if (!cfg->nhugetlbfs) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "%s", _("hugetlbfs filesystem is not mounted "
+                               "or disabled by administrator config"));
+        return -1;
+    }
+
+    if (!(p = virFileGetDefaultHugepage(cfg->hugetlbfs, cfg->nhugetlbfs)))
+        p = &cfg->hugetlbfs[0];
+
+    *pagesize = p->size;
+    return 0;
+}
+
+
 /**
  * qemuBuildMemoryBackendProps:
  * @backendProps: [out] constructed object
@@ -3546,6 +3567,9 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendProps,
         pagesize = 0;
         needHugepage = false;
         useHugepage = false;
+    } else if (pagesize == 0) {
+        if (qemuqemuBuildMemoryBackendPropsGetPagesize(cfg, &pagesize) < 0)
+            goto cleanup;
     }
 
     if (!(props = virJSONValueNewObject()))
diff --git a/tests/qemuxml2argvdata/memfd-memory-default-hugepage.x86_64-latest.args b/tests/qemuxml2argvdata/memfd-memory-default-hugepage.x86_64-latest.args
new file mode 100644 (file)
index 0000000..c582878
--- /dev/null
@@ -0,0 +1,37 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/tmp/lib/domain--1-instance-00000092 \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/tmp/lib/domain--1-instance-00000092/.local/share \
+XDG_CACHE_HOME=/tmp/lib/domain--1-instance-00000092/.cache \
+XDG_CONFIG_HOME=/tmp/lib/domain--1-instance-00000092/.config \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu-system-x86_64 \
+-name guest=instance-00000092,debug-threads=on \
+-S \
+-object secret,id=masterKey0,format=raw,\
+file=/tmp/lib/domain--1-instance-00000092/master-key.aes \
+-machine pc-i440fx-wily,accel=kvm,usb=off,dump-guest-core=off \
+-m 14336 \
+-mem-prealloc \
+-realtime mlock=off \
+-smp 8,sockets=1,cores=8,threads=1 \
+-object memory-backend-memfd,id=ram-node0,hugetlb=yes,hugetlbsize=2097152,\
+share=yes,size=15032385536,host-nodes=3,policy=preferred \
+-numa node,nodeid=0,cpus=0-7,memdev=ram-node0 \
+-uuid 126f2720-6f8e-45ab-a886-ec9277079a67 \
+-display none \
+-no-user-config \
+-nodefaults \
+-chardev socket,id=charmonitor,fd=1729,server,nowait \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-no-acpi \
+-boot strict=on \
+-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 \
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
+resourcecontrol=deny \
+-msg timestamp=on
diff --git a/tests/qemuxml2argvdata/memfd-memory-default-hugepage.xml b/tests/qemuxml2argvdata/memfd-memory-default-hugepage.xml
new file mode 100644 (file)
index 0000000..45ff012
--- /dev/null
@@ -0,0 +1,42 @@
+<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>
+    <hugepages/>
+    <source type='memfd'/>
+    <access mode='shared'/>
+    <allocation mode='immediate'/>
+  </memoryBacking>
+  <vcpu placement='static'>8</vcpu>
+  <numatune>
+    <memnode cellid='0' mode='preferred' nodeset='3'/>
+  </numatune>
+  <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>
+    <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>
index 0c0dcae197c33f7b050f7694a949de80f0b08f3f..ae9b77eee6aed669976621bf8ab64c43fd46f64a 100644 (file)
@@ -3045,6 +3045,7 @@ mymain(void)
             QEMU_CAPS_KVM);
 
     DO_TEST_CAPS_LATEST("memfd-memory-numa");
+    DO_TEST_CAPS_LATEST("memfd-memory-default-hugepage");
 
     DO_TEST("cpu-check-none", QEMU_CAPS_KVM);
     DO_TEST("cpu-check-partial", QEMU_CAPS_KVM);
diff --git a/tests/qemuxml2xmloutdata/memfd-memory-default-hugepage.xml b/tests/qemuxml2xmloutdata/memfd-memory-default-hugepage.xml
new file mode 120000 (symlink)
index 0000000..27d3852
--- /dev/null
@@ -0,0 +1 @@
+../qemuxml2argvdata/memfd-memory-default-hugepage.xml
\ No newline at end of file
index 057483237f509e841021fb7e9d68f544f07d366d..f8f00a18bebffe09f9278c5143157a68e11916ef 100644 (file)
@@ -1171,6 +1171,9 @@ mymain(void)
     DO_TEST("memfd-memory-numa",
             QEMU_CAPS_OBJECT_MEMORY_MEMFD,
             QEMU_CAPS_OBJECT_MEMORY_MEMFD_HUGETLB);
+    DO_TEST("memfd-memory-default-hugepage",
+            QEMU_CAPS_OBJECT_MEMORY_MEMFD,
+            QEMU_CAPS_OBJECT_MEMORY_MEMFD_HUGETLB);
 
     DO_TEST("acpi-table", NONE);