How to Enable vSAN Sparse Swap to Save vSAN Datastore Space

VMware vSAN is the distributed layer of software that runs natively as a part of the ESXi hypervisor. vSAN aggregates local or direct-attached storage disks of a host cluster and creates a single storage pool shared across all hosts of the cluster. It is very important save space on VSAN datastore. When we think about saving space on VSAN datastore, VSAN RAID5/RAID 6 Erasure coding Compression and deduplication come into everyone’s mind. I agree with that. In addition to these, VSAN Sparse Swap is one of the enhancements to VSAN which also helps you save space on the VSAN Datastore.

Every powered on Virtual Machine on the ESXi host will have a .vswp file (swap file ) associated with it. This .vswp file will be stored in the Virtual Machine directory by default. This .vswp file will be automatically deleted when the virtual machine is powered off. By default, the .vSwp file size is same as the configured memory size of the Virtual machine. For Example, the Virtual machine configured with 16 GB of memory will consume 16 GB swap for swap files in the VSAN datastore. This .vswp file will be used if the host is actively over-committed and highly utilized.

Until VSAN 6.2, all virtual machine swap files were created with 100% space reservation on the VSAN datastore. For example, If you 300 virtual machines in the VSAN cluster and each configured with 8 GB of memory will consume around 2400 GB (2 TB) without VSAN FTT consideration. it will increase 2* when considering VSAN FTT requirements.

You cannot get rid of VM swap files space until you configure memory reservation of the virtual machine.  Memory reservation is a guarantee of memory resources for a virtual machine from the available physical resources. If you reserve 2 Gb of memory on a guest with 4 Gb of RAM, you are guaranteeing that the guest will always have access to 2 Gb of physical memory on the host. Take a look at my article to understand the Impact of Changing Memory reservation settings on Power On VM

For example, if you are setting up full memory reservation on a guest configured with 4 Gb of RAM means VM will never swap out to the .vswp file. SWAP file size will be 0KB but configuring Memory reservation to all virtual machines to save swap on the VSAN datastore is not an affordable idea.

With VSAN 6.2, One of the Space Efficiency features of Virtual SAN 6.2 that is available for both All-Flash and Hybrid configurations, is the introduction of Sparse Virtual Swap files. This space efficiency can be achieved using an advanced host setting called SwapThickProvisionDisabled, when enabled, removes the space reservation for .vswp files.

How to Enable VSAN Sparse Swap – Thin Provisioned Swap Files for VSAN Datastore

As I already discussed, Space saving by making Thin Provisioned Virtual machine Swap files vSAN Datastore can be achieved using ESXI advanced setting “SwapThickProvisionDisabled“.

You need to configure this advanced setting on each of the ESXi hosts in the VSAN cluster. Log in to each of the ESXi hosts in the vsan cluster using SSH.

To get the currently configured value of  “SwapThickProvisionDisabled” advanced setting. By default, Value of this advanced setting is “0”. It means virtual machine swap files are thick provisioned by default.  Execute the below command.

esxcfg-advcfg -g /VSAN/SwapThickProvisionDisabled

VSAN Sparse Swap

To enable the Thin provisioned virtual swap files (VSAN Sparse swap), Execute the below command:

esxcfg-advcfg -s 1 /VSAN/SwapThickProvisionDisabled

VSAN Sparse Swap

Once the SwapThickProvisionDisabled value is configured to 1. You need to power off and power on all the virtual machines on the VSAN datastore to have the .vswp file space reservation policy change from 100% reserved to 0% reserved.

Virtual machines created after this settings, Will not reserve any space on the VSAN datastore for virtual machine swap files.

Once VM’s are Power Cycled, you can Check the swap objects  Space consumption on your VSAN datastore. Select your VSAN cluster > Monitor > Virtual SAN > Capacity.

It was around 1.2 TB of space consumption of swap objects on the VSAN datastore for 46 virtual machines on the VSAN Datastore. After the VSAN Sparse Swap, It is reduced it to 612 MB.

VSAN Sparse Swap

1.2 TB of space consuming for swap objects down to 600 MB is a great saving rite. You can make this VSAN Sparse swap as one of the mandatory settings before delivering your VSAN cluster into production will avoid production virtual machine power cycle. I hope this is informative for you. Thanks for Reading!!! Be social and share it with social media, if you feel worth sharing it.