diff --git a/qemu.go b/qemu.go index 21868ac232..3bd79284b7 100644 --- a/qemu.go +++ b/qemu.go @@ -1015,11 +1015,22 @@ func (config *Config) appendKnobs() { if config.Knobs.Realtime == true { config.qemuParams = append(config.qemuParams, "-realtime") + // This path is redundant as the default behaviour is locked memory + // Realtime today does not control any other feature even though + // other features may be added in the future + // https://lists.gnu.org/archive/html/qemu-devel/2012-12/msg03330.html if config.Knobs.Mlock == true { config.qemuParams = append(config.qemuParams, "mlock=on") } else { config.qemuParams = append(config.qemuParams, "mlock=off") } + } else { + // In order to turn mlock off we need the -realtime option as well + if config.Knobs.Mlock == false { + //Enable realtime anyway just to get the right swapping behaviour + config.qemuParams = append(config.qemuParams, "-realtime") + config.qemuParams = append(config.qemuParams, "mlock=off") + } } } diff --git a/qemu_test.go b/qemu_test.go index 317d2a0488..09ed2a92e2 100644 --- a/qemu_test.go +++ b/qemu_test.go @@ -223,9 +223,8 @@ func TestAppendEmptyDevice(t *testing.T) { testAppend(device, "", t) } -var knobsString = "-no-user-config -nodefaults -nographic -daemonize -realtime mlock=on" - func TestAppendKnobsAllTrue(t *testing.T) { + var knobsString = "-no-user-config -nodefaults -nographic -daemonize -realtime mlock=on" knobs := Knobs{ NoUserConfig: true, NoDefaults: true, @@ -240,6 +239,7 @@ func TestAppendKnobsAllTrue(t *testing.T) { } func TestAppendKnobsAllFalse(t *testing.T) { + var knobsString = "-realtime mlock=off" knobs := Knobs{ NoUserConfig: false, NoDefaults: false, @@ -249,7 +249,7 @@ func TestAppendKnobsAllFalse(t *testing.T) { Mlock: false, } - testAppend(knobs, "", t) + testAppend(knobs, knobsString, t) } var kernelString = "-kernel /opt/vmlinux.container -append root=/dev/pmem0p1 rootflags=dax,data=ordered,errors=remount-ro rw rootfstype=ext4 tsc=reliable"