Skip to content

Commit

Permalink
machine/linux: Use memory-backend-memfd by default
Browse files Browse the repository at this point in the history
This is prep for using virtiofsd; it has no real
impact otherwise.

Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters committed Jun 7, 2024
1 parent 0e57573 commit 406f130
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions pkg/machine/qemu/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/machine/qemu/options_linux_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ func (q *QEMUStubber) addArchOptions(_ *setNewMachineCMDOpts) []string {
opts := []string{
"-accel", "kvm",
"-cpu", "host",
"-M", "memory-backend=mem",
}
return opts
}
2 changes: 1 addition & 1 deletion pkg/machine/qemu/options_linux_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 406f130

Please sign in to comment.