Choosing the right format for the right scenario is critical when it comes to performance and management of virtual hard disks (VHDs). We'll look at the pros and cons of the three methods -- fixed, pass-through and dynamic disks -- and highlight some necessary steps to maintain VHDs and reduce unnecessary I/O in your virtual environment.
Pass-through disks: Best performance, greatest loss of benefits (Hyper-V only)
In short: Pass-through allows Hyper-V VMs to directly access physical hard drives.
Pros: One major advantage of Hyper-V is its inherent ability to directly access the host's hardware (Type 1 Hypervisor).There's no need to handle the virtual hard disk layer, which, thanks to a decrease in CPU utilization, gives you the best performance of all three choices. There's also the advantage of mapping a SAN (Storage Area Network) unit to Hyper-V, giving you more flexibility. Another plus: You're not stuck with Hyper-V's current 2 TB VHD limit -- you can essentially throw in multiple TB hard disks and use within your virtual machines. If your scenario requires such massive storage options at maximum performance, you are basically forced to use pass-through (or wait for Hyper-V 3.0).
[ Windows 8 Hyper-V and MinWin: A game changing strategy? | Sign up for ITworld newsletters ]
Cons: In most scenarios, however, the possible downsides outweigh the benefit. First of all, you lose the ability to take snapshots, which is a no-go for some admins. Second, the physical hard disk must be taken offline -- you must exclusively use it with your Hyper-V machine, as outlined here.
Fixed VHDs: Great performance and portability
In short: Fixed-size VHDs occupy a pre-defined amount of disk space.
Pros: A fixed-size VHD has the best performance of all virtual hard disk formats; there's barely a difference in speed when compared to the pass-through method. For an extremely advanced performance analysis of VHDs, check out this Microsoft whitepaper entitled "Virtual Hard Disk Performance" (35 pages of pure performance considerations for all three disk formats). Obviously, having a single VHD file that contains all VM data makes it easy to manage, migrate and backup. Besides, by imposing a limit to its size, the VM is in no position to run amok and eat up your physical server's hard disk space, which might bring it down (and other VMs with it!).
Cons: Creating a fixed size VHD takes a bit of time as Hyper-V needs to zero out the allocated space in order to create the VHD file. However, Microsoft greatly improved disk creation performance with R2, so this is only an issue if you're deploying new VHDs regularly. And keep in mind: the size of your VHD needs to be calculated based on your needs in order to avoid wasting disk space or running into problems later.
Dynamic VHDs: Good performance and saves space
In short: Dynamically sized (or differencing) VHDs expand based on current needs. They always start at a couple of KB and expand as the OS, applications and data get written to the VM.
Pros: Dynamic disks were often frowned upon. That changed a bit when Hyper-V 2 came out as part of Windows Server 2008 R2, which sported improved performance of dynamic VHD files. According to this MSDN post, writes to a fixed drive were up to 3x faster than writes to a dynamic drive in WS08 SP2 when compared to R2. A dynamically sized VHD sports good overall performance (still a bit lower than a fixed drive) and it also saves disk space -- if that is an issue in your scenario. And you can use the VHD compactor to reduce its size again.
Cons: During the expanding process, write performance still suffers momentarily. If your VMs need to deliver top performance 24/7, you should consider going with a fixed-sized VHD.
Optimizing your server for virtual storage
Now that you've chosen the right format -- and installed the proper guest OS -- it's time to make sure that Hyper-V and your applications don't get bogged down by unnecessary I/O operations and that VHDs are regularly maintained. Remember, disk I/O inside a VM has more impact on overall performance than on your physical rig, which is why it's essential to keep all unnecessary I/O operations down to a bare minimum:
Tip 1: Adjust the I/O bandwidth algorithm (host machine)
When using more than one VM, Hyper-V balances I/O response times between the machines. It essentially prevents one busy VM from bogging down another (less-busy) VM. The I/O balancer's settings are located under the following registry key:
If you don't want this balancing algorithm to be active at all, you can simply disable it by creating a DWORD value called "IOBalance_Enabled" and set it to "0" -- use this only if you don't care that one VM might negatively affect another, while under heavy stress. To adjust the balancing mechanism, simply create the DWORD "IOBalance_KeepHwBusyLatencyTarget_Microseconds". This entry controls how much of the total I/O operations can be processed before throttling takes effect -- you need to define a latency value (ms); the default is "83" (ms). The lower you set this value, the better the balancing, but it comes at the price of throughput.
The last DWORD value I'd like to mention here is "IOBalance_AllowedPercentOverheadDueToFlowSwitching". It defines at what percentage of disk utilization of one VM the balancer moves on to reduce the throughput of another VM. By default, its threshold is defined at 8% overall utilization in order to treat VMs equally. Before changing any of these values, I suggest running thorough speed tests using IOMeter, which has proven to be a reliable performance test tool for virtual machine environments. Carefully evaluate performance before and after changing the value.
Tip 2: Disable typical disk thrashers (Guest OS)
If you decided to run a client Windows OS (such as Windows 7) in Hyper-V, you need to turn off some features that will cause performance to drop -- all of which are not enabled by default on Windows Server 2008 R2. First, turn off SuperFetch. What makes sense on a client (with little workload and smaller data operations), might literally destroy performance on a virtual server. Same goes for Windows Search, which has a habit of constantly indexing files and causing I/O operations that just aren't necessary in about 99% of VM scenarios. Both SuperFetch and Windows Search can be disabled using "services.msc". Also, check out Windows Task Scheduler and go through the list of scheduled tasks (there are several dozen active!) and see which are necessary or not. Hint: Again, most of them -- such as error reporting or Media Center update tasks -- don't make any sense in your virtualized environment. In all of these cases, right-click and "Disable"!
Tip 3: Chkdsk and Defrag (Guest OS)
Are Disk Defragmenter and Checkdisk really necessary inside a VM? Yes, they are! But there are some caveats: Checkdisk only helps if data and the file system inside the VM got corrupted (for example, due to a power failure). It can't recover a defective VHD header. The Virtual PC Guy Ben Armstrong gives great advice on what chkdsk can and cannot do to help fix VHDs.
Defragmenting is always a good idea on the physical hardware (which avoids bottlenecks when accessing the often huge VHDs) and also helpful inside the VM, if you're using a fixed-size and dynamic VHD. The virtual disk's file system behaves the same as it would on a physical machine -- fragmentation will occur eventually.
This article, "Hyper-V & virtual PCs: How to handle virtual disks," was originally published at ITworld. For the latest IT news, analysis and how-tos, follow ITworld on Twitter and Facebook.
Sandro Villinger is a contributor to ITworld. For more by Sandro, see: Windows won't boot? Try these tips and 15 incredibly useful (and free) Microsoft tools for IT pros.