How much RAM is recommended to be assigned to a virtual machine in VirtualBox

memorysleep-wakevirtualboxvirtualization

I have installed Ubuntu in VirtualBox under OS X on a MacBook Pro.

The laptop has 16 GB RAM, and I assigned about 11 GB to Ubuntu, because I thought that most work would be done in Ubuntu anyway.

But some said that I have to give OS X sufficient RAM, to maintain Host regular operations.

Is 5 GB too little for OS X?

I noticed that when the guest Ubuntu is running, waking up of OS X from sleep can take 30 secs or so. If OS X can have more RAM, will it wake up sooner?

Best Answer

My best practice is to think about how to get the best use of your RAM and not make configuration decisions that lock down memory and instead monitor for problems on each OS and then make small adjustments.

On the Mac - open Activity monitor and watch the memory pressure. I would try to keep things in Green. If you are in the orange, that's ok, but you might want to try changing the reservations (less RAM to ubuntu guest or quit apps on either OS that take most active memory). In the red, you will be swapping and slowing down the response times.

enter image description here

So - you have 16 GB of RAM and one OS X running the hardware with Ubuntu running in Virtual Box. Virtual box makes a file or files to act as the storage for Ubuntu but OS X is handling all the actual reads/writes.

Second - both Ubuntu and OS X use virtual memory so that you could allocate 1 GB of Ram to the guest OS and it will use a swap file to make more memory as needed.

To initially monitor things, I would open terminal on both the host and guest and run something like vm_stat 5 - pay attention initially to only two numbers - the free and the swap out. Also pay attention to the memory pressure on OS X.

Over time, you can shift to logging things more slowly with vm_stat 60 / vmstat 60 or even time stamp the usage.

Since free memory is a waste on both OS X and Ubuntu - you will want to allocate all the RAM to OS X so it can cache all the file input and output for both OS X and virtual box. Allocating too much memory on ubuntu will make the OS X starved for RAM to cache the guest OS. Add memory to the guest OS when the applications you run there start to swap out to disk.

Here are some links to get started on tuning and learning: