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:
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).
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.
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.
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:
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.
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.
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
Comments
- Anonymous
September 22, 2005
Excellent post!
The only question is what are the optimal sizes for all of the main OSes Virtual PC had in the Wizard menu? Is 128 MB good enough for XP and 64 MB for Windows 98? - Anonymous
September 22, 2005
> Virtual PC and Virtual Server wire down the
> memory that they use for each virtual machine
That is true. And therefore:
> If a guest operating system needs to page
> excessively then it is going to cause that
> virtual machine to run slowly.
Actually it will also cause the the real machine to run slowly, because the real machine's excessive paging will be competing with the guest machine's excessive paging and everyone will lose.
VPC User asked:
> Is 128 MB good enough for XP and 64 MB for
> Windows 98?
That depends on what you want to do in them. To run VS2005 (where VS = Visual Studio) betas, I needed a minimum of 256 MB for a release build of XP in a guest machine, or 384 MB for a checked build. To run a few simple executables that I built and just verify whether they run in Windows 98, 64 MB was enough for those guests (and probably 32 MB would be enough). - Anonymous
September 22, 2005
To fully understand your explanation: "Repeat the above process inside of each of the virtual machines that you intend to run."
I have a virtual machine currently allocated 523MB and available 324MB. (all needed applications running)
Will this mean +/- 300MB of memory would be enough?
(523-324+100=299)
And what about the page file on the virtual machine? Is there also a golden rule...
Ray - Anonymous
September 22, 2005
Norman -
Your point about guest paging is only true if the host is paging as well. If you have enough memory for the host - but not enough memory for the guest then only the guest will page and the host will be fine.
Ray -
Yup - that is what I mean. As for the page file in the virtual machine my advice is always to let Windows manage the page file. It knows what is best to do.
Cheers,
Ben - Anonymous
September 22, 2005
Would also be nice to hear about CPU sizing. Its usually quite hard to know how much processing power you need on a host when you consolidate phisical servers into virtual ones.
Any tips and trick on this matter?
Simon - Anonymous
September 23, 2005
The comment has been removed - Anonymous
September 24, 2005
The comment has been removed - Anonymous
September 24, 2005
The comment has been removed - Anonymous
October 15, 2011
I have a problem with virtual memory. i have 256 MB RAM.wt should i do?