Anyone that has to work with LUNs and Datastores with VMware should know the term.
If not, here’s a quick refresher:
You have a 2TB datastore that has a single VM with two drives. A C: drive that is 50GB and an F: drive that is 150GB.
You are using thick provisioning on the VM side, but thin on the SAN side.
The SAN says that you are currently using 200GB of space. Easy.
Now, you create a snapshot before applying patches. That snapshot is left alone for a few days, and grows to about 50GB in size.
Check the SAN – it says that you are currently using 250GB of space.
Delete that snapshot and presto! What does the SAN say you are using now?
… 250GB!
Wait! How is that possible? We just deleted that snapshot data, so we should be back to 200GB in use.
This excess space is considered Phantom Space. It’s no longer being used by VMware, but the SAN still sees it and holds on to that space.
The same thing happens if you create a new VMDK file and then later delete it.
How can you reclaim this Phantom Space? Ask most SAN Engineers and they’ll tell you that you have to migrate anything remaining on the datastore to a new one and delete the old datastore.
Thats not so easy if you have to move lots of VMs. Plus, the next time you create a new snapshot, your right back where you started with excessive phantom space.
What to do? Powershell to rescue!
$vc = "vcenter" $vmHost = "esxi01" $nacon = "netapp3" $vol = "T3V_0128" $lun = "t3L_0128" $path = "/vol/$vol/$lun" $Size = 800 Connect-VIServer $vc | Out-Null Connect-NaController $nacon | Out-Null $DSData = Get-NaLun $Path $BeforeUsed = "{0:N3}" -f ($DSData.SizeUsed / 1024 / 1024 / 1024) $esxcli = Get-EsxCli -vmhost $vmHost $esxcli.storage.vmfs.unmap($Size, $lun, $null) $DSData = Get-NaLun $Path $AfterUsed = "{0:N3}" -f ($DSData.SizeUsed / 1024 / 1024 / 1024)
The snippet of code above will perform a SCSI UNMAP (old name) or VMFS UNMAP (new name) on a particular datastore. This is a task that should be scheduled and run multiple times per datastore to see any real benefit.
Some things to note:
$Size is how big of a block to work with – This is usually 200, 400, 800 or 1600. The bigger the block size, the more IOPS will be committed to the process. Be careful when using in a production environment and be sure to test!
$BeforeUsed is simply the amount of space the SAN says is in use before the VMFS UnMap command is run.
$AfterUsed is simply the amount of space the SAN says is in use after the command completes.
$lun and $vol are CASE Sensitive!
If there is any interest, I’ll add a new post with some samples of how to use this process in a scheduled task.