7

I've set up a virtual machine through KVM-libvirt (virt-manager) with Windows 10 on it and I'm getting an odd behavior on the host side. I'm running a 64bit Arch host with 24GB of RAM, 12 of which are allocated to it and the other 12 to the VM.

After starting up the VM and letting it sit for a while, not too long maybe an hour so, my entire host's remaining RAM gets buffered/cached. For instance, right now I get this from free -m:

              total        used        free      shared  buff/cache   available
Mem:          24064       13887         253         110        9923        9957
Swap:          4095        1313        2782

Before starting the VM I had a couple of applications running, but they didn't amount to more than 2GB or so of RAM, and nothing new has been opened since then, just some normal web browsing (writing this question actually).

Now, I've read around a lot about linux caching RAM because free RAM is wasted RAM and whatnot, but this is causing almost everything that's running on the host to get swapped. And that is a big problem for me because everything gets so slow.

As far as I can tell, RAM caching should not cause memory to be swapped. I know linux is supposed to be smarter than me about efficient memory utilization, such as how I shouldn't clear the swap and/or cache... but, having everything swapped out thus slowing down the system considerably doesn't sound smart nor efficient to me.

What could possibly be going on? Is linux caching the VM disk accesses and that's why it's always using the entire remainder of my RAM? The VM is installed in a disk image, should I try using a separate physical disk for it?

elpato
  • 145
  • 1
  • 7
  • Disabling the swap space is one fairly blunt way to stop Linux from scittering bits off to disk... – thrig Nov 06 '15 at 00:48
  • 1
    search this site for `swappiness`: http://unix.stackexchange.com/search?q=swappiness – cas Nov 06 '15 at 01:12
  • Thank you, I know about it, but I'd rather know **why** it's swapping memory rather than lowering the swappiness. My understanding is that as long as there's buffered/cached RAM it shouldn't use swap, is that correct? – elpato Nov 06 '15 at 10:58
  • As long as there's available memory, it will be used, to hold in flight data, and avoid too much disk activity. – dyasny Nov 06 '15 at 17:26
  • Then, is there any way to prevent it from using swap if there's cached RAM available? I don't mean lowering the swappiness because I'm perfectly fine with linux using swap when it's run out of memory, but not when there's clearly plenty available somewhere else... – elpato Nov 06 '15 at 22:15
  • “As far as I can tell, RAM caching should not cause memory to be swapped”. That's completely bogus. Of course RAM caching of often-used files should cause rarely-used non-file-backed memory to go to swap! If it wasn't swapping, it would spend more time reading and writing files. – Gilles 'SO- stop being evil' Nov 06 '15 at 22:44
  • Well, is there any way to configure swap vs caching usage then? Because I'd rather have a slower VM (because of slower disk accesses) than having the entire host slow down to a crawl because of getting everything swapped out. – elpato Nov 08 '15 at 19:15
  • Setting lower priority of the VM process might help a bit. – peterph Jul 19 '16 at 23:16
  • what is the swappiness value set on your system? you can check by doing ```cat /proc/sys/vm/swappiness ``` – Heysus Escobar Apr 20 '21 at 16:52
  • Putting the disk image onto a device of its own will help. – Nils Jan 05 '22 at 22:06

0 Answers0