On Mon, Apr 04, 2011 at 04:18:00PM -0600, Alberto Trevi?o wrote: > On Monday, April 04, 2011 3:02:19 PM Jeff Anderson wrote: > > Hello, > > > > This question is frequently posed by those new to Linux: "Where has all > > my ram gone?!" > > > > The answer is disk caching! > > > > I'd like to do some testing where I'll be firing up about 7 virtual > > machines on my workstation. I'm using qemu+kvm, which does a good job > > about not grabbing ram until it is used. That way, I can fire up 7 VMs, > > each allowed to use up to 512 MB of ram. I'm still below my actual > > physical ram capacity of 4GB, but I'd like to still have use of any ram > > that I can on the host. As long as my VMs don't allocate any memory, I > > should be fine. The disk caching feature of Linux will guarantee that > > over time, with use, each VM will eventually make full use of the 512MB > > of ram. > > The idea of virtualization is to give your VMs as much memory as you would > like them to have. If your virtual server only needs about 100mb to run, > then you give the VM 128 MB of ram, not 512. Otherwise, as you have > mentioned, your host OS is going to eat up 512 MB one way or another. > > > If I'm overlooking another feature of qemu-kvm that'd make my life > > easier, I'd love to know about it. I do believe that since each VM is > > running the same version of Linux, that kvm can do some shared memory > > magic, but I don't know if I have to explicitly request that feature. > > The proper solution to your problem is the Memory Balloon driver. It is a > fake driver that sits in your VM which, under memory crunch from the host, > will begin to consume memory in your VM to give it back to the host. This > sounds kind of weird, but it does exactly what you want. Let's say your VM > has 512 MB of memory, but only using 100 MB for applications. The balloon > driver, when signaled by the host, will begin to use up memory. Let's say it > grows to 380 MB. In your VM, your memory usage will be 100 MB for system and > apps, 380 MB for the balloon, with the remaining 32 MB for cache (ignore > swap for now). But, what your hosts sees is a VM with 132 MB of memory being > used. Tada! > > The "shared memory magic" is called KSM which will merge similar pages > together when using the same version of the OS for more than one VM. Let's > say, in theory, you have two VMs that were created from the same template. > Everything is the same, except for the configuration. Let's say each VM uses > 100MB at startup. KSM will begin to look for identical pages and merge them > so that instead of using 200 MB for 2 VMs, you only use 120 MB for both: 80 > MB in common plus 20 MB of unique pages in each VM (80 + 2 * 20). If you > fire up another VM just like the other two, your memory usage may only go up > to 140 MB (80 + 3 * 20). This is all in theory of course, and your mileage > will vary. (The same with the balloon driver). > > I hope this helps.
Thanks for the clarification! I'd read about the existence of the ballooning,
but I didn't really understand what it did or how it worked. qemu-kvm doesn't
seem to have a method to automatically handle ballooning, but it should be
fairly easy to script since I'm running the qemu monitory on a unix socket.
I'd say this is much cleaner than my crazy "disable disk cache" idea.
I also figured out how to enable KSM in my running kernel (for kernels above
2.6.32):
echo 1 > /sys/kernel/mm/ksm/run
Thanks!
Jeff Anderson
pgphLdgsiWAiG.pgp
Description: PGP signature
-------------------- BYU Unix Users Group http://uug.byu.edu/ The opinions expressed in this message are the responsibility of their author. They are not endorsed by BYU, the BYU CS Department or BYU-UUG. ___________________________________________________________________ List Info (unsubscribe here): http://uug.byu.edu/mailman/listinfo/uug-list
