16

I've read conflicting advice on this issue so thought I'd ask here.

Should I be running a scheduled defrag within my VM?

MDMarra
  • 100,734
  • 32
  • 197
  • 329
SteB
  • 989
  • 6
  • 15
  • 31

5 Answers5

32

Storage folks refer to VMs as I/O blenders. This is because all of the guest's files are typically inside of a "container" like a VMDK. This VMDK is a single file that contains all other files used by the VM.

Consider that an 80GB VMDK might not have all block allocated sequentially on the disk - this is even more likely if you're using thin provisioning. By running a defrag inside of the VM, you're not actually making the files sequential on the physical disk, you're making them sequential inside of the container and that container is likely not sequential on the physical disk. Basically, in a lot of cases it's a waste of time and performance gains are very minimal at best.

MDMarra
  • 100,734
  • 32
  • 197
  • 329
  • Thanks, I'm primarily interested in the performance aspect. – SteB Oct 19 '12 at 13:04
  • @SteB ...that's exactly what my answer is about. The increase in performance is directly related to being able to perform sequential reads/writes instead of random reads/writes on the physical disk. If the container is fragmented, then you're not really doing anything useful to the files inside of that container. – MDMarra Oct 19 '12 at 13:07
  • 2
    If you're going to compact a dynamic VMDK (or any other virtual HD file) you generally have to defrag it first to get correct results. Other than that, no reason to run defrag ever, the performance gain is completely negligible. – Chris S Oct 19 '12 at 13:11
  • Is it theoretically possible for a guest's HD to be "fragmented" (as the VM sees it) badly enough for split I/O to become a problem inside the VM? That would be one of very few use cases I can think of for defragmenting inside a VM. I'm not sure how a VM would get to that state while still being otherwise useful though. – afrazier Oct 19 '12 at 14:00
  • @afrazier Sorry, I don't understand what you mean. The performance won't be any worse than a physical disk that's fragmented. – MDMarra Oct 19 '12 at 14:15
  • In my case I P2V'd an existing system running on an SSD and stored the vmdk on an HDD. The guest OS was fragmented by 20+%. After trying everything to speed up I/O performance to no avail I finally ran the Wndows 7 defragmenter from within the guest OS. There was an instant and dramatic performance gain. The boot time of the guest OS dropped to 50% of what it was prior to defragmenting. – Brian Gideon May 02 '15 at 04:03
7

If you allocated all disk space on creation and defragment that file on your real disk and then defragment the virtual disk then I expect to see a small advantage.

@MDMarra's explained perfectly why it makes no sense to just defragment the virtual disk. No way to improve that.

Hennes
  • 4,842
  • 1
  • 19
  • 29
1

As a real answer, I've never seen much impact from defragging virtual machines. That being said, if you are going to potentially shrink the drive at some point, you would want to defrag to help with that process.

Driftpeasant
  • 3,217
  • 2
  • 22
  • 28
1

If defragmenting is your goal, here's what you can do:

  1. Shutdown your guest OS. Proper Shutdown, not Suspend

  2. In the VM Ware Player Window click on the Guest OS once and click on "Edit Virtual Machine"

  3. In "Hardware" tab click on "Hard disk". On the right side you will see a button named "Utilities". Clicking it will give you a drop-down menu. Select "defragment".

I have a Ubuntu 12.04 Guest OS and I must say, I did not see any performance difference after defragmenting.

Oliver Salzburg
  • 4,635
  • 17
  • 55
  • 82
Yash
  • 111
  • 3
  • Ubuntu uses ext4 by default, which does not normally fragment, so there is no need to de-frag ext3/4, and you won't aim any advantage if you do, in physical or virty – Rqomey Oct 25 '12 at 20:30
-2

Even though the Windows XP is on VMWare Player, the maintenance of that OS should be carried out the same for best performance.

Even if you have defragmented the VM HD you will also have to make sure that the VHD file is defragmented fully on the host OS otherwise this will not have the best effect.