Sizing memory for virtual machines appropriately

Sizing memory for virtual machines appropriately

Rate This
  • Comments 9

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

Leave a Comment
  • Please add 2 and 6 and type the answer here:
  • Post
  • 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?
  • > 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).
  • 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
  • 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
  • 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
  • You've stated that VPC pins the memory so it's not swapped.

    I'm often doing development, and have a VPC instance running in the background. While I'm not using it, I pause the VPC. I know this opens up a lot of CPU cycles, but is the memory un-pinned while it's paused?

    I'm on a 1.5 GB box, but w/ VPC running and VS 2003, there's not a lot of room :-)

    Also, why can't you see where VPC's memory is in the task mananger? If I've got a 384mb Virtual machine running, why doesn't the VPC process show that memory?
  • > Excessive paging == bad

    > 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).


    If you're trying to keep your virtual machine images / snapshots / deltas as small as possibly any paging can be bad as it can increase the size of your saved virtual machines just because you happened to be using a lot of memory at a certain moment in time.

  • > Excessive paging == bad

    > 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).


    If you're trying to keep your virtual machine images / snapshots / deltas as small as possibly any paging can be bad as it can increase the size of your saved virtual machines just because you happened to be using a lot of memory at a certain moment in time.

  • I have a problem with virtual memory. i have 256 MB RAM.wt should i do?

Page 1 of 1 (9 items)