From 406f13059054369de5247f16431463869395a470 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 5 Jun 2024 16:57:49 -0400 Subject: [PATCH] machine/linux: Use memory-backend-memfd by default This is prep for using virtiofsd; it has no real impact otherwise. Signed-off-by: Colin Walters --- pkg/machine/qemu/command/command.go | 6 ++++-- pkg/machine/qemu/options_linux_amd64.go | 1 + pkg/machine/qemu/options_linux_arm64.go | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/machine/qemu/command/command.go b/pkg/machine/qemu/command/command.go index 1062ce2ee1dc..2102a79ab21f 100644 --- a/pkg/machine/qemu/command/command.go +++ b/pkg/machine/qemu/command/command.go @@ -35,8 +35,10 @@ func NewQemuBuilder(binary string, options []string) QemuCmd { // SetMemory adds the specified amount of memory for the machine func (q *QemuCmd) SetMemory(m strongunits.MiB) { - // qemu accepts the memory in MiB - *q = append(*q, "-m", strconv.FormatUint(uint64(m), 10)) + serializedMem := strconv.FormatUint(uint64(m), 10) + // In order to use virtiofsd, we must enable shared memory + *q = append(*q, "-object", fmt.Sprintf("memory-backend-memfd,id=mem,size=%sM,share=on", serializedMem)) + *q = append(*q, "-m", serializedMem) } // SetCPUs adds the number of CPUs the machine will have diff --git a/pkg/machine/qemu/options_linux_amd64.go b/pkg/machine/qemu/options_linux_amd64.go index 9e8c680ab0ca..67b6c61fee25 100644 --- a/pkg/machine/qemu/options_linux_amd64.go +++ b/pkg/machine/qemu/options_linux_amd64.go @@ -10,6 +10,7 @@ func (q *QEMUStubber) addArchOptions(_ *setNewMachineCMDOpts) []string { opts := []string{ "-accel", "kvm", "-cpu", "host", + "-M", "memory-backend=mem", } return opts } diff --git a/pkg/machine/qemu/options_linux_arm64.go b/pkg/machine/qemu/options_linux_arm64.go index 7cfdae08e677..09be86a62db3 100644 --- a/pkg/machine/qemu/options_linux_arm64.go +++ b/pkg/machine/qemu/options_linux_arm64.go @@ -16,7 +16,7 @@ func (q *QEMUStubber) addArchOptions(_ *setNewMachineCMDOpts) []string { opts := []string{ "-accel", "kvm", "-cpu", "host", - "-M", "virt,gic-version=max", + "-M", "virt,gic-version=max,memory-backend=mem", "-bios", getQemuUefiFile("QEMU_EFI.fd"), } return opts