From 0c206170c43deda44ba51156e74aeb0237c942b3 Mon Sep 17 00:00:00 2001 From: Manohar Castelino Date: Fri, 15 Sep 2017 09:44:23 -0700 Subject: [PATCH] Knobs: Modify the behaviour of the Mlock knob. The Mlock knob is unfortunately tied to realtime. Allow Mlock knob to implicitly enable realtime to get the desired swapping behavior when swapping is desired. Note: Realtime as implemented today can only be used to enable swap, and as such does not really control realtime behaviour. The knob is redundant but retained here just to ensure that when more capabilities are added in future QEMU iterations we can take advantage of the same. Signed-off-by: Manohar Castelino --- qemu.go | 11 +++++++++++ qemu_test.go | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) 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"