Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 3f1fc92

Browse files
committed
QemuContext.arguments: X86_64 use host ram size as maxmem
Signed-off-by: Hui Zhu <[email protected]>
1 parent e3640af commit 3f1fc92

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

hypervisor/qemu/qemu_amd64.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import (
66
"fmt"
77
"os"
88
"runtime"
9+
"syscall"
910

1011
"github.com/golang/glog"
12+
"github.com/hyperhq/hypercontainer-utils/hlog"
1113
"github.com/hyperhq/runv/hypervisor"
1214
)
1315

@@ -28,14 +30,22 @@ func (qc *QemuContext) arguments(ctx *hypervisor.VmContext) []string {
2830
boot := ctx.Boot
2931
qc.cpus = boot.CPU
3032

33+
maxmem := hypervisor.DefaultMaxMem
34+
var sysInfo syscall.Sysinfo_t
35+
err := syscall.Sysinfo(&sysInfo)
36+
if err == nil {
37+
maxmem = int(sysInfo.Totalram / 1024 / 1024)
38+
} else {
39+
ctx.Log(hlog.DEBUG, "syscall.Sysinfo got error %v, use hypervisor.DefaultMaxMem", err)
40+
}
3141
maxcpus := runtime.NumCPU()
3242
if maxcpus > X86_64_CONFIG_NR_CPUS {
3343
maxcpus = X86_64_CONFIG_NR_CPUS
3444
}
3545

3646
var machineClass, memParams, cpuParams string
3747
machineClass = "pc-i440fx-2.1"
38-
memParams = fmt.Sprintf("size=%d,slots=1,maxmem=%dM", boot.Memory, hypervisor.DefaultMaxMem) // TODO set maxmem to the total memory of the system
48+
memParams = fmt.Sprintf("size=%d,slots=1,maxmem=%dM", boot.Memory, maxmem)
3949
cpuParams = fmt.Sprintf("cpus=%d,maxcpus=%d", boot.CPU, maxcpus)
4050

4151
cmdline := "console=ttyS0 panic=1 no_timer_check iommu=off"

0 commit comments

Comments
 (0)