From 4ecb9de5b33be61e0c77d0142a94171fde0db8ea Mon Sep 17 00:00:00 2001 From: Manohar Castelino Date: Tue, 12 Sep 2017 15:45:16 -0700 Subject: [PATCH] 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 --- qemu.go | 17 +++++++++++++++++ qemu_test.go | 2 ++ 2 files changed, 19 insertions(+) diff --git a/qemu.go b/qemu.go index 710a573fd..e6ace3f94 100644 --- a/qemu.go +++ b/qemu.go @@ -741,6 +741,9 @@ type Knobs struct { // Daemonize will turn the qemu process into a daemon Daemonize bool + + // MemPrealloc will allocate all the RAM upfront + MemPrealloc bool } // Config is the qemu configuration structure. @@ -988,6 +991,20 @@ func (config *Config) appendKnobs() { if config.Knobs.Daemonize == true { 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. diff --git a/qemu_test.go b/qemu_test.go index ea3ddc68a..ae9d31d9a 100644 --- a/qemu_test.go +++ b/qemu_test.go @@ -231,6 +231,7 @@ func TestAppendKnobsAllTrue(t *testing.T) { NoDefaults: true, NoGraphic: true, Daemonize: true, + MemPrealloc: true, } testAppend(knobs, knobsString, t) @@ -241,6 +242,7 @@ func TestAppendKnobsAllFalse(t *testing.T) { NoUserConfig: false, NoDefaults: false, NoGraphic: false, + MemPrealloc: false, } testAppend(knobs, "", t)