From: Ján Tomko <jtomko(a)redhat.com>
For any vhost-user device to work, the memory needs to be marked as
shared.
What we recommend to users (e.g. in the virtiofs quide [0]) is:
<memoryBacking>
<source type='memfd'/>
<access mode='shared'/>
</memoryBacking>
Technically, only the access mode is needed:
<memoryBacking>
<access mode='shared'/>
</memoryBacking>
But this results in libvirt assuming the file backend.
Switch this case to use memfd which should offer better performance,
and less disk usage, at the cost of eating unswappable RAM.
The latter is a pretty significant cost, that I think has a non-trivial
risk of creating deployment regressions for apps.
It is not uncommon for mgmt apps to over-commit RAM, and if we're
switching to a backend that's unswappable, this over-commit will
now be more likely trigger the OOM killer. I don't think we can
take that risk with a change like this.
Any app that supports virtiofs will long have known the need to
add memfd, so I don't think we win much by changing the default
for that use case.
[0]
https://libvirt.org/kbase/virtiofs.html
Signed-off-by: Ján Tomko <jtomko(a)redhat.com>
---
src/qemu/qemu_command.c | 9 +++++++--
tests/qemuxmlconfdata/disk-vhostvdpa.x86_64-latest.args | 2 +-
.../net-vhostuser-multiq.x86_64-latest.args | 2 +-
.../net-vhostuser-passt.x86_64-latest.args | 2 +-
tests/qemuxmlconfdata/net-vhostuser.x86_64-latest.args | 2 +-
.../schema-reorder-domain-subelements.x86_64-latest.args | 2 +-
.../qemuxmlconfdata/vhost-user-fs-ccw.s390x-latest.args | 2 +-
7 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 7658cc4d39..ca9d4d6609 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3417,8 +3417,13 @@ qemuBuildMemoryBackendProps(virJSONValue **backendProps,
if (!priv->memPrealloc)
prealloc = true;
- } else if (!nvdimmPath &&
- def->mem.source == VIR_DOMAIN_MEMORY_SOURCE_MEMFD) {
+ } else if ((!nvdimmPath &&
+ def->mem.source == VIR_DOMAIN_MEMORY_SOURCE_MEMFD) ||
+ (systemMemory &&
+ memAccess &&
+ !useHugepage &&
+ def->mem.source == VIR_DOMAIN_MEMORY_SOURCE_NONE &&
+ virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_OBJECT_MEMORY_MEMFD))) {
backendType = "memory-backend-memfd";
if (useHugepage &&
diff --git a/tests/qemuxmlconfdata/disk-vhostvdpa.x86_64-latest.args
b/tests/qemuxmlconfdata/disk-vhostvdpa.x86_64-latest.args
index 93d2ef0d98..04732df68a 100644
--- a/tests/qemuxmlconfdata/disk-vhostvdpa.x86_64-latest.args
+++ b/tests/qemuxmlconfdata/disk-vhostvdpa.x86_64-latest.args
@@ -14,7 +14,7 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \
-accel tcg \
-cpu qemu64 \
-m size=219136k \
--object
'{"qom-type":"memory-backend-file","id":"pc.ram","mem-path":"/var/lib/libvirt/qemu/ram/-1-QEMUGuest1/pc.ram","share":true,"x-use-canonical-path-for-ramblock-id":false,"size":224395264}'
\
+-object
'{"qom-type":"memory-backend-memfd","id":"pc.ram","share":true,"x-use-canonical-path-for-ramblock-id":false,"size":224395264}'
\
-overcommit mem-lock=off \
-smp 1,sockets=1,cores=1,threads=1 \
-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
diff --git a/tests/qemuxmlconfdata/net-vhostuser-multiq.x86_64-latest.args
b/tests/qemuxmlconfdata/net-vhostuser-multiq.x86_64-latest.args
index 4ea3d4eebd..ac5c8b7652 100644
--- a/tests/qemuxmlconfdata/net-vhostuser-multiq.x86_64-latest.args
+++ b/tests/qemuxmlconfdata/net-vhostuser-multiq.x86_64-latest.args
@@ -14,7 +14,7 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \
-accel tcg \
-cpu qemu64 \
-m size=219136k \
--object
'{"qom-type":"memory-backend-file","id":"pc.ram","mem-path":"/var/lib/libvirt/qemu/ram/-1-QEMUGuest1/pc.ram","share":true,"x-use-canonical-path-for-ramblock-id":false,"size":224395264}'
\
+-object
'{"qom-type":"memory-backend-memfd","id":"pc.ram","share":true,"x-use-canonical-path-for-ramblock-id":false,"size":224395264}'
\
-overcommit mem-lock=off \
-smp 1,sockets=1,cores=1,threads=1 \
-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
diff --git a/tests/qemuxmlconfdata/net-vhostuser-passt.x86_64-latest.args
b/tests/qemuxmlconfdata/net-vhostuser-passt.x86_64-latest.args
index afbbe188cf..ee395deffe 100644
--- a/tests/qemuxmlconfdata/net-vhostuser-passt.x86_64-latest.args
+++ b/tests/qemuxmlconfdata/net-vhostuser-passt.x86_64-latest.args
@@ -14,7 +14,7 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \
-accel tcg \
-cpu qemu64 \
-m size=219136k \
--object
'{"qom-type":"memory-backend-file","id":"pc.ram","mem-path":"/var/lib/libvirt/qemu/ram/-1-QEMUGuest1/pc.ram","share":true,"x-use-canonical-path-for-ramblock-id":false,"size":224395264}'
\
+-object
'{"qom-type":"memory-backend-memfd","id":"pc.ram","share":true,"x-use-canonical-path-for-ramblock-id":false,"size":224395264}'
\
-overcommit mem-lock=off \
-smp 1,sockets=1,cores=1,threads=1 \
-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
diff --git a/tests/qemuxmlconfdata/net-vhostuser.x86_64-latest.args
b/tests/qemuxmlconfdata/net-vhostuser.x86_64-latest.args
index f5925c77fe..74454d3d24 100644
--- a/tests/qemuxmlconfdata/net-vhostuser.x86_64-latest.args
+++ b/tests/qemuxmlconfdata/net-vhostuser.x86_64-latest.args
@@ -14,7 +14,7 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \
-accel tcg \
-cpu qemu64 \
-m size=219136k \
--object
'{"qom-type":"memory-backend-file","id":"pc.ram","mem-path":"/var/lib/libvirt/qemu/ram/-1-QEMUGuest1/pc.ram","share":true,"x-use-canonical-path-for-ramblock-id":false,"size":224395264}'
\
+-object
'{"qom-type":"memory-backend-memfd","id":"pc.ram","share":true,"x-use-canonical-path-for-ramblock-id":false,"size":224395264}'
\
-overcommit mem-lock=off \
-smp 1,sockets=1,cores=1,threads=1 \
-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
diff --git a/tests/qemuxmlconfdata/schema-reorder-domain-subelements.x86_64-latest.args
b/tests/qemuxmlconfdata/schema-reorder-domain-subelements.x86_64-latest.args
index 76df9c30b0..5fb594df87 100644
--- a/tests/qemuxmlconfdata/schema-reorder-domain-subelements.x86_64-latest.args
+++ b/tests/qemuxmlconfdata/schema-reorder-domain-subelements.x86_64-latest.args
@@ -14,7 +14,7 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-passtvhostuu/.config \
-accel kvm \
-cpu qemu64 \
-m size=16777216k \
--object
'{"qom-type":"memory-backend-file","id":"pc.ram","mem-path":"/var/lib/libvirt/qemu/ram/-1-passtvhostuu/pc.ram","share":true,"x-use-canonical-path-for-ramblock-id":false,"size":17179869184}'
\
+-object
'{"qom-type":"memory-backend-memfd","id":"pc.ram","share":true,"x-use-canonical-path-for-ramblock-id":false,"size":17179869184}'
\
-overcommit mem-lock=off \
-smp 16,sockets=16,cores=1,threads=1 \
-uuid d79698e0-46b2-4459-87ee-7c762990dd6e \
diff --git a/tests/qemuxmlconfdata/vhost-user-fs-ccw.s390x-latest.args
b/tests/qemuxmlconfdata/vhost-user-fs-ccw.s390x-latest.args
index 72ca38c305..eed9af8bb1 100644
--- a/tests/qemuxmlconfdata/vhost-user-fs-ccw.s390x-latest.args
+++ b/tests/qemuxmlconfdata/vhost-user-fs-ccw.s390x-latest.args
@@ -14,7 +14,7 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \
-accel tcg \
-cpu qemu \
-m size=219136k \
--object
'{"qom-type":"memory-backend-file","id":"s390.ram","mem-path":"/var/lib/libvirt/qemu/ram/-1-QEMUGuest1/s390.ram","share":true,"x-use-canonical-path-for-ramblock-id":false,"size":224395264}'
\
+-object
'{"qom-type":"memory-backend-memfd","id":"s390.ram","share":true,"x-use-canonical-path-for-ramblock-id":false,"size":224395264}'
\
-overcommit mem-lock=off \
-smp 1,sockets=1,cores=1,threads=1 \
-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
--
2.50.0