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 <walters@verbum.org>
This commit is contained in:
Colin Walters 2024-06-05 16:57:49 -04:00
parent 0e57573d1e
commit 406f130590
3 changed files with 6 additions and 3 deletions

View File

@ -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

View File

@ -10,6 +10,7 @@ func (q *QEMUStubber) addArchOptions(_ *setNewMachineCMDOpts) []string {
opts := []string{
"-accel", "kvm",
"-cpu", "host",
"-M", "memory-backend=mem",
}
return opts
}

View File

@ -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