mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-29 16:57:18 +00:00
qemu: fix memory prealloc option handling
Memory preallocation is just a property that hugepage, file backed memory and memory-backend-ram can each choose to configure. Signed-off-by: Peng Tao <bergwolf@hyper.sh>
This commit is contained in:
parent
6c77d76f24
commit
aebc49692b
@ -430,7 +430,7 @@ func (q *qemu) setupTemplate(knobs *govmmQemu.Knobs, memory *govmmQemu.Memory) g
|
||||
memory.Path = q.config.MemoryPath
|
||||
|
||||
if q.config.BootToBeTemplate {
|
||||
knobs.FileBackedMemShared = true
|
||||
knobs.MemShared = true
|
||||
}
|
||||
|
||||
if q.config.BootFromTemplate {
|
||||
@ -454,7 +454,7 @@ func (q *qemu) setupFileBackedMem(knobs *govmmQemu.Knobs, memory *govmmQemu.Memo
|
||||
}
|
||||
|
||||
knobs.FileBackedMem = true
|
||||
knobs.FileBackedMemShared = true
|
||||
knobs.MemShared = true
|
||||
memory.Path = target
|
||||
}
|
||||
|
||||
@ -522,6 +522,9 @@ func (q *qemu) createSandbox(ctx context.Context, id string, networkNS NetworkNa
|
||||
} else {
|
||||
return errors.New("VM templating has been enabled with either virtio-fs or file backed memory and this configuration will not work")
|
||||
}
|
||||
if q.config.HugePages {
|
||||
knobs.MemPrealloc = true
|
||||
}
|
||||
}
|
||||
|
||||
rtc := govmmQemu.RTC{
|
||||
@ -1484,7 +1487,7 @@ func (q *qemu) hotplugAddMemory(memDev *memoryDevice) (int, error) {
|
||||
target = q.qemuConfig.Memory.Path
|
||||
memoryBack = "memory-backend-file"
|
||||
}
|
||||
if q.qemuConfig.Knobs.FileBackedMemShared {
|
||||
if q.qemuConfig.Knobs.MemShared {
|
||||
share = true
|
||||
}
|
||||
err = q.qmpMonitorCh.qmp.ExecHotplugMemory(q.qmpMonitorCh.ctx, memoryBack, "mem"+strconv.Itoa(memDev.slot), target, memDev.sizeMB, share)
|
||||
|
@ -7,7 +7,6 @@ package virtcontainers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@ -20,6 +19,7 @@ import (
|
||||
"github.com/kata-containers/runtime/virtcontainers/device/config"
|
||||
"github.com/kata-containers/runtime/virtcontainers/store"
|
||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@ -445,7 +445,7 @@ func TestQemuAddDeviceToBridge(t *testing.T) {
|
||||
// fail to add device to bridge cause no more available bridge slot
|
||||
_, _, err := q.addDeviceToBridge("qemu-bridge-31")
|
||||
exceptErr := errors.New("no more bridge slots available")
|
||||
assert.Equal(exceptErr, err)
|
||||
assert.Equal(exceptErr.Error(), err.Error())
|
||||
|
||||
// addDeviceToBridge fails cause q.state.Bridges == 0
|
||||
config.HypervisorMachineType = QemuPCLite
|
||||
@ -456,7 +456,7 @@ func TestQemuAddDeviceToBridge(t *testing.T) {
|
||||
q.state.Bridges = q.arch.bridges(q.config.DefaultBridges)
|
||||
_, _, err = q.addDeviceToBridge("qemu-bridge")
|
||||
exceptErr = errors.New("failed to get available address from bridges")
|
||||
assert.Equal(exceptErr, err)
|
||||
assert.Equal(exceptErr.Error(), err.Error())
|
||||
}
|
||||
|
||||
func TestQemuFileBackedMem(t *testing.T) {
|
||||
@ -472,7 +472,7 @@ func TestQemuFileBackedMem(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
|
||||
assert.Equal(q.qemuConfig.Knobs.FileBackedMem, true)
|
||||
assert.Equal(q.qemuConfig.Knobs.FileBackedMemShared, true)
|
||||
assert.Equal(q.qemuConfig.Knobs.MemShared, true)
|
||||
assert.Equal(q.qemuConfig.Memory.Path, fallbackFileBackedMemDir)
|
||||
|
||||
// Check failure for VM templating
|
||||
@ -487,7 +487,7 @@ func TestQemuFileBackedMem(t *testing.T) {
|
||||
err = q.createSandbox(context.Background(), sandbox.id, NetworkNamespace{}, &sandbox.config.HypervisorConfig, sandbox.store)
|
||||
|
||||
expectErr := errors.New("VM templating has been enabled with either virtio-fs or file backed memory and this configuration will not work")
|
||||
assert.Equal(expectErr, err)
|
||||
assert.Equal(expectErr.Error(), err.Error())
|
||||
|
||||
// Check Setting of non-existent shared-mem path
|
||||
sandbox, err = createQemuSandboxConfig()
|
||||
@ -498,7 +498,7 @@ func TestQemuFileBackedMem(t *testing.T) {
|
||||
err = q.createSandbox(context.Background(), sandbox.id, NetworkNamespace{}, &sandbox.config.HypervisorConfig, sandbox.store)
|
||||
assert.NoError(err)
|
||||
assert.Equal(q.qemuConfig.Knobs.FileBackedMem, false)
|
||||
assert.Equal(q.qemuConfig.Knobs.FileBackedMemShared, false)
|
||||
assert.Equal(q.qemuConfig.Knobs.MemShared, false)
|
||||
assert.Equal(q.qemuConfig.Memory.Path, "")
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user