-4

I have virtual machine windows server 2008 which stands on Oracle VM VirtualBox. I declare 8GB of RAM for this machine.

On my host machine (windows 7) I have 16GB of RAM. When I start virtual machine and look on host machine task manager I see 8GB RAM allocation and I have 8GB RAM allocated for virtual machine and circa 3 GB (rather less) allocated for host system.

When I start application on my windows server and look on my host machine a graph shows 11GB already allocated but in details windows (physical memory) there is only 4MB free. With 4MB free RAM memory on my host system virtual machine start doing operation on my hard drive. Why my virtual machine (or host system) cannot use RAM correctly? Why my virutal machine uses memory of hard drive instead of RAM?

  • 2
    Is your question actually why are all remaining memory "Cached" (or shown as "Standby") instead of "Free" (or, "Cached" memory ~= "Available" memory)? – Tom Yan Mar 25 '16 at 12:19
  • 1
    This is a very frequent misconception : Windows tries to use all memory. There is no such concept as "free memory" - the part of the memory that is not actively being used is always available for immediate allocation. – harrymc Mar 25 '16 at 18:33
  • I don't understand what you're having trouble with. Maybe give this a read brandonlive.com/2010/02/21/measuring-memory-usage-in-windows-7 – Raystafarian Mar 28 '16 at 18:10
1
+100

Answer

The reason launching programs in the VM causes the swap files to be used is because there is too much stuff trying to be in memory on the host. I know you've said the host is using less than 3GB, but that seems like only part of the story, and it may be the host is severely limiting itself due to the massive allocation to the guest VM. Before switching on the guest VM and after letting the host do whatever else it normally does for at least 20 minutes what is the available and cached memory listed as in task manager performance tab?

To increase overall performance, I would reduce the amount of RAM allocated to the VM to about 6GB, to allow the host to have more frequently used data in RAM. I know this sounds counter-intuitive but this will let the guest VM know that there isn't as much RAM available in the whole system and so it will be more frugal in its RAM usage so when it uses the mentality of "all ram should be used for something" it is not filling the host ram with useless garbage because the guest vm no longer thinks there is plenty of ram. Reducing the guest VM ram allocation will mean that the host won't have to use hdd swap space to provide the vm its full ram allocation. Note that the processes tab in task manager has many different "memory" classifications available in the view->select columns screen.

I find that when task manager reports that cached memory is low, this is a cause and effect of the whole system being slow. For my usage patterns on an 8GB machine I find that if the machine is running with less than 33% of its physical ram as cache it is intolerably slow. So for you I'd round that up to 6GB for cache 6GB for the VM and 4GB for the host. You may find that the guest VM needs to have its ram reduced even further due to the ram requirements on the host, though don't go too far or the guest VM will be using its swap file too much. Having adequate cache is a must for performance, for both guest VM and host. Though I have noticed the 32gb remote desktop server at work gets by with only 4-6GB of cache.

Additional Info

In windows task manager

  • Total memory = physical ram that windows can use (some hardware can use/share physical memory like some graphics hardware)
  • Cached memory = stuff windows has in ram just in case something needs it, plus stuff that it needs to finish writing to the hdd.
  • Available memory = what you should consider as usuable
  • Free memory = wasted memory that is currently used for nothing. You should ignore this value, unless it stays a big number, then windows is broken. It should slowly decrease as more and more ram is made useful.

There are some relationships between them, particularly if you delve into the details available from the resource monitor and/or the MS Sysinternals utility RAMmap.

  • Taskmanager cached = resource monitor standby + modified
  • Taskmanager Available = resource monitor standby + free + zeroed
  • Taskmanager free = resource monitor free + zeroed

It is important to understand that standby memory can be immediately discarded and reused for something else, which is why it is considered as available. If windows is doing nothing else, and there is free and/or zeroed ram it will slowly read stuff from the hdd in to the cache and mark it as standby memory. This makes the ram useful for something instead of just being wasted.

All OS developers should rename the "free ram" metric to be "wasted ram"

As you open programs on either the guest or host OS, the host OS needs to open files or parts of files from the hdd. Note that the guest hdd is a file on the host machine, that gets read from and written to by the host process that runs the VM. The host OS will cache that information as it is read, and if there was still wasted (aka free) memory on the host it will be kept in memory as standby data. Also note that the cache system does not have to cache a whole file, it can cache just parts of it, this is how an 80GB+ file can have parts of it in the 16gb of ram that the host has.

The host and guest OSes balance what memory programs are wanting to allocate with providing cached data of the files on the hdd. Often, programs allocate some memory that they need very rarely, while they make frequent demands of the files on the hdd. The OS uses the swap file on the HDD to store that infrequently used program info in, so it can have more ram available for caching files. The only way the OS can decide what to have in RAM and what to leave on the HDD is with statistics of how often that piece of info is requested or written to. This includes parts of the VM hdd file that the host OS may want to cache.

If your VM needs to use files from its vhdd, like opening programs, that translates to the host os having to read/write from/to the file that contains the vhdd. If the guest VM is busy this makes the host machine busy too.

0

You paid for the RAM, so Windows is using it. There's enough free to immediately satisfy any request, and Windows can quickly free up more if needed.

Windows is also using your harddisk before it's strictly needed. This isn't instead of RAM, but in addition to.

  • I have 16GB RAM on host. 8GB are constantly allocated for VM, 3GB are constantly allocated by host OS, so I should have 3GB of free memory on host system. On virtual machine in task manager I have 8GB RAM total memory and system uses circa 3GB. When I start application on my VM, I see on my host that I don't have free memory (only 4MB) so VM uses hard disk memory. It's a problem because HD operation is more slowly. I would like to use only RAM on my VM, because I see on task manager and resource monitor that there is a lot of free space. Only on details windows I see 4MB free space. – ElConrado Mar 23 '16 at 10:07
  • I have total RAM on host 16GB, cached 5GB, Available 3GB and free 0MB when I started application on VM. So VM, as you said, additionaly use HD memory. – ElConrado Mar 23 '16 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.