diff --git a/qemu/qemu.go b/qemu/qemu.go index 9cfe39cbd1..a1d05a9093 100644 --- a/qemu/qemu.go +++ b/qemu/qemu.go @@ -2528,9 +2528,6 @@ func (config *Config) appendMemoryKnobs() { if config.Memory.Size == "" { return } - if !isDimmSupported(config) { - return - } var objMemParam, numaMemParam string dimmName := "dimm1" if config.Knobs.HugePages { @@ -2553,8 +2550,13 @@ func (config *Config) appendMemoryKnobs() { config.qemuParams = append(config.qemuParams, "-object") config.qemuParams = append(config.qemuParams, objMemParam) - config.qemuParams = append(config.qemuParams, "-numa") - config.qemuParams = append(config.qemuParams, numaMemParam) + if isDimmSupported(config) { + config.qemuParams = append(config.qemuParams, "-numa") + config.qemuParams = append(config.qemuParams, numaMemParam) + } else { + config.qemuParams = append(config.qemuParams, "-machine") + config.qemuParams = append(config.qemuParams, "memory-backend="+dimmName) + } } func (config *Config) appendKnobs() { diff --git a/qemu/qemu_test.go b/qemu/qemu_test.go index 5555ef1a7e..69caa1c207 100644 --- a/qemu/qemu_test.go +++ b/qemu/qemu_test.go @@ -542,10 +542,6 @@ func TestAppendKnobsAllFalse(t *testing.T) { } func TestAppendMemoryHugePages(t *testing.T) { - if !isDimmSupported(nil) { - t.Skip("Dimm not supported") - } - conf := &Config{ Memory: Memory{ Size: "1G", @@ -563,17 +559,22 @@ func TestAppendMemoryHugePages(t *testing.T) { FileBackedMem: true, MemShared: true, } - knobsString := "-object memory-backend-file,id=dimm1,size=1G,mem-path=/dev/hugepages,share=on,prealloc=on -numa node,memdev=dimm1" + objMemString := "-object memory-backend-file,id=dimm1,size=1G,mem-path=/dev/hugepages,share=on,prealloc=on" + numaMemString := "-numa node,memdev=dimm1" + memBackendString := "-machine memory-backend=dimm1" mlockFalseString := "-realtime mlock=off" + knobsString := objMemString + " " + if isDimmSupported(nil) { + knobsString += numaMemString + } else { + knobsString += memBackendString + } + testConfigAppend(conf, knobs, memString+" "+knobsString+" "+mlockFalseString, t) } func TestAppendMemoryMemPrealloc(t *testing.T) { - if !isDimmSupported(nil) { - t.Skip("Dimm not supported") - } - conf := &Config{ Memory: Memory{ Size: "1G", @@ -589,17 +590,22 @@ func TestAppendMemoryMemPrealloc(t *testing.T) { MemPrealloc: true, MemShared: true, } - knobsString := "-object memory-backend-ram,id=dimm1,size=1G,share=on,prealloc=on -numa node,memdev=dimm1" + objMemString := "-object memory-backend-ram,id=dimm1,size=1G,share=on,prealloc=on" + numaMemString := "-numa node,memdev=dimm1" + memBackendString := "-machine memory-backend=dimm1" mlockFalseString := "-realtime mlock=off" + knobsString := objMemString + " " + if isDimmSupported(nil) { + knobsString += numaMemString + } else { + knobsString += memBackendString + } + testConfigAppend(conf, knobs, memString+" "+knobsString+" "+mlockFalseString, t) } func TestAppendMemoryMemShared(t *testing.T) { - if !isDimmSupported(nil) { - t.Skip("Dimm not supported") - } - conf := &Config{ Memory: Memory{ Size: "1G", @@ -615,17 +621,22 @@ func TestAppendMemoryMemShared(t *testing.T) { FileBackedMem: true, MemShared: true, } - knobsString := "-object memory-backend-file,id=dimm1,size=1G,mem-path=foobar,share=on -numa node,memdev=dimm1" + objMemString := "-object memory-backend-file,id=dimm1,size=1G,mem-path=foobar,share=on" + numaMemString := "-numa node,memdev=dimm1" + memBackendString := "-machine memory-backend=dimm1" mlockFalseString := "-realtime mlock=off" + knobsString := objMemString + " " + if isDimmSupported(nil) { + knobsString += numaMemString + } else { + knobsString += memBackendString + } + testConfigAppend(conf, knobs, memString+" "+knobsString+" "+mlockFalseString, t) } func TestAppendMemoryFileBackedMem(t *testing.T) { - if !isDimmSupported(nil) { - t.Skip("Dimm not supported") - } - conf := &Config{ Memory: Memory{ Size: "1G", @@ -641,17 +652,22 @@ func TestAppendMemoryFileBackedMem(t *testing.T) { FileBackedMem: true, MemShared: false, } - knobsString := "-object memory-backend-file,id=dimm1,size=1G,mem-path=foobar -numa node,memdev=dimm1" + objMemString := "-object memory-backend-file,id=dimm1,size=1G,mem-path=foobar" + numaMemString := "-numa node,memdev=dimm1" + memBackendString := "-machine memory-backend=dimm1" mlockFalseString := "-realtime mlock=off" + knobsString := objMemString + " " + if isDimmSupported(nil) { + knobsString += numaMemString + } else { + knobsString += memBackendString + } + testConfigAppend(conf, knobs, memString+" "+knobsString+" "+mlockFalseString, t) } func TestAppendMemoryFileBackedMemPrealloc(t *testing.T) { - if !isDimmSupported(nil) { - t.Skip("Dimm not supported") - } - conf := &Config{ Memory: Memory{ Size: "1G", @@ -668,9 +684,18 @@ func TestAppendMemoryFileBackedMemPrealloc(t *testing.T) { MemShared: true, MemPrealloc: true, } - knobsString := "-object memory-backend-file,id=dimm1,size=1G,mem-path=foobar,share=on,prealloc=on -numa node,memdev=dimm1" + objMemString := "-object memory-backend-file,id=dimm1,size=1G,mem-path=foobar,share=on,prealloc=on" + numaMemString := "-numa node,memdev=dimm1" + memBackendString := "-machine memory-backend=dimm1" mlockFalseString := "-realtime mlock=off" + knobsString := objMemString + " " + if isDimmSupported(nil) { + knobsString += numaMemString + } else { + knobsString += memBackendString + } + testConfigAppend(conf, knobs, memString+" "+knobsString+" "+mlockFalseString, t) }