Virtual machines running on an ESXi host uses a swap file (vSwap) for any memory that is not reserved.
VMware ESXi swap files are temporary files created by the hypervisor when the VM is powered on to store data that cannot fit in the physical memory (RAM) of a virtual machine. This swap file is used when the virtual machine is unable to allocate physical memory from the ESXi host. When the memory is overcommitted, the hypervisor moves the least used memory pages to the swap file and frees up memory for other processes. In larger environments this can increase the storage usage to provide multiple virtual machines with vSwap space.
Configuring memory reservation on the VM will change the size of the required swap file. An example:
- VM – 4 GB – no memory reservation ==> 4 GB swap file
- VM – 4 GB – 1 GB memory reservation ==> 3 GB swap file
- VM – 4 GB – all guest memory reserved ==> 0 GB swap file
There is also a second swap file (50-150 MB) created with the prefix vmx that is the swap file for the overhead memory reserved for the VMX process. This can be disabled by configuring the advanced setting “schedule.swap.vmxSwapEnabled” to false
Swap files are by default stored at the same location as the VMs configuration file, but the swap file location can be configured:
- Per host ==> See https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsphere.resmgmt.doc/GUID-12B8E0FB-CD43-4972-AC2C-4B4E2955A5DA.html
- Per cluster ==> See https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsphere.resmgmt.doc/GUID-2A031EBB-BEBA-4DDE-BEA1-B8062974806E.html
The location of the virtual machine swap file affects vMotion compatibility in different ways depending on the version of ESXi running on the virtual machine’s host. For example, if the swap file location on the destination host differs from the swap file location on the source host, the swap file is copied to the new location, which can result in slower migrations with vMotion.