I'm using latest ubuntu quantal and start a kvm guest which should have 2048 MB of memory. Now after a few hours I can see that the kvm process of this guest is around 2700 MB, so 700 MB more than the guest should be able to consume. I mean a small overhead like 1% would be ok, but not 30%?!
root 8631 74.0 22.2 4767484 2752336 ? Sl Nov07 512:58 kvm -cpu kvm64 -smp sockets=1,cores=2 -cpu kvm64 -m 2048 -device virtio-blk-pci,drive=drive-virtio0,id=virtio0,bus=pci.0,addr=0xa,bootindex=100 -drive file=rbd:data/vm-disk-1,if=none,id=drive-virtio0,cache=writeback,aio=native -device virtio-net-pci,netdev=net0,bus=pci.0,addr=0x12,id=net0,mac=02:7a:86:e6:1a:6c,bootindex=200 -netdev type=tap,id=net0,vhost=on -usbdevice tablet -nodefaults -enable-kvm -daemonize -boot menu=on -vga cirrus
root 8694 0.0 0.0 0 0 ? S Nov07 0:00 [kvm-pit/8631]
How is this possible and how to prevent it?
You could use the virtio balloon device to try and return memory to the system but this only helps if the guest OS is not using all of its memory
KVM does need some memory for itself to run, but I believe a lot of this gets swapped out after a while
Also, if you end up running lots of similar VMs make sure you have linux same page merging enabled. This will allow memory from similar VMs to be shared; takes more CPU usage up, but is worth it with lots of VMs. I think this is on now by default in ubuntu
One possible problem can be that you use cache=writeback on your drive. that can eat some of your memory apart from the memory used by the guest.
Haven't had time to verify if this is the case, but it's a guess.