lima icon indicating copy to clipboard operation
lima copied to clipboard

Support memory ballooning in VMs

Open msimkunas opened this issue 2 months ago • 3 comments

Description

I have a VM which uses approximately half of its allocated memory most of the time but sometimes spikes up near the allocated memory limit. To ensure uninterrupted execution of processes inside the VM, I have to allocate much more memory than the VM needs most of the time.

This could be improved if Lima VMs released unused memory automatically without user intervention.

Lima doesn't support memory ballooning currently. Apple docs indicate that VZ supports this but I'm not sure of the scope of the changes required.

Relevant discussion: https://github.com/lima-vm/lima/discussions/2720

msimkunas avatar Oct 17 '25 14:10 msimkunas

Currently there is a memory balloon device.

        configuration, err := vz.NewVirtioTraditionalMemoryBalloonDeviceConfiguration()
        if err != nil {
                return err
        }
        vmConfig.SetMemoryBalloonDevicesVirtualMachineConfiguration([]vz.MemoryBalloonDeviceConfiguration{
                configuration,
        })

Just that it is never called, after creation...

MemoryBalloonDevices

SetTargetVirtualMachineMemorySize

I think it would need to have some more support, for instance to have the agents report the current memory etc.

  • https://github.com/lima-vm/lima/issues/835

A workaround could be to have some hidden command for it, so that the feature can be experimented with?

Trying to figure out how it was that you see the memory allocation of a running process (I have top and free)

EDIT: top -l 1 works

(it is like top -b -n 1)

afbjorklund avatar Oct 17 '25 15:10 afbjorklund

A workaround could be to have some hidden command for it, so that the feature can be experimented with?

You mean having a limactl command for inflating/deflating the memory balloon manually?

msimkunas avatar Oct 17 '25 16:10 msimkunas

If implemented, it should be done for QEMU as well as for VZ. There are available QMP commands to do it.

https://qemu-project.gitlab.io/qemu/interop/qemu-qmp-ref.html#command-QMP-machine.balloon

afbjorklund avatar Oct 19 '25 07:10 afbjorklund