Force an Azure Storage optimize for a VHD to reduce storage cost
Force an optimize in your Azure VMs after a big delete to reduce your Azure Storage costs.
April 21, 2015
Q. I have deleted a number of files in my Azure VM, how can I ensure I no longer pay for that deleted space?
A. Azure Storage uses sparse storage behind the scenes. This means that even though VHDs in Azure are fixed in size and allocates the space at creation time, the only space actually allocated on the Azure Storage is the space that has data written to and therefore that is what you are charged for. If you have a 500 GB VHD and only 20 GB written to it you only pay for 20 GB. If you then wrote 100 GB of data and then deleted that data, the TRIM functionality is implemented which would mean that behind the scenes the storage would be notified. The blocks representing those files are no longer needed and would be removed from Azure Storage and therefore you would stop paying. The amount of time taken for the space to be reclaimed varies as a job runs inside Windows to perform an optimize. If you wish to force the trim to occur immediately you can run the following PowerShell scriptlet.
Optimize-Volume -DriveLetter -ReTrim
Note that this trim action depends on the OS. For example Windows Server 2012 and 2012 R2 both support trim for the OS and data disks while 2008 R2 would only trim on the OS drive since TRIM is not supported on SCSI (which is how data disks attach in Azure). Linux would depend on the specific version and distribution.
About the Author
You May Also Like