Sizing memory for virtual machines appropriately

For some of you reading this - this post will seem like I am stating the obvious - however the question of how to determine the correct amount of memory for a virtual machine is one that gets asked of me quite regularly. To answer this question I am going to have to set some background:

  1. Excessive paging == bad

    To be completely clear here, paging (the act of using physical hard disk space as a slow backing store for memory) in and of itself is not a bad thing. In fact it is very good. What is bad is when you configure a system with so little memory that it is forced to page excessively. This will result in the entire performance of your system being bottle necked around the speed of your hard disk (which is about the slowest thing in your system).

  2. Virtual PC / Virtual Server use memory differently to most applications

    Most applications use memory in a fashion that allows the operating system to 'page them out' if it needs to use their memory for something else. Doing this does cause things to be slower - but it is handy none the less. However, Virtual PC and Virtual Server wire down the memory that they use for each virtual machine so that the host operating system cannot reclaim it - no matter how much it needs it - while the virtual machine is running.

  3. Excessive paging in the guest operating system == bad; excessive paging in the host operating system == really bad

    If a guest operating system needs to page excessively then it is going to cause that virtual machine to run slowly. But if the host operating system needs to page excessively then everything (virtual machines included) is going to run slowly.

  4. Once you have sufficient memory for your working set, adding more memory will not make it run faster.

    If you are trying to run to many applications at the same time on an operating system, and do not have enough memory for them all, you will see excessive paging in the operating system. In this scenario adding more memory will speed things up as paging is reduced. However once you have sufficient memory, adding even more memory will not make the system run any faster, it will simply allow you to run more applications concurrently. The real thing to remember here is that the point of having more memory is to allow you to run more programs simultaneously, not to speed up the system.

With all of this in mind - here are my recommendations:

  1. On the host computer: Clean boot the computer and configure it the way you usually use it (e.g. for me this means having Outlook, Internet Explorer and Windows Media player open). Then check the Performance tab under Task Manager for how much physical memory is available (on my work system with 1GB of ram this is 600mb). Now plan to leave an extra 50 - 100mb available for any other programs that you may launch as you are using the system. This means that I should plan on using 500 - 550mb of memory for my virtual machines.

  2. Repeat the above process inside of each of the virtual machines that you intend to run. The interesting thing about virtual machines is that they tend to be a lot my 'single task focused' than physical computers are (e.g. I am not running Outlook inside of my virtual machine) and this means that you can regularly trim back on the ammount of memory needed. For instance; I have an IIS server setup that I use for demos - but it is an IIS server which only serves 500k of static pages and is only ever hit by one client (one of my other virtual machines) so I can run it with 192mb of memory quite comfortably. Remember that giving more memory to this virtual machine will not make it run faster and may end up starving the host of memory and even degrading performance as a result.

  3. Add in a per-virtual machine overhead of ~25mb of ram.

Once you have done this you should be using you memory in an optimal fashion.

Cheers,
Ben