April 19, 2024

Virtual SAN 6.2 & PowerCLI – Sparse Virtual Swap files

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. Swap files on Virtual SAN by default, are created with the .vswp 100% reserved. In a thin provisioned/guaranteed capacity perspective, it could be said that they effectively Lazy Zeroed Thick (LZT).

Virtual Swap files (.vswp) are created when a virtual machine doesn’t have a memory reservation equal to the amount of memory the virtual machine is configured to use. In short, a VM with 4GB of RAM configured, with no memory reservation will create a 4GB .vswp file. If a reservation is used, then the .vswp file will be the configured amount of memory minus the reserved amount of memory. The same VM with 4GB of RAM, along with a 2GB reservation, will create a 2GB .vswp file.

Virtual Swap files are given a Number of Failures to Tolerate setting of 1 (FTT=1) with a Failure Tolerance Method of Mirroring or FTM=RAID1 (Mirroring). As the storage policy of FTT=1/FTM=Mirroring stands, each object with that policy will require 2x the space (1 Mirror). 200 virtual machines with 4GB of RAM each (I’m thinking a small VDI deployment) with no reservations, would require 200 x (4GB + 4GB) or 1.6TB of space. That’s significant!

In cases where there is no memory congestion, and a virtual machine doesn’t use the swap file, it might be advantageous to have a swap file that is truly thin provisioned (the default in Virtual SAN).

In Virtual SAN 6.2, we introduced an advanced host setting called SwapThickProvisionDisabled, when enabled, removes the space reservation for .vswp files.  The generic syntax for this command is:

esxcfg-advcfg -g /VSAN/SwapThickProvisionDisabled

Having to determine this configuration across more than a few hosts can be a bit of a pain without some scripting/automation.

On a 4 node cluster I spun up about 500 virtual machines with 4GB of RAM allocated each, and no memory reservations. Those swap files, as well as FTT mirrors consumed over 4TB of capacity.

thickswap

*Note the .vswp Mirrors don’t appear in Swap objects, but rather File System Overhead.

I powered off those virtual machines, changed the SwapThickProvisionDisabled setting, and consumed less than 4GB of Virtual SAN capacity.

thinswap

*Note the displayed File System Overhead includes mirrors of other virtual machines on the cluster.

That’s a huge difference. I could run the above esxcfg command on my hosts, but that’s a bit problematic. I’d much rather script this.

So I wrote a couple simple scripts for just that.

First I wrote one to query each host for each of the clusters attached to vCenter. It also checks for vSphere 6.0 Update 2, as the setting isn’t valid with previous releases of vSphere.

Get-VSANThinSwap.ps1

<#================================ Script Name: Get-VSANThinSwap.ps1 Created on: 2/21/2016 Created by: Jase McCarty Github: http://www.github.com/jasemccarty Twitter: @jasemccarty Website: http://www.jasemccarty.com ==================================== .DESCRIPTION This script will go through each host in a cluster and determine read the Advanced Configuration Setting /VSAN/SwapThickProvisionDisabled A setting of 0 means that vSwp files are created with a 100% Object Space Reservation (default) A setting of 1 means that vSwp files are created thin, with 0% Object Space Reservation .Notes This is only applicable to ESXi hosts with Virtual SAN 6.2 or greater #>

# Must be connected to vCenter Server 1st
# Connect-VIServer 

# Get each cluster managed by vCenter Server
Foreach ($Cluster in (Get-Cluster |Sort Name)){

 # Display the Current Cluster
 Write-Host ìCluster: $($Cluster.name)

 # Cycle through each ESXi Host in the cluster
 Foreach ($ESXHost in ($Cluster |Get-VMHost |Sort Name)){

 # Grab EsxCLI content to check for proper host version
 $esxcli = Get-EsxCli -VMHost $ESXHost

 # Grab the major host version
 $esxmajor = $esxcli.system.version.get().version

 # Grab the update version
 $esxupdate = $esxcli.system.version.get().update

 # Make sure a version 6.0.0 host is being checked
 If ($esxmajor -eq "6.0.0") {

 # Make sure the host is ESXi 6.0.0 Update 2
 If ($esxupdate -gt "1") {

 # Grab the current SwapThickProvisionDisabled Setting
 $Setting = Get-AdvancedSetting -Entity $ESXHost -Name "VSAN.SwapThickProvisionDisabled"

 If ($Setting.Value -eq "1") {

 # Display the current setting
 Write-Host " $ESXHost is set for Thin Swap Files " 

 } else {

 # Display the current setting
 Write-Host " $ESXHost is set for Thick Swap Files"
   }
  }
  }
 }
}

Pointing this script at my vCenter, I see the following:

getvsanthin

 

My hosts are set to SwapThickProvisionDisabled = 0, for Thick Swap Files.

Another script Set-VSANThinSwap.ps1 changes that setting to SwapThickProvisionDisabled = 1.


<pre><#================================
Script Name: Set-VSANThinSwap.ps1
Created on: 2/21/2016 
Created by: Jase McCarty
Github: http://www.github.com/jasemccarty
Twitter: @jasemccarty
Website: http://www.jasemccarty.com
====================================</pre>

.DESCRIPTION
This script will go through each host in a cluster set /VSAN/SwapThickProvisionDisabled to Thin Provisioned Swap Files

.Notes
This is only applicable to ESXi hosts with Virtual SAN 6.2 or greater
#>

# Must be connected to vCenter Server 1st
# Connect-VIServer

# Get each cluster managed by vCenter Server
Foreach ($Cluster in (Get-Cluster |Sort Name)){

# Display the Current Cluster
Write-Host Cluster: $($Cluster.name)

# Cycle through each ESXi Host in the cluster
Foreach ($ESXHost in ($Cluster |Get-VMHost |Sort Name)){

# Grab EsxCLI content to check for proper host version
$esxcli = Get-EsxCli -VMHost $ESXHost

# Grab the major host version
$esxmajor = $esxcli.system.version.get().version

# Grab the update version
$esxupdate = $esxcli.system.version.get().update

# Make sure a version 6.0.0 host is being checked
If ($esxmajor -eq "6.0.0") {

# Make sure the host is ESXi 6.0.0 Update 2
If ($esxupdate -gt "1") {

# Get the current setting for SwapThickProvisionDisabled
$SwapThickProvisionDisabled = Get-AdvancedSetting -Entity $ESXHost -Name "VSAN.SwapThickProvisionDisabled"

# If Swaps are Thick, set them to thin
If($SwapThickProvisionDisabled.value -ne "1"){

# Show that host is being updated
Write-Host "Updating VM Swap Thin Setting for $ESXHost"
$SwapThickProvisionDisabled | Set-AdvancedSetting -Value 1 -Confirm:$false
} else {

# Show that the host is already set for Thin Swap Files
Write-Host "$esx is already configured for Thin Swap Files"
}
}
}
}
}

And now each host will apply a space reservation of 0% to the .vswp files upon VM power on.

Screenshot 2016-02-24 10.41.06

Keep in mind that VM’s will have to be powered off to have the .vswp file space reservation policy change from 100% reserved to 0% reserved.

These scripts are have been combined into a single script available on the VMware Developer Center: https://developercenter.vmware.com/samples?id=1665

6 thoughts on “Virtual SAN 6.2 & PowerCLI – Sparse Virtual Swap files

  1. Nice scripts. They will prove useful I’m sure.

    This setting could also be audited/managed by Host Profiles correct?

    I think there might be a bug in your last command of the Set-VSANThinSwap.ps1 script – you used $esx as your host variable instead of $ESXHost. It didn’t show up in your output because all of your hosts needed to be modified so nothing matched the else condition of your if statement. 🙂

Leave a Reply to Aaron Wilk Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.