mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-13 23:24:14 +00:00
hypervisor: Add GetTotalMemoryMB to interface
It'll be useful to get the total memory provided to the guest (hotplugged + coldplugged). We'll use this information when calcualting how much memory we can add at a time when utilizing ACPI hotplug. Signed-off-by: Eric Ernst <eric_ernst@apple.com>
This commit is contained in:
parent
8f40927df8
commit
1c0e6b4356
@ -667,6 +667,10 @@ func (a *Acrn) GetThreadIDs(ctx context.Context) (VcpuThreadIDs, error) {
|
|||||||
return VcpuThreadIDs{}, nil
|
return VcpuThreadIDs{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *Acrn) GetTotalMemoryMB(ctx context.Context) uint32 {
|
||||||
|
return a.config.MemorySize
|
||||||
|
}
|
||||||
|
|
||||||
func (a *Acrn) ResizeMemory(ctx context.Context, reqMemMB uint32, memoryBlockSizeMB uint32, probe bool) (uint32, MemoryDevice, error) {
|
func (a *Acrn) ResizeMemory(ctx context.Context, reqMemMB uint32, memoryBlockSizeMB uint32, probe bool) (uint32, MemoryDevice, error) {
|
||||||
return 0, MemoryDevice{}, nil
|
return 0, MemoryDevice{}, nil
|
||||||
}
|
}
|
||||||
|
@ -1576,6 +1576,16 @@ func (clh *cloudHypervisor) cleanupVM(force bool) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (clh *cloudHypervisor) GetTotalMemoryMB(ctx context.Context) uint32 {
|
||||||
|
vminfo, err := clh.vmInfo()
|
||||||
|
if err != nil {
|
||||||
|
clh.Logger().WithError(err).Error("failed to get vminfo")
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return uint32(vminfo.GetMemoryActualSize() >> utils.MibToBytesShift)
|
||||||
|
}
|
||||||
|
|
||||||
// vmInfo ask to hypervisor for current VM status
|
// vmInfo ask to hypervisor for current VM status
|
||||||
func (clh *cloudHypervisor) vmInfo() (chclient.VmInfo, error) {
|
func (clh *cloudHypervisor) vmInfo() (chclient.VmInfo, error) {
|
||||||
cl := clh.client()
|
cl := clh.client()
|
||||||
|
@ -1165,6 +1165,10 @@ func (fc *firecracker) HypervisorConfig() HypervisorConfig {
|
|||||||
return fc.config
|
return fc.config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fc *firecracker) GetTotalMemoryMB(ctx context.Context) uint32 {
|
||||||
|
return fc.config.MemorySize
|
||||||
|
}
|
||||||
|
|
||||||
func (fc *firecracker) ResizeMemory(ctx context.Context, reqMemMB uint32, memoryBlockSizeMB uint32, probe bool) (uint32, MemoryDevice, error) {
|
func (fc *firecracker) ResizeMemory(ctx context.Context, reqMemMB uint32, memoryBlockSizeMB uint32, probe bool) (uint32, MemoryDevice, error) {
|
||||||
return 0, MemoryDevice{}, nil
|
return 0, MemoryDevice{}, nil
|
||||||
}
|
}
|
||||||
|
@ -913,6 +913,7 @@ type Hypervisor interface {
|
|||||||
HotplugRemoveDevice(ctx context.Context, devInfo interface{}, devType DeviceType) (interface{}, error)
|
HotplugRemoveDevice(ctx context.Context, devInfo interface{}, devType DeviceType) (interface{}, error)
|
||||||
ResizeMemory(ctx context.Context, memMB uint32, memoryBlockSizeMB uint32, probe bool) (uint32, MemoryDevice, error)
|
ResizeMemory(ctx context.Context, memMB uint32, memoryBlockSizeMB uint32, probe bool) (uint32, MemoryDevice, error)
|
||||||
ResizeVCPUs(ctx context.Context, vcpus uint32) (uint32, uint32, error)
|
ResizeVCPUs(ctx context.Context, vcpus uint32) (uint32, uint32, error)
|
||||||
|
GetTotalMemoryMB(ctx context.Context) uint32
|
||||||
GetVMConsole(ctx context.Context, sandboxID string) (string, string, error)
|
GetVMConsole(ctx context.Context, sandboxID string) (string, string, error)
|
||||||
Disconnect(ctx context.Context)
|
Disconnect(ctx context.Context)
|
||||||
Capabilities(ctx context.Context) types.Capabilities
|
Capabilities(ctx context.Context) types.Capabilities
|
||||||
|
@ -98,6 +98,9 @@ func (m *mockHypervisor) ResizeVCPUs(ctx context.Context, cpus uint32) (uint32,
|
|||||||
return 0, 0, nil
|
return 0, 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *mockHypervisor) GetTotalMemoryMB(ctx context.Context) uint32 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
func (m *mockHypervisor) Disconnect(ctx context.Context) {
|
func (m *mockHypervisor) Disconnect(ctx context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2159,6 +2159,10 @@ func (q *qemu) Disconnect(ctx context.Context) {
|
|||||||
q.qmpShutdown()
|
q.qmpShutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (q *qemu) GetTotalMemoryMB(ctx context.Context) uint32 {
|
||||||
|
return q.config.MemorySize + uint32(q.state.HotpluggedMemory)
|
||||||
|
}
|
||||||
|
|
||||||
// ResizeMemory gets a request to update the VM memory to reqMemMB
|
// ResizeMemory gets a request to update the VM memory to reqMemMB
|
||||||
// Memory update is managed with two approaches
|
// Memory update is managed with two approaches
|
||||||
// Add memory to VM:
|
// Add memory to VM:
|
||||||
@ -2172,7 +2176,7 @@ func (q *qemu) Disconnect(ctx context.Context) {
|
|||||||
// A longer term solution is evaluate solutions like virtio-mem
|
// A longer term solution is evaluate solutions like virtio-mem
|
||||||
func (q *qemu) ResizeMemory(ctx context.Context, reqMemMB uint32, memoryBlockSizeMB uint32, probe bool) (uint32, MemoryDevice, error) {
|
func (q *qemu) ResizeMemory(ctx context.Context, reqMemMB uint32, memoryBlockSizeMB uint32, probe bool) (uint32, MemoryDevice, error) {
|
||||||
|
|
||||||
currentMemory := q.config.MemorySize + uint32(q.state.HotpluggedMemory)
|
currentMemory := q.GetTotalMemoryMB(ctx)
|
||||||
if err := q.qmpSetup(); err != nil {
|
if err := q.qmpSetup(); err != nil {
|
||||||
return 0, MemoryDevice{}, err
|
return 0, MemoryDevice{}, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user