← 输入框|github.com|刷新
Skip to content

[Request]: Cloud Hypervisor backend: virtio-balloon config and vm.resize #978

Open

Description

@kunalkushwaha

Feature or enhancement request details

The Cloud Hypervisor backend has no way to attach or drive a virtio-balloon. Cloud Hypervisor supports one (balloon in vm.create's VmConfig, and desired_balloon in vm.resize), but CloudHypervisor.VmConfig / DeviceConfigs have no balloon type and the client has no vm.resize endpoint, so even a CHInstanceExtension.configureCH cannot add one. The instance's REST client is internal, so a caller also can't resize it after boot.

#882 proposed balloon support across both backends together with a reclaim policy; it and its PRs (#893, #894) were closed without discussion. This request is only the mechanism on the Cloud Hypervisor side, which is additive and policy-free:

  • CloudHypervisor.BalloonConfig (size, deflate_on_oom, free_page_reporting) and VmConfig.balloon: BalloonConfig?
  • CloudHypervisor.VmResize and Client.vmResize(_:) → PUT /api/v1/vm.resize
  • CHVirtualMachineInstance.setBalloonSize(_:) and memoryActualSize() (from vm.info's memory_actual_size)

Usage:

struct Balloon: CHInstanceExtension {
    func configureCH(_ config: inout CloudHypervisor.VmConfig) throws {
        config.balloon = .init(size: 0, deflateOnOom: false)
    }
}
// ... after start:
try await instance.setBalloonSize(512 * 1024 * 1024)
let actual = try await instance.memoryActualSize()

Checked on Cloud Hypervisor v52.0, x86_64 KVM, 1 GiB guest: a 512 MiB balloon takes memory_actual_size from 1152 to 640 MiB and the guest's MemTotal from 1122276 to 597988 KiB (exactly 512 MiB); setting it back to 0 restores both.

Implementation with unit tests (made against 0.47.0; cherry-picks cleanly onto main): kunalkushwaha@bc78926 — happy to open a PR against main if this is wanted.

Note the semantics differ from VZ's VZVirtioTraditionalMemoryBalloonDevice.targetVirtualMachineMemorySize (memory the guest keeps) — Cloud Hypervisor's balloon size is memory taken from the guest. A cross-backend API would need to convert; this request doesn't propose one.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions