diff --git a/qemu.go b/qemu.go index 66bf21ebc..364f291be 100644 --- a/qemu.go +++ b/qemu.go @@ -768,6 +768,16 @@ type Knobs struct { // Daemonize will turn the qemu process into a daemon Daemonize bool + // Both HugePages and MemPrealloc require the Memory.Size of the VM + // to be set, as they need to reserve the memory upfront in order + // for the VM to boot without errors. + // + // HugePages always results in memory pre-allocation. + // However the setup is different from normal pre-allocation. + // Hence HugePages has precedence over MemPrealloc + // HugePages will pre-allocate all the RAM from huge pages + HugePages bool + // MemPrealloc will allocate all the RAM upfront MemPrealloc bool @@ -1025,7 +1035,19 @@ func (config *Config) appendKnobs() { config.qemuParams = append(config.qemuParams, "-daemonize") } - if config.Knobs.MemPrealloc == true { + if config.Knobs.HugePages == true { + if config.Memory.Size != "" { + dimmName := "dimm1" + objMemParam := "memory-backend-file,id=" + dimmName + ",size=" + config.Memory.Size + ",mem-path=/dev/hugepages,share=on,prealloc=on" + numaMemParam := "node,memdev=" + dimmName + + config.qemuParams = append(config.qemuParams, "-object") + config.qemuParams = append(config.qemuParams, objMemParam) + + config.qemuParams = append(config.qemuParams, "-numa") + config.qemuParams = append(config.qemuParams, numaMemParam) + } + } else if config.Knobs.MemPrealloc == true { if config.Memory.Size != "" { dimmName := "dimm1" objMemParam := "memory-backend-ram,id=" + dimmName + ",size=" + config.Memory.Size + ",prealloc=on"