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 are 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:
1 |
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.
*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.
*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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
<#================================ 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 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:
My hosts are set to SwapThickProvisionDisabled = 0, for Thick Swap Files.
Another script changes that setting to SwapThickProvisionDisabled = 1.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
<#================================ 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 ==================================== .DESCRIPTION This script will go through each host in a cluster and 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.
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.
If you want to change the setting back, the (another) script will change the setting back to the default.
I hope this script helps better use this advanced Virtual SAN 6.2 feature to reclaim some space.
These scripts are have been combined into a single script available on the VMware Developer Center: https://developercenter.vmware.com/samples?id=1665
Reposted from jasemccarty.com