qemu: Add support for memory pre-allocation

Add support for pre-allocating all of the RAM.
This increases the memory footprint of QEMU and should be used
only when needed.

Signed-off-by: Manohar Castelino <manohar.r.castelino@intel.com>
This commit is contained in:
Manohar Castelino 2017-09-12 15:45:16 -07:00
parent 1fbe6c5d1d
commit 4ecb9de5b3
2 changed files with 19 additions and 0 deletions

17
qemu.go
View File

@ -741,6 +741,9 @@ type Knobs struct {
// Daemonize will turn the qemu process into a daemon // Daemonize will turn the qemu process into a daemon
Daemonize bool Daemonize bool
// MemPrealloc will allocate all the RAM upfront
MemPrealloc bool
} }
// Config is the qemu configuration structure. // Config is the qemu configuration structure.
@ -988,6 +991,20 @@ func (config *Config) appendKnobs() {
if config.Knobs.Daemonize == true { if config.Knobs.Daemonize == true {
config.qemuParams = append(config.qemuParams, "-daemonize") config.qemuParams = append(config.qemuParams, "-daemonize")
} }
if config.Knobs.MemPrealloc == true {
if config.Memory.Size != "" {
dimmName := "dimm1"
objMemParam := "memory-backend-ram,id=" + dimmName + ",size=" + config.Memory.Size + ",prealloc=on"
deviceMemParam := "pc-dimm,id=" + dimmName + ",memdev=" + dimmName
config.qemuParams = append(config.qemuParams, "-object")
config.qemuParams = append(config.qemuParams, objMemParam)
config.qemuParams = append(config.qemuParams, "-device")
config.qemuParams = append(config.qemuParams, deviceMemParam)
}
}
} }
// LaunchQemu can be used to launch a new qemu instance. // LaunchQemu can be used to launch a new qemu instance.

View File

@ -231,6 +231,7 @@ func TestAppendKnobsAllTrue(t *testing.T) {
NoDefaults: true, NoDefaults: true,
NoGraphic: true, NoGraphic: true,
Daemonize: true, Daemonize: true,
MemPrealloc: true,
} }
testAppend(knobs, knobsString, t) testAppend(knobs, knobsString, t)
@ -241,6 +242,7 @@ func TestAppendKnobsAllFalse(t *testing.T) {
NoUserConfig: false, NoUserConfig: false,
NoDefaults: false, NoDefaults: false,
NoGraphic: false, NoGraphic: false,
MemPrealloc: false,
} }
testAppend(knobs, "", t) testAppend(knobs, "", t)