mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-03 02:26:37 +00:00
memory: Add new option memory_offset
This value will be plused to max memory of hypervisor. It is the memory address space for the NVDIMM devie. If set block storage driver (block_device_driver) to "nvdimm", should set memory_offset to the size of block device. Signed-off-by: Hui Zhu <teawater@hyper.sh>
This commit is contained in:
parent
ef75c3d19e
commit
dd28ff5986
@ -82,6 +82,13 @@ default_memory = @DEFMEMSZ@
|
|||||||
# This is will determine the times that memory will be hotadded to sandbox/VM.
|
# This is will determine the times that memory will be hotadded to sandbox/VM.
|
||||||
#memory_slots = @DEFMEMSLOTS@
|
#memory_slots = @DEFMEMSLOTS@
|
||||||
|
|
||||||
|
# The size in MiB will be plused to max memory of hypervisor.
|
||||||
|
# It is the memory address space for the NVDIMM devie.
|
||||||
|
# If set block storage driver (block_device_driver) to "nvdimm",
|
||||||
|
# should set memory_offset to the size of block device.
|
||||||
|
# Default 0
|
||||||
|
#memory_offset = 0
|
||||||
|
|
||||||
# Disable block device from being used for a container's rootfs.
|
# Disable block device from being used for a container's rootfs.
|
||||||
# In case of a storage driver like devicemapper where a container's
|
# In case of a storage driver like devicemapper where a container's
|
||||||
# root file system is backed by a block device, the block device is passed
|
# root file system is backed by a block device, the block device is passed
|
||||||
|
@ -24,6 +24,7 @@ const defaultVCPUCount uint32 = 1
|
|||||||
const defaultMaxVCPUCount uint32 = 0
|
const defaultMaxVCPUCount uint32 = 0
|
||||||
const defaultMemSize uint32 = 2048 // MiB
|
const defaultMemSize uint32 = 2048 // MiB
|
||||||
const defaultMemSlots uint32 = 10
|
const defaultMemSlots uint32 = 10
|
||||||
|
const defaultMemOffset uint32 = 0 // MiB
|
||||||
const defaultBridgesCount uint32 = 1
|
const defaultBridgesCount uint32 = 1
|
||||||
const defaultInterNetworkingModel = "macvtap"
|
const defaultInterNetworkingModel = "macvtap"
|
||||||
const defaultDisableBlockDeviceUse bool = false
|
const defaultDisableBlockDeviceUse bool = false
|
||||||
|
@ -98,6 +98,7 @@ type hypervisor struct {
|
|||||||
DefaultMaxVCPUs uint32 `toml:"default_maxvcpus"`
|
DefaultMaxVCPUs uint32 `toml:"default_maxvcpus"`
|
||||||
MemorySize uint32 `toml:"default_memory"`
|
MemorySize uint32 `toml:"default_memory"`
|
||||||
MemSlots uint32 `toml:"memory_slots"`
|
MemSlots uint32 `toml:"memory_slots"`
|
||||||
|
MemOffset uint32 `toml:"memory_offset"`
|
||||||
DefaultBridges uint32 `toml:"default_bridges"`
|
DefaultBridges uint32 `toml:"default_bridges"`
|
||||||
Msize9p uint32 `toml:"msize_9p"`
|
Msize9p uint32 `toml:"msize_9p"`
|
||||||
DisableBlockDeviceUse bool `toml:"disable_block_device_use"`
|
DisableBlockDeviceUse bool `toml:"disable_block_device_use"`
|
||||||
@ -281,6 +282,15 @@ func (h hypervisor) defaultMemSlots() uint32 {
|
|||||||
return slots
|
return slots
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h hypervisor) defaultMemOffset() uint32 {
|
||||||
|
offset := h.MemOffset
|
||||||
|
if offset == 0 {
|
||||||
|
offset = defaultMemOffset
|
||||||
|
}
|
||||||
|
|
||||||
|
return offset
|
||||||
|
}
|
||||||
|
|
||||||
func (h hypervisor) defaultBridges() uint32 {
|
func (h hypervisor) defaultBridges() uint32 {
|
||||||
if h.DefaultBridges == 0 {
|
if h.DefaultBridges == 0 {
|
||||||
return defaultBridgesCount
|
return defaultBridgesCount
|
||||||
@ -514,6 +524,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
|
|||||||
DefaultMaxVCPUs: h.defaultMaxVCPUs(),
|
DefaultMaxVCPUs: h.defaultMaxVCPUs(),
|
||||||
MemorySize: h.defaultMemSz(),
|
MemorySize: h.defaultMemSz(),
|
||||||
MemSlots: h.defaultMemSlots(),
|
MemSlots: h.defaultMemSlots(),
|
||||||
|
MemOffset: h.defaultMemOffset(),
|
||||||
EntropySource: h.GetEntropySource(),
|
EntropySource: h.GetEntropySource(),
|
||||||
DefaultBridges: h.defaultBridges(),
|
DefaultBridges: h.defaultBridges(),
|
||||||
DisableBlockDeviceUse: h.DisableBlockDeviceUse,
|
DisableBlockDeviceUse: h.DisableBlockDeviceUse,
|
||||||
@ -677,6 +688,7 @@ func initConfig() (config oci.RuntimeConfig, err error) {
|
|||||||
NumVCPUs: defaultVCPUCount,
|
NumVCPUs: defaultVCPUCount,
|
||||||
DefaultMaxVCPUs: defaultMaxVCPUCount,
|
DefaultMaxVCPUs: defaultMaxVCPUCount,
|
||||||
MemorySize: defaultMemSize,
|
MemorySize: defaultMemSize,
|
||||||
|
MemOffset: defaultMemOffset,
|
||||||
DefaultBridges: defaultBridgesCount,
|
DefaultBridges: defaultBridgesCount,
|
||||||
MemPrealloc: defaultEnableMemPrealloc,
|
MemPrealloc: defaultEnableMemPrealloc,
|
||||||
HugePages: defaultEnableHugePages,
|
HugePages: defaultEnableHugePages,
|
||||||
|
@ -169,6 +169,9 @@ type HypervisorConfig struct {
|
|||||||
// MemSlots specifies default memory slots the VM.
|
// MemSlots specifies default memory slots the VM.
|
||||||
MemSlots uint32
|
MemSlots uint32
|
||||||
|
|
||||||
|
// MemOffset specifies memory space for nvdimm device
|
||||||
|
MemOffset uint32
|
||||||
|
|
||||||
// KernelParams are additional guest kernel parameters.
|
// KernelParams are additional guest kernel parameters.
|
||||||
KernelParams []Param
|
KernelParams []Param
|
||||||
|
|
||||||
|
@ -1435,12 +1435,11 @@ func genericBridges(number uint32, machineType string) []Bridge {
|
|||||||
return bridges
|
return bridges
|
||||||
}
|
}
|
||||||
|
|
||||||
func genericMemoryTopology(memoryMb, hostMemoryMb uint64, slots uint8) govmmQemu.Memory {
|
func genericMemoryTopology(memoryMb, hostMemoryMb uint64, slots uint8, memoryOffset uint32) govmmQemu.Memory {
|
||||||
// NVDIMM device needs memory space 1024MB
|
// image NVDIMM device needs memory space 1024MB
|
||||||
// See https://github.com/clearcontainers/runtime/issues/380
|
// See https://github.com/clearcontainers/runtime/issues/380
|
||||||
memoryOffset := 1024
|
memoryOffset += 1024
|
||||||
|
|
||||||
// add 1G memory space for nvdimm device (vm guest image)
|
|
||||||
memMax := fmt.Sprintf("%dM", hostMemoryMb+uint64(memoryOffset))
|
memMax := fmt.Sprintf("%dM", hostMemoryMb+uint64(memoryOffset))
|
||||||
|
|
||||||
mem := fmt.Sprintf("%dM", memoryMb)
|
mem := fmt.Sprintf("%dM", memoryMb)
|
||||||
|
@ -87,6 +87,7 @@ func newQemuArch(config HypervisorConfig) qemuArch {
|
|||||||
q := &qemuAmd64{
|
q := &qemuAmd64{
|
||||||
qemuArchBase{
|
qemuArchBase{
|
||||||
machineType: machineType,
|
machineType: machineType,
|
||||||
|
memoryOffset: config.MemOffset,
|
||||||
qemuPaths: qemuPaths,
|
qemuPaths: qemuPaths,
|
||||||
supportedQemuMachines: supportedQemuMachines,
|
supportedQemuMachines: supportedQemuMachines,
|
||||||
kernelParamsNonDebug: kernelParamsNonDebug,
|
kernelParamsNonDebug: kernelParamsNonDebug,
|
||||||
@ -96,6 +97,7 @@ func newQemuArch(config HypervisorConfig) qemuArch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
q.handleImagePath(config)
|
q.handleImagePath(config)
|
||||||
|
|
||||||
return q
|
return q
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +128,7 @@ func (q *qemuAmd64) cpuModel() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (q *qemuAmd64) memoryTopology(memoryMb, hostMemoryMb uint64, slots uint8) govmmQemu.Memory {
|
func (q *qemuAmd64) memoryTopology(memoryMb, hostMemoryMb uint64, slots uint8) govmmQemu.Memory {
|
||||||
return genericMemoryTopology(memoryMb, hostMemoryMb, slots)
|
return genericMemoryTopology(memoryMb, hostMemoryMb, slots, q.memoryOffset)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *qemuAmd64) appendImage(devices []govmmQemu.Device, path string) ([]govmmQemu.Device, error) {
|
func (q *qemuAmd64) appendImage(devices []govmmQemu.Device, path string) ([]govmmQemu.Device, error) {
|
||||||
|
@ -103,6 +103,7 @@ type qemuArch interface {
|
|||||||
|
|
||||||
type qemuArchBase struct {
|
type qemuArchBase struct {
|
||||||
machineType string
|
machineType string
|
||||||
|
memoryOffset uint32
|
||||||
nestedRun bool
|
nestedRun bool
|
||||||
vhost bool
|
vhost bool
|
||||||
networkIndex int
|
networkIndex int
|
||||||
|
@ -136,6 +136,7 @@ func newQemuArch(config HypervisorConfig) qemuArch {
|
|||||||
q := &qemuArm64{
|
q := &qemuArm64{
|
||||||
qemuArchBase{
|
qemuArchBase{
|
||||||
machineType: machineType,
|
machineType: machineType,
|
||||||
|
memoryOffset: config.MemOffset,
|
||||||
qemuPaths: qemuPaths,
|
qemuPaths: qemuPaths,
|
||||||
supportedQemuMachines: supportedQemuMachines,
|
supportedQemuMachines: supportedQemuMachines,
|
||||||
kernelParamsNonDebug: kernelParamsNonDebug,
|
kernelParamsNonDebug: kernelParamsNonDebug,
|
||||||
|
@ -74,6 +74,7 @@ func newQemuArch(config HypervisorConfig) qemuArch {
|
|||||||
q := &qemuPPC64le{
|
q := &qemuPPC64le{
|
||||||
qemuArchBase{
|
qemuArchBase{
|
||||||
machineType: machineType,
|
machineType: machineType,
|
||||||
|
memoryOffset: config.MemOffset,
|
||||||
qemuPaths: qemuPaths,
|
qemuPaths: qemuPaths,
|
||||||
supportedQemuMachines: supportedQemuMachines,
|
supportedQemuMachines: supportedQemuMachines,
|
||||||
kernelParamsNonDebug: kernelParamsNonDebug,
|
kernelParamsNonDebug: kernelParamsNonDebug,
|
||||||
@ -83,6 +84,9 @@ func newQemuArch(config HypervisorConfig) qemuArch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
q.handleImagePath(config)
|
q.handleImagePath(config)
|
||||||
|
|
||||||
|
q.memoryOffset = config.MemOffset
|
||||||
|
|
||||||
return q
|
return q
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +125,7 @@ func (q *qemuPPC64le) memoryTopology(memoryMb, hostMemoryMb uint64, slots uint8)
|
|||||||
hostMemoryMb = defaultMemMaxPPC64le
|
hostMemoryMb = defaultMemMaxPPC64le
|
||||||
}
|
}
|
||||||
|
|
||||||
return genericMemoryTopology(memoryMb, hostMemoryMb, slots)
|
return genericMemoryTopology(memoryMb, hostMemoryMb, slots, q.memoryOffset)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *qemuPPC64le) appendImage(devices []govmmQemu.Device, path string) ([]govmmQemu.Device, error) {
|
func (q *qemuPPC64le) appendImage(devices []govmmQemu.Device, path string) ([]govmmQemu.Device, error) {
|
||||||
|
@ -61,6 +61,7 @@ func newQemuArch(config HypervisorConfig) qemuArch {
|
|||||||
q := &qemuS390x{
|
q := &qemuS390x{
|
||||||
qemuArchBase{
|
qemuArchBase{
|
||||||
machineType: machineType,
|
machineType: machineType,
|
||||||
|
memoryOffset: config.MemOffset,
|
||||||
qemuPaths: qemuPaths,
|
qemuPaths: qemuPaths,
|
||||||
supportedQemuMachines: supportedQemuMachines,
|
supportedQemuMachines: supportedQemuMachines,
|
||||||
kernelParamsNonDebug: kernelParamsNonDebug,
|
kernelParamsNonDebug: kernelParamsNonDebug,
|
||||||
|
Loading…
Reference in New Issue
Block a user