Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
memory: Add new option memory_offset
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
teawater committed Dec 24, 2018
1 parent ef75c3d commit dd28ff5
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 6 deletions.
7 changes: 7 additions & 0 deletions cli/config/configuration.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ default_memory = @DEFMEMSZ@
# This is will determine the times that memory will be hotadded to sandbox/VM.
#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.
# 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
Expand Down
1 change: 1 addition & 0 deletions pkg/katautils/config-settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const defaultVCPUCount uint32 = 1
const defaultMaxVCPUCount uint32 = 0
const defaultMemSize uint32 = 2048 // MiB
const defaultMemSlots uint32 = 10
const defaultMemOffset uint32 = 0 // MiB
const defaultBridgesCount uint32 = 1
const defaultInterNetworkingModel = "macvtap"
const defaultDisableBlockDeviceUse bool = false
Expand Down
12 changes: 12 additions & 0 deletions pkg/katautils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ type hypervisor struct {
DefaultMaxVCPUs uint32 `toml:"default_maxvcpus"`
MemorySize uint32 `toml:"default_memory"`
MemSlots uint32 `toml:"memory_slots"`
MemOffset uint32 `toml:"memory_offset"`
DefaultBridges uint32 `toml:"default_bridges"`
Msize9p uint32 `toml:"msize_9p"`
DisableBlockDeviceUse bool `toml:"disable_block_device_use"`
Expand Down Expand Up @@ -281,6 +282,15 @@ func (h hypervisor) defaultMemSlots() uint32 {
return slots
}

func (h hypervisor) defaultMemOffset() uint32 {
offset := h.MemOffset
if offset == 0 {
offset = defaultMemOffset
}

return offset
}

func (h hypervisor) defaultBridges() uint32 {
if h.DefaultBridges == 0 {
return defaultBridgesCount
Expand Down Expand Up @@ -514,6 +524,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
DefaultMaxVCPUs: h.defaultMaxVCPUs(),
MemorySize: h.defaultMemSz(),
MemSlots: h.defaultMemSlots(),
MemOffset: h.defaultMemOffset(),
EntropySource: h.GetEntropySource(),
DefaultBridges: h.defaultBridges(),
DisableBlockDeviceUse: h.DisableBlockDeviceUse,
Expand Down Expand Up @@ -677,6 +688,7 @@ func initConfig() (config oci.RuntimeConfig, err error) {
NumVCPUs: defaultVCPUCount,
DefaultMaxVCPUs: defaultMaxVCPUCount,
MemorySize: defaultMemSize,
MemOffset: defaultMemOffset,
DefaultBridges: defaultBridgesCount,
MemPrealloc: defaultEnableMemPrealloc,
HugePages: defaultEnableHugePages,
Expand Down
3 changes: 3 additions & 0 deletions virtcontainers/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ type HypervisorConfig struct {
// MemSlots specifies default memory slots the VM.
MemSlots uint32

// MemOffset specifies memory space for nvdimm device
MemOffset uint32

// KernelParams are additional guest kernel parameters.
KernelParams []Param

Expand Down
7 changes: 3 additions & 4 deletions virtcontainers/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -1435,12 +1435,11 @@ func genericBridges(number uint32, machineType string) []Bridge {
return bridges
}

func genericMemoryTopology(memoryMb, hostMemoryMb uint64, slots uint8) govmmQemu.Memory {
// NVDIMM device needs memory space 1024MB
func genericMemoryTopology(memoryMb, hostMemoryMb uint64, slots uint8, memoryOffset uint32) govmmQemu.Memory {
// image NVDIMM device needs memory space 1024MB
// 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))

mem := fmt.Sprintf("%dM", memoryMb)
Expand Down
4 changes: 3 additions & 1 deletion virtcontainers/qemu_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func newQemuArch(config HypervisorConfig) qemuArch {
q := &qemuAmd64{
qemuArchBase{
machineType: machineType,
memoryOffset: config.MemOffset,
qemuPaths: qemuPaths,
supportedQemuMachines: supportedQemuMachines,
kernelParamsNonDebug: kernelParamsNonDebug,
Expand All @@ -96,6 +97,7 @@ func newQemuArch(config HypervisorConfig) qemuArch {
}

q.handleImagePath(config)

return q
}

Expand Down Expand Up @@ -126,7 +128,7 @@ func (q *qemuAmd64) cpuModel() string {
}

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) {
Expand Down
1 change: 1 addition & 0 deletions virtcontainers/qemu_arch_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ type qemuArch interface {

type qemuArchBase struct {
machineType string
memoryOffset uint32
nestedRun bool
vhost bool
networkIndex int
Expand Down
1 change: 1 addition & 0 deletions virtcontainers/qemu_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func newQemuArch(config HypervisorConfig) qemuArch {
q := &qemuArm64{
qemuArchBase{
machineType: machineType,
memoryOffset: config.MemOffset,
qemuPaths: qemuPaths,
supportedQemuMachines: supportedQemuMachines,
kernelParamsNonDebug: kernelParamsNonDebug,
Expand Down
6 changes: 5 additions & 1 deletion virtcontainers/qemu_ppc64le.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func newQemuArch(config HypervisorConfig) qemuArch {
q := &qemuPPC64le{
qemuArchBase{
machineType: machineType,
memoryOffset: config.MemOffset,
qemuPaths: qemuPaths,
supportedQemuMachines: supportedQemuMachines,
kernelParamsNonDebug: kernelParamsNonDebug,
Expand All @@ -83,6 +84,9 @@ func newQemuArch(config HypervisorConfig) qemuArch {
}

q.handleImagePath(config)

q.memoryOffset = config.MemOffset

return q
}

Expand Down Expand Up @@ -121,7 +125,7 @@ func (q *qemuPPC64le) memoryTopology(memoryMb, hostMemoryMb uint64, slots uint8)
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) {
Expand Down
1 change: 1 addition & 0 deletions virtcontainers/qemu_s390x.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func newQemuArch(config HypervisorConfig) qemuArch {
q := &qemuS390x{
qemuArchBase{
machineType: machineType,
memoryOffset: config.MemOffset,
qemuPaths: qemuPaths,
supportedQemuMachines: supportedQemuMachines,
kernelParamsNonDebug: kernelParamsNonDebug,
Expand Down

0 comments on commit dd28ff5

Please sign in to comment.