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:
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.
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.
The output shows whether the allocation succeeded. On our 8GB VM we expect the 4GB allocation to work, and it does:
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.
Starting with the 8GB we click to edit, and enter 32768 MB for a 32GB usable capacity.
Now we have allocated 32 GB to the VM as shown in the Capacity properties.
The vmsquared
command can also be used to set the memory of the VM:
Validating the increased RAM
Back in Windows we can see in Task Manager that 32GB is now available out of the total of 32GB.
Looking at sysinternals TestLimit we can now successfully allocate the 16GB amount:
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.