0

Please correct me if I am wrong. I assume VirtualBox, like any other application, is swapped to disk if it uses too much memory. Is there any way to force the system to always keep all the VirtualBox processes in memory?

f.ardelian
  • 147
  • 1
  • 7
  • @mgorven: I really don't want swap at all for VirtualBox. Setting /proc/sys/vm/swappiness applies to the entire system and *still* swaps if the system is out of memory. I know I could do *swapoff -a* to avoid swapping, but that still applies to the entire system. I only want certain processes (VirtualBox). – f.ardelian Feb 13 '13 at 23:10

2 Answers2

1

Is there any way to force the system to always keep all the VirtualBox processes in memory?

There's mlock(2) which "locks part or all of the calling process's virtual address space into RAM, preventing that memory from being paged to the swap area". In case you manage it to be called from VirtualBox, it would do, yep.

poige
  • 9,171
  • 2
  • 24
  • 50
  • Except that mlock will not do anything for the guest OS should it (the guest OS) decide it needs to write pages to disk. All it will do is prevent the host from paging it out but not the guest from doing so. – hookenz Feb 13 '13 at 23:20
  • @Matt, man page doesn't have any "except"s. It locks pages in RAM and that's all. – poige Feb 13 '13 at 23:37
  • @poige: Yes, you are correct. – f.ardelian Mar 10 '13 at 17:14
0

Give your host machine sufficient RAM for both the host OS and the virtual machine and set your swappiness value low to zero.

Inside the guest VM, turn off the swapfile. That might not seem so obvious, but it's the guest OS and it's applications that are making VirtualBox use RAM and it's the guest OS that will also page to disk (or virtual disk - which is rather slow).

The key is to have sufficient RAM for both the host and the guest vm.

hookenz
  • 14,132
  • 22
  • 86
  • 142
  • Thanks, but this is not good enough. I do not want any swap at all. Setting swappiness to 0 only means the kernel will do its best to avoid swapping, but it will still swap if needed. "Sufficient RAM" is arbitrary and depends a lot on what other applications are running on the host. – f.ardelian Feb 13 '13 at 23:32