Why does my computer use so much of my RAM?

Brian_109

Commendable
Apr 12, 2016
1
0
1,510
Hello all,

I currently use a Lenovo ThinkPad Edge E540 machine with an intel i7 CPU and 8GB DDR3 RAM. I am a computer science student so I use this machine for mostly programming purposes and surfing the web. In a recent course we had to use a virtual machine and my professor and I noticed that when the virtual machine was running, my computer ran very slow. I will note that at this point, my machine only had 4GB RAM (I later upgraded to 8 to solve the problem). We concluded that it was a lack of RAM that was causing it to run so slow, hence I upgraded. But it still uses a ton of RAM (way too much in my opinion) and will run slow from time to time. If I have close to no programs running, for example, it will be using over 4GB RAM and I don't even know what for. It was using half the RAM while doing nothing when I only had 4GB, and now it's still using half and I upgraded. Can anyone tell me what the problem could be?

Thanks!
 
Solution


You're running a virtual machine, that's why.

Memory allocated to a virtual machine cannot be overcommitted like CPUs can. That is, memory allocated to all virtual machines must still fit within the host operating system's total virtual memory pool. Each virtual machine can have its own swap/page file to increase this amount further.

Some Virtual Machine software products such as VMWare Workstation allow the memory allocated to VMs to be marked as unswappable so that it will always sit in memory. Guest memory that is resident (not swapped to a guest page file) will always be resident on the host as well; alternatively, some guest memory may be swapped on the host to free up more resources for the host. In this case, guest memory that is resident in the guest may in fact be swapped on the host.

Consider the following example. You have 4GiB of memory and a 4GiB page file for a total host virtual commit limit of 8GiB. You create a virtual machine and allocate 2GiB to the VM; this VM is configured such that its memory is never swapped. Inside of the VM you create a 2GiB page file for a total guest virtual commit limit of 4GiB.

On your host operating system, the existence of the VM reduces the total virtual commit to 6GiB when the VM is running. However, 2GiB is physical memory and 4GiB is the page file. The other 2GiB is inaccessible to the host because it is allocated to the VM and the host is not allowed to swap it. Of the 2GiB, around 1GiB is used by the operating system and system services. This leaves about 1GiB for host applications and 4GiB for swapping.

Allowing the VM memory to be swapped will slow down the responsiveness of the VM (especially after being idle for a bit) because portions will have to be read from the host's swap but this will greatly improve host performance. Going back to the above example, of the 2GiB dedicated to the VM, 1.5GiB may be swappable. The host's total virtual commit is still reduced to 6GiB because the guest-physical address space still needs to fit within the host-virtual address space when the VM is running but most of the guest-physical address space can be swapped. This shifts the balance on the host. 1GiB will still be used by the host operating system and system services, but only 512MiB will be used by the unswappable portion of the VM. This leaves 2.5GiB for host applications and 2.5GiB for swapping.
 
Solution