{"id":3455,"date":"2016-02-24T12:58:32","date_gmt":"2016-02-24T18:58:32","guid":{"rendered":"http:\/\/www.jasemccarty.com\/blog\/?p=3455"},"modified":"2017-01-20T15:11:47","modified_gmt":"2017-01-20T21:11:47","slug":"vsan62-powercli-sparse-vswp","status":"publish","type":"post","link":"https:\/\/www.jasemccarty.com\/blog\/vsan62-powercli-sparse-vswp\/","title":{"rendered":"Virtual SAN 6.2 &#038; PowerCLI &#8211; Sparse Virtual Swap files"},"content":{"rendered":"<p>One of the Space Efficiency features of Virtual SAN 6.2 that is available for <strong><em>both All-Flash and Hybrid configurations<\/em><\/strong>, 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\u00a0Lazy Zeroed Thick (LZT).<\/p>\n<p>Virtual Swap files (.vswp) are created when a virtual machine doesn&#8217;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\u00a0configured, 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.<\/p>\n<p><!--more-->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&#8217;m thinking a small VDI deployment) with no reservations, would require 200 x (4GB + 4GB) or 1.6TB of space. That&#8217;s significant!<\/p>\n<p>In cases where there is no memory congestion, and a virtual machine doesn&#8217;t use the swap file, it might be advantageous to have a swap file that is truly thin provisioned (the default in Virtual SAN).<\/p>\n<p>In Virtual SAN 6.2, we introduced an advanced host setting called SwapThickProvisionDisabled, when enabled, removes the space reservation for .vswp files. \u00a0The generic syntax for this command is:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">esxcfg-advcfg -g \/VSAN\/SwapThickProvisionDisabled<\/pre>\n<p>Having to determine this configuration across more than a few hosts can be a bit of a pain without some scripting\/automation.<\/p>\n<p>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.<\/p>\n<p><a href=\"http:\/\/www.jasemccarty.com\/blog\/wp-content\/uploads\/2016\/02\/thickswap-1.png\" rel=\"attachment wp-att-3458\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3458\" src=\"http:\/\/www.jasemccarty.com\/blog\/wp-content\/uploads\/2016\/02\/thickswap-1.png\" alt=\"thickswap\" width=\"600\" height=\"398\" srcset=\"https:\/\/www.jasemccarty.com\/blog\/wp-content\/uploads\/2016\/02\/thickswap-1.png 880w, https:\/\/www.jasemccarty.com\/blog\/wp-content\/uploads\/2016\/02\/thickswap-1-300x199.png 300w, https:\/\/www.jasemccarty.com\/blog\/wp-content\/uploads\/2016\/02\/thickswap-1-768x509.png 768w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p><em>*Note the .vswp Mirrors don&#8217;t appear in Swap objects, but rather File System Overhead.<\/em><\/p>\n<p>I powered off those virtual machines, changed the SwapThickProvisionDisabled setting, and consumed less than 4GB of Virtual SAN capacity.<\/p>\n<p><a href=\"http:\/\/www.jasemccarty.com\/blog\/wp-content\/uploads\/2016\/02\/thinswap.png\" rel=\"attachment wp-att-3459\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3459\" src=\"http:\/\/www.jasemccarty.com\/blog\/wp-content\/uploads\/2016\/02\/thinswap.png\" alt=\"thinswap\" width=\"600\" height=\"400\" srcset=\"https:\/\/www.jasemccarty.com\/blog\/wp-content\/uploads\/2016\/02\/thinswap.png 881w, https:\/\/www.jasemccarty.com\/blog\/wp-content\/uploads\/2016\/02\/thinswap-300x200.png 300w, https:\/\/www.jasemccarty.com\/blog\/wp-content\/uploads\/2016\/02\/thinswap-768x512.png 768w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p><em>*Note the displayed File System Overhead includes mirrors of other virtual machines on the cluster.<\/em><\/p>\n<p>That&#8217;s a huge difference. I could run the above esxcfg command on my hosts, but that&#8217;s a bit problematic. I&#8217;d much rather script this.<\/p>\n<p>So I wrote a couple simple scripts for just that.<\/p>\n<p>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&#8217;t valid with previous releases of vSphere.<\/p>\n<p><strong>Get-VSANThinSwap.ps1<\/strong><\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n&lt;#================================ 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 #&gt;\r\n\r\n# Must be connected to vCenter Server 1st\r\n# Connect-VIServer \r\n\r\n# Get each cluster managed by vCenter Server\r\nForeach ($Cluster in (Get-Cluster |Sort Name)){\r\n\r\n # Display the Current Cluster\r\n Write-Host \u00ecCluster: $($Cluster.name)\r\n\r\n # Cycle through each ESXi Host in the cluster\r\n Foreach ($ESXHost in ($Cluster |Get-VMHost |Sort Name)){\r\n\r\n # Grab EsxCLI content to check for proper host version\r\n $esxcli = Get-EsxCli -VMHost $ESXHost\r\n\r\n # Grab the major host version\r\n $esxmajor = $esxcli.system.version.get().version\r\n\r\n # Grab the update version\r\n $esxupdate = $esxcli.system.version.get().update\r\n\r\n # Make sure a version 6.0.0 host is being checked\r\n If ($esxmajor -eq &quot;6.0.0&quot;) {\r\n\r\n # Make sure the host is ESXi 6.0.0 Update 2\r\n If ($esxupdate -gt &quot;1&quot;) {\r\n\r\n # Grab the current SwapThickProvisionDisabled Setting\r\n $Setting = Get-AdvancedSetting -Entity $ESXHost -Name &quot;VSAN.SwapThickProvisionDisabled&quot;\r\n\r\n If ($Setting.Value -eq &quot;1&quot;) {\r\n\r\n # Display the current setting\r\n Write-Host &quot; $ESXHost is set for Thin Swap Files &quot; \r\n\r\n } else {\r\n\r\n # Display the current setting\r\n Write-Host &quot; $ESXHost is set for Thick Swap Files&quot;\r\n   }\r\n  }\r\n  }\r\n }\r\n}\r\n<\/pre>\n<p>Pointing this script at my vCenter, I see the following:<\/p>\n<p><a href=\"http:\/\/www.jasemccarty.com\/blog\/wp-content\/uploads\/2016\/02\/getvsanthin.png\" rel=\"attachment wp-att-3467\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3467\" src=\"http:\/\/www.jasemccarty.com\/blog\/wp-content\/uploads\/2016\/02\/getvsanthin.png\" alt=\"getvsanthin\" width=\"540\" height=\"141\" srcset=\"https:\/\/www.jasemccarty.com\/blog\/wp-content\/uploads\/2016\/02\/getvsanthin.png 540w, https:\/\/www.jasemccarty.com\/blog\/wp-content\/uploads\/2016\/02\/getvsanthin-300x78.png 300w\" sizes=\"auto, (max-width: 540px) 100vw, 540px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>My hosts are set to SwapThickProvisionDisabled = 0, for Thick Swap Files.<\/p>\n<p>Another script <strong>Set-VSANThinSwap.ps1<\/strong> changes that setting to SwapThickProvisionDisabled = 1.<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n\r\n&lt;pre&gt;&lt;#================================\r\nScript Name: Set-VSANThinSwap.ps1\r\nCreated on: 2\/21\/2016 \r\nCreated by: Jase McCarty\r\nGithub: http:\/\/www.github.com\/jasemccarty\r\nTwitter: @jasemccarty\r\nWebsite: http:\/\/www.jasemccarty.com\r\n====================================&lt;\/pre&gt;\r\n\r\n.DESCRIPTION\r\nThis script will go through each host in a cluster set \/VSAN\/SwapThickProvisionDisabled to Thin Provisioned Swap Files\r\n\r\n.Notes\r\nThis is only applicable to ESXi hosts with Virtual SAN 6.2 or greater\r\n#&gt;\r\n\r\n# Must be connected to vCenter Server 1st\r\n# Connect-VIServer\r\n\r\n# Get each cluster managed by vCenter Server\r\nForeach ($Cluster in (Get-Cluster |Sort Name)){\r\n\r\n# Display the Current Cluster\r\nWrite-Host Cluster: $($Cluster.name)\r\n\r\n# Cycle through each ESXi Host in the cluster\r\nForeach ($ESXHost in ($Cluster |Get-VMHost |Sort Name)){\r\n\r\n# Grab EsxCLI content to check for proper host version\r\n$esxcli = Get-EsxCli -VMHost $ESXHost\r\n\r\n# Grab the major host version\r\n$esxmajor = $esxcli.system.version.get().version\r\n\r\n# Grab the update version\r\n$esxupdate = $esxcli.system.version.get().update\r\n\r\n# Make sure a version 6.0.0 host is being checked\r\nIf ($esxmajor -eq &quot;6.0.0&quot;) {\r\n\r\n# Make sure the host is ESXi 6.0.0 Update 2\r\nIf ($esxupdate -gt &quot;1&quot;) {\r\n\r\n# Get the current setting for SwapThickProvisionDisabled\r\n$SwapThickProvisionDisabled = Get-AdvancedSetting -Entity $ESXHost -Name &quot;VSAN.SwapThickProvisionDisabled&quot;\r\n\r\n# If Swaps are Thick, set them to thin\r\nIf($SwapThickProvisionDisabled.value -ne &quot;1&quot;){\r\n\r\n# Show that host is being updated\r\nWrite-Host &quot;Updating VM Swap Thin Setting for $ESXHost&quot;\r\n$SwapThickProvisionDisabled | Set-AdvancedSetting -Value 1 -Confirm:$false\r\n} else {\r\n\r\n# Show that the host is already set for Thin Swap Files\r\nWrite-Host &quot;$esx is already configured for Thin Swap Files&quot;\r\n}\r\n}\r\n}\r\n}\r\n}\r\n\r\n<\/pre>\n<p>And now each host will apply a space reservation of 0% to the .vswp files upon VM power on.<\/p>\n<p><a href=\"http:\/\/www.jasemccarty.com\/blog\/wp-content\/uploads\/2016\/02\/Screenshot-2016-02-24-10.41.06.png\" rel=\"attachment wp-att-3469\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3469\" src=\"http:\/\/www.jasemccarty.com\/blog\/wp-content\/uploads\/2016\/02\/Screenshot-2016-02-24-10.41.06.png\" alt=\"Screenshot 2016-02-24 10.41.06\" width=\"600\" height=\"328\" srcset=\"https:\/\/www.jasemccarty.com\/blog\/wp-content\/uploads\/2016\/02\/Screenshot-2016-02-24-10.41.06.png 633w, https:\/\/www.jasemccarty.com\/blog\/wp-content\/uploads\/2016\/02\/Screenshot-2016-02-24-10.41.06-300x164.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>Keep in mind that VM&#8217;s will have to be powered off to have the .vswp file space reservation policy change from 100% reserved to 0% reserved.<\/p>\n<p>These scripts are have been combined into a single script available on the VMware Developer Center:\u00a0<a href=\"https:\/\/developercenter.vmware.com\/samples?id=1665\" target=\"_blank\">https:\/\/developercenter.vmware.com\/samples?id=1665<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[135,10,168],"tags":[65,151,152],"class_list":["post-3455","post","type-post","status-publish","format-standard","hentry","category-software-defined","category-storage-2","category-vsan","tag-powercli","tag-virtual-san","tag-vsan"],"_links":{"self":[{"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/posts\/3455","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/comments?post=3455"}],"version-history":[{"count":21,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/posts\/3455\/revisions"}],"predecessor-version":[{"id":3477,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/posts\/3455\/revisions\/3477"}],"wp:attachment":[{"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/media?parent=3455"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/categories?post=3455"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/tags?post=3455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}