A random Hyper-V forum issue is that of defragmentation - an often used practice to improve performance of disk IO on a physical system.
The intent of this article is to discuss the issues around fragmentation in a virtualized situation as well as provide some community best practices.
The content of this article has been gleaned from a forum post and requires edit for clarity.
Q: Is there any reason to run a defrag within a virtual machine that resides on a SAN? I create fixed disk VMs, but with the vhd's being spread across a shared RAID-5 LUN it
seems as though the defrag job would only create additional I/O load on the SAN without offering the I/O performance improvement one would expect in a single disk environment.
A: If the virtual disk is fixed, then there is little chance of the virtual disk binary file becoming fragmented on the SAN - however, within the virtual disk file the operating
system behaves the same way and will create fragmentation within the virtual disk itself.
The fragmentation within the virtual disk is caused by the OS running in the VM. The fragmentation at the storage level is generally caused by having many dynamic disks on the same physical volume.
In my mind, we can look at storage level fragmentation the same as we look at the performance degradation from snapshots. A snapshot chain of many little snapshot files is fundamentally no different than binary fragmentation of
a single, dynamic, VHD.
Is a rule of thumb we generally do not see that much fragmentation within the virtual disk of a VM, because the life of a VM is relatively short. Thus the system is more frequently rebuilt instead of patched during its three year
life than was the general practice with physical machines.
The cases where high fragmentation can be seen is when a P2V process performs a block by block copy of a physical drive to a virtual disk - instead of a file by file copy (thus defragmenting by nature) - and where there is a large
amount of read and write activity within the VM - or the VM has a very long life (this is the same case or physical machines).
Q: Rather than how fragmentation occurs, I am trying to determine whether there is any benefit from running a defrag from within a VM if the guest OS perceives the virtual disk
to be fragmented. Basically, is there any reason to care about fragmentation in this scenario?
As soon as I create a fixed VHD and place the file in a SAN volume the file will be spread across multiple disks. Given this physical fragmentation of the VHD, running a defrag within a virtual machine would really just shuffle
around logical blocks on multiple physical disks without necessarily improving I/O performance. Frequently accessed blocks could be moved to slower sectors.
So taking this line of thought, a VM with a fixed disk on a SAN that shows little to no fragmentation should have the same I/O performance as a VM with a fixed disk on a SAN with a high level of fragmentation. Am I off base with
A: This very issue so far has been a debate of personal preference - this is why I took the time to describe it. Personally, I think it worth anyone understanding and making
a personal decision.
The striping of the binary VHD file across the various disks of a SAN, yes, technically is fragmentation, however that is not fragmentation that we generally concern ourselves with. As it is managed by hardware and it is the responsibility
of the hardware to optimize the reads and writes.
Since were are talking fixed VHD in your example, we actually have very little to no chance of fragmentation of the VHD binary at the file system level (the NTFS storage volume where the VHD resides - not the underlying distribution
of the binary across the spindles). Most folks defragement here - especially if they use dynamic virtual disks.
Within the VHD - that is where most of the debate is. Is there value defragmenting here.
Personally, I see value in defragmenting within the VHD, but at the same time I only see at as an action that needs to be performed occasionally to rarely. It does help to optimize the OS in the VM.
My thinking is that if you have fragmentation inside fo the VHD, then you have a third tier of fragmentation - inside (VM OS), outside (LUN file system), and physical (SAN RAID configuration). And it would seem to me that as you
add more fragmentation you increase spindle seeks. However, as the sheer speed of spindles and heads increases - the actual performance gain from defragmentation is diminished. So there is the technical way of looking at this as well - do you gain performance?
Most storage folks would say that there is really no gain in performance and thus it is a waste of time. Most old time admins say to do it. My personal preference is middle between the two.
I have seen where a fragmented disk within the VM can cause horrible performance issues. clearly, keeping the disk inside the VM defragmented is required.
Where the virtual disk container is a *fixed* virtual VHD, it is true that you should consider defragmenting at all levels even though I've rarely seen normal NTFS framentation to have a particularly noticeable performance drag.
Where dynamic disks are used, the disk's physical layout is not visible to the guest OS, as a secondary logical mapping layer controls how the physical disk is used. Without this mapping you would not have the key feature of a dynamic disk - the capability of the physical VHD files being smaller than the reported size of the disk the guest OS receives. Even if the guest writes a few files at the 'logical' end of the disk, the disk does not need to expand to the full size.
So, with this logical / physical disconnect, normal guest defragmenting programs will seemingly work, but they are only defragmenting the logical view, usually increasing the fragmentation of the physical layout and generally expanding the size of the VHD. Without specialist defragrmenters that understand dynamic disks, a common technique is to use something like Ghost to copy from the existing VHD to a new VHD. As it copies at a file level, when the data is written to the new VHD it will allocate these sequentially. The new VHD may still need to be defragmented by the host.
Thanks for amazing information.