virtcontainers: change memory_offset to uint64

`memory_offset` is used to increase the maximum amount of memory
supported in a VM, this offset is equal to the NVDIMM/PMEM device that
is hot added, in real use case workloads such devices are bigger than
4G, which is the current limit (uint32).

fixes #2006

Signed-off-by: Julio Montes <julio.montes@intel.com>
This commit is contained in:
Julio Montes 2021-06-14 15:14:05 -05:00
parent fb318532b9
commit 7834f4127f
9 changed files with 13 additions and 13 deletions

View File

@ -26,7 +26,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 defaultMemOffset uint64 = 0 // MiB
const defaultVirtioMem bool = false const defaultVirtioMem bool = false
const defaultBridgesCount uint32 = 1 const defaultBridgesCount uint32 = 1
const defaultInterNetworkingModel = "tcfilter" const defaultInterNetworkingModel = "tcfilter"

View File

@ -114,7 +114,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"` MemOffset uint64 `toml:"memory_offset"`
DefaultBridges uint32 `toml:"default_bridges"` DefaultBridges uint32 `toml:"default_bridges"`
Msize9p uint32 `toml:"msize_9p"` Msize9p uint32 `toml:"msize_9p"`
PCIeRootPort uint32 `toml:"pcie_root_port"` PCIeRootPort uint32 `toml:"pcie_root_port"`
@ -359,7 +359,7 @@ func (h hypervisor) defaultMemSlots() uint32 {
return slots return slots
} }
func (h hypervisor) defaultMemOffset() uint32 { func (h hypervisor) defaultMemOffset() uint64 {
offset := h.MemOffset offset := h.MemOffset
if offset == 0 { if offset == 0 {
offset = defaultMemOffset offset = defaultMemOffset

View File

@ -242,7 +242,7 @@ type HypervisorConfig struct {
MemSlots uint32 MemSlots uint32
// MemOffset specifies memory space for nvdimm device // MemOffset specifies memory space for nvdimm device
MemOffset uint32 MemOffset uint64
// VirtioFSCacheSize is the DAX cache size in MiB // VirtioFSCacheSize is the DAX cache size in MiB
VirtioFSCacheSize uint32 VirtioFSCacheSize uint32

View File

@ -33,7 +33,7 @@ type HypervisorConfig struct {
MemSlots uint32 MemSlots uint32
// MemOffset specifies memory space for nvdimm device // MemOffset specifies memory space for nvdimm device
MemOffset uint32 MemOffset uint64
// VirtioFSCacheSize is the DAX cache size in MiB // VirtioFSCacheSize is the DAX cache size in MiB
VirtioFSCacheSize uint32 VirtioFSCacheSize uint32

View File

@ -576,13 +576,13 @@ func addHypervisorMemoryOverrides(ocispec specs.Spec, sbConfig *vc.SandboxConfig
} }
if value, ok := ocispec.Annotations[vcAnnotations.MemOffset]; ok { if value, ok := ocispec.Annotations[vcAnnotations.MemOffset]; ok {
moffset, err := strconv.ParseUint(value, 10, 32) moffset, err := strconv.ParseUint(value, 10, 64)
if err != nil { if err != nil {
return fmt.Errorf("Error parsing annotation for memory_offset: %v, please specify positive numeric value", err) return fmt.Errorf("Error parsing annotation for memory_offset: %v, please specify positive numeric value", err)
} }
if moffset > 0 { if moffset > 0 {
sbConfig.HypervisorConfig.MemOffset = uint32(moffset) sbConfig.HypervisorConfig.MemOffset = moffset
} }
} }

View File

@ -870,7 +870,7 @@ func TestAddHypervisorAnnotations(t *testing.T) {
assert.Equal(config.HypervisorConfig.DefaultMaxVCPUs, uint32(1)) assert.Equal(config.HypervisorConfig.DefaultMaxVCPUs, uint32(1))
assert.Equal(config.HypervisorConfig.MemorySize, uint32(1024)) assert.Equal(config.HypervisorConfig.MemorySize, uint32(1024))
assert.Equal(config.HypervisorConfig.MemSlots, uint32(20)) assert.Equal(config.HypervisorConfig.MemSlots, uint32(20))
assert.Equal(config.HypervisorConfig.MemOffset, uint32(512)) assert.Equal(config.HypervisorConfig.MemOffset, uint64(512))
assert.Equal(config.HypervisorConfig.VirtioMem, true) assert.Equal(config.HypervisorConfig.VirtioMem, true)
assert.Equal(config.HypervisorConfig.MemPrealloc, true) assert.Equal(config.HypervisorConfig.MemPrealloc, true)
assert.Equal(config.HypervisorConfig.Mlock, false) assert.Equal(config.HypervisorConfig.Mlock, false)

View File

@ -2116,12 +2116,12 @@ func genericBridges(number uint32, machineType string) []types.Bridge {
} }
// nolint: unused, deadcode // nolint: unused, deadcode
func genericMemoryTopology(memoryMb, hostMemoryMb uint64, slots uint8, memoryOffset uint32) govmmQemu.Memory { func genericMemoryTopology(memoryMb, hostMemoryMb uint64, slots uint8, memoryOffset uint64) govmmQemu.Memory {
// image 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
memMax := fmt.Sprintf("%dM", hostMemoryMb+uint64(memoryOffset)) memMax := fmt.Sprintf("%dM", hostMemoryMb+memoryOffset)
mem := fmt.Sprintf("%dM", memoryMb) mem := fmt.Sprintf("%dM", memoryMb)

View File

@ -109,7 +109,7 @@ func TestQemuAmd64CPUModel(t *testing.T) {
func TestQemuAmd64MemoryTopology(t *testing.T) { func TestQemuAmd64MemoryTopology(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
amd64 := newTestQemu(assert, QemuPC) amd64 := newTestQemu(assert, QemuPC)
memoryOffset := 1024 memoryOffset := uint64(1024)
hostMem := uint64(100) hostMem := uint64(100)
mem := uint64(120) mem := uint64(120)
@ -117,7 +117,7 @@ func TestQemuAmd64MemoryTopology(t *testing.T) {
expectedMemory := govmmQemu.Memory{ expectedMemory := govmmQemu.Memory{
Size: fmt.Sprintf("%dM", mem), Size: fmt.Sprintf("%dM", mem),
Slots: slots, Slots: slots,
MaxMem: fmt.Sprintf("%dM", hostMem+uint64(memoryOffset)), MaxMem: fmt.Sprintf("%dM", hostMem+memoryOffset),
} }
m := amd64.memoryTopology(mem, hostMem, slots) m := amd64.memoryTopology(mem, hostMem, slots)

View File

@ -177,7 +177,7 @@ const (
type qemuArchBase struct { type qemuArchBase struct {
qemuMachine govmmQemu.Machine qemuMachine govmmQemu.Machine
qemuExePath string qemuExePath string
memoryOffset uint32 memoryOffset uint64
nestedRun bool nestedRun bool
vhost bool vhost bool
disableNvdimm bool disableNvdimm bool