mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-30 12:44:39 +00:00
qemu: add file backed memory device support
It allows a caller to use a local file as the memory backend of the guest, and it also allows the file backed memory device to be set shared or not. Signed-off-by: Peng Tao <bergwolf@gmail.com>
This commit is contained in:
parent
9cf8ce6c6d
commit
283d7df99e
26
qemu/qemu.go
26
qemu/qemu.go
@ -1126,6 +1126,10 @@ type Memory struct {
|
|||||||
// MaxMem is the maximum amount of memory that can be made available
|
// MaxMem is the maximum amount of memory that can be made available
|
||||||
// to the guest through e.g. hot pluggable memory.
|
// to the guest through e.g. hot pluggable memory.
|
||||||
MaxMem string
|
MaxMem string
|
||||||
|
|
||||||
|
// Path is the file path of the memory device. It points to a local
|
||||||
|
// file path used by FileBackedMem.
|
||||||
|
Path string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kernel is the guest kernel configuration structure.
|
// Kernel is the guest kernel configuration structure.
|
||||||
@ -1167,6 +1171,13 @@ type Knobs struct {
|
|||||||
// MemPrealloc will allocate all the RAM upfront
|
// MemPrealloc will allocate all the RAM upfront
|
||||||
MemPrealloc bool
|
MemPrealloc bool
|
||||||
|
|
||||||
|
// FileBackedMem requires Memory.Size and Memory.Path of the VM to
|
||||||
|
// be set.
|
||||||
|
FileBackedMem bool
|
||||||
|
|
||||||
|
// FileBackedMemShared will set the FileBackedMem device as shared.
|
||||||
|
FileBackedMemShared bool
|
||||||
|
|
||||||
// Mlock will control locking of memory
|
// Mlock will control locking of memory
|
||||||
// Only active when Realtime is set to true
|
// Only active when Realtime is set to true
|
||||||
Mlock bool
|
Mlock bool
|
||||||
@ -1474,6 +1485,21 @@ func (config *Config) appendKnobs() {
|
|||||||
config.qemuParams = append(config.qemuParams, "-device")
|
config.qemuParams = append(config.qemuParams, "-device")
|
||||||
config.qemuParams = append(config.qemuParams, deviceMemParam)
|
config.qemuParams = append(config.qemuParams, deviceMemParam)
|
||||||
}
|
}
|
||||||
|
} else if config.Knobs.FileBackedMem == true {
|
||||||
|
if config.Memory.Size != "" && config.Memory.Path != "" {
|
||||||
|
dimmName := "dimm1"
|
||||||
|
objMemParam := "memory-backend-file,id=" + dimmName + ",size=" + config.Memory.Size + ",mem-path=" + config.Memory.Path
|
||||||
|
if config.Knobs.FileBackedMemShared == true {
|
||||||
|
objMemParam += ",share=on"
|
||||||
|
}
|
||||||
|
numaMemParam := "node,memdev=" + dimmName
|
||||||
|
|
||||||
|
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 config.Knobs.Realtime == true {
|
if config.Knobs.Realtime == true {
|
||||||
|
@ -390,13 +390,15 @@ func TestAppendEmptyDevice(t *testing.T) {
|
|||||||
func TestAppendKnobsAllTrue(t *testing.T) {
|
func TestAppendKnobsAllTrue(t *testing.T) {
|
||||||
var knobsString = "-no-user-config -nodefaults -nographic -daemonize -realtime mlock=on"
|
var knobsString = "-no-user-config -nodefaults -nographic -daemonize -realtime mlock=on"
|
||||||
knobs := Knobs{
|
knobs := Knobs{
|
||||||
NoUserConfig: true,
|
NoUserConfig: true,
|
||||||
NoDefaults: true,
|
NoDefaults: true,
|
||||||
NoGraphic: true,
|
NoGraphic: true,
|
||||||
Daemonize: true,
|
Daemonize: true,
|
||||||
MemPrealloc: true,
|
MemPrealloc: true,
|
||||||
Realtime: true,
|
FileBackedMem: true,
|
||||||
Mlock: true,
|
FileBackedMemShared: true,
|
||||||
|
Realtime: true,
|
||||||
|
Mlock: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
testAppend(knobs, knobsString, t)
|
testAppend(knobs, knobsString, t)
|
||||||
@ -405,12 +407,14 @@ func TestAppendKnobsAllTrue(t *testing.T) {
|
|||||||
func TestAppendKnobsAllFalse(t *testing.T) {
|
func TestAppendKnobsAllFalse(t *testing.T) {
|
||||||
var knobsString = "-realtime mlock=off"
|
var knobsString = "-realtime mlock=off"
|
||||||
knobs := Knobs{
|
knobs := Knobs{
|
||||||
NoUserConfig: false,
|
NoUserConfig: false,
|
||||||
NoDefaults: false,
|
NoDefaults: false,
|
||||||
NoGraphic: false,
|
NoGraphic: false,
|
||||||
MemPrealloc: false,
|
MemPrealloc: false,
|
||||||
Realtime: false,
|
FileBackedMem: false,
|
||||||
Mlock: false,
|
FileBackedMemShared: false,
|
||||||
|
Realtime: false,
|
||||||
|
Mlock: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
testAppend(knobs, knobsString, t)
|
testAppend(knobs, knobsString, t)
|
||||||
@ -435,6 +439,7 @@ func TestAppendMemory(t *testing.T) {
|
|||||||
Size: "2G",
|
Size: "2G",
|
||||||
Slots: 2,
|
Slots: 2,
|
||||||
MaxMem: "3G",
|
MaxMem: "3G",
|
||||||
|
Path: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
testAppend(memory, memoryString, t)
|
testAppend(memory, memoryString, t)
|
||||||
|
Loading…
Reference in New Issue
Block a user