Live resize CPU and RAM

Introducing VM live resizing

VM resizing can be done whilst a VM is running, with some limitations.

  • Hotplug support for RAM and CPU is present in newer OS and recommended
    • Windows requires drivers to be installed (present in Amplifier App images)
  • Growing a VM to provide more resources is straightforward but shrinking may not be
    • If the new RAM size is less than currently allocated RAM swapping must occur

VM template

We are starting with a VM allocated 8GB of RAM but with a max memory of 32GB set in the template:

Windows allocated 8GB RAM but with a 32GB max size

The VM will be deployed with 8GB of usable RAM but we will have the option to increase the RAM whilst running. Select Enable hot resize to use this option. Note that the slot number option is no longe required and will be removed in future releases.

Two options are available for hot resizing memory:

  • Hotplug - virtual firmware ACPI calls notify the OS of memory insertion/removal
  • Balloon - driver is used to claim unallocated VM memory for the hypervisor to use elsewhere

In general, hotplug is faster at reclaiming memory and is preferred. Ballooning causes reclaimed memory to be swapped to disk, slowing the reclaim process dramatically, whereas hotplugging performs page migration in memory.

8 GB memory - max 32 GB

Linux generally does this seamlessly and you simply see the resources allocated at that point in time. Windows is slightly different, you will see the maximum possible RAM value but it will be unusable.

Windows allocated 8GB RAM but with a 32GB max size

8GB allocated but a further 24GB is shown in Task Manager and currently unusable

We can verify the allocatable RAM using the Windows SysInternals tool TestLimit.

test allocate 4GB RAM with TestLimit
 .\Testlimit64.exe -d 4096 -c 1

The output shows whether the allocation succeeded. On our 8GB VM we expect the 4GB allocation to work, and it does:

Windows fails to allocate 16 GB memory as limit is 8 GB

16GB allocation fails however - the OS has only 8GB available and cannot allocate the entire 16GB to our process.

Increasing memory capacity

Memory capacity can be increased in the Capacity properties of the VM.

Windows allocated 8GB RAM

Starting with the 8GB we click to edit, and enter 32768 MB for a 32GB usable capacity.

Increase RAM capacity to 32 GB

Now we have allocated 32 GB to the VM as shown in the Capacity properties.

Windows allocated 32GB RAM

The vmsquared command can also be used to set the memory of the VM:

VM memory resizing
vmsquared vm resize <vm name>|<vm ID> --memory <MiB>

Validating the increased RAM

Back in Windows we can see in Task Manager that 32GB is now available out of the total of 32GB.

Windows allocated 32GB RAM and able to fully use the 32GB max size

Looking at sysinternals TestLimit we can now successfully allocate the 16GB amount:

test allocate 4GB RAM with TestLimit
 .\Testlimit64.exe -d 16384 -c 1

Windows successfully allocates 16GB memory

We can see that the VM was not powered off, it simply grew the aviailable memory.

If no processes are using the memory we can also shrink the VM back down to 8GB.