Defragmenting VMs for Performance

If you’ve worked with virtualization long enough, you may have noticed that performance can degrade over time.  This phenomenon is related to disk fragmentation, particularly in scenarios where a lot of software installation, removal, and updates are performed.  As you might imagine, this is the situation for many test environments and development environments.  To recover lost performance capabilities, try defragmenting your virtual machines.  Note that there is a special process involved when defragmenting virtual disks, though.  Let’s dig into that process using VMware Workstation and Microsoft Windows Server hosts and guests as an example.

Why Fragmentation Slows Performance

First, let’s discuss a high-level view of why fragmentation creates performance problems for computers.  Because of the physical arrangement of many of today’s hard disks (ones with spinning magnetic platters), the optimum performance is achieved when data can be written to the disk, and read from the disk, in contiguous blocks.  When data is located randomly across the disk, the read/write head has to travel in and out on the platters as they spin, creating a lot of travel time that isn’t spent reading or writing data.  Overall, this means that it is slower to read and write files to the disk.

Fragmentation and Virtualization

Fragmentation of data on a virtual disk is slightly different from fragmentation on a physical disk.  This is because virtual disk fragmentation takes place at both the virtual and physical layers.  Consider a file like Drawing.dwg that is stored in the virtual machine.  After analyzing the file with a defragmentation utility like Windows’ built-in defragmenter, Diskeeper, or Defraggler, you may find that the file is divided into four fragments.  What you can’t tell from the defrag software on the virtual machine is how fragmented the virtual disk is on the host’s physical disk.  Perhaps that file is fragmented into 3 pieces.  The image below diagrams how this layering effect can compound the issue of fragmentation (four virtual fragments become six physical fragments).

Because of this layering effect, you need to take multiple steps to defragment a virtual machine.  You need to defragment the virtual disk, and then defragment the physical disk.  Defragmenting the virtual disk frequently requires two steps – running a defrag utility inside of the guest operating system and then using your virtualization software’s tools to defragment its virtual disk files.  Defragmenting the physical disk is a repeat of the first part of the virtual defragmentation – running a defrag utility inside of the host operating system.

Step 1 – Defrag the Guest

The first step is to defragment the operating system inside of the guest virtual machine.  You can use any number of tools to do this like the built-in Windows defrag utility (shown below), Diskeeper, or Defraggler.

Step 2 – Defrag the Virtual Disk

The second step is to shut down the virtual machine and run the virtualization software’s disk defrag utility.  In VMware, this tool can be accessed by double-clicking on the virtual disk in the Devices tab, and selecting the Defragment command from the Utilities button.

The virtual disk file is then defragmented by VMware Workstation.

This completes defragmentation of the virtual disk file, and results in a situation like the image below:

Step 3 – Defrag the Host

The last step is a repeat of step 1, but the defragmentation is performed on the host machine’s operating system.  After this step is complete, the fragmentation situation should look more like this:

Of course, there are a number of things that you can do to improve virtualization performance, but defragmentation is a common problem with VMs.  If you have other tips or tricks for improving VM performance, please leave us a comment below or contact us to share your knowledge.

Tags: , , , , , ,

Read more posts by

This entry was posted on Wednesday, March 31st, 2010 at 4:30 pm and is filed under Platform Technologies, Technical Tips, Utilities. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.